xmlBlaster 2.2.0 API

org.xmlBlaster.engine.cluster
Class ClusterManager

java.lang.Object
  extended by org.xmlBlaster.engine.cluster.ClusterManager
All Implemented Interfaces:
java.util.EventListener, ClusterManagerMBean, I_RunlevelListener, I_AdminPlugin, I_AdminUsage, I_Plugin

public final class ClusterManager
extends java.lang.Object
implements I_RunlevelListener, I_Plugin, ClusterManagerMBean

The manager instance for a cluster node.

Each xmlBlaster server instance has one instance of this class to manage its behavior in the cluster.

Note: Our own node id is available via glob.getNodeId()

See the cluster requirement for a detailed description.

Since:
0.79e
Author:
xmlBlaster@marcelruff.info

Nested Class Summary
(package private)  class ClusterManager.NodeComparator
          Sorts the cluster nodes for the clusterNodeMap First is the local node Others by node id
 
Field Summary
private  boolean allowDirectLoopback
          If sender node == destination node throw exception back (circular loop) If configured to true (behaviour befor 2008-10-09) the message is send back and there the loop is detected and error handled.
private  java.util.Map clusterNodeMap
          Map containing ClusterNode objects, the key is a 'node Id' The entries are sorted to contain the local node as first entry.
private  ClusterNode[] clusterNodesCache
           
private  ContextNode contextNode
           
private  ServerScope glob
           
