org.jboss.soa.esb.listeners.gateway
Class JBossRemotingGatewayListener

java.lang.Object
  extended by org.jboss.soa.esb.listeners.lifecycle.AbstractManagedLifecycle
      extended by org.jboss.soa.esb.listeners.gateway.JBossRemotingGatewayListener
All Implemented Interfaces:
org.jboss.remoting.ServerInvocationHandler, ManagedLifecycle

public class JBossRemotingGatewayListener
extends AbstractManagedLifecycle
implements org.jboss.remoting.ServerInvocationHandler

JBoss Remoting listener implementation for receiving ESB unaware messages over a JBoss Remoting channel.

This class implements the JBoss Remoting interface ServerInvocationHandler. Messages are pushed in through the invoke(org.jboss.remoting.InvocationRequest) method, which is an implementation of the ServerInvocationHandler.invoke(org.jboss.remoting.InvocationRequest) method.

The JBoss Remoting Connector configuration is populated by the initaliseJBRConnectorConfiguration(java.util.Map) method. The remoting server locator URI is constructed by the getJbrServerLocatorURI() method.

The default MessageComposer used by this listener is the JBossRemotingGatewayListener.JBossRemotingMessageComposer. All message composer implementation supplied to this class will be supplied an instance of InvocationRequest, from which they must compose an ESB aware Message instance.

See the JBoss Remoting docs for details on configuring specific remoting server protocols.

Author:
tom.fennelly@jboss.com

Nested Class Summary
static class JBossRemotingGatewayListener.JBossRemotingMessageComposer<T extends org.jboss.remoting.InvocationRequest>
          Message composer for a JBoss Remoting InvocationRequest instance.
 
Field Summary
static java.lang.String JBR_PREFIX
          JBoss Remoting connector config attribute name prefix.
static java.lang.String JBR_SERVER_HOST
          Server Host config attribute name.
static java.lang.String JBR_SERVER_PORT
          Server port config attribute name.
static java.lang.String JBR_SERVER_PROTOCOL
          Server Protocol config attribute name.
 
Fields inherited from class org.jboss.soa.esb.listeners.lifecycle.AbstractManagedLifecycle
PARAM_TERMINATION_PERIOD
 
Constructor Summary
JBossRemotingGatewayListener(ConfigTree config)
          Construct the threaded managed lifecycle.
 
Method Summary
 void addListener(org.jboss.remoting.callback.InvokerCallbackHandler invokerCallbackHandler)
           
protected  UncomposedMessageDeliveryAdapter createDeliveryAdapter()
          Factory method for adapter creation.
protected  void doDestroy()
          Handle the destroy of the managed instance.
protected  void doInitialise()
          Handle the initialisation of the managed instance.
protected  void doStart()
          Handle the start of the managed instance.
protected  void doStop()
          Handle the stop of the managed instance.
static org.jboss.remoting.InvocationRequest getCurrentRequest()
           
protected  java.net.URI getJbrServerLocatorURI()
          Get the Service Locator URI for this remotng based listener.
protected  void initaliseJBRConnectorConfiguration(java.util.Map<java.lang.String,java.lang.String> connectorConfig)
          Initialise the JBossRemoting connector configuration.
 java.lang.Object invoke(org.jboss.remoting.InvocationRequest invocationRequest)
          Process a remoting invocation message.
 boolean isInitialised()
          Is this listener instance initialised.
 boolean isStarted()
          Is this listener instance started.
 void removeListener(org.jboss.remoting.callback.InvokerCallbackHandler invokerCallbackHandler)
           
 void setInvoker(org.jboss.remoting.ServerInvoker serverInvoker)
           
 void setMBeanServer(javax.management.MBeanServer mBeanServer)
           
 
Methods inherited from class org.jboss.soa.esb.listeners.lifecycle.AbstractManagedLifecycle
addManagedLifecycleEventListener, changeState, destroy, getConfig, getState, getTerminationPeriod, initialise, removeManagedLifecycleEventListener, start, stop, waitUntilDestroyed, waitUntilDestroyed, waitUntilNotState, waitUntilState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jboss.remoting.ServerInvocationHandler
toString
 

Field Detail

JBR_PREFIX

public static final java.lang.String JBR_PREFIX
JBoss Remoting connector config attribute name prefix.

See Also:
Constant Field Values

JBR_SERVER_PROTOCOL

public static final java.lang.String JBR_SERVER_PROTOCOL
Server Protocol config attribute name.

See Also:
Constant Field Values

JBR_SERVER_HOST

public static final java.lang.String JBR_SERVER_HOST
Server Host config attribute name.

See Also:
Constant Field Values

JBR_SERVER_PORT

public static final java.lang.String JBR_SERVER_PORT
Server port config attribute name.

See Also:
Constant Field Values
Constructor Detail

JBossRemotingGatewayListener

