Class RmiClientService

All Implemented Interfaces:
ClientService, Service<ClientServiceManager>

public class RmiClientService extends AbstractClientService
A service that can be added to the client to support a simple shared objects protocol.

Objects are shared by adding them to the RmiRegistry with one of the share() methods. Shared objects must have a separate interface and implementation. The interface is what the other end of the connection will use to interact with the object and that interface class must be available on both ends of the connection. The implementing class need only be on the sharing end.

Shared objects can be accessed on the other end of the connection by using one of the RmiRegistry's getRemoteObject() methods. These can be used to lookup an object by class if it is a shared singleton or by name if it was registered with a name.

Note: This RMI implementation is not as advanced as Java's regular RMI as it won't marshall shared references, ie: you can't pass a shared objects as an argument to another shared object's method.

Author:
Paul Speed
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an RMI client service using the default object id and reliable channel.
    RmiClientService(short rmiObjectId, byte defaultChannel)
    Creates an RMI client service.
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    Looks up a remote object on the server by type and returns a local proxy to the remote object that was shared on the other end of the network connection.
    <T> T
    getRemoteObject(String name, Class<T> type)
    Looks up a remote object on the server by name and returns a local proxy to the remote object that was shared on the other end of the network connection.
    protected void
    Called during initialize() for the subclass to perform implementation specific initialization.
    <T> void
    share(byte channel, String name, T object, Class<? super T> type)
    Shares the specified object with the server and associates it with the specified name.
    <T> void
    share(byte channel, T object, Class<? super T> type)
    Shares the specified object with the server and associates it with the specified type.
    <T> void
    share(String name, T object, Class<? super T> type)
    Shares the specified object with the server and associates it with the specified name.
    <T> void
    share(T object, Class<? super T> type)
    Shares the specified object with the server and associates it with the specified type.
    void
    Default implementation does nothing.

    Methods inherited from class AbstractClientService

    getClient

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface ClientService

    initialize, stop, terminate
  • Constructor Details

    • RmiClientService

      public RmiClientService()
      Creates an RMI client service using the default object id and reliable channel.
    • RmiClientService

      public RmiClientService(short rmiObjectId, byte defaultChannel)
      Creates an RMI client service.
      Parameters:
      rmiObjectId - the shared RMI object id
      defaultChannel - the default network channel for RMI traffic
  • Method Details

    • share

      public <T> void share(T object, Class<? super T> type)
      Shares the specified object with the server and associates it with the specified type. Objects shared in this way are available in the connection-specific RMI registry on the server and are not available to other connections.
      Type Parameters:
      T - the shared object type
      Parameters:
      object - the object to share
      type - the shared interface type
    • share

      public <T> void share(byte channel, T object, Class<? super T> type)
      Shares the specified object with the server and associates it with the specified type. Objects shared in this way are available in the connection-specific RMI registry on the server and are not available to other connections. All object related communication will be done over the specified connection channel.
      Type Parameters:
      T - the shared object type
      Parameters:
      channel - the network channel to use
      object - the object to share
      type - the shared interface type
    • share

      public <T> void share(String name, T object, Class<? super T> type)
      Shares the specified object with the server and associates it with the specified name. Objects shared in this way are available in the connection-specific RMI registry on the server and are not available to other connections.
      Type Parameters:
      T - the shared object type
      Parameters:
      name - the exported object name
      object - the object to share
      type - the shared interface type
    • share

      public <T> void share(byte channel, String name, T object, Class<? super T> type)
      Shares the specified object with the server and associates it with the specified name. Objects shared in this way are available in the connection-specific RMI registry on the server and are not available to other connections. All object related communication will be done over the specified connection channel.
      Type Parameters:
      T - the shared object type
      Parameters:
      channel - the network channel to use
      name - the exported object name
      object - the object to share
      type - the shared interface type
    • getRemoteObject

      public <T> T getRemoteObject(Class<T> type)
      Looks up a remote object on the server by type and returns a local proxy to the remote object that was shared on the other end of the network connection.
      Type Parameters:
      T - the requested proxy type
      Parameters:
      type - the shared interface type
      Returns:
      the remote object proxy
    • getRemoteObject

      public <T> T getRemoteObject(String name, Class<T> type)
      Looks up a remote object on the server by name and returns a local proxy to the remote object that was shared on the other end of the network connection.
      Type Parameters:
      T - the requested proxy type
      Parameters:
      name - the exported object name
      type - the shared interface type
      Returns:
      the remote object proxy
    • onInitialize

      protected void onInitialize(ClientServiceManager s)
      Description copied from class: AbstractService
      Called during initialize() for the subclass to perform implementation specific initialization.
      Specified by:
      onInitialize in class AbstractService<ClientServiceManager>
      Parameters:
      s - the service manager initializing this service
    • start

      public void start()
      Description copied from class: AbstractService
      Default implementation does nothing. Implementations can override this to perform custom startup behavior.
      Specified by:
      start in interface ClientService
      Specified by:
      start in interface Service<ClientServiceManager>
      Overrides:
      start in class AbstractService<ClientServiceManager>