Class CheckUniqueMetadataValueService
- java.lang.Object
-
- com.adaptris.core.ServiceImp
-
- com.adaptris.core.BranchingServiceImp
-
- com.adaptris.core.services.metadata.CheckUniqueMetadataValueService
-
- All Implemented Interfaces:
AdaptrisComponent
,ComponentLifecycle
,ComponentLifecycleExtension
,MessageEventGenerator
,Service
,StateManagedComponent
@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
- If the looked-up value is null or empty, a
ServiceException
is thrown. - If the value is set and has previously been received, the configured
nextServiceIdIfDuplicate
is set on the message. - If the looked-up value is not contained in the store of previous values
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.
-
-
Field Summary
Fields Modifier and Type Field 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.-
Fields inherited from class com.adaptris.core.ServiceImp
log
-
-
Constructor Summary
Constructors Constructor Description CheckUniqueMetadataValueService()
Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 nextService
to apply if the metadata exists if the store of previous values.java.lang.String
getNextServiceIdIfUnique()
Returns the ID of the nextService
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 nextService
to apply if the metadata exists if the store of previous values.void
setNextServiceIdIfUnique(java.lang.String s)
Sets the ID of the nextService
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.-
Methods inherited from class com.adaptris.core.BranchingServiceImp
isBranching
-
Methods inherited from class com.adaptris.core.ServiceImp
changeState, close, continueOnFailure, createName, createQualifier, getContinueOnFail, getIsTrackingEndpoint, getUniqueId, init, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, setContinueOnFail, setIsTrackingEndpoint, setUniqueId, start, stop
-
-
-
-
Field Detail
-
DEFAULT_SERVICE_ID_UNIQUE
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.
- See Also:
- Constant Field Values
-
DEFAULT_SERVICE_ID_DUPLICATE
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.
- See Also:
- Constant Field Values
-
-
Method Detail
-
initService
protected void initService() throws CoreException
- Specified by:
initService
in classServiceImp
- Throws:
CoreException
-
closeService
protected void closeService()
- Specified by:
closeService
in classServiceImp
-
doService
public void doService(AdaptrisMessage msg) throws ServiceException
Description copied from interface:Service
Apply the service to the message.
- Parameters:
msg
- theAdaptrisMessage
to process- Throws:
ServiceException
- wrapping any underlyingException
s- See Also:
#doService(com.adaptris.core.AdaptrisMessage)
-
getMetadataKeyToCheck
public java.lang.String getMetadataKeyToCheck()
Returns the metadata key whose value should be checked.
- Returns:
- metadataKey the metadata key whose value should be checked
-
setMetadataKeyToCheck
public void setMetadataKeyToCheck(java.lang.String s)
Sets the metadata key whose value should be checked. May not be null.
- Parameters:
s
- the metadata key whose value should be checked
-
getNumberOfPreviousValuesToStore
public int getNumberOfPreviousValuesToStore()
Returns the number of previous values to keep.
- Returns:
- the number of previous values to keep
-
setNumberOfPreviousValuesToStore
public void setNumberOfPreviousValuesToStore(int i)
Sets the number of previous values to keep. Must be greater than 0.
- Parameters:
i
- the number of previous values to keep
-
getStoreFileUrl
public 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/
.- Returns:
- the persistent store for previously received values in the form of a file URL
-
setStoreFileUrl
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.- Parameters:
s
- the persistent store for previously received values in the form of a file URL
-
getNextServiceIdIfDuplicate
public java.lang.String getNextServiceIdIfDuplicate()
Returns the ID of the next
Service
to apply if the metadata exists if the store of previous values.- Returns:
- the ID of the next
Service
to apply if the metadata exists if the store of previous values
-
setNextServiceIdIfDuplicate
public 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.- Parameters:
s
- the ID of the nextService
to apply if the metadata exists if the store of previous values
-
getNextServiceIdIfUnique
public 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.- Returns:
- the ID of the next
Service
to apply if the metadata does not exist if the store of previous values
-
setNextServiceIdIfUnique
public 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.- Parameters:
s
- the ID of the nextService
to apply if the metadata does not exist if the store of previous values
-
prepare
public void prepare() throws CoreException
Description copied from interface:ComponentLifecycleExtension
Prepare for initialisation.- Throws:
CoreException
-
-