public abstract class ServiceCollectionImp extends java.util.AbstractCollection<Service> implements Service, ServiceCollection
Behaviour common to ServiceCollection
s.
Modifier and Type | Field and Description |
---|---|
protected EventHandler |
eventHandler |
protected org.slf4j.Logger |
log |
Constructor and Description |
---|
ServiceCollectionImp() |
ServiceCollectionImp(java.util.Collection<Service> list) |
Modifier and Type | Method and Description |
---|---|
void |
add(int index,
Service element) |
boolean |
add(Service service) |
boolean |
addAll(java.util.Collection<? extends Service> c) |
boolean |
addAll(int index,
java.util.Collection<? extends Service> c) |
void |
addService(Service service)
Adds a
Service to the end of the configured List . |
protected abstract void |
applyServices(AdaptrisMessage msg)
Apply the required services to the message.
|
void |
changeState(ComponentState newState)
Updates the state for the component
ComponentState . |
void |
clear() |
void |
close()
Closes the component.
|
boolean |
continueOnFailure()
If true containers should continue and apply the next configured
Service even if this Service throws an
Exception . |
java.lang.String |
createName()
Create a name for any
MleMarker that is generated. |
java.lang.String |
createQualifier()
Create a qualifier for any
MleMarker 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 java.util.Collection<? extends Service> |
enforceRequirements(java.util.Collection<? extends Service> collection)
Enforce any requirements of the list.
|
protected Service |
enforceRequirements(Service service)
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 configured
List of Service 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 record
ComponentState . |
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 the
ServiceException 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 this
Service . |
int |
size() |
void |
start()
Starts the component.
|
void |
stop()
Stop the component
|
java.util.List<Service> |
subList(int fromIndex,
int toIndex) |
<T extends ServiceCollection> |
withServices(Service... services) |
contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
protected transient org.slf4j.Logger log
protected transient EventHandler eventHandler
public ServiceCollectionImp()
public ServiceCollectionImp(java.util.Collection<Service> list)
public void registerEventHandler(EventHandler eh)
EventHandlerAware
registerEventHandler
in interface EventHandlerAware
eh
- the event handler currently in use.public java.lang.String createName()
MessageEventGenerator
MleMarker
that is generated.
The default implementation is to return the classname of the component in question.
* @return the name for anyMleMarker
that is generated.createName
in interface MessageEventGenerator
public java.lang.String createQualifier()
MessageEventGenerator
MleMarker
that is generated.
The default implementation is to return the unique-id of the component in question, or the empty string if not configured
createQualifier
in interface MessageEventGenerator
MleMarker
that is generated.public java.lang.String getUniqueId()
AdaptrisComponent
getUniqueId
in interface AdaptrisComponent
public void setUniqueId(java.lang.String s)
Service
Sets the unique identifier for this Service
. These unique
identifiers are optional but maybe required by some implementations of
ServiceCollection
.
setUniqueId
in interface Service
s
- this Service
's unique identifierpublic boolean isBranching()
Service
Returns true if the implementation supports branching.
isBranching
in interface Service
BranchingServiceCollection
public boolean continueOnFailure()
Service
If true containers should continue and apply the next configured
Service
even if this Service
throws an
Exception
.
continueOnFailure
in interface Service
public java.lang.Boolean getContinueOnFail()
Service.continueOnFailure()
public void setContinueOnFail(java.lang.Boolean b)
public java.lang.Boolean getIsTrackingEndpoint()
public void setIsTrackingEndpoint(java.lang.Boolean b)
public boolean isTrackingEndpoint()
MessageEventGenerator
Returns true if this should be considered an 'end-point' for tracking purposes, otherwise false.
isTrackingEndpoint
in interface MessageEventGenerator
MessageEventGenerator.isTrackingEndpoint()
public void addService(Service service)
Adds a Service
to the end of the configured List
.
addService
in interface ServiceCollection
service
- the Service
to add to the end of the configured List
may not be nullpublic java.util.List<Service> getServices()
Returns the configured List
of Service
s. May be empty but not null.
getServices
in interface ServiceCollection
List
of Service
spublic void setServices(java.util.List<Service> serviceList)
serviceList
- the service list.public void setComments(java.lang.String s)
setComments
in interface ConfigComment
public java.lang.String getComments()
getComments
in interface ConfigComment
public final void doService(AdaptrisMessage msg) throws ServiceException
Service
Apply the service to the message.
doService
in interface Service
msg
- the AdaptrisMessage
to processServiceException
- wrapping any underlying Exception
sprotected abstract void applyServices(AdaptrisMessage msg) throws ServiceException
msg
- the messageServiceException
- wrapping any underlying exception.public final void init() throws CoreException
ComponentLifecycle
Component initialisation includes config verification, creation of connections etc.
init
in interface ComponentLifecycle
CoreException
- wrapping any underlying Exception
sprotected abstract void doInit() throws CoreException
CoreException
- wrapping any underlying exceptionpublic final void start() throws CoreException
ComponentLifecycle
Once a component is started it should be ready to process messages. In the case of AdaptrisMessageConsumer
, calling start
will begin message delivery.
start
in interface ComponentLifecycle
CoreException
- wrapping any underlying Exception
sprotected abstract void doStart() throws CoreException
CoreException
- wrapping any underlying exceptionpublic final void stop()
ComponentLifecycle
A stopped component is not expected to be ready to process messages. In the case of AdaptrisMessageConsumer
, calling stop
will pause message delivery. Throwing a RuntimeException
may cause unintended consequences
stop
in interface ComponentLifecycle
protected abstract void doStop()
public final void close()
ComponentLifecycle
A closed component should release any connections it uses, etc. and clean up completely. Throwing a RuntimeException
may
cause unintended consequences
close
in interface ComponentLifecycle
protected abstract void doClose()
public void changeState(ComponentState newState)
Updates the state for the component ComponentState
.
changeState
in interface StateManagedComponent
public ComponentState retrieveComponentState()
Returns the last record ComponentState
.
retrieveComponentState
in interface StateManagedComponent
ComponentState
public void requestInit() throws CoreException
Request this component is init'd.
requestInit
in interface StateManagedComponent
CoreException
- wrapping any underlying Exceptionspublic void requestStart() throws CoreException
Request this component is started.
requestStart
in interface StateManagedComponent
CoreException
- wrapping any underlying Exceptionspublic void requestStop()
Request this component is stopped.
requestStop
in interface StateManagedComponent
public void requestClose()
Request this component is closed.
requestClose
in interface StateManagedComponent
public void prepare() throws CoreException
ComponentLifecycleExtension
prepare
in interface ComponentLifecycleExtension
CoreException
public void handleException(Service service, AdaptrisMessage msg, java.lang.Exception e) throws ServiceException
ServiceCollection
Handles any exceptions thrown from an embedded Service.
handleException
in interface ServiceCollection
service
- service which threw the Exceptionmsg
- the message which caused the exceptione
- the exception which was thrownServiceException
- wrapping the exception if
Service.continueOnFailure()
is falsepublic java.lang.Boolean getRestartAffectedServiceOnException()
public void setRestartAffectedServiceOnException(java.lang.Boolean b)
ServiceException
during processing.b
- true to restart affected services, default falsepublic boolean add(Service service)
public java.util.Iterator<Service> iterator()
public int size()
public void add(int index, Service element)
add
in interface java.util.List<Service>
public boolean addAll(java.util.Collection<? extends Service> c)
public boolean addAll(int index, java.util.Collection<? extends Service> c)
addAll
in interface java.util.List<Service>
public int indexOf(java.lang.Object o)
indexOf
in interface java.util.List<Service>
public int lastIndexOf(java.lang.Object o)
lastIndexOf
in interface java.util.List<Service>
public java.util.ListIterator<Service> listIterator()
listIterator
in interface java.util.List<Service>
public java.util.ListIterator<Service> listIterator(int index)
listIterator
in interface java.util.List<Service>
public Service set(int index, Service element)
set
in interface java.util.List<Service>
public java.util.List<Service> subList(int fromIndex, int toIndex)
subList
in interface java.util.List<Service>
public void clear()
protected Service enforceRequirements(Service service)
service
- the service due to be added.java.lang.IllegalArgumentException
- if the requirements are not metprotected java.util.Collection<? extends Service> enforceRequirements(java.util.Collection<? extends Service> collection)
collection
- the services due to be added.java.lang.IllegalArgumentException
- if the requirements are not metpublic OutOfStateHandler getOutOfStateHandler()
public void setOutOfStateHandler(OutOfStateHandler handler)
handler
- if not specified defaults to RaiseExceptionOutOfStateHandler
.public <T extends ServiceCollection> T withServices(Service... services)