/** * 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); } }
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; }
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; }
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; }
@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); }
/** * 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 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); } }
RmiRegistry rmi = rmiService.getRmiRegistry(conn); rmi.share(NetworkConstants.LOBBY_CHANNEL, session, LobbySession.class);