org.elkoserver.foundation.actor
Class NonRoutingActor

java.lang.Object
  extended by org.elkoserver.foundation.actor.Actor
      extended by org.elkoserver.foundation.actor.NonRoutingActor
All Implemented Interfaces:
Deliverer, DispatchTarget, MessageHandler, Referenceable

public abstract class NonRoutingActor
extends Actor
implements Referenceable, DispatchTarget

An Actor that receives untargeted JSON messages over its connection.

This class is abstract, in that its implementation of the MessageHandler interface is incomplete: it implements the processMessage() method, but subclasses must implement the connectionDied() method (as well as any JSONMethod methods for whatever specific object behavior the subclass is intended for).

In contrast to RoutingActor, objects of this class disregard the message targets of messages received, blindly assuming instead that all messages received are for them. This avoids setting up a lot of expensive mechanism for a common special case, wherein a connection has a simple, static message protocol with no object addressing.

This class provides default implementations for the 'ping', 'pong', and 'debug' messages, since objects of the variety that would use this class should always support those particular messages anyway.


Constructor Summary
NonRoutingActor(Connection connection, MessageDispatcher dispatcher)
          Constructor.
 
Method Summary
 void debug(Deliverer from, String msg)
          JSON method for the 'debug' message.
 void ping(Deliverer from, OptString tag)
          JSON method for the 'ping' message.
 void pong(Deliverer from, OptString tag)
          JSON method for the 'pong' message.
 void processMessage(Connection connection, Object rawMessage)
          Process a received message by dispatching to this object directly using the dispatcher that was provided in this actor's constructor.
 
Methods inherited from class org.elkoserver.foundation.actor.Actor
close, msgAuth, msgAuth, send
 
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
 
Methods inherited from interface org.elkoserver.foundation.net.MessageHandler
connectionDied
 

Constructor Detail

NonRoutingActor

public NonRoutingActor(Connection connection,
                       MessageDispatcher dispatcher)
Constructor.

Parameters:
connection - Connection associated with this actor.
dispatcher - Dispatcher to invoke message handlers based on 'op'.
Method Detail

processMessage

public void processMessage(Connection connection,
                           Object rawMessage)
Process a received message by dispatching to this object directly using the dispatcher that was provided in this actor's constructor.

Specified by:
processMessage in interface MessageHandler
Parameters:
connection - Connection over which the message was received.
rawMessage - The message received. Normally this should be a JSONObject, but it could be a Throwable indicating a problem receiving or parsing the message.

debug

@JSONMethod(value="msg")
public void debug(Deliverer 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;

ping

@JSONMethod(value="tag")
public void ping(Deliverer from,
                                 OptString tag)
JSON method for the 'ping' message. This message is a simple connectivity test. Respond 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(Deliverer 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: there is no reply sent

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