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
ServiceCollection
s.
-
-
Field Summary
Fields Modifier and Type Field Description protected EventHandler
eventHandler
protected org.slf4j.Logger
log
-
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 void
add(int index, Service element)
boolean
add(Service service)
boolean
addAll(int index, java.util.Collection<? extends Service> c)
boolean
addAll(java.util.Collection<? extends Service> c)
void
addService(Service service)
Adds aService
to the end of the configuredList
.protected abstract void
applyServices(AdaptrisMessage msg)
Apply the required services to the message.void
changeState(ComponentState newState)
Updates the state for the componentComponentState
.void
clear()
void
close()
Closes the component.boolean
continueOnFailure()
If true containers should continue and apply the next configuredService
even if thisService
throws anException
.java.lang.String
createName()
Create a name for anyMleMarker
that is generated.java.lang.String
createQualifier()
Create a qualifier for anyMleMarker
that is generated.protected abstract void
doClose()
Close any additional components.protected abstract void
doInit()
Start any additional components.void
doService(AdaptrisMessage msg)
Apply the service to the message.protected abstract void
doStart()
Start any additional components.protected abstract void
doStop()
Stop any additional components.protected Service
enforceRequirements(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.Service
get(int index)
java.lang.String
getComments()
java.lang.Boolean
getContinueOnFail()
java.lang.Boolean
getIsTrackingEndpoint()
OutOfStateHandler
getOutOfStateHandler()
java.lang.Boolean
getRestartAffectedServiceOnException()
java.util.List<Service>
getServices()
Returns the configuredList
ofService
s.java.lang.String
getUniqueId()
Get the unique-id that is associated with this component.void
handleException(Service service, AdaptrisMessage msg, java.lang.Exception e)
Handles any exceptions thrown from an embedded Service.int
indexOf(java.lang.Object o)
void
init()
Initialises the component.boolean
isBranching()
Returns true if the implementation supports branching.boolean
isTrackingEndpoint()
Returns true if this should be considered an 'end-point' for tracking purposes, otherwise false.java.util.Iterator<Service>
iterator()
int
lastIndexOf(java.lang.Object o)
java.util.ListIterator<Service>
listIterator()
java.util.ListIterator<Service>
listIterator(int index)
void
prepare()
Prepare for initialisation.void
registerEventHandler(EventHandler eh)
Register the current event handler against this component.Service
remove(int index)
void
requestClose()
Request this component is closed.void
requestInit()
Request this component is init'd.void
requestStart()
Request this component is started.void
requestStop()
Request this component is stopped.ComponentState
retrieveComponentState()
Returns the last recordComponentState
.Service
set(int index, Service element)
void
setComments(java.lang.String s)
void
setContinueOnFail(java.lang.Boolean b)
void
setIsTrackingEndpoint(java.lang.Boolean b)
void
setOutOfStateHandler(OutOfStateHandler handler)
Set the behaviour when internal services are not in the correct state.void
setRestartAffectedServiceOnException(java.lang.Boolean b)
Whether to restart the service that threw theServiceException
during processing.void
setServices(java.util.List<Service> serviceList)
Override the underlying service list.void
setUniqueId(java.lang.String s)
Sets the unique identifier for thisService
.int
size()
void
start()
Starts the component.void
stop()
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:EventHandlerAware
Register the current event handler against this component.- Specified by:
registerEventHandler
in interfaceEventHandlerAware
- Parameters:
eh
- the event handler currently in use.
-
createName
public java.lang.String createName()
Description copied from interface:MessageEventGenerator
Create a name for anyMleMarker
that is generated.The default implementation is to return the classname of the component in question.
* @return the name for anyMleMarker
that is generated.- Specified by:
createName
in interfaceMessageEventGenerator
-
createQualifier
public java.lang.String createQualifier()
Description copied from interface:MessageEventGenerator
Create a qualifier for anyMleMarker
that 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:
createQualifier
in interfaceMessageEventGenerator
- Returns:
- the qualifier for any
MleMarker
that is generated.
-
getUniqueId
public java.lang.String getUniqueId()
Description copied from interface:AdaptrisComponent
Get the unique-id that is associated with this component.- Specified by:
getUniqueId
in interfaceAdaptrisComponent
- Returns:
- the unique-id
-
setUniqueId
public void setUniqueId(java.lang.String s)
Description copied from interface:Service
Sets the unique identifier for this
Service
. These unique identifiers are optional but maybe required by some implementations ofServiceCollection
.- Specified by:
setUniqueId
in interfaceService
- Parameters:
s
- thisService
's unique identifier
-
isBranching
public boolean isBranching()
Description copied from interface:Service
Returns true if the implementation supports branching.
- Specified by:
isBranching
in interfaceService
- Returns:
- true if the implementation supports branching
- See Also:
BranchingServiceCollection
-
continueOnFailure
public boolean continueOnFailure()
Description copied from interface:Service
If true containers should continue and apply the next configured
Service
even if thisService
throws anException
.- Specified by:
continueOnFailure
in 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:MessageEventGenerator
Returns true if this should be considered an 'end-point' for tracking purposes, otherwise false.
- Specified by:
isTrackingEndpoint
in 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
Service
to the end of the configuredList
.- Specified by:
addService
in interfaceServiceCollection
- Parameters:
service
- theService
to add to the end of the configuredList
may not be null
-
getServices
public java.util.List<Service> getServices()
Returns the configured
List
ofService
s. May be empty but not null.- Specified by:
getServices
in interfaceServiceCollection
- Returns:
- the configured
List
ofService
s
-
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:
setComments
in interfaceConfigComment
-
getComments
public java.lang.String getComments()
- Specified by:
getComments
in interfaceConfigComment
-
doService
public final void doService(AdaptrisMessage msg) throws ServiceException
Description copied from interface:Service
Apply the service to the message.
- Specified by:
doService
in interfaceService
- Parameters:
msg
- theAdaptrisMessage
to process- Throws:
ServiceException
- wrapping any underlyingException
s
-
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 CoreException
Description copied from interface:ComponentLifecycle
Initialises the component.Component initialisation includes config verification, creation of connections etc.
- Specified by:
init
in interfaceComponentLifecycle
- Throws:
CoreException
- wrapping any underlyingException
s
-
doInit
protected abstract void doInit() throws CoreException
Start any additional components.- Throws:
CoreException
- wrapping any underlying exception
-
start
public final void start() throws CoreException
Description copied from interface:ComponentLifecycle
Starts 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:
start
in interfaceComponentLifecycle
- Throws:
CoreException
- wrapping any underlyingException
s
-
doStart
protected abstract void doStart() throws CoreException
Start any additional components.- Throws:
CoreException
- wrapping any underlying exception
-
stop
public final void stop()
Description copied from interface:ComponentLifecycle
Stop 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 aRuntimeException
may cause unintended consequences- Specified by:
stop
in interfaceComponentLifecycle
-
doStop
protected abstract void doStop()
Stop any additional components.
-
close
public final void close()
Description copied from interface:ComponentLifecycle
Closes the component.A closed component should release any connections it uses, etc. and clean up completely. Throwing a
RuntimeException
may cause unintended consequences- Specified by:
close
in 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:
changeState
in interfaceStateManagedComponent
-
retrieveComponentState
public ComponentState retrieveComponentState()
Returns the last record
ComponentState
.- Specified by:
retrieveComponentState
in interfaceStateManagedComponent
- Returns:
- the current
ComponentState
-
requestInit
public void requestInit() throws CoreException
Request this component is init'd.
- Specified by:
requestInit
in interfaceStateManagedComponent
- Throws:
CoreException
- wrapping any underlying Exceptions
-
requestStart
public void requestStart() throws CoreException
Request this component is started.
- Specified by:
requestStart
in interfaceStateManagedComponent
- Throws:
CoreException
- wrapping any underlying Exceptions
-
requestStop
public void requestStop()
Request this component is stopped.
- Specified by:
requestStop
in interfaceStateManagedComponent
-
requestClose
public void requestClose()
Request this component is closed.
- Specified by:
requestClose
in interfaceStateManagedComponent
-
prepare
public void prepare() throws CoreException
Description copied from interface:ComponentLifecycleExtension
Prepare for initialisation.- Specified by:
prepare
in interfaceComponentLifecycleExtension
- Throws:
CoreException
-
handleException
public void handleException(Service service, AdaptrisMessage msg, java.lang.Exception e) throws ServiceException
Description copied from interface:ServiceCollection
Handles any exceptions thrown from an embedded Service.
- Specified by:
handleException
in 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 theServiceException
during 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:
add
in 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:
addAll
in interfacejava.util.List<Service>
-
indexOf
public int indexOf(java.lang.Object o)
- Specified by:
indexOf
in interfacejava.util.List<Service>
-
lastIndexOf
public int lastIndexOf(java.lang.Object o)
- Specified by:
lastIndexOf
in interfacejava.util.List<Service>
-
listIterator
public java.util.ListIterator<Service> listIterator()
- Specified by:
listIterator
in interfacejava.util.List<Service>
-
listIterator
public java.util.ListIterator<Service> listIterator(int index)
- Specified by:
listIterator
in interfacejava.util.List<Service>
-
set
public Service set(int index, Service element)
- Specified by:
set
in interfacejava.util.List<Service>
-
subList
public java.util.List<Service> subList(int fromIndex, int toIndex)
- Specified by:
subList
in 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)
-
-