@ComponentProfile(summary="Perform a branch by checking a metadata key and comparing it against a list of previously received values", tag="service,branching", branchSelector=true) public class CheckUniqueMetadataValueService extends BranchingServiceImp
Branching Service
implementation which checks the value stored against a configured metadata key against a list of
previously received values.
The service obeys the following rules when checking the metadata key
ServiceException
is thrown.nextServiceIdIfDuplicate
is set on the
message.nextServiceIdIfUnique
is set and the
value is added to this store for future checking.The store of previous values has a configurable maximum size. After a new value is added, if the store exceeds the maximum size the oldest value is removed. The store is then persisted to the configured store file.
In the adapter configuration file this class is aliased as check-unique-metadata-value-service which is the preferred alternative to the fully qualified classname when building your configuration.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_SERVICE_ID_DUPLICATE
Default next Service ID to set if the message metadata value does
appear in the store of previously received values.
|
static java.lang.String |
DEFAULT_SERVICE_ID_UNIQUE
Default next Service ID to set if the message metadata value does not
appear in the store of previously received values.
|
log
CONFIRMATION_ID_KEY
Constructor and Description |
---|
CheckUniqueMetadataValueService()
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
protected void |
closeService() |
void |
doService(AdaptrisMessage msg)
Apply the service to the message.
|
java.lang.String |
getMetadataKeyToCheck()
Returns the metadata key whose value should be checked.
|
java.lang.String |
getNextServiceIdIfDuplicate()
Returns the ID of the next
Service to apply if the metadata
exists if the store of previous values. |
java.lang.String |
getNextServiceIdIfUnique()
Returns the ID of the next
Service to apply if the metadata
does not exist if the store of previous values. |
int |
getNumberOfPreviousValuesToStore()
Returns the number of previous values to keep.
|
java.lang.String |
getStoreFileUrl()
Returns the persistent store for previously received values in the form of
a file URL.
|
protected void |
initService() |
void |
prepare()
Prepare for initialisation.
|
void |
setMetadataKeyToCheck(java.lang.String s)
Sets the metadata key whose value should be checked.
|
void |
setNextServiceIdIfDuplicate(java.lang.String s)
Sets the ID of the next
Service to apply if the metadata
exists if the store of previous values. |
void |
setNextServiceIdIfUnique(java.lang.String s)
Sets the ID of the next
Service to apply if the metadata does
not exist if the store of previous values. |
void |
setNumberOfPreviousValuesToStore(int i)
Sets the number of previous values to keep.
|
void |
setStoreFileUrl(java.lang.String s)
Sets the persistent store for previously received values in the form of a
file URL.
|
isBranching
changeState, close, continueOnFailure, createName, createQualifier, getContinueOnFail, getIsTrackingEndpoint, getLookupName, getUniqueId, init, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, setContinueOnFail, setIsTrackingEndpoint, setLookupName, setUniqueId, start, stop
public static final java.lang.String DEFAULT_SERVICE_ID_UNIQUE
Default next Service ID to set if the message metadata value does not appear in the store of previously received values.
public static final java.lang.String DEFAULT_SERVICE_ID_DUPLICATE
Default next Service ID to set if the message metadata value does appear in the store of previously received values.
public CheckUniqueMetadataValueService()
Creates a new instance. Default history size is 1000.
protected void initService() throws CoreException
initService
in class ServiceImp
CoreException
protected void closeService()
closeService
in class ServiceImp
public void doService(AdaptrisMessage msg) throws ServiceException
Service
Apply the service to the message.
msg
- the AdaptrisMessage
to processServiceException
- wrapping any underlying Exception
s#doService(com.adaptris.core.AdaptrisMessage)
public java.lang.String getMetadataKeyToCheck()
Returns the metadata key whose value should be checked.
public void setMetadataKeyToCheck(java.lang.String s)
Sets the metadata key whose value should be checked. May not be null.
s
- the metadata key whose value should be checkedpublic int getNumberOfPreviousValuesToStore()
Returns the number of previous values to keep.
public void setNumberOfPreviousValuesToStore(int i)
Sets the number of previous values to keep. Must be greater than 0.
i
- the number of previous values to keeppublic java.lang.String getStoreFileUrl()
Returns the persistent store for previously received values in the form of
a file URL. E.g. file:////Users/adaptris/store.dat/
.
public void setStoreFileUrl(java.lang.String s)
Sets the persistent store for previously received values in the form of a
file URL. E.g. file:////Users/adaptris/store.dat
. May not be
null or empty.
s
- the persistent store for previously received values in the form of
a file URLpublic java.lang.String getNextServiceIdIfDuplicate()
Returns the ID of the next Service
to apply if the metadata
exists if the store of previous values.
Service
to apply if the metadata
exists if the store of previous valuespublic void setNextServiceIdIfDuplicate(java.lang.String s)
Sets the ID of the next Service
to apply if the metadata
exists if the store of previous values. May not be null or empty.
s
- the ID of the next Service
to apply if the metadata
exists if the store of previous valuespublic java.lang.String getNextServiceIdIfUnique()
Returns the ID of the next Service
to apply if the metadata
does not exist if the store of previous values.
Service
to apply if the metadata
does not exist if the store of previous valuespublic void setNextServiceIdIfUnique(java.lang.String s)
Sets the ID of the next Service
to apply if the metadata does
not exist if the store of previous values. May not be null or empty.
s
- the ID of the next Service
to apply if the metadata
does not exist if the store of previous valuespublic void prepare() throws CoreException
ComponentLifecycleExtension
CoreException