|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.axonframework.commandhandling.distributed.jgroups.JGroupsConnector
public class JGroupsConnector
A CommandBusConnector that uses JGroups to discover and connect to other JGroupsConnectors in the network. Depending
on the configuration of the channel
that was provided, this implementation allows for a dynamic
discovery and addition of new members. When members disconnect, their portion of the processing is divided over the
remaining members.
connect(int)
). This load factor defines the number
of sections on the consistent hash ring a node will receive. The more nodes on the ring, the bigger the relative
load a member receives. Using a higher number of hashes will also result in a more evenly distribution of load over
the different members.
Constructor Summary | |
---|---|
JGroupsConnector(org.jgroups.JChannel channel,
String clusterName,
CommandBus localSegment,
Serializer serializer)
Initializes the Connector using given resources. |
|
JGroupsConnector(org.jgroups.JChannel channel,
String clusterName,
CommandBus localSegment,
Serializer serializer,
HashChangeListener hashChangeListener)
Initializes the Connector using given resources. |
Method Summary | ||
---|---|---|
boolean |
awaitJoined()
this method blocks until this member has successfully joined the other members, until the thread is interrupted, or when joining has failed. |
|
boolean |
awaitJoined(long timeout,
TimeUnit timeUnit)
this method blocks until this member has successfully joined the other members, until the thread is interrupted, when the given number of milliseconds have passed, or when joining has failed. |
|
void |
connect(int loadFactor)
Connects this member to the cluster using the given loadFactor . |
|
ConsistentHash |
getConsistentHash()
Returns the consistent hash on which current assignment of commands to nodes is being executed. |
|
Set<ConsistentHash.Member> |
getMembers()
Returns the set of members currently registered with the connector. |
|
String |
getNodeName()
Returns the name of this node in the cluster, or null if this member is not connected. |
|
void |
send(String routingKey,
CommandMessage<?> commandMessage)
Sends the given command to the node assigned to handle messages with the given
routingKey . |
|
|
send(String routingKey,
CommandMessage<?> commandMessage,
CommandCallback<R> callback)
Sends the given command to the node assigned to handle messages with the given
routingKey . |
|
|
subscribe(String commandName,
CommandHandler<? super C> handler)
Subscribe the given handler to commands of type commandType to the local segment of the
command bus. |
|
|
unsubscribe(String commandName,
CommandHandler<? super C> handler)
Unsubscribe the given handler to commands of type commandType . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public JGroupsConnector(org.jgroups.JChannel channel, String clusterName, CommandBus localSegment, Serializer serializer)
channel
is used to connect this connector to
the other members. The clusterName
is the name of the cluster the channel will be connected to. For
local dispatching of commands, the given localSegment
is used. When messages are remotely
dispatched, the given serializer
is used to serialize and deserialize the messages.
Note that Connectors on different members need to have the same channel
configuration,
clusterName
and serializer
configuration in order to successfully set up a distributed
cluster.
channel
- The channel (configured, but not connected) used to discover and connect with the other
membersclusterName
- The name of the cluster to connect tolocalSegment
- The command bus on which messages with this member as destination are dispatched onserializer
- The serialized used to serialize messages before sending them to other members.public JGroupsConnector(org.jgroups.JChannel channel, String clusterName, CommandBus localSegment, Serializer serializer, HashChangeListener hashChangeListener)
channel
is used to connect this connector to
the other members. The clusterName
is the name of the cluster the channel will be connected to. For
local dispatching of commands, the given localSegment
is used. When messages are remotely
dispatched, the given serializer
is used to serialize and deserialize the messages.
Note that Connectors on different members need to have the same channel
configuration,
clusterName
and serializer
configuration in order to successfully set up a distributed
cluster.
channel
- The channel (configured, but not connected) used to discover and connect with the other
membersclusterName
- The name of the cluster to connect tolocalSegment
- The command bus on which messages with this member as destination are dispatched onserializer
- The serialized used to serialize messages before sending them to other members.Method Detail |
---|
public void connect(int loadFactor) throws ConnectionFailedException
loadFactor
. The loadFactor
defines
the (approximate) relative load that this member will receive.
A good default value is 100, which will give this member 100 nodes on the distributed hash ring. Giving all
members (proportionally) lower values will result in a less evenly distributed hash.
loadFactor
- The load factor for this node.
ConnectionFailedException
- when an error occurs while connectingpublic boolean awaitJoined() throws InterruptedException
true
if the member successfully joined, otherwise false
.
InterruptedException
- when the thread is interrupted while joiningpublic boolean awaitJoined(long timeout, TimeUnit timeUnit) throws InterruptedException
timeout
- The amount of time to wait for the connection to completetimeUnit
- The time unit of the timeout
true
if the member successfully joined, otherwise false
.
InterruptedException
- when the thread is interrupted while joiningpublic <R> void send(String routingKey, CommandMessage<?> commandMessage, CommandCallback<R> callback) throws Exception
CommandBusConnector
command
to the node assigned to handle messages with the given
routingKey
. The sender expect a reply, and will be notified of the result in the given
callback
.
If this method throws an exception, the sender is guaranteed that the destination of the command did not receive
it. If the method returns normally, the actual implementation of the connector defines the delivery guarantees.
Implementations should always invoke the callback with an outcome.
If a member's connection was lost, and the result of the command is unclear, the CommandCallback.onFailure(Throwable)
method is invoked with a RemoteCommandHandlingException
describing
the failed connection. A client may choose to resend a command.
Connectors route the commands based on the given routingKey
. Using the same routingKey
will result in the command being sent to the same member.
send
in interface CommandBusConnector
R
- The type of object expected as return value in the callbackroutingKey
- The key describing the routing requirements of this command. Generally, commands with the same
routingKey will be sent to the same destination.commandMessage
- The command to send to the (remote) membercallback
- The callback on which result notifications are sent
Exception
- when an error occurs before or during the sending of the messagepublic void send(String routingKey, CommandMessage<?> commandMessage) throws Exception
CommandBusConnector
command
to the node assigned to handle messages with the given
routingKey
. The sender does not expect a reply.
If this method throws an exception, the sender is guaranteed that the destination of the command did not receive
it. If the method returns normally, the actual implementation of the connector defines the delivery guarantees.
Connectors route the commands based on the given routingKey
. Using the same routingKey
will result in the command being sent to the same member. Each message must be sent to exactly one
member.
send
in interface CommandBusConnector
routingKey
- The key describing the routing requirements of this command. Generally, commands with the same
routingKey will be sent to the same destination.commandMessage
- The command to send to the (remote) member
Exception
- when an error occurs before or during the sending of the messagepublic <C> void subscribe(String commandName, CommandHandler<? super C> handler)
CommandBusConnector
handler
to commands of type commandType
to the local segment of the
command bus.
If a subscription already exists for the given type, the behavior is undefined. Implementations may throw an
Exception to refuse duplicate subscription or alternatively decide whether the existing or new
handler
gets the subscription.
subscribe
in interface CommandBusConnector
C
- The Type of commandcommandName
- The name of the command to subscribe the handler tohandler
- The handler instance that handles the given type of commandpublic <C> boolean unsubscribe(String commandName, CommandHandler<? super C> handler)
CommandBusConnector
handler
to commands of type commandType
. If the handler is not
currently assigned to that type of command, no action is taken.
unsubscribe
in interface CommandBusConnector
C
- The Type of commandcommandName
- The name of the command the handler is subscribed tohandler
- The handler instance to unsubscribe from the CommandBus
true
of this handler is successfully unsubscribed, false
of the given
handler
was not the current handler for given commandType
.public ConsistentHash getConsistentHash()
public Set<ConsistentHash.Member> getMembers()
public String getNodeName()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |