protected void addStandardServices() { log.fine("Adding standard services..."); services.addService(new ServerSerializerRegistrationsService()); }
public DefaultServer( String gameName, int version, Kernel reliable, Kernel fast ) { if( reliable == null ) throw new IllegalArgumentException( "Default server reqiures a reliable kernel instance." ); this.gameName = gameName; this.version = version; this.services = new HostedServiceManager(this); addStandardServices(); reliableAdapter = new KernelAdapter( this, reliable, dispatcher, true ); channels.add( reliableAdapter ); if( fast != null ) { fastAdapter = new KernelAdapter( this, fast, dispatcher, false ); channels.add( fastAdapter ); } }
@Override public void connectionAdded(Server server, HostedConnection hc) { addConnection(hc); }
@Override public void close() { if( !isRunning ) throw new IllegalStateException( "Server is not started." ); // First stop the services since we are about to // kill the connections they are using services.stop(); try { // Kill the adpaters, they will kill the kernels for( KernelAdapter ka : channels ) { ka.close(); } isRunning = false; // Now terminate all of the services services.terminate(); } catch( InterruptedException e ) { throw new RuntimeException( "Interrupted while closing", e ); } }
public void start() throws IOException { if (server == null) { server = Network.createServer(NetworkConstants.GAME_NAME, NetworkConstants.PROTOCOL_VERSION, port, port); } server.addChannel(port + 1); // Lobby server.addChannel(port + 2); // Chat initialize(); server.addConnectionListener(new ServerConnectionListener(this)); // Adding a delay for the connectionAdded right after the serializer registration // service gets to run let's the client get a small break in the buffer that should // generally prevent the RpcCall messages from coming too quickly and getting processed // before the SerializerRegistrationMessage has had a chance to process. // This "feature" happens with Linux almost all the time server.getServices().addService(new DelayService()); server.getServices().addServices(new RpcHostedService(), new RmiHostedService(), new AccountHostedService(name), new LobbyHostedService(), new ChatHostedService() ); // Add the SimEtheral host that will serve object sync updates to // the clients. EtherealHost ethereal = new EtherealHost(NetworkConstants.OBJECT_PROTOCOL, NetworkConstants.ZONE_GRID, NetworkConstants.ZONE_RADIUS); server.getServices().addService(ethereal); server.start(); start = System.nanoTime(); }
/** * 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(); }
/** * 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); } }
@Override public void connectionRemoved(Server server, HostedConnection hc) { removeConnection(hc); } }
@Override public void start() { if( isRunning ) throw new IllegalStateException( "Server is already started." ); // Initialize the kernels for( KernelAdapter ka : channels ) { ka.initialize(); } // Start em up for( KernelAdapter ka : channels ) { ka.start(); } isRunning = true; // Start the services services.start(); }
@Override public void close() { if( !isRunning ) throw new IllegalStateException( "Server is not started." ); // First stop the services since we are about to // kill the connections they are using services.stop(); try { // Kill the adpaters, they will kill the kernels for( KernelAdapter ka : channels ) { ka.close(); } isRunning = false; // Now terminate all of the services services.terminate(); } catch( InterruptedException e ) { throw new RuntimeException( "Interrupted while closing", e ); } }
/** * Used internally to remove the message delegator from the * server. */ @Override public void terminate(HostedServiceManager serviceManager) { Server server = serviceManager.getServer(); server.removeMessageListener(delegator, delegator.getMessageTypes()); }
/** * 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); } }
@Override public void connectionRemoved(Server server, HostedConnection hc) { removeConnection(hc); } }
@Override public void start() { if( isRunning ) throw new IllegalStateException( "Server is already started." ); // Initialize the kernels for( KernelAdapter ka : channels ) { ka.initialize(); } // Start em up for( KernelAdapter ka : channels ) { ka.start(); } isRunning = true; // Start the services services.start(); }
/** * Used internally to setup the message delegator that will * handle HostedConnection specific messages and forward them * to that connection's RpcConnection. */ @Override protected void onInitialize( HostedServiceManager serviceManager ) { Server server = serviceManager.getServer(); // A general listener for forwarding the messages // to the client-specific handler this.delegator = new SessionDataDelegator(RpcConnection.class, ATTRIBUTE_NAME, true); server.addMessageListener(delegator, delegator.getMessageTypes()); if( log.isLoggable(Level.FINEST) ) { log.log(Level.FINEST, "Registered delegator for message types:{0}", Arrays.asList(delegator.getMessageTypes())); } }
protected void addStandardServices() { log.fine("Adding standard services..."); services.addService(new ServerSerializerRegistrationsService()); }
/** * 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); } }
@Override public void connectionAdded(Server server, HostedConnection hc) { addConnection(hc); }
public DefaultServer( String gameName, int version, Kernel reliable, Kernel fast ) { if( reliable == null ) throw new IllegalArgumentException( "Default server reqiures a reliable kernel instance." ); this.gameName = gameName; this.version = version; this.services = new HostedServiceManager(this); addStandardServices(); reliableAdapter = new KernelAdapter( this, reliable, dispatcher, true ); channels.add( reliableAdapter ); if( fast != null ) { fastAdapter = new KernelAdapter( this, fast, dispatcher, false ); channels.add( fastAdapter ); } }
/** * 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(); }