Class SimpleRMI


  • public final class SimpleRMI
    extends Object
    For internal use only; public as a matter of implementation. Provides a simple, stripped-down RMI mechanism. This does not have a concept of distributed garbage collection or distributed objects. Rather, all remotable objects are stateless singletons. All method input objects are mashalled via Java serialization. Method returns and exceptions are also marshalled via java serialization. Note that there is special handling for a methods returning InputStreams or OutputStreams:
    • OutputStreams: these are returned as a "live" object. That is, the client is handled back a stream to which they can write data. As the client writes bytes to the stream, data is streamed over the socket to the object that was returned from the remote service.
    • InputStreams: these are returned as a "live" object. That is, the client is handled back a stream from which they can read data. As the client requests bytes from the stream, data is requested from the object that was returned from the remote service.
    • Constructor Detail

      • SimpleRMI

        public SimpleRMI()
    • Method Detail

      • createServer

        public static GenericTCPServer createServer​(SimpleRMI.Registry registry)
        Creates a server that can host the list of services listed in the given registry.
        Parameters:
        registry - the registry
        Returns:
        a new server. the server will be started.
      • createClient

        public static <T> T createClient​(Class<T> clazz,
                                         InetSocketAddress address)
        Creates a remote client proxy to the given address.
        Type Parameters:
        T - the service interface
        Parameters:
        clazz - the service interface
        address - the address to connect to. must be the host and port of a server that contains a registered implementation of the given service interface.
        Returns:
        a remote client proxy
      • createClient

        public static <T> T createClient​(Class<T> clazz,
                                         InetSocketAddress address,
                                         NetworkConfiguration netConfig)
        Creates a remote client proxy to the given address.
        Type Parameters:
        T - the service interface
        Parameters:
        clazz - the service interface
        address - the address to connect to. must be the host and port of a server that contains a registered implementation of the given service interface.
        netConfig - the network configuration to use
        Returns:
        a remote client proxy
      • getRemoteClientAddress

        public static InetSocketAddress getRemoteClientAddress​(Object remoteClient)
        Returns the remote client address for the given proxy.
        Parameters:
        remoteClient - the remote client proxy.
        Returns:
        the remote client address for the given proxy or null if the remoteClient is not a remote proxy
      • getNetworkConfiguration

        public static NetworkConfiguration getNetworkConfiguration​(Object remoteClient)
        Returns the network configuration for the given proxy.
        Parameters:
        remoteClient - the remote client proxy.
        Returns:
        the network configuration for the given proxy or null if the client is not a remote client proxy
      • transferNetworkConfiguration

        public static <T> T transferNetworkConfiguration​(Object from,
                                                         T to)
        Returns a new remote client, obtaining a network configuration from another remote interface
        Parameters:
        from - the remote interface from which to obtain the network configuration
        to - the remote client that we want to set the network configuration on
        Returns:
        a new remote client
      • withNetworkConfiguration

        public static <T> T withNetworkConfiguration​(T remoteClient,
                                                     NetworkConfiguration socketProvider)
        Returns a new remote client, specifying the socket factory to use
        Parameters:
        remoteClient - the remote client proxy
        socketProvider - the provider to use
        Returns:
        a new remote client
      • isRemoteProxy

        public static boolean isRemoteProxy​(Object client)
        Returns whether the given client is a remote proxy handler
        Parameters:
        client - the client
        Returns:
        true if the client is a remote proxy handler;
      • createLocalClient

        public static <T> T createLocalClient​(Class<T> clazz,
                                              T target)
        Returns a local client proxy to the given service. The returned client will emulate remote by serializing/deserializing all inputs/outputs and exceptions.
        Type Parameters:
        T - the service interface
        Parameters:
        clazz - the service interface
        target - the service implementation
        Returns:
        a local client proxy
      • getLocalClientTarget

        public static Object getLocalClientTarget​(Object client)
        Returns the underlying implementation of a local client proxy
        Parameters:
        client - the local client proxy. Must be an object returned by createLocalClient(Class, Object)
        Returns:
        the underlying implementation of a local client proxy