org.resoa.node.core
Class ResoaServiceGateway

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

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


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  java.util.HashMap<java.lang.String,javolution.util.FastMap<java.lang.String,org.resoa.grid.ResoaServiceDescriptor>> deployedServices
           
protected  java.util.concurrent.locks.ReentrantLock lockServices
          synchronization object for Deployment Update and Service caching
 
Fields inherited from class org.resoa.node.core.ResoaBaseGateway
executionExceptions, gatewayRunner, initialControllers, localProfile, lockConnection, lockNodeState, lockResoaUpdate, logger, nodeDomains, nodeType, pendingMessages, permissionExceptions, properties, rcl, requestExceptions, running, security, sessionExceptions, stack
 
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 ResoaServiceGateway()
          Constructor for Gateway without Resoa Grid Functionality
  ResoaServiceGateway(java.lang.String configPath)
          Constructor
 
Method Summary
 void broadcastToControllers(java.lang.Object request, org.resoa.grid.ResoaStackChannel channel, org.resoa.util.Priority prio, int stackProtocolActivation)
          Broadcast an object to all Resoa controllers
 void broadcastToDomainNodes(java.lang.Object request, java.lang.String domain, org.resoa.grid.ResoaStackChannel channel, org.resoa.util.Priority prio, int stackProtocolActivation, java.lang.String excludedSessionID)
          Broadcast an object to all Resoa nodes, registered for a domain
 void createHotBackup(java.lang.String domain)
          Used by Resoa persistence services.
 org.resoa.topology.RestSession createRestSession(java.util.List<org.resoa.topology.Permission> perm, java.lang.String userID, java.lang.String userAgent, int timeout, org.resoa.grid.GridSession requestor)
          Creates a RESTSession handle
protected  void deployServiceDomain(org.resoa.util.codedom.DomainDescriptor domainDescriptor)
          Deploy a service domain Lock the lockService instance before!
 org.resoa.grid.ResoaResponse executeService(org.resoa.grid.GridSession session, java.lang.Object request, org.resoa.grid.ResoaStackChannel channel, boolean isSecureProtocol, org.resoa.util.Priority responsePrio)
          Executes a service
 void executeService(org.resoa.grid.Message msg)
          Executes a service from a stack message
 org.resoa.topology.RestSession getRestSession(java.lang.String sessionID, boolean awake)
           
 java.lang.Object getServiceImplementation(java.lang.String domain, java.lang.String name, boolean createNewInstance)
           
protected  void initializeServices()
          Call the service initialize method
protected  byte[] marshallRequest(java.lang.Object request)
          Marshalls a request object to bytes
 void onMessage(java.lang.Object channel, org.resoa.grid.Message msg)
          Gets invoked on message arrival from stack.
 org.resoa.grid.Transaction performControllerTransaction(java.lang.Object request, java.lang.String domain, java.lang.String methodName)
          Perform a transaction to a Controller node
 org.resoa.grid.Transaction performTransaction(java.lang.Object request, org.resoa.grid.ResoaStackChannel channel, org.resoa.grid.GridSession session, org.resoa.util.Priority prio, int stackProtocolActivation)
          Performs a transaction on an underlying session
 org.resoa.grid.Message processResoaResponse(org.resoa.grid.ResoaResponse response, org.resoa.grid.Message requestMessage, org.resoa.grid.Channel channel)
          Invoked AFTER the service execution, where a business implementation might set a ResonseObject and an action.
 java.lang.Object readChannel(org.resoa.util.ByteBuffer buffer)
           
 void removeRestSession(java.lang.String restSessionID, org.resoa.grid.GridSession requestor)
           
 org.resoa.topology.RestSession requestRestSessionFromController(org.resoa.topology.RestSession session)
          Request a RestSession handle from controller
 void sendMessage(java.lang.Object request, org.resoa.grid.ResoaStackChannel channel, org.resoa.grid.GridSession session, org.resoa.util.Priority prio, int stackProtocolActivation)
          Sends a request to a session
<T> T
unmarshallTransactionResult(org.resoa.grid.Transaction t, java.lang.Class<T> type)
          Unmarshall a transaction response object to a service instance
 void writeChannel(java.lang.Object channel, org.resoa.util.ByteBuffer buffer)
           
 
Methods inherited from class org.resoa.node.core.ResoaBaseGateway
addMessageToPending, afterGridConnection, beforeGridConnection, beforeNodeStop, connectToInitialController, connectToNode, getConfigurationPath, getConnectedProfiles, getControllerSession, getDomainNodes, getErrorCodeFromException, getGridConnectionsNodes, getLocalProfile, getLogger, getNodeHandle, getNodeState, getNodeType, getStack, getTransactionState, indicateTransactionError, isAccessPoint, isRunning, onSessionInitialized, removeIdleSessions, sendPendingMessage, sessionDisconnected, sessionInitialized, setConfigurationPath, setGatewayRunner, stop, updateMonitoring, updateResoaInfo
 
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
connectToInitialController, getConfigurationPath, getLocalProfile, getLogger, getNodeState, getNodeType, getPersistor, isDeployed, isRunning, removeIdleSessions, setGatewayRunner, stop, updateResoaInfo
 
