org.resoa.node.core
Class ResoaBaseGateway

java.lang.Object
  extended by org.resoa.node.core.ResoaBaseGateway
All Implemented Interfaces:
org.resoa.grid.ResoaGateway, org.resoa.stack.Callbacks.SessionState, org.resoa.stack.StackChannelProcessor
Direct Known Subclasses:
ResoaServiceGateway

public abstract class ResoaBaseGateway
extends java.lang.Object
implements org.resoa.grid.ResoaGateway, org.resoa.stack.StackChannelProcessor, org.resoa.stack.Callbacks.SessionState

ResoaBaseGateway class implements common grid connection functionality for nodes of all types


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.resoa.grid.ResoaGateway
org.resoa.grid.ResoaGateway.ControllerGateway, org.resoa.grid.ResoaGateway.GatewayRunner
 
Field Summary
protected  int executionExceptions
           
protected  org.resoa.grid.ResoaGateway.GatewayRunner gatewayRunner
          The ResoaNode wrapper for runtime
protected  java.util.List<org.resoa.stack.config.StackProfile> initialControllers
          node friends' profiles, interpreted as potential Controllers inside the grid
protected  org.resoa.stack.config.StackProfile localProfile
          stackProfile of node itself
protected  java.util.concurrent.locks.ReentrantLock lockConnection
          synchronization object for connections
protected  java.util.concurrent.locks.ReentrantLock lockNodeState
          synchronization object for NodeState
protected  java.util.concurrent.locks.ReentrantLock lockResoaUpdate
          synchronization object for Deployment Update and Service caching
protected static org.slf4j.Logger logger
          The central node logger instance
protected  NodeDomainRelationManager<?> nodeDomains
          The manager of the grid nodes and their deployed service domains
protected  org.resoa.grid.ResoaNodeType nodeType
          The node type
protected  java.util.Vector<org.resoa.grid.Message> pendingMessages
          Cache of all message sends, run into SystemOverloadException
protected  int permissionExceptions
           
protected  java.util.HashMap<java.lang.String,java.lang.String> properties
          Maps of properties
protected  org.resoa.util.ResoaClassLoader rcl
          The ClassLoader instance
protected  int requestExceptions
           
protected  boolean running
           
protected  ResoaSecurity security
          resoaSecurity handler
protected  int sessionExceptions
           
protected  org.resoa.stack.Stack stack
          protocol stack handler
 
Fields inherited from interface org.resoa.grid.ResoaGateway
DOMAIN_PERSISTENCE, DOMAIN_TOPOLOGY, PROP_CONTROLLERDATAPATH, RESOAINFO_FILE, ResoaNodeTimeout, ROLE_CONTROLLER, ROLE_GRID, STACKCONFIG_FILE
 
Constructor Summary
protected ResoaBaseGateway()
          Constructor for Gateway without Resoa Grid Functionality
  ResoaBaseGateway(java.lang.String configPath, T domainType)
          Constructor reads config and license file and initializes internal objects and handlers
 
Method Summary
protected  void addMessageToPending(org.resoa.grid.Message msg)
          Cache a message for later sending
protected  void afterGridConnection(boolean isUpdate)
          Event after the container connects to grid nodes
protected  void beforeGridConnection(boolean isUpdate)
          Event before the container connects to grid nodes
