/** * Returns the server for this hosted service or null if * the service is not yet attached. */ protected Server getServer() { HostedServiceManager hsm = getServiceManager(); return hsm == null ? null : hsm.getServer(); }
/** * Returns the client for this client service or null if * the service is not yet attached. */ protected Client getClient() { ClientServiceManager csm = getServiceManager(); return csm == null ? null : csm.getClient(); }
/** * Called internally when a new connection has been added so that the * services can be notified. */ protected void addConnection( HostedConnection hc ) { for( Service s : getServices() ) { ((HostedService)s).connectionAdded(server, hc); } }
/** * Called internally when a connection has been removed so that the * services can be notified. */ protected void removeConnection( HostedConnection hc ) { for( Service s : getServices() ) { ((HostedService)s).connectionRemoved(server, hc); } }
/** * Adds the specified HostedService and initializes it. If the service manager * has already been started then the service will also be started. */ public void addService( HostedService s ) { super.addService(s); }
@Override public void connectionAdded(Server server, HostedConnection hc) { // Just in case super.connectionAdded(server, hc); // Send the client the registration information hc.send(SerializerRegistrationsMessage.INSTANCE); } }
/** * Removes the specified HostedService from this service manager, stopping * and terminating it as required. If this service manager is in a * started state then the service will be stopped. After removal, * the service will be terminated. */ public void removeService( HostedService s ) { super.removeService(s); }
@Override public void connectionRemoved(Server server, HostedConnection hc) { removeConnection(hc); } }
/** * Initializes this service by keeping a reference to * the service manager and calling onInitialize(). */ @Override public final void initialize( S serviceManager ) { this.serviceManager = serviceManager; onInitialize(serviceManager); }
@Override public void connectionAdded(Server server, HostedConnection hc) { addConnection(hc); }
protected void startServices() { log.fine("Starting client services."); // Let the services know we are finally started services.start(); }
/** * Retrieves the first sibling service of the specified * type. */ protected <T extends Service<S>> T getService( Class<T> type ) { return type.cast(serviceManager.getService(type)); }
/** * Called internally when a new connection is detected for * the server. If the current autoHost property is true then * startHostingOnConnection(hc) is called. */ @Override public void connectionAdded(Server server, HostedConnection hc) { if( log.isLoggable(Level.FINEST) ) { log.log(Level.FINEST, "connectionAdded({0}, {1})", new Object[]{server, hc}); } if( autoHost ) { startHostingOnConnection(hc); } }
public DefaultClient( String gameName, int version ) { this.gameName = gameName; this.version = version; this.services = new ClientServiceManager(this); addStandardServices(); }
/** * Creates a HostedServiceManager for the specified network Server. */ public HostedServiceManager( Server server ) { this.server = server; this.connectionObserver = new ConnectionObserver(); server.addConnectionListener(connectionObserver); }
/** * Adds the specified ClientService and initializes it. If the service manager * has already been started then the service will also be started. */ public void addService( ClientService s ) { super.addService(s); }
/** * Removes the specified ClientService from this service manager, stopping * and terminating it as required. If this service manager is in a * started state then the service will be stopped. After removal, * the service will be terminated. */ public void removeService( ClientService s ) { super.removeService(s); } }
/** * Adds all of the specified ClientServices and initializes them. If the service manager * has already been started then the services will also be started. * This is a convenience method that delegates to addService(), thus each * service will be initialized (and possibly started) in sequence rather * than doing them all at the end. */ public void addServices( ClientService... services ) { for( ClientService s : services ) { super.addService(s); } }
/** * Adds all of the specified HostedServices and initializes them. If the service manager * has already been started then the services will also be started. * This is a convenience method that delegates to addService(), thus each * service will be initialized (and possibly started) in sequence rather * than doing them all at the end. */ public void addServices( HostedService... services ) { for( HostedService s : services ) { super.addService(s); } }