org.sandev.tools.SandBossRoot
Class SandBossRootNode

java.lang.Object
  extended byorg.sandev.tools.SandBossRoot.SandBossRootNodeDecl
      extended byorg.sandev.tools.SandBossRoot.SandBossRootNodeBase
          extended byorg.sandev.tools.SandBossRoot.SandBossRootNode
All Implemented Interfaces:
org.sandev.basics.nodecommon.Controllable, org.sandev.basics.nodecommon.Loggable, org.sandev.basics.nodecommon.Messageable, org.sandev.basics.nodecommon.SandRoot

public class SandBossRootNode
extends SandBossRootNodeBase
implements org.sandev.basics.nodecommon.SandRoot

Implementation of SandBossRootNodeDecl. The root instance is accessable through the SingletonAccessor class, which is maintained by the startup and shutdown methods.


Field Summary
protected  org.sandev.basics.nodecommon.CharSerializer charSerializer
          The CharSerializer to use when reading the Configuration from file.
protected  org.sandev.basics.sandmessages.Configuration config
          On startup, we load the configuration.
protected  java.util.HashMap dictionary
          Messageable instances keyed by instance name.
protected static java.lang.String LOGGER_NAME
           
protected  org.sandev.basics.nodecommon.NodeInstanceFactory nodeInstanceFactory
          The NodeInstanceFactory to use when instantiating nodes.
protected  org.sandev.basics.nodecommon.SingletonAccessor singletonAccessor
          Our SingletonAccessor reference.
 
Fields inherited from class org.sandev.tools.SandBossRoot.SandBossRootNodeBase
ctrlwrappers, helperNodes, LOGDEBUG, LOGERROR, LOGFATAL, logger, LOGINFO, logLevel, LOGLEVEL_DEBUG, LOGLEVEL_ERROR, LOGLEVEL_FATAL, LOGLEVEL_INFO, LOGLEVEL_WARN, LOGWARN, messager, nodeInstance, parent, sandNodeErrorMessage, sandNodeState, SANDNODESTATE_FAILED, SANDNODESTATE_FAILING, SANDNODESTATE_RESUMING, SANDNODESTATE_RUNNING, SANDNODESTATE_STARTING, SANDNODESTATE_STOPPED, SANDNODESTATE_STOPPING, SANDNODESTATE_SUSPENDED, SANDNODESTATE_SUSPENDING, SANDNODESTATE_UNDEFINED, sandRoot
 
Fields inherited from class org.sandev.tools.SandBossRoot.SandBossRootNodeDecl
charSerializerClassName, nodeInstanceFactoryClassName, propertiesPath
 
Fields inherited from interface org.sandev.basics.nodecommon.Controllable
OPERATION_FAIL, OPERATION_RESUME, OPERATION_SHUTDOWN, OPERATION_STARTUP, OPERATION_STR_FAIL, OPERATION_STR_RESUME, OPERATION_STR_SHUTDOWN, OPERATION_STR_STARTUP, OPERATION_STR_SUSPEND, OPERATION_STR_UNDEFINED, OPERATION_STRINGS, OPERATION_SUSPEND, OPERATION_UNDEFINED, SHUTDOWN_ERROR_RESTART_GLOBAL, SHUTDOWN_ERROR_RESTART_LOCAL, SHUTDOWN_ERROR_TERMINATE, SHUTDOWN_NORMAL, STATE_FAILED, STATE_FAILING, STATE_RESUMING, STATE_RUNNING, STATE_STARTING, STATE_STOPPED, STATE_STOPPING, STATE_STR_FAILED, STATE_STR_FAILING, STATE_STR_RESUMING, STATE_STR_RUNNING, STATE_STR_STARTING, STATE_STR_STOPPED, STATE_STR_STOPPING, STATE_STR_SUSPENDED, STATE_STR_SUSPENDING, STATE_STR_UNDEFINED, STATE_STRINGS, STATE_SUSPENDED, STATE_SUSPENDING, STATE_UNDEFINED
 
