/** * Exposes the specified object to the other end of the connection as * the specified interface type. The object can be looked up by type * on the other end. */ public <T> void share( T object, Class<? super T> type ) { share(defaultChannel, object, type); }
/** * Exposes the specified object to the other end of the connection as * the specified interface type and associates it with the specified name. * The object can be looked up by the associated name on the other end of * the connection. */ public <T> void share( String name, T object, Class<? super T> type ) { share(defaultChannel, name, object, type); }
/** * Exposes, through a specific connection channel, the specified object * to the other end of the connection as the specified interface type. * The object can be looked up by type on the other end. * The specified channel will be used for all network communication * specific to this object. */ public <T> void share( byte channel, T object, Class<? super T> type ) { share(channel, type.getName(), object, type); }
@Override public void start() { super.start(); // Register all of the classes that have been waiting. synchronized(pending) { for( ObjectInfo info : pending ) { rmi.share(info.channel, info.name, info.object, info.type); } pending.clear(); isStarted = true; } }
/** * Shares the specified object with the server and associates it with the * specified name. Objects shared in this way are available in the connection-specific * RMI registry on the server and are not available to other connections. * All object related communication will be done over the specified connection * channel. */ public <T> void share( byte channel, String name, T object, Class<? super T> type ) { if( !isStarted ) { synchronized(pending) { if( !isStarted ) { pending.add(new ObjectInfo(channel, name, object, type)); return; } } } // Else we can add it directly. rmi.share(channel, name, object, type); }
/** * Sets up RMI hosting services for the hosted connection allowing * getRmiRegistry() to return a valid RmiRegistry object. * This method is called automatically for all new connections if * autohost is set to true. */ public void startHostingOnConnection( HostedConnection hc ) { if( log.isLoggable(Level.FINEST) ) { log.log(Level.FINEST, "startHostingOnConnection:{0}", hc); } RmiRegistry rmi = new RmiRegistry(hc, rpcService.getRpcConnection(hc), rmiId, defaultChannel); hc.setAttribute(ATTRIBUTE_NAME, rmi); // Register any global shares for( Map.Entry<String, GlobalShare> e : globalShares.entrySet() ) { GlobalShare share = e.getValue(); rmi.share(share.channel, e.getKey(), share.object, share.type); } }
/** * 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); } }
/** * Exposes the specified object to the other end of the connection as * the specified interface type. The object can be looked up by type * on the other end. */ public <T> void share( T object, Class<? super T> type ) { share(defaultChannel, object, type); }
/** * Exposes the specified object to the other end of the connection as * the specified interface type and associates it with the specified name. * The object can be looked up by the associated name on the other end of * the connection. */ public <T> void share( String name, T object, Class<? super T> type ) { share(defaultChannel, name, object, type); }
/** * Exposes, through a specific connection channel, the specified object * to the other end of the connection as the specified interface type. * The object can be looked up by type on the other end. * The specified channel will be used for all network communication * specific to this object. */ public <T> void share( byte channel, T object, Class<? super T> type ) { share(channel, type.getName(), object, type); }
@Override public void start() { super.start(); // Register all of the classes that have been waiting. synchronized(pending) { for( ObjectInfo info : pending ) { rmi.share(info.channel, info.name, info.object, info.type); } pending.clear(); isStarted = true; } }
/** * Shares the specified object with the server and associates it with the * specified name. Objects shared in this way are available in the connection-specific * RMI registry on the server and are not available to other connections. * All object related communication will be done over the specified connection * channel. */ public <T> void share( byte channel, String name, T object, Class<? super T> type ) { if( !isStarted ) { synchronized(pending) { if( !isStarted ) { pending.add(new ObjectInfo(channel, name, object, type)); return; } } } // Else we can add it directly. rmi.share(channel, name, object, type); }
/** * Sets up RMI hosting services for the hosted connection allowing * getRmiRegistry() to return a valid RmiRegistry object. * This method is called automatically for all new connections if * autohost is set to true. */ public void startHostingOnConnection( HostedConnection hc ) { if( log.isLoggable(Level.FINEST) ) { log.log(Level.FINEST, "startHostingOnConnection:{0}", hc); } RmiRegistry rmi = new RmiRegistry(hc, rpcService.getRpcConnection(hc), rmiId, defaultChannel); hc.setAttribute(ATTRIBUTE_NAME, rmi); // Register any global shares for( Map.Entry<String, GlobalShare> e : globalShares.entrySet() ) { GlobalShare share = e.getValue(); rmi.share(share.channel, e.getKey(), share.object, share.type); } }
@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 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); } }
/** * 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); } }
rmi.share(NetworkConstants.LOBBY_CHANNEL, session, LobbySession.class);