/** * 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 protected void onInitialize( HostedServiceManager s ) { this.rpcService = getService(RpcHostedService.class); if( rpcService == null ) { throw new RuntimeException("RmiHostedService requires RpcHostedService"); } }
/** * Shares a server-wide object associated with the specified name. 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. */ public <T> void shareGlobal( String name, T object, Class<? super T> type ) { shareGlobal(defaultChannel, name, object, type); }
protected ChatSessionListener getCallback() { if (callback == null) { RmiRegistry rmi = rmiService.getRmiRegistry(conn); callback = rmi.getRemoteObject(ChatSessionListener.class); if (callback == null) { throw new RuntimeException("Unable to locate client callback for ChatSessionListener"); } } return callback; }
/** * Called internally when an existing connection is leaving * the server. If the current autoHost property is true then * stopHostingOnConnection(hc) is called. */ @Override public void connectionRemoved(Server server, HostedConnection hc) { if( log.isLoggable(Level.FINEST) ) { log.log(Level.FINEST, "connectionRemoved({0}, {1})", new Object[]{server, hc}); } if( autoHost ) { stopHostingOnConnection(hc); } }
/** * 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 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(); }
protected AccountSessionListener getCallback() { if (callback == null) { RmiRegistry rmi = rmiService.getRmiRegistry(conn); callback = rmi.getRemoteObject(AccountSessionListener.class); if (callback == null) { throw new RuntimeException("Unable to locate client callback for AccountSessionListener"); } } return callback; }
/** * Called internally when an existing connection is leaving * the server. If the current autoHost property is true then * stopHostingOnConnection(hc) is called. */ @Override public void connectionRemoved(Server server, HostedConnection hc) { if( log.isLoggable(Level.FINEST) ) { log.log(Level.FINEST, "connectionRemoved({0}, {1})", new Object[]{server, hc}); } if( autoHost ) { stopHostingOnConnection(hc); } }
/** * 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); } }
protected LobbySessionListener getCallback() { if (callback == null) { RmiRegistry rmi = rmiService.getRmiRegistry(conn); callback = rmi.getRemoteObject(LobbySessionListener.class); if (callback == null) { throw new RuntimeException("Unable to locate client callback for LobbySessionListener"); } } return callback; }
/** * 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); } }
/** * Shares a server-wide object associated with the specified type. 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. */ public <T> void shareGlobal( T object, Class<? super T> type ) { shareGlobal(defaultChannel, type.getName(), object, type); }
@Override protected void onInitialize( HostedServiceManager s ) { this.rpcService = getService(RpcHostedService.class); if( rpcService == null ) { throw new RuntimeException("RmiHostedService requires RpcHostedService"); } }
@Override public void startHostingOnConnection(HostedConnection conn) { logger.log(Level.FINER, "startHostingOnConnection({0})", conn); AccountSessionImpl session = new AccountSessionImpl(conn); conn.setAttribute(ATTRIBUTE_SESSION, session); // Expose the session as an RMI resource to the client RmiRegistry rmi = rmiService.getRmiRegistry(conn); rmi.share(NetworkConstants.LOBBY_CHANNEL, session, AccountSession.class); }
/** * Shares a server-wide object associated with the specified name. 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. */ public <T> void shareGlobal( String name, T object, Class<? super T> type ) { shareGlobal(defaultChannel, name, object, type); }
/** * Starts hosting the chat services on the specified connection using a * specified player name. This causes the player to 'enter' the chat room * and will then be able to send/receive messages. */ public void startHostingOnConnection(HostedConnection conn, String playerName) { logger.log(Level.FINER, "startHostingOnConnection({0})", conn); ChatSessionImpl session = new ChatSessionImpl(conn, playerName); conn.setAttribute(ATTRIBUTE_SESSION, session); // Expose the session as an RMI resource to the client RmiRegistry rmi = rmiService.getRmiRegistry(conn); rmi.share(NetworkConstants.CHAT_CHANNEL, session, ChatSession.class); players.add(session); // Send the enter event to other players for (ChatSessionImpl chatter : players) { if (chatter == session) { // Don't send our enter event to ourselves continue; } chatter.playerJoined(conn.getId(), playerName); } }
/** * Shares a server-wide object associated with the specified type. 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. */ public <T> void shareGlobal( T object, Class<? super T> type ) { shareGlobal(defaultChannel, type.getName(), object, type); }
RmiRegistry rmi = rmiService.getRmiRegistry(conn); rmi.share(NetworkConstants.LOBBY_CHANNEL, session, LobbySession.class);