protected abstract  void beforeNodeStop(boolean waitForPoolThreadsEnd)
          Implement service stops
 void connectToInitialController()
          Connects to resoaInfo listed Controllers protected void connectToControllers (){ // connect to all controllers, listed in ResoaInfo List controllers = nodeDomains.getControllerNodes(false); for (ResoaNodeHandle node : controllers){ connectToNode(node); } } /** connects to first available controller node (from friends list in license file)
protected  org.resoa.grid.GridSession connectToNode(ResoaNodeHandle node)
          Connect to all known nodes, where the deployment information requires connection to protected void connectToGridNodes(){ // we request nodes, we must hold connections to List connections = nodeDomains.getGridConnectionList(); for (ResoaNodeHandle node : connections) { connectToNode(node); } } /** Connects to a node, avoiding SystemOverload Exceptions
 java.lang.String getConfigurationPath()
           
 java.util.List<java.lang.String> getConnectedProfiles()
          Returns a List of connected profiles
 org.resoa.grid.GridSession getControllerSession()
          Returns a handle to a connected controller session
 java.util.List<ResoaNodeHandle> getDomainNodes(java.lang.String domain)
          Returns the grid session to nodes, serving on the same domain
 int getErrorCodeFromException(java.lang.Throwable th)
          Maps an ResoaException to a HTTPStatusCode
protected  java.util.List<ResoaNodeHandle> getGridConnectionsNodes()
          Generate a list of nodes, we need to connect to
 org.resoa.stack.config.StackProfile getLocalProfile()
          The local stack profile
 org.slf4j.Logger getLogger()
           
 ResoaNodeHandle getNodeHandle(java.lang.String profileName)
          Returns the node handle of a stack profile name
 org.resoa.topology.NodeState getNodeState()
          Returns status data of the node (monitoring data)
 org.resoa.grid.ResoaNodeType getNodeType()
           
 org.resoa.stack.Stack getStack()
          Returns ResoaStack instance
protected  org.resoa.grid.Transaction.TransactionState getTransactionState(boolean isTransactionRequest, org.resoa.grid.ResoaResponse.ResponseAction action)
          Adapts the transaction state of a message, according to desired response action
 void indicateTransactionError(org.resoa.grid.Message msg, org.resoa.grid.ResoaStackChannel channel, java.lang.String errorMsg, java.lang.Throwable th)
          Indicates an error to the requesting session, in case it was a transaction request
 boolean isAccessPoint()
          Returns true if node acts as AccesPoint (means, other can connect to).
 boolean isRunning()
          Returns true if the gateway is up and running
protected  ResoaNodeHandle onSessionInitialized(org.resoa.grid.GridSession session)
          Gets invoked on session initialized.
 void removeIdleSessions()
           
abstract  org.resoa.topology.RestSession requestRestSessionFromController(org.resoa.topology.RestSession session)
          Request RestSession handle from Controller.
 void sendPendingMessage()
          Send pending message (formerly run into SystemOverloadException)
 void sessionDisconnected(org.resoa.grid.GridSession session)
           
 void sessionInitialized(org.resoa.grid.GridSession session)
           
protected  void setConfigurationPath(java.lang.String configPath)
           
 void setGatewayRunner(org.resoa.grid.ResoaGateway.GatewayRunner runner)
           
 void stop(boolean waitForPoolThreadsEnd)
           
protected abstract  void updateMonitoring(org.resoa.topology.NodeState state)
          Update monitoring data within locked state
 org.resoa.grid.ResoaInfoState updateResoaInfo(org.resoa.topology.ResoaInfo newResoaInfo, boolean refreshClassLoader)
          Process a new arrived ResoaInfo and updates deployment information of the node
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.resoa.grid.ResoaGateway
broadcastToControllers, broadcastToDomainNodes, createRestSession, executeService, executeService, getPersistor, getRestSession, getServiceImplementation, isDeployed, performTransaction, removeRestSession, sendMessage
 
Methods inherited from interface org.resoa.stack.StackChannelProcessor
onMessage, onTransactionDelay, readChannel, writeChannel
 

Field Detail

logger

protected static org.slf4j.Logger logger
The central node logger instance


gatewayRunner

protected org.resoa.grid.ResoaGateway.GatewayRunner gatewayRunner
The ResoaNode wrapper for runtime


stack

protected org.resoa.stack.Stack stack
protocol stack handler


localProfile

protected org.resoa.stack.config.StackProfile localProfile
stackProfile of node itself


nodeType

protected org.resoa.grid.ResoaNodeType nodeType
The node type


security

protected ResoaSecurity security
resoaSecurity handler


rcl

protected org.resoa.util.ResoaClassLoader rcl
The ClassLoader instance


nodeDomains

protected NodeDomainRelationManager<?> nodeDomains
The manager of the grid nodes and their deployed service domains


initialControllers

protected java.util.List<org.resoa.stack.config.StackProfile> initialControllers
node friends' profiles, interpreted as potential Controllers inside the grid


properties

protected java.util.HashMap<java.lang.String,java.lang.String> properties
Maps of properties


pendingMessages

protected java.util.Vector<org.resoa.grid.Message> pendingMessages
Cache of all message sends, run into SystemOverloadException


lockResoaUpdate

protected java.util.concurrent.locks.ReentrantLock lockResoaUpdate
synchronization object for Deployment Update and Service caching


lockConnection

protected java.util.concurrent.locks.ReentrantLock lockConnection
synchronization object for connections


lockNodeState

protected java.util.concurrent.locks.ReentrantLock lockNodeState
synchronization object for NodeState


sessionExceptions

protected volatile int sessionExceptions

permissionExceptions

protected volatile int permissionExceptions

requestExceptions

protected volatile int requestExceptions

executionExceptions

protected volatile int executionExceptions

running

protected volatile boolean running
Constructor Detail

ResoaBaseGateway

protected ResoaBaseGateway()
Constructor for Gateway without Resoa Grid Functionality


ResoaBaseGateway

public ResoaBaseGateway(java.lang.String configPath,
                        T domainType)
                 throws org.resoa.exception.ResoaException
Constructor reads config and license file and initializes internal objects and handlers

Parameters:
configPath - path to node config directory
Throws:
org.resoa.exception.ResoaException
Method Detail

isAccessPoint

public boolean isAccessPoint()
Returns true if node acts as AccesPoint (means, other can connect to).

Returns:
true if accessPoint

setGatewayRunner

public void setGatewayRunner(org.resoa.grid.ResoaGateway.GatewayRunner runner)
Specified by:
setGatewayRunner in interface org.resoa.grid.ResoaGateway

getStack

public org.resoa.stack.Stack getStack()
Returns ResoaStack instance

Returns:
the stack

getLocalProfile

public org.resoa.stack.config.StackProfile getLocalProfile()
The local stack profile

Specified by:
getLocalProfile in interface org.resoa.grid.ResoaGateway
Returns:
the localProfile

getNodeType

public org.resoa.grid.ResoaNodeType getNodeType()
Specified by:
getNodeType in interface org.resoa.grid.ResoaGateway

getConfigurationPath

public java.lang.String getConfigurationPath()
Specified by:
getConfigurationPath in interface org.resoa.grid.ResoaGateway

setConfigurationPath

protected void setConfigurationPath(java.lang.String configPath)
Parameters:
configPath - the configurationPath to set

isRunning

public boolean isRunning()
Returns true if the gateway is up and running

Specified by:
isRunning in interface org.resoa.grid.ResoaGateway
Returns:
gate up mode
See Also:
ResoaGateway.isRunning()

removeIdleSessions

public void removeIdleSessions()
Specified by:
removeIdleSessions in interface org.resoa.grid.ResoaGateway

stop

public void stop(boolean waitForPoolThreadsEnd)
Specified by:
stop in interface org.resoa.grid.ResoaGateway

beforeNodeStop

protected abstract void beforeNodeStop(boolean waitForPoolThreadsEnd)
Implement service stops

Parameters:
waitForPoolThreadsEnd -

getConnectedProfiles

public java.util.List<java.lang.String> getConnectedProfiles()
Returns a List of connected profiles

Returns:
a List of connected profiles

connectToNode

protected org.resoa.grid.GridSession connectToNode(ResoaNodeHandle node)
Connect to all known nodes, where the deployment information requires connection to protected void connectToGridNodes(){ // we request nodes, we must hold connections to List connections = nodeDomains.getGridConnectionList(); for (ResoaNodeHandle node : connections) { connectToNode(node); } } /** Connects to a node, avoiding SystemOverload Exceptions

Parameters:
node - the remote node handle
Returns:
The new established session or null

connectToInitialController

public void connectToInitialController()
                                throws org.resoa.exception.ResoaException
Connects to resoaInfo listed Controllers protected void connectToControllers (){ // connect to all controllers, listed in ResoaInfo List controllers = nodeDomains.getControllerNodes(false); for (ResoaNodeHandle node : controllers){ connectToNode(node); } } /** connects to first available controller node (from friends list in license file)

Specified by:
connectToInitialController in interface org.resoa.grid.ResoaGateway
Throws:
org.resoa.exception.ResoaException

addMessageToPending

protected void addMessageToPending(org.resoa.grid.Message msg)
Cache a message for later sending

Parameters:
msg -

sendPendingMessage

public void sendPendingMessage()
Send pending message (formerly run into SystemOverloadException)


getNodeHandle

public ResoaNodeHandle getNodeHandle(java.lang.String profileName)
Returns the node handle of a stack profile name

Parameters:
profileName - the profile name of the node
Returns:
the node handle or null

getDomainNodes

public java.util.List<ResoaNodeHandle> getDomainNodes(java.lang.String domain)
Returns the grid session to nodes, serving on the same domain

Parameters:
domain - the service(jar) domain
Returns:
a list of stack session handles

getControllerSession

public org.resoa.grid.GridSession getControllerSession()
Returns a handle to a connected controller session

Returns:
an active controller session

sessionInitialized

public void sessionInitialized(org.resoa.grid.GridSession session)
Specified by:
sessionInitialized in interface org.resoa.stack.Callbacks.SessionState

onSessionInitialized

protected ResoaNodeHandle onSessionInitialized(org.resoa.grid.GridSession session)
Gets invoked on session initialized. It validates the remote node profile.

Parameters:
session - the session
Returns:
the ResoaNodeHandle if node is accepted, or null if the connection refused

sessionDisconnected

public void sessionDisconnected(org.resoa.grid.GridSession session)
Specified by:
sessionDisconnected in interface org.resoa.stack.Callbacks.SessionState

getGridConnectionsNodes

protected java.util.List<ResoaNodeHandle> getGridConnectionsNodes()
Generate a list of nodes, we need to connect to

Returns:
a list of nodes, we need to connect to

updateResoaInfo

public org.resoa.grid.ResoaInfoState updateResoaInfo(org.resoa.topology.ResoaInfo newResoaInfo,
                                                     boolean refreshClassLoader)
Process a new arrived ResoaInfo and updates deployment information of the node

Specified by:
updateResoaInfo in interface org.resoa.grid.ResoaGateway
Parameters:
newResoaInfo - the new ResoaInfo
refreshClassLoader - true if the resoa classloader should be refreshed

beforeGridConnection

protected void beforeGridConnection(boolean isUpdate)
Event before the container connects to grid nodes

Parameters:
isUpdate - true, if the connection is caused by an update

afterGridConnection

protected void afterGridConnection(boolean isUpdate)
Event after the container connects to grid nodes

Parameters:
isUpdate - true, if the connection is caused by an update

requestRestSessionFromController

public abstract org.resoa.topology.RestSession requestRestSessionFromController(org.resoa.topology.RestSession session)
Request RestSession handle from Controller. Implemented by ServiceGateway

Parameters:
session -
Returns:
the RestSession from Controller or null, if not existent

getTransactionState

protected org.resoa.grid.Transaction.TransactionState getTransactionState(boolean isTransactionRequest,
                                                                          org.resoa.grid.ResoaResponse.ResponseAction action)
Adapts the transaction state of a message, according to desired response action

Parameters:
isTransactionRequest - true, if request was performed within transactional cotnext
action - the action

getErrorCodeFromException

public int getErrorCodeFromException(java.lang.Throwable th)
Maps an ResoaException to a HTTPStatusCode

Parameters:
th - the exception
Returns:
the error code

indicateTransactionError

public void indicateTransactionError(org.resoa.grid.Message msg,
                                     org.resoa.grid.ResoaStackChannel channel,
                                     java.lang.String errorMsg,
                                     java.lang.Throwable th)
Indicates an error to the requesting session, in case it was a transaction request

Parameters:
msg - the message
channel - the underlying stack channel instance
errorMsg - the error message
th - the causing exception

getNodeState

public org.resoa.topology.NodeState getNodeState()
Returns status data of the node (monitoring data)

Specified by:
getNodeState in interface org.resoa.grid.ResoaGateway
Returns:
a node state handle
See Also:
ResoaGateway.getNodeState()

updateMonitoring

protected abstract void updateMonitoring(org.resoa.topology.NodeState state)
Update monitoring data within locked state

Parameters:
state -

getLogger

public org.slf4j.Logger getLogger()
Specified by:
getLogger in interface org.resoa.grid.ResoaGateway


Read more about license conditions at www.resoa.org.