Constructor Summary
SandBossRootNode()
          The default ctor initializes the basics for this node, since it doesn't get the benefit of the work done by initNode.
 
Method Summary
protected  org.sandev.basics.nodecommon.Messageable findNodeForName(java.lang.String key, org.sandev.basics.nodecommon.Controllable[] nodes)
          Walk the tree of nodes and return the one with the specified name.
 org.sandev.basics.nodecommon.CharSerializer getCharSerializer()
          accessor for charSerializer
 org.sandev.basics.sandmessages.Configuration getConfiguration()
          accessor for config
protected  java.util.Map getDictionary()
           
protected  org.sandev.basics.structs.NodeInstance[] getLocalNodes(org.sandev.basics.sandmessages.Configuration conf)
          Given a Configuration, return an array of those nodes which are to run on this server.
protected  org.sandev.basics.nodecommon.Logger getLoggerForNode(org.sandev.basics.structs.NodeInstance decl)
          Return a new Logger for use by the node instance corresponding to the declaration.
protected  org.sandev.basics.nodecommon.Logger getLoggerForNode(java.lang.String loggerName)
          Return a new Logger with the given name.
protected  org.sandev.basics.nodecommon.Messager getMessagerForNode(org.sandev.basics.nodecommon.Messageable node, org.sandev.basics.structs.NodeInstance decl)
          Return a new Messager for use by the node instance corresponding to the declaration.
 org.sandev.basics.nodecommon.Messageable getNode(java.lang.String instanceName)
          Using the dictionary and the node tree, find the Messageable corresponding to the instance name specified.
 org.sandev.basics.nodecommon.NodeInstanceFactory getNodeInstanceFactory()
          accessor for nodeInstanceFactory
 java.lang.String getNodeInstanceName()
          Override of standard generated method.
 java.lang.String getPropertiesPath()
          Initializing accessor for propertiesPath.
 org.sandev.basics.nodecommon.SingletonAccessor getRootSingletonAccessor()
           
 java.lang.String getServername()
          Override of standard generated method.
 org.sandev.basics.nodecommon.SingletonAccessor getSingletonAccessor()
          accessor for singletonAccessor
protected  void initNode(java.lang.Object node, org.sandev.basics.structs.NodeInstance decl)
          Initialize a node with the basics it needs.
protected  void initNodeInstanceFactory()
          Initialize our NodeInstanceFactory reference.
protected  void loadConfiguration()
          Load the configuration from file
protected  void onShutdown()
          Clean up what we created.
 void setCharSerializer(org.sandev.basics.nodecommon.CharSerializer val)
          mutator for charSerializer
 void setConfiguration(org.sandev.basics.sandmessages.Configuration config)
          mutator for config
 void setNodeInstanceFactory(org.sandev.basics.nodecommon.NodeInstanceFactory val)
          mutator for nodeInstanceFactory
 void setSingletonAccessor(org.sandev.basics.nodecommon.SingletonAccessor val)
          mutator for singletonAccessor
protected  void setupServices(org.sandev.basics.nodecommon.Controllable parent, org.sandev.basics.structs.NodeInstance[] nodes)
          Walk the node declaration tree creating the nodes and their corresponding control services.
protected  void signalRemoteShutdown(int code)
          Signal the other servers in this configuration that they need to perform a systemwide shutdown with the specified code.
 void startup()
          On startup, we load the configuration, and initialize the top level nodes as our helper nodes.
 void systemwideShutdown(int code)
          Override to handle the global signalling.
 
