Added server-side client-specific session attributes

for tucking player data, etc..


git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7018 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
PSp..om 14 years ago
parent 43cb19c934
commit f9976ec817
  1. 23
      engine/src/networking/com/jme3/network/HostedConnection.java
  2. 21
      engine/src/networking/com/jme3/network/base/DefaultServer.java
  3. 1
      engine/src/networking/com/jme3/network/package.html

@ -32,6 +32,7 @@
package com.jme3.network;
import java.util.Set;
/**
* This is the connection back to a client that is being
@ -51,5 +52,25 @@ public interface HostedConnection extends MessageConnection
* Closes and removes this connection from the server
* sending the optional reason to the remote client.
*/
public void close( String reason );
public void close( String reason );
/**
* Sets a session attribute specific to this connection.
*
* @return The previous session value for this key or null
* if there was no previous value.
*/
public Object setAttribute( String name, Object value );
/**
* Retrieves a previosly stored session attribute or
* null if no such attribute exists.
*/
public <T> T getAttribute( String name );
/**
* Returns a read-only set of attribute names currently stored
* for this client session.
*/
public Set<String> attributeNames();
}

@ -328,7 +328,9 @@ public class DefaultServer implements Server
{
private long id;
private Endpoint reliable;
private Endpoint fast;
private Endpoint fast;
private Map<String,Object> sessionData = new ConcurrentHashMap<String,Object>();
public Connection()
{
@ -368,7 +370,22 @@ public class DefaultServer implements Server
if( reliable != null ) {
reliable.close();
}
}
}
public Object setAttribute( String name, Object value )
{
return sessionData.put(name, value);
}
public <T> T getAttribute( String name )
{
return (T)sessionData.get(name);
}
public Set<String> attributeNames()
{
return Collections.unmodifiableSet(sessionData.keySet());
}
}
protected class Redispatch implements MessageListener<HostedConnection>

@ -6,6 +6,5 @@ SpiderMonkey networking module. The {@link com.jme3.network.Network}
class is the entry point for creating default implementations
of {@link com.jme3.network.Client} and {@link com.jme3.network.Server}
implementations.
</body>
</html>

Loading…
Cancel
Save