Class RpcHostedService

All Implemented Interfaces:
ConnectionListener, HostedService, Service<HostedServiceManager>

public class RpcHostedService extends AbstractHostedConnectionService
RPC service that can be added to a network Server to add RPC send/receive capabilities. For a particular HostedConnection, Remote procedure calls can be made to the associated Client and responses retrieved. Any remote procedure calls that the Client performs for this connection will be received by this service and delegated to the appropriate RpcHandlers. Note: it can be dangerous for a server to perform synchronous RPC calls to a client but especially so if not done as part of the response to some other message. ie: iterating over all or some HostedConnections to perform synchronous RPC calls will be slow and potentially block the server's threads in ways that can cause deadlocks or odd contention.
  • Constructor Details

    • RpcHostedService

      public RpcHostedService()
      Creates a new RPC host service that can be registered with the Network server and will automatically 'host' RPC services and each new network connection.
    • RpcHostedService

      public RpcHostedService(boolean autoHost)
      Creates a new RPC host service that can be registered with the Network server and will optionally 'host' RPC services and each new network connection depending on the specified 'autoHost' flag.
  • Method Details

    • onInitialize

      protected void onInitialize(HostedServiceManager serviceManager)
      Used internally to set up the message delegator that will handle HostedConnection specific messages and forward them to that connection's RpcConnection.
      Specified by:
      onInitialize in class AbstractService<HostedServiceManager>
    • getRpcConnection

      public RpcConnection getRpcConnection(HostedConnection hc)
      Retrieves the RpcConnection for the specified HostedConnection if that HostedConnection has had RPC services started using startHostingOnConnection() (or via autohosting). Returns null if the connection currently doesn't have RPC hosting services attached.
    • startHostingOnConnection

      public void startHostingOnConnection(HostedConnection hc)
      Sets up RPC hosting services for the hosted connection allowing getRpcConnection() to return a valid RPC connection object. This method is called automatically for all new connections if autohost is set to true.
      Specified by:
      startHostingOnConnection in class AbstractHostedConnectionService
    • stopHostingOnConnection

      public void stopHostingOnConnection(HostedConnection hc)
      Removes any RPC hosting services associated with the specified connection. Calls to getRpcConnection() will return null for this connection. The connection's RpcConnection is also closed, releasing any waiting synchronous calls with a "Connection closing" error. This method is called automatically for all leaving connections if autohost is set to true.
      Specified by:
      stopHostingOnConnection in class AbstractHostedConnectionService
    • terminate

      public void terminate(HostedServiceManager serviceManager)
      Used internally to remove the message delegator from the server.
      Specified by:
      terminate in interface HostedService
      Specified by:
      terminate in interface Service<HostedServiceManager>
      Overrides:
      terminate in class AbstractService<HostedServiceManager>