diff --git a/engine/src/networking/com/jme3/network/HostedConnection.java b/engine/src/networking/com/jme3/network/HostedConnection.java index e0daec48a..d8d3b40be 100644 --- a/engine/src/networking/com/jme3/network/HostedConnection.java +++ b/engine/src/networking/com/jme3/network/HostedConnection.java @@ -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 getAttribute( String name ); + + /** + * Returns a read-only set of attribute names currently stored + * for this client session. + */ + public Set attributeNames(); } diff --git a/engine/src/networking/com/jme3/network/base/DefaultServer.java b/engine/src/networking/com/jme3/network/base/DefaultServer.java index e5cc01665..0d05fb93c 100644 --- a/engine/src/networking/com/jme3/network/base/DefaultServer.java +++ b/engine/src/networking/com/jme3/network/base/DefaultServer.java @@ -328,7 +328,9 @@ public class DefaultServer implements Server { private long id; private Endpoint reliable; - private Endpoint fast; + private Endpoint fast; + + private Map sessionData = new ConcurrentHashMap(); 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 getAttribute( String name ) + { + return (T)sessionData.get(name); + } + + public Set attributeNames() + { + return Collections.unmodifiableSet(sessionData.keySet()); + } } protected class Redispatch implements MessageListener diff --git a/engine/src/networking/com/jme3/network/package.html b/engine/src/networking/com/jme3/network/package.html index 4c01ab769..ffb0138cf 100644 --- a/engine/src/networking/com/jme3/network/package.html +++ b/engine/src/networking/com/jme3/network/package.html @@ -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. -