Methods inherited from interface org.resoa.stack.StackChannelProcessor
onTransactionDelay
 
Methods inherited from interface org.resoa.stack.Callbacks.SessionState
sessionDisconnected, sessionInitialized
 

Field Detail

lockServices

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


deployedServices

protected java.util.HashMap<java.lang.String,javolution.util.FastMap<java.lang.String,org.resoa.grid.ResoaServiceDescriptor>> deployedServices
Constructor Detail

ResoaServiceGateway

public ResoaServiceGateway(java.lang.String configPath)
                    throws org.resoa.exception.ResoaException
Constructor

Parameters:
configPath -
Throws:
org.resoa.exception.ResoaException

ResoaServiceGateway

protected ResoaServiceGateway()
Constructor for Gateway without Resoa Grid Functionality

Method Detail

broadcastToDomainNodes

public void broadcastToDomainNodes(java.lang.Object request,
                                   java.lang.String domain,
                                   org.resoa.grid.ResoaStackChannel channel,
                                   org.resoa.util.Priority prio,
                                   int stackProtocolActivation,
                                   java.lang.String excludedSessionID)
Broadcast an object to all Resoa nodes, registered for a domain

Specified by:
broadcastToDomainNodes in interface org.resoa.grid.ResoaGateway
Parameters:
request - the service request instance
domain - the service domain (jarName), for which the broadcast should happen
channel - the channel instance
prio - the priority
stackProtocolActivation - the stack protocol activation
excludedSessionID - the stackSessionID, which should be excluded

broadcastToControllers

public void broadcastToControllers(java.lang.Object request,
                                   org.resoa.grid.ResoaStackChannel channel,
                                   org.resoa.util.Priority prio,
                                   int stackProtocolActivation)
Broadcast an object to all Resoa controllers

Specified by:
broadcastToControllers in interface org.resoa.grid.ResoaGateway
Parameters:
request - the service request instance
channel - the channel
prio - the priority
stackProtocolActivation - the stack protocol activation

sendMessage

public void sendMessage(java.lang.Object request,
                        org.resoa.grid.ResoaStackChannel channel,
                        org.resoa.grid.GridSession session,
                        org.resoa.util.Priority prio,
                        int stackProtocolActivation)
                 throws org.resoa.exception.ProtocolException,
                        java.io.IOException
Sends a request to a session

Specified by:
sendMessage in interface org.resoa.grid.ResoaGateway
Parameters:
request - the service request instance
channel - the channel
session - the stack session
prio - the priority
stackProtocolActivation - the stack protocol activation
Throws:
org.resoa.exception.ResoaException
org.resoa.exception.ProtocolException
java.io.IOException

performTransaction

public org.resoa.grid.Transaction performTransaction(java.lang.Object request,
                                                     org.resoa.grid.ResoaStackChannel channel,
                                                     org.resoa.grid.GridSession session,
                                                     org.resoa.util.Priority prio,
                                                     int stackProtocolActivation)
                                              throws org.resoa.exception.ResoaException,
                                                     java.io.IOException
Performs a transaction on an underlying session

Specified by:
performTransaction in interface org.resoa.grid.ResoaGateway
Parameters:
request - the service request instance
channel - the channel
session - the stack session
prio - the priority
stackProtocolActivation - the stack protocol activation
Returns:
the Transaction handle with the response data
Throws:
org.resoa.exception.ResoaException
java.io.IOException

performControllerTransaction

public org.resoa.grid.Transaction performControllerTransaction(java.lang.Object request,
                                                               java.lang.String domain,
                                                               java.lang.String methodName)
                                                        throws org.resoa.exception.ServiceExecutionException
Perform a transaction to a Controller node

Parameters:
request - the service request object
domain - the domain
methodName - the method to invoke
Returns:
the Transaction handle with the response data
Throws:
org.resoa.exception.ServiceExecutionException - The request itself might do a cycle invocation, if a timeout or protocol exception happen during transaction. Maximum cycle time is 3.

onMessage

public void onMessage(java.lang.Object channel,
                      org.resoa.grid.Message msg)
Gets invoked on message arrival from stack. Passes messages to service executions

Specified by:
onMessage in interface org.resoa.stack.StackChannelProcessor
Parameters:
msg - message the message
channel - the channel object

createRestSession

public org.resoa.topology.RestSession createRestSession(java.util.List<org.resoa.topology.Permission> perm,
                                                        java.lang.String userID,
                                                        java.lang.String userAgent,
                                                        int timeout,
                                                        org.resoa.grid.GridSession requestor)
Creates a RESTSession handle

Specified by:
createRestSession in interface org.resoa.grid.ResoaGateway
Parameters:
perm - provide the permissions, associated with this session
userID - the userID of the session
userAgent - the user agent
timeout - the timeout
requestor - the base stack session
Returns:
the newly generated RestSession or null if failed

getRestSession

public org.resoa.topology.RestSession getRestSession(java.lang.String sessionID,
                                                     boolean awake)