Methods inherited from class org.sandev.tools.SandBossRoot.SandBossRootNodeBase
addWrapper, deliver, fieldHasFlag, getCharSerializerClassName, getCharSerializerClassNameDefaultValue, getCharSerializerClassNameFieldPrintValue, getCharSerializerClassNameFlag, getCharSerializerClassNameInvalidValue, getCharSerializerClassNameLengthMax, getCharSerializerClassNameLengthNorm, getCharSerializerClassNameMetatype, getCharSerializerClassNamePrintValue, getCharSerializerClassNameRange, getCharSerializerClassNameValidityCheck, getHelperNodes, getIDCache, getLogger, getLoggerDefaultValue, getLoggerFieldPrintValue, getLoggerFlag, getLoggerInvalidValue, getLoggerMetatype, getLoggerPrintValue, getLoggerRange, getLoggerValidityCheck, getLogLevel, getLogLevelActualVals, getLogLevelDefaultValue, getLogLevelEnumSummary, getLogLevelFieldPrintValue, getLogLevelFlag, getLogLevelInvalidValue, getLogLevelKeyVals, getLogLevelMetatype, getLogLevelPrintVals, getLogLevelPrintValue, getLogLevelRange, getLogLevelValidityCheck, getMessager, getMessagerDefaultValue, getMessagerFieldPrintValue, getMessagerFlag, getMessagerInvalidValue, getMessagerMetatype, getMessagerPrintValue, getMessagerRange, getMessagerValidityCheck, getNodeInstance, getNodeInstanceDefaultValue, getNodeInstanceFactoryClassName, getNodeInstanceFactoryClassNameDefaultValue, getNodeInstanceFactoryClassNameFieldPrintValue, getNodeInstanceFactoryClassNameFlag, getNodeInstanceFactoryClassNameInvalidValue, getNodeInstanceFactoryClassNameLengthMax, getNodeInstanceFactoryClassNameLengthNorm, getNodeInstanceFactoryClassNameMetatype, getNodeInstanceFactoryClassNamePrintValue, getNodeInstanceFactoryClassNameRange, getNodeInstanceFactoryClassNameValidityCheck, getNodeInstanceFieldPrintValue, getNodeInstanceFlag, getNodeInstanceInvalidValue, getNodeInstanceMetatype, getNodeInstancePrintValue, getNodeInstanceRange, getNodeInstanceValidityCheck, getParent, getPropertiesPathDefaultValue, getPropertiesPathFieldPrintValue, getPropertiesPathFlag, getPropertiesPathInvalidValue, getPropertiesPathLengthMax, getPropertiesPathLengthNorm, getPropertiesPathMetatype, getPropertiesPathPrintValue, getPropertiesPathRange, getPropertiesPathValidityCheck, getSandNodeErrorMessage, getSandNodeErrorMessageDefaultValue, getSandNodeErrorMessageFieldPrintValue, getSandNodeErrorMessageFlag, getSandNodeErrorMessageInvalidValue, getSandNodeErrorMessageLengthMax, getSandNodeErrorMessageLengthNorm, getSandNodeErrorMessageMetatype, getSandNodeErrorMessagePrintValue, getSandNodeErrorMessageRange, getSandNodeErrorMessageValidityCheck, getSandNodeState, getSandNodeStateActualVals, getSandNodeStateDefaultValue, getSandNodeStateEnumSummary, getSandNodeStateFieldPrintValue, getSandNodeStateFlag, getSandNodeStateInvalidValue, getSandNodeStateKeyVals, getSandNodeStateMetatype, getSandNodeStatePrintVals, getSandNodeStatePrintValue, getSandNodeStateRange, getSandNodeStateValidityCheck, getSandRoot, init, log, log, logLevelActual2Print, logLevelLabelToValue, logLevelPrint2Actual, logLevelPrint2Key, logLevelValueToLabel, notifyStateChange, onFailure, onRestart, onResume, onStartup, onSuspend, receive, restart, resume, sandNodeStateActual2Print, sandNodeStateLabelToValue, sandNodeStatePrint2Actual, sandNodeStatePrint2Key, sandNodeStateValueToLabel, setCharSerializerClassName, setCharSerializerClassName, setHelperNodes, setLogger, setLogger, setLogLevel, setMessager, setMessager, setNodeInstance, setNodeInstance, setNodeInstanceFactoryClassName, setNodeInstanceFactoryClassName, setParent, setPropertiesPath, setPropertiesPath, setSandNodeErrorMessage, setSandNodeErrorMessage, setSandNodeState, setSandRoot, setupSecureReceive, setupSubscriptions, shutdown, suspend, validTransition
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGER_NAME

