public synchronized void close() { if( !isRunning ) { return; } // Gracefully let any connections know that the server is // going down. Without this, their connections will simply // error out. for( HostedConnection conn : server.getConnections() ) { conn.close("Server is shutting down."); } try { Thread.sleep(1000); // wait a couple beats to let the messages go out } catch( InterruptedException e ) { e.printStackTrace(); } server.close(); isRunning = false; notifyAll(); }
/** * Shares a server-wide object associated with the specified name over the specified * channel. All connections with RMI hosting started will have access to this shared * object as soon as they connect and they will all share the same instance. It is up * to the shared object to handle any multithreading that might be required. * All network communcation associated with the shared object will be done over * the specified channel. */ public <T> void shareGlobal( byte channel, String name, T object, Class<? super T> type ) { GlobalShare share = new GlobalShare(channel, object, type); GlobalShare existing = globalShares.put(name, share); if( existing != null ) { // Shouldn't need to do anything actually. } // Go through all of the children for( HostedConnection conn : getServer().getConnections() ) { RmiRegistry child = getRmiRegistry(conn); if( child == null ) { continue; } child.share(channel, name, object, type); } }
@Override public void stop() { for( HostedConnection conn : getServer().getConnections() ) { stopHostingOnConnection(conn); } }
/** * Causes this service to stop listening for new connections and * all existing connections will have stopHostingOnConnection() called * for them. */ public void stop() { server.removeConnectionListener(connectionObserver); for( HostedConnection conn : server.getConnections() ) { stopHostingOnConnection(conn); } }
/** * Must be called by the game server to send pending updates * to the relevant clients. */ public void sendUpdates() { for( HostedConnection conn : server.getConnections() ) { HostedEntityData hed = conn.getAttribute(HostedEntityData.ATTRIBUTE_NAME); if( hed == null ) { continue; } hed.sendUpdates(); } }
/** * Must be called by the game server to send pending updates * to the relevant clients. */ public void sendUpdates() { for( HostedConnection conn : getServer().getConnections() ) { HostedEntityData hed = conn.getAttribute(HostedEntityData.ATTRIBUTE_NAME); if( hed == null ) { continue; } hed.sendUpdates(); } }
public void close() { if (server != null && server.isRunning()) { // Close the client connections gracefully for (HostedConnection conn : server.getConnections()) { conn.close("Server closing!"); } server.close(); // FIXME: Really, I'm sure this is not meant to be // https://hub.jmonkeyengine.org/t/solved-for-now-serializer-locked-error-what-does-it-mean-version-jme-3-1/33671 Serializer.setReadOnly(false); } }
/** * Shares a server-wide object associated with the specified name over the specified * channel. All connections with RMI hosting started will have access to this shared * object as soon as they connect and they will all share the same instance. It is up * to the shared object to handle any multithreading that might be required. * All network communcation associated with the shared object will be done over * the specified channel. */ public <T> void shareGlobal( byte channel, String name, T object, Class<? super T> type ) { GlobalShare share = new GlobalShare(channel, object, type); GlobalShare existing = globalShares.put(name, share); if( existing != null ) { // Shouldn't need to do anything actually. } // Go through all of the children for( HostedConnection conn : getServer().getConnections() ) { RmiRegistry child = getRmiRegistry(conn); if( child == null ) { continue; } child.share(channel, name, object, type); } }