Class ServiceCollectionImp
- java.lang.Object
-
- java.util.AbstractCollection<Service>
-
- com.adaptris.core.ServiceCollectionImp
-
- All Implemented Interfaces:
AdaptrisComponent,ComponentLifecycle,ComponentLifecycleExtension,ConfigComment,EventHandlerAware,MessageEventGenerator,Service,ServiceCollection,StateManagedComponent,java.lang.Iterable<Service>,java.util.Collection<Service>,java.util.List<Service>
- Direct Known Subclasses:
BranchingServiceCollection,ServiceListBase
public abstract class ServiceCollectionImp extends java.util.AbstractCollection<Service> implements Service, ServiceCollection
Behaviour common to
ServiceCollections.
-
-
Field Summary
Fields Modifier and Type Field Description protected EventHandlereventHandlerprotected org.slf4j.Loggerlog
-
Constructor Summary
Constructors Constructor Description ServiceCollectionImp()ServiceCollectionImp(java.util.Collection<Service> list)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidadd(int index, Service element)booleanadd(Service service)booleanaddAll(int index, java.util.Collection<? extends Service> c)booleanaddAll(java.util.Collection<? extends Service> c)voidaddService(Service service)Adds aServiceto the end of the configuredList.protected abstract voidapplyServices(AdaptrisMessage msg)Apply the required services to the message.voidchangeState(ComponentState newState)Updates the state for the componentComponentState.voidclear()voidclose()Closes the component.booleancontinueOnFailure()If true containers should continue and apply the next configuredServiceeven if thisServicethrows anException.java.lang.StringcreateName()Create a name for anyMleMarkerthat is generated.java.lang.StringcreateQualifier()Create a qualifier for anyMleMarkerthat is generated.protected abstract voiddoClose()Close any additional components.protected abstract voiddoInit()Start any additional components.voiddoService(AdaptrisMessage msg)Apply the service to the message.protected abstract voiddoStart()Start any additional components.protected abstract voiddoStop()Stop any additional components.protected ServiceenforceRequirements(Service service)Enforce any requirements of the list.protected java.util.Collection<? extends Service>enforceRequirements(java.util.Collection<? extends Service> collection)Enforce any requirements of the list.Serviceget(int index)java.lang.StringgetComments()java.lang.BooleangetContinueOnFail()java.lang.BooleangetIsTrackingEndpoint()OutOfStateHandlergetOutOfStateHandler()java.lang.BooleangetRestartAffectedServiceOnException()java.util.List<Service>getServices()Returns the configuredListofServices.java.lang.StringgetUniqueId()Get the unique-id that is associated with this component.voidhandleException(Service service, AdaptrisMessage msg, java.lang.Exception e)Handles any exceptions thrown from an embedded Service.intindexOf(java.lang.Object o)voidinit()Initialises the component.booleanisBranching()Returns true if the implementation supports branching.booleanisTrackingEndpoint()Returns true if this should be considered an 'end-point' for tracking purposes, otherwise false.java.util.Iterator<Service>iterator()intlastIndexOf(java.lang.Object o)java.util.ListIterator<Service>listIterator()java.util.ListIterator<Service>listIterator(int index)voidprepare()Prepare for initialisation.voidregisterEventHandler(EventHandler eh)Register the current event handler against this component.Serviceremove(int index)voidrequestClose()Request this component is closed.voidrequestInit()Request this component is init'd.voidrequestStart()Request this component is started.voidrequestStop()Request this component is stopped.ComponentStateretrieveComponentState()Returns the last recordComponentState.Serviceset(int index, Service element)voidsetComments(java.lang.String s)voidsetContinueOnFail(java.lang.Boolean b)voidsetIsTrackingEndpoint(java.lang.Boolean b)voidsetOutOfStateHandler(OutOfStateHandler handler)Set the behaviour when internal services are not in the correct state.voidsetRestartAffectedServiceOnException(java.lang.Boolean b)Whether to restart the service that threw theServiceExceptionduring processing.voidsetServices(java.util.List<Service> serviceList)Override the underlying service list.voidsetUniqueId(java.lang.String s)Sets the unique identifier for thisService.intsize()voidstart()Starts the component.voidstop()Stop the componentjava.util.List<Service>subList(int fromIndex, int toIndex)<T extends ServiceCollection>
TwithServices(Service... services)-
Methods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
-
-
-
-
Field Detail
-
log
protected transient org.slf4j.Logger log
-
eventHandler
protected transient EventHandler eventHandler
-
-
Constructor Detail
-
ServiceCollectionImp
public ServiceCollectionImp()
-
ServiceCollectionImp
public ServiceCollectionImp(java.util.Collection<Service> list)
-
-
Method Detail
-
registerEventHandler
public void registerEventHandler(EventHandler eh)
Description copied from interface:EventHandlerAwareRegister the current event handler against this component.- Specified by:
registerEventHandlerin interfaceEventHandlerAware- Parameters:
eh- the event handler currently in use.
-
createName
public java.lang.String createName()
Description copied from interface:MessageEventGeneratorCreate a name for anyMleMarkerthat is generated.The default implementation is to return the classname of the component in question.
* @return the name for anyMleMarkerthat is generated.- Specified by:
createNamein interfaceMessageEventGenerator
-
createQualifier
public java.lang.String createQualifier()
Description copied from interface:MessageEventGeneratorCreate a qualifier for anyMleMarkerthat is generated.The default implementation is to return the unique-id of the component in question, or the empty string if not configured
- Specified by:
createQualifierin interfaceMessageEventGenerator- Returns:
- the qualifier for any
MleMarkerthat is generated.
-
getUniqueId
public java.lang.String getUniqueId()
Description copied from interface:AdaptrisComponentGet the unique-id that is associated with this component.- Specified by:
getUniqueIdin interfaceAdaptrisComponent- Returns:
- the unique-id
-
setUniqueId
public void setUniqueId(java.lang.String s)
Description copied from interface:ServiceSets the unique identifier for this
Service. These unique identifiers are optional but maybe required by some implementations ofServiceCollection.- Specified by:
setUniqueIdin interfaceService- Parameters:
s- thisService's unique identifier
-
isBranching
public boolean isBranching()
Description copied from interface:ServiceReturns true if the implementation supports branching.
- Specified by:
isBranchingin interfaceService- Returns:
- true if the implementation supports branching
- See Also:
BranchingServiceCollection
-
continueOnFailure
public boolean continueOnFailure()
Description copied from interface:ServiceIf true containers should continue and apply the next configured
Serviceeven if thisServicethrows anException.- Specified by:
continueOnFailurein interfaceService- Returns:
- continueOnFail
-
getContinueOnFail
public java.lang.Boolean getContinueOnFail()
- Returns:
- whether or not this service is configured to continue on failure.
- See Also:
Service.continueOnFailure()
-
setContinueOnFail
public void setContinueOnFail(java.lang.Boolean b)
-
getIsTrackingEndpoint
public java.lang.Boolean getIsTrackingEndpoint()
-
setIsTrackingEndpoint
public void setIsTrackingEndpoint(java.lang.Boolean b)
-
isTrackingEndpoint
public boolean isTrackingEndpoint()
Description copied from interface:MessageEventGeneratorReturns true if this should be considered an 'end-point' for tracking purposes, otherwise false.
- Specified by:
isTrackingEndpointin interfaceMessageEventGenerator- Returns:
- true if this should be considered an 'end-point' for tracking purposes, otherwise false
- See Also:
MessageEventGenerator.isTrackingEndpoint()
-
addService
public void addService(Service service)
Adds a
Serviceto the end of the configuredList.- Specified by:
addServicein interfaceServiceCollection- Parameters:
service- theServiceto add to the end of the configuredListmay not be null
-
getServices
public java.util.List<Service> getServices()
Returns the configured
ListofServices. May be empty but not null.- Specified by:
getServicesin interfaceServiceCollection- Returns:
- the configured
ListofServices
-
setServices
public void setServices(java.util.List<Service> serviceList)
Override the underlying service list.- Parameters:
serviceList- the service list.
-
setComments
public void setComments(java.lang.String s)
- Specified by:
setCommentsin interfaceConfigComment
-
getComments
public java.lang.String getComments()
- Specified by:
getCommentsin interfaceConfigComment
-
doService
public final void doService(AdaptrisMessage msg) throws ServiceException
Description copied from interface:ServiceApply the service to the message.
- Specified by:
doServicein interfaceService- Parameters:
msg- theAdaptrisMessageto process- Throws:
ServiceException- wrapping any underlyingExceptions
-
applyServices
protected abstract void applyServices(AdaptrisMessage msg) throws ServiceException
Apply the required services to the message.- Parameters:
msg- the message- Throws:
ServiceException- wrapping any underlying exception.
-
init
public final void init() throws CoreExceptionDescription copied from interface:ComponentLifecycleInitialises the component.Component initialisation includes config verification, creation of connections etc.
- Specified by:
initin interfaceComponentLifecycle- Throws:
CoreException- wrapping any underlyingExceptions
-
doInit
protected abstract void doInit() throws CoreExceptionStart any additional components.- Throws:
CoreException- wrapping any underlying exception
-
start
public final void start() throws CoreExceptionDescription copied from interface:ComponentLifecycleStarts the component.Once a component is started it should be ready to process messages. In the case of
AdaptrisMessageConsumer, calling start will begin message delivery.- Specified by:
startin interfaceComponentLifecycle- Throws:
CoreException- wrapping any underlyingExceptions
-
doStart
protected abstract void doStart() throws CoreExceptionStart any additional components.- Throws:
CoreException- wrapping any underlying exception
-
stop
public final void stop()
Description copied from interface:ComponentLifecycleStop the componentA stopped component is not expected to be ready to process messages. In the case of
AdaptrisMessageConsumer, calling stop will pause message delivery. Throwing aRuntimeExceptionmay cause unintended consequences- Specified by:
stopin interfaceComponentLifecycle
-
doStop
protected abstract void doStop()
Stop any additional components.
-
close
public final void close()
Description copied from interface:ComponentLifecycleCloses the component.A closed component should release any connections it uses, etc. and clean up completely. Throwing a
RuntimeExceptionmay cause unintended consequences- Specified by:
closein interfaceComponentLifecycle
-
doClose
protected abstract void doClose()
Close any additional components.
-
changeState
public void changeState(ComponentState newState)
Updates the state for the component
ComponentState.- Specified by:
changeStatein interfaceStateManagedComponent
-
retrieveComponentState
public ComponentState retrieveComponentState()
Returns the last record
ComponentState.- Specified by:
retrieveComponentStatein interfaceStateManagedComponent- Returns:
- the current
ComponentState
-
requestInit
public void requestInit() throws CoreExceptionRequest this component is init'd.
- Specified by:
requestInitin interfaceStateManagedComponent- Throws:
CoreException- wrapping any underlying Exceptions
-
requestStart
public void requestStart() throws CoreExceptionRequest this component is started.
- Specified by:
requestStartin interfaceStateManagedComponent- Throws:
CoreException- wrapping any underlying Exceptions
-
requestStop
public void requestStop()
Request this component is stopped.
- Specified by:
requestStopin interfaceStateManagedComponent
-
requestClose
public void requestClose()
Request this component is closed.
- Specified by:
requestClosein interfaceStateManagedComponent
-
prepare
public void prepare() throws CoreExceptionDescription copied from interface:ComponentLifecycleExtensionPrepare for initialisation.- Specified by:
preparein interfaceComponentLifecycleExtension- Throws:
CoreException
-
handleException
public void handleException(Service service, AdaptrisMessage msg, java.lang.Exception e) throws ServiceException
Description copied from interface:ServiceCollectionHandles any exceptions thrown from an embedded Service.
- Specified by:
handleExceptionin interfaceServiceCollection- Parameters:
service- service which threw the Exceptionmsg- the message which caused the exceptione- the exception which was thrown- Throws:
ServiceException- wrapping the exception ifService.continueOnFailure()is false
-
getRestartAffectedServiceOnException
public java.lang.Boolean getRestartAffectedServiceOnException()
-
setRestartAffectedServiceOnException
public void setRestartAffectedServiceOnException(java.lang.Boolean b)
Whether to restart the service that threw theServiceExceptionduring processing.- Parameters:
b- true to restart affected services, default false
-
add
public boolean add(Service service)
-
iterator
public java.util.Iterator<Service> iterator()
-
size
public int size()
-
add
public void add(int index, Service element)- Specified by:
addin interfacejava.util.List<Service>
-
addAll
public boolean addAll(java.util.Collection<? extends Service> c)
-
addAll
public boolean addAll(int index, java.util.Collection<? extends Service> c)- Specified by:
addAllin interfacejava.util.List<Service>
-
indexOf
public int indexOf(java.lang.Object o)
- Specified by:
indexOfin interfacejava.util.List<Service>
-
lastIndexOf
public int lastIndexOf(java.lang.Object o)
- Specified by:
lastIndexOfin interfacejava.util.List<Service>
-
listIterator
public java.util.ListIterator<Service> listIterator()
- Specified by:
listIteratorin interfacejava.util.List<Service>
-
listIterator
public java.util.ListIterator<Service> listIterator(int index)
- Specified by:
listIteratorin interfacejava.util.List<Service>
-
set
public Service set(int index, Service element)
- Specified by:
setin interfacejava.util.List<Service>
-
subList
public java.util.List<Service> subList(int fromIndex, int toIndex)
- Specified by:
subListin interfacejava.util.List<Service>
-
clear
public void clear()
-
enforceRequirements
protected Service enforceRequirements(Service service)
Enforce any requirements of the list.- Parameters:
service- the service due to be added.- Returns:
- the service
- Throws:
java.lang.IllegalArgumentException- if the requirements are not met
-
enforceRequirements
protected java.util.Collection<? extends Service> enforceRequirements(java.util.Collection<? extends Service> collection)
Enforce any requirements of the list.- Parameters:
collection- the services due to be added.- Returns:
- the collection
- Throws:
java.lang.IllegalArgumentException- if the requirements are not met
-
getOutOfStateHandler
public OutOfStateHandler getOutOfStateHandler()
-
setOutOfStateHandler
public void setOutOfStateHandler(OutOfStateHandler handler)
Set the behaviour when internal services are not in the correct state.- Parameters:
handler- if not specified defaults toRaiseExceptionOutOfStateHandler.
-
withServices
public <T extends ServiceCollection> T withServices(Service... services)
-
-