org.apache.servicemix.common
Class DefaultComponent

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

public abstract class DefaultComponent
extends BaseLifeCycle
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: 584990 $

Field Summary
protected  Log logger
           
protected  Registry registry
           
protected  ServiceUnit serviceUnit
           
protected  BaseServiceUnitManager serviceUnitManager
           
 
Fields inherited from class org.apache.servicemix.common.AsyncBaseLifeCycle
channel, component, context, correlationId, currentState, executor, executorFactory, INITIALIZED, mbeanName, poller, polling, processors, running, transactionManager, workManagerCreated
 
Constructor Summary
DefaultComponent()
           
 
Method Summary
 void addEndpoint(Endpoint endpoint)
          Dynamically adds a new endpoint
protected static List asList(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()
           
 String getComponentName()
           
protected abstract  List getConfiguredEndpoints()
          Returns an array of configured endpoints for the component or null if there are no configured endpoints
protected abstract  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
 QName getEPRElementName()
           
protected  String[] getEPRProtocols()
           
 QName getEPRServiceName()
           
 javax.jbi.component.ComponentLifeCycle getLifeCycle()
           
 Log getLogger()
           
 Registry getRegistry()
           
 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)
           
 void removeEndpoint(Endpoint endpoint)
           
 javax.jbi.servicedesc.ServiceEndpoint resolveEndpointReference(DocumentFragment epr)
           
protected  void validateEndpoint(Endpoint endpoint)
          Provides a hook to validate the statically configured endpoint
 
Methods inherited from class org.apache.servicemix.common.BaseLifeCycle
onMessageExchange
 
Methods inherited from class org.apache.servicemix.common.AsyncBaseLifeCycle
createExecutorFactory, createExtensionMBeanName, exceptionShouldRollbackTx, findExecutorFactory, getContext, getCurrentState, getExecutor, getExtensionMBean, getExtensionMBeanName, getResolvedEPR, init, isInitialized, isShutDown, isStarted, isStopped, isUnknown, pollDeliveryChannel, prepareConsumerExchange, processExchange, processExchangeInTx, sendConsumerExchange, sendConsumerExchange, setComponent, setCurrentState, 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
getExecutor, prepareConsumerExchange, sendConsumerExchange
 

Field Detail

logger

protected final transient Log logger

registry

protected Registry registry

serviceUnitManager

protected BaseServiceUnitManager serviceUnitManager

serviceUnit

protected ServiceUnit serviceUnit
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 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 QName getEPRServiceName()
Overrides:
getEPRServiceName in class AsyncBaseLifeCycle

getEPRElementName

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

getEPRProtocols

protected String[] getEPRProtocols()

resolveEndpointReference

public javax.jbi.servicedesc.ServiceEndpoint resolveEndpointReference(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 String getComponentName()
Specified by:
getComponentName in interface ServiceMixComponent
Returns:
Returns the name of the component

getLogger

public Log 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 abstract List getConfiguredEndpoints()
Returns an array of configured endpoints for the component or null if there are no configured endpoints


getEndpointClasses

protected abstract 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 List asList(Object[] endpoints)
A little helper method to turn a possibly null list of endpoints into a list of endpoints


doInit

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

addEndpoint

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

Throws:
Exception

removeEndpoint

public void removeEndpoint(Endpoint endpoint)
                    throws Exception
Throws:
Exception

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

doStart

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

doStop

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

doShutDown

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


Copyright © 2005-2007 Apache Software Foundation. All Rights Reserved.