org.elkoserver.server.context
Class User

java.lang.Object
  extended by org.elkoserver.server.context.BasicObject
      extended by org.elkoserver.server.context.User
All Implemented Interfaces:
DefaultDispatchTarget, Deliverer, DispatchTarget, MessageRetargeter, Encodable, Referenceable

public class User
extends BasicObject
implements Deliverer

A User represents a connection to someone entered into a context from a client. It is one of the three basic object types (along with Context and Item).


Field Summary
 
Fields inherited from class org.elkoserver.server.context.BasicObject
VIS_CONTAINER, VIS_NONE, VIS_PERSONAL, VIS_PUBLIC
 
Constructor Summary
User(String name, Mod[] mods, Item[] contents, String ref, Position pos)
          Direct constructor.
 
Method Summary
 int connectionID()
          Obtain this user's connection ID.
 Context context()
          Obtain the context this user is currently contained by.
 JSONLiteral encode(EncodeControl control)
          Encode this user for transmission or persistence.
 void exitContext(String why, String whyCode, boolean reload)
          Remove this user from their context.
 void forceDisconnect()
          Force this user to actually disconnect from the server.
 boolean isContainer()
          Test if this object is a container.
 Deliverer neighbors()
          Obtain a message deliverer for sending messages to the other users in this user's context.
 void pushNewContext(String contextRef)
          Begin the sequence of events that will push this user to a different context.
 void send(JSONLiteral message)
          Send a message to this user.
 void sendObjectDescription(Deliverer to, Referenceable maker)
          Transmit a description of this user as a series of 'make' messages, such that the receiver will be able to construct a local presence of it.
 void sendUserDescription(Deliverer to, Referenceable maker, boolean you)
          Transmit a description of this user as a series of 'make' messages.
 String toString()
          Obtain a printable string representation of this user.
 User user()
          Obtain the user this object is currently associated with.
 
Methods inherited from class org.elkoserver.server.context.BasicObject
baseRef, checkpoint, checkpoint, container, contents, contextor, createItem, findActualTarget, getMod, handleMessage, holder, isClone, isEphemeral, markAsChanged, markAsDeleted, markAsEphemeral, name, noteCodependent, objectIsComplete, position, ref, sendToClones, setName, setPosition, setVisibility, visibleTo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

User

public User(String name,
            Mod[] mods,
            Item[] contents,
            String ref,
            Position pos)
Direct constructor.

Parameters:
name - The name of the user.
mods - Array of mods to attach to the user; can be null if no mods are to be attached at initial creation time.
contents - Array of inactive items that will be the initial contents of this user, or null if there are no contents now.
pos - Optional position of the user within its context.
Method Detail

connectionID

public int connectionID()
Obtain this user's connection ID.

Returns:
the ID number of the connection associated with this user.

context

public Context context()
Obtain the context this user is currently contained by.

Specified by:
context in class BasicObject
Returns:
the context the user is in.

encode

public JSONLiteral encode(EncodeControl control)
Encode this user for transmission or persistence.

Specified by:
encode in interface Encodable
Parameters:
control - Encode control determining what flavor of encoding should be done.
Returns:
a JSON literal representing this user.

exitContext

public void exitContext(String why,
                        String whyCode,
                        boolean reload)
Remove this user from their context.

Parameters:
why - Explanation string to send to this user as the last thing they see from the context.
whyCode - Machine readable tag encoding 'why'.
reload - true if the client should attempt a reload (i.e., immediately try to enter again), false if not.

forceDisconnect

public void forceDisconnect()
Force this user to actually disconnect from the server.


isContainer

public boolean isContainer()
Test if this object is a container. (Note: in this case, it is).

Overrides:
isContainer in class BasicObject
Returns:
true -- all users are containers.

neighbors

public Deliverer neighbors()
Obtain a message deliverer for sending messages to the other users in this user's context.

Returns:
a deliverer representing this user's current neighbors.

pushNewContext

public void pushNewContext(String contextRef)
Begin the sequence of events that will push this user to a different context. This will trigger a reservation request to the director and ultimately a message to the user telling them where to go and how to get in.

Parameters:
contextRef - The ref of the context to push them to.

send

public void send(JSONLiteral message)
Send a message to this user. The message will be delivered on the client connection this user is currently connected by.

Specified by:
send in interface Deliverer
Parameters:
message - The message to send.

sendObjectDescription

public void sendObjectDescription(Deliverer to,
                                  Referenceable maker)
Transmit a description of this user as a series of 'make' messages, such that the receiver will be able to construct a local presence of it.

Specified by:
sendObjectDescription in class BasicObject
Parameters:
to - Where to send the description.
maker - Maker object to address the message(s) to.

sendUserDescription

public void sendUserDescription(Deliverer to,
                                Referenceable maker,
                                boolean you)
Transmit a description of this user as a series of 'make' messages.

Parameters:
to - Where to send the description.
maker - Maker object to address message to.
you - If true, user description is being sent to the user being described.

toString

public String toString()
Obtain a printable string representation of this user.

Overrides:
toString in class Object
Returns:
a printable representation of this user.

user

public User user()
Obtain the user this object is currently associated with.

Specified by:
user in class BasicObject
Returns:
the user itself.