protected static final java.lang.String LOGGER_NAME
See Also:
Constant Field Values

singletonAccessor

protected org.sandev.basics.nodecommon.SingletonAccessor singletonAccessor
Our SingletonAccessor reference. We initialize this at startup to provide general access to this root instance from UI adaptor technologies that are started independently.


charSerializer

protected org.sandev.basics.nodecommon.CharSerializer charSerializer
The CharSerializer to use when reading the Configuration from file. This must be set before the node is started.


nodeInstanceFactory

protected org.sandev.basics.nodecommon.NodeInstanceFactory nodeInstanceFactory
The NodeInstanceFactory to use when instantiating nodes. This is initialized on startup.


config

protected org.sandev.basics.sandmessages.Configuration config
On startup, we load the configuration. We keep a copy around for use by things like the DataManager, or for other nodes that may want to check it for consistency on startup.


dictionary

protected java.util.HashMap dictionary
Messageable instances keyed by instance name.

Constructor Detail

SandBossRootNode

public SandBossRootNode()
The default ctor initializes the basics for this node, since it doesn't get the benefit of the work done by initNode.

Method Detail

getSingletonAccessor

public org.sandev.basics.nodecommon.SingletonAccessor getSingletonAccessor()
accessor for singletonAccessor


setSingletonAccessor

public void setSingletonAccessor(org.sandev.basics.nodecommon.SingletonAccessor val)
mutator for singletonAccessor


getRootSingletonAccessor

public org.sandev.basics.nodecommon.SingletonAccessor getRootSingletonAccessor()
Specified by:
getRootSingletonAccessor in interface org.sandev.basics.nodecommon.SandRoot

getCharSerializer

public org.sandev.basics.nodecommon.CharSerializer getCharSerializer()
accessor for charSerializer

Specified by:
getCharSerializer in interface org.sandev.basics.nodecommon.SandRoot

setCharSerializer

public void setCharSerializer(org.sandev.basics.nodecommon.CharSerializer val)
mutator for charSerializer

Specified by:
setCharSerializer in interface org.sandev.basics.nodecommon.SandRoot

getNodeInstanceFactory

public org.sandev.basics.nodecommon.NodeInstanceFactory getNodeInstanceFactory()
accessor for nodeInstanceFactory


setNodeInstanceFactory

public void setNodeInstanceFactory(org.sandev.basics.nodecommon.NodeInstanceFactory val)
mutator for nodeInstanceFactory


getConfiguration

public org.sandev.basics.sandmessages.Configuration getConfiguration()
accessor for config

Specified by:
getConfiguration in interface org.sandev.basics.nodecommon.SandRoot

setConfiguration

public void setConfiguration(org.sandev.basics.sandmessages.Configuration config)
mutator for config


getDictionary

protected java.util.Map getDictionary()

startup

public void startup()
             throws org.sandev.basics.nodecommon.ControlException
On startup, we load the configuration, and initialize the top level nodes as our helper nodes. The SingletonAccessor reference must be set before making this call since we initialize it here.

Specified by:
startup in interface org.sandev.basics.nodecommon.Controllable
Overrides:
startup in class SandBossRootNodeBase
Throws:
org.sandev.basics.nodecommon.ControlException

onShutdown

protected void onShutdown()
                   throws org.sandev.basics.structs.SandException
Clean up what we created. Remove singleton access.

Overrides:
onShutdown in class SandBossRootNodeBase
Throws:
org.sandev.basics.structs.SandException

systemwideShutdown

public void systemwideShutdown(int code)
                        throws org.sandev.basics.nodecommon.ControlException
Override to handle the global signalling. The local nodes are handled directly via their Controllable interface since they are all on this local VM. We then signal across as needed.

Specified by:
systemwideShutdown in interface org.sandev.basics.nodecommon.Controllable
Overrides:
systemwideShutdown in class SandBossRootNodeBase
Throws:
org.sandev.basics.nodecommon.ControlException

getNodeInstanceName

