org.elkoserver.foundation.actor
Class BasicProtocolHandler

java.lang.Object
  extended by org.elkoserver.foundation.actor.BasicProtocolHandler
All Implemented Interfaces:
DispatchTarget, Referenceable
Direct Known Subclasses:
AdminObject

public abstract class BasicProtocolHandler
extends Object
implements Referenceable, DispatchTarget

Utility message handler implementation base class that supports a basic JSON protocol for connection housekeeping. The supported protocol is common to many actors in Elko. It includes the messages 'auth', 'debug', 'disconnect', 'ping', and 'pong'. This base class provides default implementations for these messages that should be satisfactory in nearly all circumstances.


Constructor Summary
protected BasicProtocolHandler()
          Constructor.
 
Method Summary
 void auth(BasicProtocolActor from, AuthDesc auth, OptString label)
          JSON method for the 'auth' message.
 void debug(BasicProtocolActor from, String msg)
          JSON method for the 'debug' message.
 void disconnect(BasicProtocolActor from)
          JSON method for the 'disconnect' message.
 void ping(BasicProtocolActor from, OptString tag)
          JSON method for the 'ping' message.
 void pong(BasicProtocolActor from, OptString tag)
          JSON method for the 'pong' message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.elkoserver.json.Referenceable
ref
 

Constructor Detail

BasicProtocolHandler

protected BasicProtocolHandler()
Constructor.

Method Detail

auth

@JSONMethod(value={"?auth","label"})
public void auth(BasicProtocolActor from,
                                 AuthDesc auth,
                                 OptString label)
JSON method for the 'auth' message. This message requests the server to authenticate the sender, according to the type of user they want to become. There is no reply, but if authentication fails, the sender is disconnected.

recv: { to:REF, op:"auth", auth:AUTHDESC, label:optSTR }
send: no reply is sent

Parameters:
from - The connection over which the message was received.
auth - Authorization information being offered.
label - Descriptive label for this connection, for logging.

debug

@JSONMethod(value="msg")
public void debug(BasicProtocolActor from,
                                  String msg)
JSON method for the 'debug' message. This message delivers textual debugging information from the other end of the connection. The received text is written to the server log.

recv: { to:ignored, op:"debug", msg:STR }
send: no reply is sent

Parameters:
from - The connection over which the message was received.
msg - Text to write to the server log;

disconnect

@JSONMethod
public void disconnect(BasicProtocolActor from)
JSON method for the 'disconnect' message. This message requests the server to close its connection to the sender.

recv: { to:ignored, op:"disconnect" }
send: there is no reply, since the connection is closed

Parameters:
from - The connection over which the message was received.

ping

@JSONMethod(value="tag")
public void ping(BasicProtocolActor from,
                                 OptString tag)
JSON method for the 'ping' message. This message is a simple connectivity test. Responds by sending a 'pong' message back to the sender.

recv: { to:REF, op:"ping", tag:optSTR }
send: { to:asReceived, op:"pong", tag:asReceived }

Parameters:
from - The connection over which the message was received.
tag - Optional tag string; if provided, it will be included in the reply.

pong

@JSONMethod(value="tag")
public void pong(BasicProtocolActor from,
                                 OptString tag)
JSON method for the 'pong' message. This message is the reply to an earlier 'ping' message. It is simply discarded.

recv: { to:ignored, op:"pong", tag:optSTR }
send: no reply is sent

Parameters:
from - The connection over which the message was received.
tag - Optional tag string, which should echo the tag (if any) from the 'ping' message that caused this 'pong' to be sent.