org.apache.servicemix.common
Class DefaultComponent

java.lang.Object
  extended by org.apache.servicemix.common.AsyncBaseLifeCycle
      extended by org.apache.servicemix.common.DefaultComponent
All Implemented Interfaces:
javax.jbi.component.Component, javax.jbi.component.ComponentLifeCycle, ServiceMixComponent

public class DefaultComponent
extends AsyncBaseLifeCycle
implements ServiceMixComponent

A useful base class for writing new JBI components which includes the ComponentLifeCycle interface methods so that you can write a new component in a single class with minimal overloading.

Version:
$Revision$

Field Summary
protected  javax.jbi.component.ComponentLifeCycle lifeCycle
           
protected  org.slf4j.Logger logger
           
protected  Registry registry
           
protected  ServiceUnit serviceUnit
           
protected  BaseServiceUnitManager serviceUnitManager
           
 
Fields inherited from class org.apache.servicemix.common.AsyncBaseLifeCycle
channel, component, consumerExecutor, container, context, correlationId, currentState, executorFactory, INITIALIZED, knownExchanges, mbeanName, poller, polling, providerExecutor, running, transactionManager, workManagerCreated
 
Constructor Summary
DefaultComponent()
           
 
Method Summary
 void addEndpoint(Endpoint endpoint)
          Dynamically adds a new endpoint
protected static java.util.List asList(java.lang.Object[] endpoints)
          A little helper method to turn a possibly null list of endpoints into a list of endpoints
protected  Registry createRegistry()
           
protected  BaseServiceUnitManager createServiceUnitManager()
          Create the service unit manager.
protected  void doInit()
           
protected  void doShutDown()
           
protected  void doStart()
           
protected  void doStop()
           
 javax.jbi.component.ComponentContext getComponentContext()
           
 java.lang.String getComponentName()
           
protected  java.util.List getConfiguredEndpoints()
          Returns an array of configured endpoints for the component or null if there are no configured endpoints
protected  java.lang.Class[] getEndpointClasses()
          Returns a list of valid endpoint classes or null if the component does not wish to programmatically restrict the list of possible endpoint classes
 javax.xml.namespace.QName getEPRElementName()
           
protected  java.lang.String[] getEPRProtocols()
           
 javax.xml.namespace.QName getEPRServiceName()
           
 javax.jbi.component.ComponentLifeCycle getLifeCycle()
           
 org.slf4j.Logger getLogger()
           
 Registry getRegistry()
           
 org.w3c.dom.Document getServiceDescription(javax.jbi.servicedesc.ServiceEndpoint endpoint)
           
 ServiceUnit getServiceUnit()
          Returns the service unit, lazily creating one on demand
 javax.jbi.component.ServiceUnitManager getServiceUnitManager()
           
 boolean isExchangeWithConsumerOkay(javax.jbi.servicedesc.ServiceEndpoint endpoint, javax.jbi.messaging.MessageExchange exchange)
           
 boolean isExchangeWithProviderOkay(javax.jbi.servicedesc.ServiceEndpoint endpoint, javax.jbi.messaging.MessageExchange exchange)
           
 boolean isKnownEndpoint(Endpoint endpoint)
           
 void removeEndpoint(Endpoint endpoint)
           
 javax.jbi.servicedesc.ServiceEndpoint resolveEndpointReference(org.w3c.dom.DocumentFragment epr)
           
protected  void validateEndpoint(Endpoint endpoint)
          Provides a hook to validate the statically configured endpoint
 
Methods inherited from class org.apache.servicemix.common.AsyncBaseLifeCycle
createExecutorFactory, createExtensionMBeanName, exceptionShouldRollbackTx, findExecutorFactory, getContainer, getContext, getCurrentState, getExecutor, getExecutorFactory, getExtensionMBean, getExtensionMBeanName, getKnownExchanges, getResolvedEPR, getSmx3Container, handleExchange, init, isInitialized, isShutDown, isStarted, isStopped, isUnknown, onMessageExchange, pollDeliveryChannel, prepareExchange, prepareShutdown, prepareShutdown, processExchange, processExchangeInTx, setComponent, setCurrentState, setExecutor, setExecutorFactory, shutDown, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.servicemix.common.ServiceMixComponent
getContainer, getExecutor, getSmx3Container, handleExchange, prepareExchange, prepareShutdown
 

Field Detail

logger

protected final transient org.slf4j.Logger logger

registry

protected Registry registry

serviceUnitManager

protected BaseServiceUnitManager serviceUnitManager

serviceUnit

protected ServiceUnit serviceUnit

lifeCycle

protected javax.jbi.component.ComponentLifeCycle lifeCycle
Constructor Detail

DefaultComponent

public DefaultComponent()
Method Detail

getLifeCycle

