org.elkoserver.server.context.mods
Class Census

java.lang.Object
  extended by org.elkoserver.server.context.Mod
      extended by org.elkoserver.server.context.mods.Census
All Implemented Interfaces:
Cloneable, DispatchTarget, Encodable, ContextMod, GeneralMod, ItemMod, UserMod

public class Census
extends Mod
implements GeneralMod

Mod to enable tracking a context's population. This mod may be attached to a context, user or item.


Constructor Summary
Census()
          JSON-driven constructor.
 
Method Summary
 void census(User from)
          Message handler for the 'census' message.
 JSONLiteral encode(EncodeControl control)
          Encode this mod for transmission or persistence.
 
Methods inherited from class org.elkoserver.server.context.Mod
attachTo, clone, context, ensureHolding, ensureInContext, ensureReachable, ensureSameContext, ensureSameUser, holder, isEphemeral, markAsChanged, markAsEphemeral, object
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Census

@JSONMethod
public Census()
JSON-driven constructor.

Method Detail

encode

public JSONLiteral encode(EncodeControl control)
Encode this mod 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 mod.

census

@JSONMethod
public void census(User from)
            throws MessageHandlerException
Message handler for the 'census' message. This message requests the current number of users in the context where this mod resides.

recv: { to:REF, op:"census" }
send: { to:REF, op:"census", occupancy:int }

Parameters:
from - The user requesting the census.
Throws:
MessageHandlerException - if 'from' is not in the same context as this mod, or if this mod is attached to a user and 'from' is not that user.