public class ClusteredServer extends DefaultServer
Server
implementation for clustering.
This implementation follows the publish and subscribe model from Java Message
Service (JMS) to support clustering. Here, the message represents invocation
of socket action and is created when one of selector actions is called. The
publisher should publish the message passed from
publishAction(Action)
to all nodes in cluster and the
subscriber should propagate a message sent from one of node in cluster to
messageAction()
.
An invocation of the following socket finder actions will propagate to all the server in cluster:
all(Action)
ClusteredServer#byId(Action)
ClusteredServer#byTag(Action)
server.all(action)
executes a given action with not only
all the sockets in this server but also all the sockets in all the other
servers in the cluster.
Accordingly, most of Message Oriented Middlware requires message to be
serialized and you may have to have pass Action
implementing
Serializable
on method call. See the provided link, serialization of
inner classes including local and anonymous classes, is discouraged and
doesn't work in some cases. Therefore, always use Sentence
instead of action
if possible.
Sentence
,
Note
of the Serializable InterfaceConstructor and Description |
---|
ClusteredServer() |
Modifier and Type | Method and Description |
---|---|
Server |
all(Action<Socket> action)
Executes the given action retrieving all of the socket in this server or
all of the server if it's in a clustered environment .
|
Server |
byId(String id,
Action<Socket> action)
Executes the given action retrieving the socket of the given id in this
server or all of the server if it's in a clustered environment.
|
Server |
byTag(String[] names,
Action<Socket> action)
Executes the given action retrieving the socket tagged with all of the
given names in this server or all of the server if it's in a clustered
environment.
|
Action<Map<String,Object>> |
messageAction()
This action receives a map fired from one of node in cluster and invokes
socket action in this server.
|
Server |
publishAction(Action<Map<String,Object>> action)
Attaches an action to be called with a map containing method name and
arguments of socket action when it's called.
|
all, byId, byTag, byTag, httpAction, parseEvent, parseURI, socketAction, stringifyEvent, websocketAction
public ClusteredServer()
public Server all(Action<Socket> action)
Server
all
in interface Server
all
in class DefaultServer
public Server byId(String id, Action<Socket> action)
Server
byId
in interface Server
byId
in class DefaultServer
public Server byTag(String[] names, Action<Socket> action)
Server
byTag
in interface Server
byTag
in class DefaultServer
public Server publishAction(Action<Map<String,Object>> action)
public Action<Map<String,Object>> messageAction()
Copyright 2012-2014, Donghwan Kim