public abstract class NonRoutingActor extends Actor implements Referenceable, DispatchTarget
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 and Description |
---|
NonRoutingActor(Connection connection,
MessageDispatcher dispatcher)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
ref
connectionDied
public NonRoutingActor(Connection connection, MessageDispatcher dispatcher)
connection
- Connection associated with this actor.dispatcher
- Dispatcher to invoke message handlers based on 'op'.public void processMessage(Connection connection, Object rawMessage)
processMessage
in interface MessageHandler
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.@JSONMethod(value="msg") public void debug(Deliverer from, String msg)
recv: { to:ignored, op:"debug",
msg:STR }
send: no reply is sent
from
- The connection over which the message was received.msg
- Text to write to the server log;@JSONMethod(value="tag") public void ping(Deliverer from, OptString tag)
recv: { to:REF, op:"ping",
tag:optSTR }
send: { to:asReceived, op:"pong",
tag:asReceived }
from
- The connection over which the message was received.tag
- Optional tag string; if provided, it will be included in the
reply.@JSONMethod(value="tag") public void pong(Deliverer from, OptString tag)
recv: { to:ignored, op:"pong",
tag:optSTR }
send: there is no reply sent
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.Copyright © 2017. All rights reserved.