public JBossRemotingGatewayListener(ConfigTree config)
                             throws ConfigurationException
Construct the threaded managed lifecycle.

Parameters:
config - The configuration associated with this instance.
Throws:
ConfigurationException - for configuration errors during initialisation.
Method Detail

getCurrentRequest

public static org.jboss.remoting.InvocationRequest getCurrentRequest()

isInitialised

public boolean isInitialised()
Is this listener instance initialised.

Returns:
True if this listener is initialised, otherwise false.

isStarted

public boolean isStarted()
Is this listener instance started.

Basically, Is this listener's JBoss Remoting Connector connected?

Returns:
True if this listener is started, otherwise false.

doInitialise

protected void doInitialise()
                     throws ManagedLifecycleException
Description copied from class: AbstractManagedLifecycle
Handle the initialisation of the managed instance.

Specified by:
doInitialise in class AbstractManagedLifecycle
Throws:
ManagedLifecycleException - for errors while initialisation.

doStart

protected void doStart()
                throws ManagedLifecycleException
Description copied from class: AbstractManagedLifecycle
Handle the start of the managed instance.

Specified by:
doStart in class AbstractManagedLifecycle
Throws:
ManagedLifecycleException - for errors while starting.

doStop

protected void doStop()
               throws ManagedLifecycleException
Description copied from class: AbstractManagedLifecycle
Handle the stop of the managed instance.

Specified by:
doStop in class AbstractManagedLifecycle
Throws:
ManagedLifecycleException - for errors while stopping.

doDestroy

protected void doDestroy()
                  throws ManagedLifecycleException
Description copied from class: AbstractManagedLifecycle
Handle the destroy of the managed instance.

Specified by:
doDestroy in class AbstractManagedLifecycle
Throws:
ManagedLifecycleException - for errors while destroying.

invoke

public java.lang.Object invoke(org.jboss.remoting.InvocationRequest invocationRequest)
                        throws java.lang.Throwable
Process a remoting invocation message.

This method uses an UncomposedMessageDeliveryAdapter to carry out the delivery. This delivery adpter is constructed with a MessageComposer instance supplied through configuration, otherwise it uses the JBossRemotingGatewayListener.JBossRemotingMessageComposer.

The message composer is responsible for mapping the remoting InvocationRequest into an ESB aware Message, while the UncomposedMessageDeliveryAdapter is responsible for its delivery to the target service.

Specified by:
invoke in interface org.jboss.remoting.ServerInvocationHandler
Parameters:
invocationRequest - JBoss Remoting request.
Returns:
Message delivery acknowledgment response.
Throws:
java.lang.Throwable - Message processing failure.

setMBeanServer

public void setMBeanServer(javax.management.MBeanServer mBeanServer)
Specified by:
setMBeanServer in interface org.jboss.remoting.ServerInvocationHandler

setInvoker

public void setInvoker(org.jboss.remoting.ServerInvoker serverInvoker)
Specified by:
setInvoker in interface org.jboss.remoting.ServerInvocationHandler

addListener

public void addListener(org.jboss.remoting.callback.InvokerCallbackHandler invokerCallbackHandler)
Specified by:
addListener in interface org.jboss.remoting.ServerInvocationHandler

removeListener

public void removeListener(org.jboss.remoting.callback.InvokerCallbackHandler invokerCallbackHandler)
Specified by:
removeListener in interface org.jboss.remoting.ServerInvocationHandler

initaliseJBRConnectorConfiguration

protected void initaliseJBRConnectorConfiguration(java.util.Map<java.lang.String,java.lang.String> connectorConfig)
                                           throws ConfigurationException
Initialise the JBossRemoting connector configuration.

Constructs the JBR InvokerLocator URI through a call to getJbrServerLocatorURI(). Also populates the server connector properties.

Default behavior for population of the connector configuration is to load all listener configuration properties whose name is prefixed with "jbr-", stripping off the "jbr-" prefix from the name before adding. So, to set the Server "timeout" configuration property on the connector, you set the property name to "jbr-timeout".

Parameters:
connectorConfig - The configuration map instance to be populated.
Throws:
ConfigurationException - Problem populating the configuration.

getJbrServerLocatorURI

protected java.net.URI getJbrServerLocatorURI()
                                       throws ConfigurationException
Get the Service Locator URI for this remotng based listener.

Uses the listener config to extract the protcol, host and port parameters for the server. The host address defaults to the value returned by InetAddress.getLocalHost().

Returns:
The Server Locator URI.
Throws:
ConfigurationException - One or more of the locator properties are missing from the listener config.

createDeliveryAdapter

protected UncomposedMessageDeliveryAdapter createDeliveryAdapter()
                                                          throws ConfigurationException
Factory method for adapter creation.

Returns:
The adapter instance.
Throws:
ConfigurationException - Configuration error.