private  boolean lazyConnect
          Usually connecting on demand is enough (e.g.
private  I_LoadBalancer loadBalancer
           
private  LoadBalancerPluginManager loadBalancerPluginManager
           
private static java.util.logging.Logger log
           
private  MapMsgToMasterPluginManager mapMsgToMasterPluginManager
           
private  java.lang.Object mbeanHandle
          My JMX registration
private  java.lang.String ME
           
private  ClusterNode myClusterNode
          Info about myself
private  PluginInfo pluginInfo
           
 java.lang.String pluginLoadBalancerType
           
 java.lang.String pluginLoadBalancerVersion
           
private  boolean postInitialized
           
private  SessionInfo sessionInfo
           
 
Constructor Summary
ClusterManager()
          If loaded by RunlevelManager.
ClusterManager(ServerScope glob, SessionInfo sessionInfo)
          You need to call postInit() after all drivers are loaded.
 
Method Summary
 void addClusterNode(ClusterNode clusterNode)
          Add a new node info object or overwrite an existing one.
 java.lang.String addClusterNode(java.lang.String xml)
           
 EraseReturnQos[] forwardErase(SessionInfo publisherSession, QueryKeyData xmlKey, EraseQosServer eraseQos)
           
 MsgUnit[] forwardGet(SessionInfo publisherSession, QueryKeyData xmlKey, GetQosServer getQos)
           
 PublishReturnQos forwardPtpPublish(SessionInfo publisherSession, MsgUnit msgUnit, Destination destination)
           
 PublishRetQosWrapper forwardPublish(SessionInfo publisherSession, MsgUnit msgUnit)
           
 SubscribeReturnQos forwardSubscribe(SessionInfo publisherSession, QueryKeyData xmlKey, SubscribeQosServer subscribeQos)
           
 UnSubscribeReturnQos[] forwardUnSubscribe(SessionInfo publisherSession, QueryKeyData xmlKey, UnSubscribeQosServer unSubscribeQos)
           
 ClusterNode getClusterNode(NodeId nodeId)
          Access the informations belonging to a node id
 ClusterNode getClusterNode(java.lang.String id)
          Access the informations belonging to a node id
 ClusterNode getClusterNodeIntermediate(NodeId nodeId)
          If a destination node is not known, we can try to use another node for hopping, probably this node knows how to route further
 ClusterNode[] getClusterNodes()
          Return array containing all known cluster nodes.
 I_XmlBlasterAccess getConnection(NodeId nodeId)
           
 NodeMasterInfo getConnection(SessionInfo publisherSession, MsgUnit msgUnit)
           
 NodeMasterInfo getConnection(SessionInfo publisherSession, MsgUnit msgUnit, Destination destination)
          Get connection to the master node (or a node at a closer stratum to the master).
 ContextNode getContextNode()
           
 java.lang.String getId()
          Access the unique cluster node id (as a String).
 MapMsgToMasterPluginManager getMapMsgToMasterPluginManager()
          The plugin loader instance to map messages to their master node.
 ClusterNode getMyClusterNode()
          Return myself
 java.lang.String getName()
          A human readable name of the listener for logging.
 NodeId getNodeId()
          Access the unique cluster node id (as NodeId object).
 java.lang.String getNodeList()
          Access a list of known cluster nodes e.g.
 java.lang.String[] getNodes()
          Access a list of known cluster nodes e.g.
 int getNumNodes()
           
 java.lang.String getType()
          Enforced by I_Plugin
 java.lang.String getUsageUrl()
           
 java.lang.String getVersion()
          Enforced by I_Plugin
 void init(Global globUtil, PluginInfo pluginInfo)
          This method is called by the PluginManager (enforced by I_Plugin).
private  void initConnections()
          Usually the connection is established on demand (a message wants to travel to a node).
private  void initMyselfClusterNode()
          Initialize ClusterNode object, containing all informations about myself.
 boolean isLocalAddress(Address other)
          Check if supplied address would connect to our own node.
 boolean isReady()
           
 boolean isShutdown()
          Check status
 void postInit()
          To initialize ClusterNode we need the addresses from the protocol drivers.
private  void publish()
          TODO: not implemented yet You can't currently configure the cluster setup with messages, only statically on startup
 void removeClusterNode(ClusterNode clusterNode)
           
 void runlevelChange(int from, int to, boolean force)
          Invoked on run level change, see RunlevelManager.RUNLEVEL_HALTED and RunlevelManager.RUNLEVEL_RUNNING

Enforced by I_RunlevelListener

 void setUsageUrl(java.lang.String url)
           
 void shutdown()
          Shutdown the plugin, free resources.
static java.lang.String staticUsage()
          Command line usage.
private  void subscribe()
          TODO: not implemented yet You can't currently configure the cluster setup with messages, only statically on startup
 java.lang.String toXml()
          Dump state of this object into a XML ASCII string.
 java.lang.String toXml(java.lang.String extraOffset)
          Dump state of this object into a XML ASCII string.
 java.lang.String usage()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ME

private java.lang.String ME

glob

private ServerScope glob

log

private static java.util.logging.Logger log

sessionInfo

private SessionInfo sessionInfo

mapMsgToMasterPluginManager

private MapMsgToMasterPluginManager mapMsgToMasterPluginManager

loadBalancerPluginManager

private LoadBalancerPluginManager loadBalancerPluginManager

loadBalancer

private I_LoadBalancer loadBalancer

pluginLoadBalancerType

public java.lang.String pluginLoadBalancerType

pluginLoadBalancerVersion

public java.lang.String pluginLoadBalancerVersion

pluginInfo

private PluginInfo pluginInfo

contextNode

private ContextNode contextNode

mbeanHandle

private java.lang.Object mbeanHandle
My JMX registration


clusterNodeMap

private java.util.Map clusterNodeMap
Map containing ClusterNode objects, the key is a 'node Id' The entries are sorted to contain the local node as first entry.


clusterNodesCache

private ClusterNode[] clusterNodesCache

myClusterNode

private ClusterNode myClusterNode
Info about myself


postInitialized

private boolean postInitialized

lazyConnect

private boolean lazyConnect
Usually connecting on demand is enough (e.g. connecting when a message needs to be delivered).

If you want to immediately resend tail back messages on server startup we can force to establish the connections to all nodes immediately.
The I_XmlBlasterAccess checks then for tailed back messages which where not yet delivered and sends them.


allowDirectLoopback

private boolean allowDirectLoopback
If sender node == destination node throw exception back (circular loop) If configured to true (behaviour befor 2008-10-09) the message is send back and there the loop is detected and error handled.

Constructor Detail

ClusterManager

public ClusterManager()
If loaded by RunlevelManager.


ClusterManager

public ClusterManager(ServerScope glob,
                      SessionInfo sessionInfo)
You need to call postInit() after all drivers are loaded. Loaded by RequestBroker.java (hard coded)

Parameters:
sessionInfo - Internal handle to be used directly with RequestBroker NOTE: We (the cluster code) are responsible for security checks as we directly write into RequestBroker.
Method Detail

getType

public java.lang.String getType()
Enforced by I_Plugin

Specified by:
getType in interface I_AdminPlugin
Specified by:
getType in interface I_Plugin
Returns:
The configured type in xmlBlaster.properties, defaults to "SOCKET"

getVersion

public java.lang.String getVersion()
Enforced by I_Plugin

Specified by:
getVersion in interface I_AdminPlugin
Specified by:
getVersion in interface I_Plugin
Returns:
For example "1.0"

init

public void init(Global globUtil,
                 PluginInfo pluginInfo)
          throws XmlBlasterException
This method is called by the PluginManager (enforced by I_Plugin).

Specified by:
init in interface I_Plugin
Throws:
XmlBlasterException
See Also:
I_Plugin.init(org.xmlBlaster.util.Global,org.xmlBlaster.util.plugin.PluginInfo)

postInit

public void postInit()
              throws XmlBlasterException
To initialize ClusterNode we need the addresses from the protocol drivers.

Throws:
XmlBlasterException

isReady

public boolean isReady()

publish

private void publish()
TODO: not implemented yet You can't currently configure the cluster setup with messages, only statically on startup


subscribe

private void subscribe()
TODO: not implemented yet You can't currently configure the cluster setup with messages, only statically on startup


initMyselfClusterNode

private void initMyselfClusterNode()
                            throws XmlBlasterException
Initialize ClusterNode object, containing all informations about myself.

Throws:
XmlBlasterException

isLocalAddress

public final boolean isLocalAddress(Address other)
Check if supplied address would connect to our own node.


getMyClusterNode

public ClusterNode getMyClusterNode()
Return myself


getNodeId

public final NodeId getNodeId()
Access the unique cluster node id (as NodeId object).


getId

public final java.lang.String getId()
Access the unique cluster node id (as a String).

Returns:
The name of this xmlBlaster instance, e.g. "heron.mycompany.com"

getMapMsgToMasterPluginManager

public MapMsgToMasterPluginManager getMapMsgToMasterPluginManager()
The plugin loader instance to map messages to their master node.


forwardPtpPublish

public PublishReturnQos forwardPtpPublish(SessionInfo publisherSession,
                                          MsgUnit msgUnit,
                                          Destination destination)
                                   throws XmlBlasterException
Returns:
null if no forwarding is done and we are the master of this message ourself
<qos><state id='OK' info='QUEUED[bilbo]'/></qos>
if message is tailed back because cluster node is temporary not available. The message will be flushed on reconnect.
Otherwise the normal publish return value of the remote cluster node
Throws:
XmlBlasterException - and RuntimeExceptions are just forwarded to the caller
ErrorCode.USER_PTP_UNKNOWNDESTINATION if destination cluster node is not found
ErrorCode.RESOURCE_CLUSTER_NOTAVAILABLE is destination cluster node is known but down

forwardPublish

public PublishRetQosWrapper forwardPublish(SessionInfo publisherSession,
                                           MsgUnit msgUnit)
                                    throws XmlBlasterException
Returns:
null if no forwarding is done, if we are the master of this message ourself
<qos><state id='OK' info='QUEUED[bilbo]'/></qos>
if message is tailed back because cluster node is temporary not available. The message will be flushed on reconnect.
Otherwise the normal publish return value of the remote cluster node and the responsible NodeMasterInfo instance.
Throws:
XmlBlasterException - and RuntimeExceptions are just forwarded to the caller

forwardSubscribe

public SubscribeReturnQos forwardSubscribe(SessionInfo publisherSession,
                                           QueryKeyData xmlKey,
                                           SubscribeQosServer subscribeQos)
                                    throws XmlBlasterException
Returns:
null if no forwarding is done, if we are the master of this message ourself
<qos><state id='OK' info='QUEUED[bilbo]'/></qos>
if message is tailed back because cluster node is temporary not available. The message will be flushed on reconnect.
Otherwise the normal subscribe return value of the remote cluster node.
Throws:
XmlBlasterException - and RuntimeExceptions are just forwarded to the caller

forwardUnSubscribe

public UnSubscribeReturnQos[] forwardUnSubscribe(SessionInfo publisherSession,
                                                 QueryKeyData xmlKey,
                                                 UnSubscribeQosServer unSubscribeQos)
                                          throws XmlBlasterException
Returns:
null if no forwarding is done, if we are the master of this message ourself
<qos><state id='OK' info='QUEUED[bilbo]'/></qos>
if message is tailed back because cluster node is temporary not available. The message will be flushed on reconnect.
Otherwise the normal unSubscribe return value of the remote cluster node.
Throws:
XmlBlasterException - and RuntimeExceptions are just forwarded to the caller

forwardGet

public MsgUnit[] forwardGet(SessionInfo publisherSession,
                            QueryKeyData xmlKey,
                            GetQosServer getQos)
                     throws XmlBlasterException
Returns:
null if no forwarding is done, if we are the master of this message ourself
msgUnit.length==0 if message is tailed back because cluster node is temporary not available. The command will be flushed on reconnect.
Otherwise the normal get return value of the remote cluster node.
Throws:
XmlBlasterException - and RuntimeExceptions are just forwarded to the caller

forwardErase

public EraseReturnQos[] forwardErase(SessionInfo publisherSession,
                                     QueryKeyData xmlKey,
                                     EraseQosServer eraseQos)
                              throws XmlBlasterException
Returns:
null if no forwarding is done, if we are the master of this message ourself
<qos><state id='OK' info='QUEUED[bilbo]/></qos>
if message is tailed back because cluster node is temporary not available. The command will be flushed on reconnect.
Otherwise the normal erase return value of the remote cluster node.
Throws:
XmlBlasterException - and RuntimeExceptions are just forwarded to the caller

addClusterNode

public final void addClusterNode(ClusterNode clusterNode)
Add a new node info object or overwrite an existing one.

Parameters:
The - ClusterNode instance
Throws:
java.lang.IllegalArgumentException

removeClusterNode

public final void removeClusterNode(ClusterNode clusterNode)

getClusterNodes

public ClusterNode[] getClusterNodes()
Return array containing all known cluster nodes.

Returns:
ClusterNode[] which is a snapshot copy of our map, is never null

getNumNodes

public int getNumNodes()
Specified by:
getNumNodes in interface ClusterManagerMBean

getNodeList

public final java.lang.String getNodeList()
Access a list of known cluster nodes e.g. "heron,avalon,bilbo,frodo"

Specified by:
getNodeList in interface ClusterManagerMBean
Returns:
If cluster is switched off just our node

getNodes

public final java.lang.String[] getNodes()
Access a list of known cluster nodes e.g. "heron","avalon","bilbo","frodo"

Specified by:
getNodes in interface ClusterManagerMBean
Returns:
If cluster is switched off just our node

addClusterNode

public java.lang.String addClusterNode(java.lang.String xml)
Specified by:
addClusterNode in interface ClusterManagerMBean

getClusterNode

public final ClusterNode getClusterNode(NodeId nodeId)
Access the informations belonging to a node id

Returns:
The ClusterNode instance or null if unknown

getClusterNode

public final ClusterNode getClusterNode(java.lang.String id)
Access the informations belonging to a node id

Parameters:
The - cluster node id as a string
Returns:
The ClusterNode instance or null if unknown

getClusterNodeIntermediate

public final ClusterNode getClusterNodeIntermediate(NodeId nodeId)
If a destination node is not known, we can try to use another node for hopping, probably this node knows how to route further

Returns:
The best guess ClusterNode instance or null if unknown

initConnections

private void initConnections()
                      throws XmlBlasterException
Usually the connection is established on demand (a message wants to travel to a node).

Here you can force to establish connections to all known cluster nodes.

Throws:
XmlBlasterException

getConnection

public final NodeMasterInfo getConnection(SessionInfo publisherSession,
                                          MsgUnit msgUnit)
                                   throws XmlBlasterException
Throws:
XmlBlasterException

getConnection

public final NodeMasterInfo getConnection(SessionInfo publisherSession,
                                          MsgUnit msgUnit,
                                          Destination destination)
                                   throws XmlBlasterException
Get connection to the master node (or a node at a closer stratum to the master).

Parameters:
publisherSession - can be null
destination - For PtP, else null
Returns:
null if local node, otherwise access other node with nodeMasterInfo.getClusterNode().getI_XmlBlasterAccess()
Throws:
XmlBlasterException

getConnection

public final I_XmlBlasterAccess getConnection(NodeId nodeId)

shutdown

public void shutdown()
Description copied from interface: I_AdminPlugin
Shutdown the plugin, free resources.

Specified by:
shutdown in interface I_AdminPlugin
Specified by:
shutdown in interface I_Plugin

toXml

public final java.lang.String toXml()
Dump state of this object into a XML ASCII string.

Specified by:
toXml in interface ClusterManagerMBean

toXml

public final java.lang.String toXml(java.lang.String extraOffset)
Dump state of this object into a XML ASCII string.

Parameters:
extraOffset - indenting of tags for nice output

getName

public java.lang.String getName()
A human readable name of the listener for logging.

Enforced by I_RunlevelListener

Specified by:
getName in interface I_RunlevelListener

runlevelChange

public void runlevelChange(int from,
                           int to,
                           boolean force)
                    throws XmlBlasterException
Invoked on run level change, see RunlevelManager.RUNLEVEL_HALTED and RunlevelManager.RUNLEVEL_RUNNING

Enforced by I_RunlevelListener

Specified by:
runlevelChange in interface I_RunlevelListener
Parameters:
from - The current runlevel
to - The runlevel we want to switch to
force - If true force the change even if messages are lost
Throws:
XmlBlasterException

getUsageUrl

public java.lang.String getUsageUrl()
Specified by:
getUsageUrl in interface I_AdminUsage
Returns:
A link for JMX usage

setUsageUrl

public void setUsageUrl(java.lang.String url)
Specified by:
setUsageUrl in interface I_AdminUsage

usage

public java.lang.String usage()
Specified by:
usage in interface I_AdminUsage
Returns:
For JMX usage

isShutdown

public boolean isShutdown()
Description copied from interface: I_AdminPlugin
Check status

Specified by:
isShutdown in interface I_AdminPlugin
Returns:
true if down

staticUsage

public static java.lang.String staticUsage()
Command line usage.

These variables may be set in your property file as well. Don't use the "-" prefix there.

Set the verbosity when loading properties (outputs with System.out).

0=nothing, 1=info, 2=trace, configure with

 java -Dproperty.verbose 2 ...

 java org.xmlBlaster.Main -property.verbose 2
 


getContextNode

public ContextNode getContextNode()

xmlBlaster 2.2.0 API

Copyright © 1999-2014 The xmlBlaster.org contributers.