public javax.jbi.component.ComponentLifeCycle getLifeCycle()
Specified by:
getLifeCycle in interface javax.jbi.component.Component

getServiceUnitManager

public javax.jbi.component.ServiceUnitManager getServiceUnitManager()
Specified by:
getServiceUnitManager in interface javax.jbi.component.Component

getServiceDescription

public org.w3c.dom.Document getServiceDescription(javax.jbi.servicedesc.ServiceEndpoint endpoint)
Specified by:
getServiceDescription in interface javax.jbi.component.Component

isExchangeWithConsumerOkay

public boolean isExchangeWithConsumerOkay(javax.jbi.servicedesc.ServiceEndpoint endpoint,
                                          javax.jbi.messaging.MessageExchange exchange)
Specified by:
isExchangeWithConsumerOkay in interface javax.jbi.component.Component

isExchangeWithProviderOkay

public boolean isExchangeWithProviderOkay(javax.jbi.servicedesc.ServiceEndpoint endpoint,
                                          javax.jbi.messaging.MessageExchange exchange)
Specified by:
isExchangeWithProviderOkay in interface javax.jbi.component.Component

getEPRServiceName

public javax.xml.namespace.QName getEPRServiceName()
Overrides:
getEPRServiceName in class AsyncBaseLifeCycle

getEPRElementName

public javax.xml.namespace.QName getEPRElementName()
Specified by:
getEPRElementName in interface ServiceMixComponent
Returns:
the QName of the element used in EPR

getEPRProtocols

protected java.lang.String[] getEPRProtocols()

resolveEndpointReference

public javax.jbi.servicedesc.ServiceEndpoint resolveEndpointReference(org.w3c.dom.DocumentFragment epr)
Specified by:
resolveEndpointReference in interface javax.jbi.component.Component

createServiceUnitManager

protected BaseServiceUnitManager createServiceUnitManager()
Create the service unit manager. Derived classes should override this method and return a BaseServiceUnitManager so that the component is able to handle service unit deployment. The default implementation will create a @{link BaseXBeanDeployer} instance using the value of @{link #getEndpointClasses()} if that method returns a non-null value otherwise it returns null.

Returns:
a newly created service unit manager

createRegistry

protected Registry createRegistry()

getComponentContext

public javax.jbi.component.ComponentContext getComponentContext()
Specified by:
getComponentContext in interface ServiceMixComponent
Returns:
Returns the components context

getComponentName

public java.lang.String getComponentName()
Specified by:
getComponentName in interface ServiceMixComponent
Returns:
Returns the name of the component

getLogger

public org.slf4j.Logger getLogger()
Specified by:
getLogger in interface ServiceMixComponent
Returns:
Returns the logger.

getRegistry

public Registry getRegistry()
Specified by:
getRegistry in interface ServiceMixComponent
Returns:
Returns the registry.

getServiceUnit

public ServiceUnit getServiceUnit()
Returns the service unit, lazily creating one on demand

Returns:
the service unit if one is being used.

getConfiguredEndpoints

protected java.util.List getConfiguredEndpoints()
Returns an array of configured endpoints for the component or null if there are no configured endpoints


getEndpointClasses

protected java.lang.Class[] getEndpointClasses()
Returns a list of valid endpoint classes or null if the component does not wish to programmatically restrict the list of possible endpoint classes

Returns:
the endpoint classes used to validate configuration or null to disable the validation

asList

protected static java.util.List asList(java.lang.Object[] endpoints)
A little helper method to turn a possibly null list of endpoints into a list of endpoints


addEndpoint

public void addEndpoint(Endpoint endpoint)
                 throws java.lang.Exception
Dynamically adds a new endpoint

Throws:
java.lang.Exception

removeEndpoint

public void removeEndpoint(Endpoint endpoint)
                    throws java.lang.Exception
Throws:
java.lang.Exception

isKnownEndpoint

public boolean isKnownEndpoint(Endpoint endpoint)

validateEndpoint

protected void validateEndpoint(Endpoint endpoint)
                         throws javax.jbi.management.DeploymentException
Provides a hook to validate the statically configured endpoint

Throws:
javax.jbi.management.DeploymentException

doInit

protected void doInit()
               throws java.lang.Exception
Overrides:
doInit in class AsyncBaseLifeCycle
Throws:
java.lang.Exception

doStart

protected void doStart()
                throws java.lang.Exception
Overrides:
doStart in class AsyncBaseLifeCycle
Throws:
java.lang.Exception

doStop

protected void doStop()
               throws java.lang.Exception
Overrides:
doStop in class AsyncBaseLifeCycle
Throws:
java.lang.Exception

doShutDown

protected void doShutDown()
                   throws java.lang.Exception
Overrides:
doShutDown in class AsyncBaseLifeCycle
Throws:
java.lang.Exception


Copyright © 2005-2012 FuseSource. All Rights Reserved.