public java.lang.String getNodeInstanceName()
Override of standard generated method. The root does not have an associated node instance declaration, but we need to return something for the control panel to display so we just return "SandRoot".

Overrides:
getNodeInstanceName in class SandBossRootNodeBase

getServername

public java.lang.String getServername()
Override of standard generated method. The root does not have an associated node instance declaration, but we need to return something for the control panel to display, so we just return "undefined".

Overrides:
getServername in class SandBossRootNodeBase

getNode

public org.sandev.basics.nodecommon.Messageable getNode(java.lang.String instanceName)
Using the dictionary and the node tree, find the Messageable corresponding to the instance name specified.

Specified by:
getNode in interface org.sandev.basics.nodecommon.SandRoot

findNodeForName

protected org.sandev.basics.nodecommon.Messageable findNodeForName(java.lang.String key,
                                                                   org.sandev.basics.nodecommon.Controllable[] nodes)
Walk the tree of nodes and return the one with the specified name. Returns null if nothing was found. This does a recursive tree traversal. The node is added to our dictionary as a side-effect, so the specified key should be interned.


getPropertiesPath

public java.lang.String getPropertiesPath()
Initializing accessor for propertiesPath. Overrides standard accessor to return something reasonable when the propertiesPath was not initialized.

Specified by:
getPropertiesPath in interface org.sandev.basics.nodecommon.SandRoot
Overrides:
getPropertiesPath in class SandBossRootNodeBase

signalRemoteShutdown

protected void signalRemoteShutdown(int code)
                             throws org.sandev.basics.nodecommon.ControlException
Signal the other servers in this configuration that they need to perform a systemwide shutdown with the specified code.

Throws:
org.sandev.basics.nodecommon.ControlException

getLocalNodes

protected org.sandev.basics.structs.NodeInstance[] getLocalNodes(org.sandev.basics.sandmessages.Configuration conf)
Given a Configuration, return an array of those nodes which are to run on this server. Each server is responsible for loading its own nodes only.

If SAND_RUNMODE=development in our environment, then all the nodes are being run on this server regardless of what is listed in the configuration. This is a typical development setup.


loadConfiguration

protected void loadConfiguration()
Load the configuration from file


setupServices

protected void setupServices(org.sandev.basics.nodecommon.Controllable parent,
                             org.sandev.basics.structs.NodeInstance[] nodes)
Walk the node declaration tree creating the nodes and their corresponding control services. We do not start the helper nodes at this point, that will be done as part of the startup processing.


initNode

protected void initNode(java.lang.Object node,
                        org.sandev.basics.structs.NodeInstance decl)
Initialize a node with the basics it needs.


getLoggerForNode

protected org.sandev.basics.nodecommon.Logger getLoggerForNode(org.sandev.basics.structs.NodeInstance decl)
Return a new Logger for use by the node instance corresponding to the declaration. This is basically a factory method that looks up the logger to be used and returns a new instance. Since the logger class is declared by name, we have to look it up using reflection.

Yes, reflection is slow, but it makes the system very flexible and we only pay for it at startup time. We are leaving open the possibility of specifying different Loggers for specific nodes within a configuration.


getLoggerForNode

protected org.sandev.basics.nodecommon.Logger getLoggerForNode(java.lang.String loggerName)
Return a new Logger with the given name.

See Also:
getLoggerForNode(NodeInstance)

getMessagerForNode

protected org.sandev.basics.nodecommon.Messager getMessagerForNode(org.sandev.basics.nodecommon.Messageable node,
                                                                   org.sandev.basics.structs.NodeInstance decl)
Return a new Messager for use by the node instance corresponding to the declaration. This is basically a factory method that looks up the Messager to be used and returns a new instance. Since the Messager class is declared by name, we have to look it up using reflection.

Yes, reflection is slow, but it makes the system very flexible and we only pay for it at startup time. We are leaving open the possibility of specifying different Messagers for specific nodes within a configuration.


initNodeInstanceFactory

protected void initNodeInstanceFactory()
Initialize our NodeInstanceFactory reference.