Java Code Examples for com.jme3.network.HostedConnection#setAttribute()

The following examples show how to use com.jme3.network.HostedConnection#setAttribute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RmiHostedService.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 *  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.
 */
@SuppressWarnings("unchecked")
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); 
    }
}
 
Example 2
Source File: TestChatServer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void messageReceived(HostedConnection source, Message m) {
    if (m instanceof ChatMessage) {
        // Keep track of the name just in case we 
        // want to know it for some other reason later and it's
        // a good example of session data
        source.setAttribute("name", ((ChatMessage) m).getName());

        System.out.println("Broadcasting:" + m + "  reliable:" + m.isReliable());

        // Just rebroadcast... the reliable flag will stay the
        // same so if it came in on UDP it will go out on that too
        source.getServer().broadcast(m);
    } else {
        System.err.println("Received odd message:" + m);
    }
}
 
Example 3
Source File: RpcHostedService.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 *  Sets up RPC hosting services for the hosted connection allowing
 *  getRpcConnection() to return a valid RPC connection object.
 *  This method is called automatically for all new connections if
 *  autohost is set to true.
 */
@Override
public void startHostingOnConnection( HostedConnection hc ) {
    if( log.isLoggable(Level.FINEST) ) {
        log.log(Level.FINEST, "startHostingOnConnection:{0}", hc);
    }
    hc.setAttribute(ATTRIBUTE_NAME, new RpcConnection(hc));
}
 
Example 4
Source File: RpcHostedService.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 *  Removes any RPC hosting services associated with the specified
 *  connection.  Calls to getRpcConnection() will return null for
 *  this connection.  The connection's RpcConnection is also closed,
 *  releasing any waiting synchronous calls with a "Connection closing"
 *  error.
 *  This method is called automatically for all leaving connections if
 *  autohost is set to true.
 */
@Override
public void stopHostingOnConnection( HostedConnection hc ) {
    RpcConnection rpc = hc.getAttribute(ATTRIBUTE_NAME);
    if( rpc == null ) {
        return;
    }
    if( log.isLoggable(Level.FINEST) ) {
        log.log(Level.FINEST, "stopHostingOnConnection:{0}", hc);
    }
    hc.setAttribute(ATTRIBUTE_NAME, null);
    rpc.close();
}
 
Example 5
Source File: RmiHostedService.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 *  Removes any RMI hosting services associated with the specified
 *  connection.  Calls to getRmiRegistry() will return null for
 *  this connection.  
 *  This method is called automatically for all leaving connections if
 *  autohost is set to true.
 */
public void stopHostingOnConnection( HostedConnection hc ) {
    RmiRegistry rmi = hc.getAttribute(ATTRIBUTE_NAME);
    if( rmi == null ) {
        return;
    }
    if( log.isLoggable(Level.FINEST) ) {
        log.log(Level.FINEST, "stopHostingOnConnection:{0}", hc);
    }
    hc.setAttribute(ATTRIBUTE_NAME, null);
    //rpc.close();
}