public class ClusteredServer extends DefaultServer
Server
implementation for clustering.
With this implementation, server.all(action)
have action
be
executed with every socket in every server in the cluster.
This implementation adopts the publish and subscribe model from Java Message Service to support clustering. Here, the exchanged message represents method invocation to be executed by every server in the cluster. The following methods create such messages.
Server.all()
Server.all(Action)
Server.byTag(String...)
Server.byTag(String, Action)
Server.byTag(String[], Action)
onpublish(Action)
and a message created by other
servers is expected to be passed to messageAction()
.
Therefore, what you need to do is to publish a message given through
onpublish(Action)
to every server in the cluster and
to subscribe a published message by other servers to delegate it to
messageAction()
.
Accordingly, such message must be able to be serialized and you have to pass
Action
implementing Serializable
. However, serialization of
inner classes doesn't work in some cases as expected so that always use
Sentence
instead of action if possible unless you use lambda
expressions.
Constructor and Description |
---|
ClusteredServer() |
Modifier and Type | Method and Description |
---|---|
Server |
all(Action<ServerSocket> action)
Executes the given action retrieving every socket in this server.
|
Server |
byTag(String[] names,
Action<ServerSocket> action)
Executes the given action retrieving the socket tagged with the given
tags in this server.
|
Action<Map<String,Object>> |
messageAction()
An action to receive a message published from one of nodes in the
cluster.
|
Server |
onpublish(Action<Map<String,Object>> action)
Adds an action to be called with a message to be published to every node
in the cluster.
|
all, byTag, byTag, on, onsocket, set_heartbeat, setHeartbeat
public Server all(Action<ServerSocket> action)
Server
all
in interface Server
all
in class DefaultServer
public Server byTag(String[] names, Action<ServerSocket> action)
Server
byTag
in interface Server
byTag
in class DefaultServer
public Server onpublish(Action<Map<String,Object>> action)
Copyright 2015, The Cettia Project