Specified by:
getRestSession in interface org.resoa.grid.ResoaGateway

removeRestSession

public void removeRestSession(java.lang.String restSessionID,
                              org.resoa.grid.GridSession requestor)
Specified by:
removeRestSession in interface org.resoa.grid.ResoaGateway

requestRestSessionFromController

public org.resoa.topology.RestSession requestRestSessionFromController(org.resoa.topology.RestSession session)
Request a RestSession handle from controller

Specified by:
requestRestSessionFromController in class ResoaBaseGateway
Returns:
the RestSession from Controller or null, if not existent

deployServiceDomain

protected void deployServiceDomain(org.resoa.util.codedom.DomainDescriptor domainDescriptor)
Deploy a service domain Lock the lockService instance before!

Parameters:
domainDescriptor - the domain

initializeServices

protected void initializeServices()
Call the service initialize method


getServiceImplementation

public java.lang.Object getServiceImplementation(java.lang.String domain,
                                                 java.lang.String name,
                                                 boolean createNewInstance)
                                          throws org.resoa.exception.ResoaException
Specified by:
getServiceImplementation in interface org.resoa.grid.ResoaGateway
Throws:
org.resoa.exception.ResoaException

executeService

public void executeService(org.resoa.grid.Message msg)
                    throws org.resoa.exception.InvalidSessionException,
                           org.resoa.exception.ACViolationException,
                           org.resoa.exception.BadRequestException,
                           org.resoa.exception.ServiceNotFoundException,
                           org.resoa.exception.InvalidProtocolException,
                           org.resoa.exception.ServiceExecutionException
Executes a service from a stack message

Specified by:
executeService in interface org.resoa.grid.ResoaGateway
Parameters:
msg - the stack message
Throws:
org.resoa.exception.ServiceExecutionException
org.resoa.exception.InvalidSessionException
org.resoa.exception.ACViolationException
org.resoa.exception.BadRequestException
org.resoa.exception.ServiceNotFoundException
org.resoa.exception.InvalidProtocolException

executeService

public org.resoa.grid.ResoaResponse executeService(org.resoa.grid.GridSession session,
                                                   java.lang.Object request,
                                                   org.resoa.grid.ResoaStackChannel channel,
                                                   boolean isSecureProtocol,
                                                   org.resoa.util.Priority responsePrio)
                                            throws org.resoa.exception.InvalidSessionException,
                                                   org.resoa.exception.ACViolationException,
                                                   org.resoa.exception.BadRequestException,
                                                   org.resoa.exception.ServiceNotFoundException,
                                                   org.resoa.exception.InvalidProtocolException,
                                                   org.resoa.exception.ServiceExecutionException
Executes a service

Specified by:
executeService in interface org.resoa.grid.ResoaGateway
Parameters:
session - the stack session
request - the request instance
channel - the ResoaStackChannel instance
isSecureProtocol - true, if request arrived on a secure protocol
responsePrio - the priority of the response for further handling
Returns:
a ResoaResponse instance with the result of the service execution
Throws:
org.resoa.exception.InvalidSessionException
org.resoa.exception.ACViolationException
org.resoa.exception.BadRequestException
org.resoa.exception.ServiceNotFoundException
org.resoa.exception.InvalidProtocolException
org.resoa.exception.ServiceExecutionException

marshallRequest

protected byte[] marshallRequest(java.lang.Object request)
Marshalls a request object to bytes

Parameters:
request - the service request object
Returns:
the byte array representation

unmarshallTransactionResult

public <T> T unmarshallTransactionResult(org.resoa.grid.Transaction t,
                                         java.lang.Class<T> type)
Unmarshall a transaction response object to a service instance

Type Parameters:
T -
Parameters:
t - the transaction
type - the type to cast into
Returns:
the instance

processResoaResponse

public org.resoa.grid.Message processResoaResponse(org.resoa.grid.ResoaResponse response,
                                                   org.resoa.grid.Message requestMessage,
                                                   org.resoa.grid.Channel channel)
Invoked AFTER the service execution, where a business implementation might set a ResonseObject and an action. The response object will be serialized, the resulting byte array set to the stack message content and the stack transaction protocol be adapted according to the indicated ResonseAction. SUCCESS(COMMIT) Action will cause a TransactionState COMMIT, ERROR(ROLLBACK) a state ROLLBACK.

Parameters:
response - the executed ServiceExecutionHandle
requestMessage - the request message
channel - the channel object
Returns:
a Stack message, ready for sending

createHotBackup

public void createHotBackup(java.lang.String domain)
Used by Resoa persistence services. A domain will be prepared for a hot backup (froozen). Use the generated backup storage file for setting up a new node for this service domain Invoke the archiveTaskLog method


readChannel

public java.lang.Object readChannel(org.resoa.util.ByteBuffer buffer)
Specified by:
readChannel in interface org.resoa.stack.StackChannelProcessor

writeChannel

public void writeChannel(java.lang.Object channel,
                         org.resoa.util.ByteBuffer buffer)
Specified by:
writeChannel in interface org.resoa.stack.StackChannelProcessor


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