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 BranchingServiceImpBranching
Serviceimplementation 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
ServiceExceptionis thrown. - If the value is set and has previously been received, the configured
nextServiceIdIfDuplicateis set on the message. - If the looked-up value is not contained in the store of previous values
nextServiceIdIfUniqueis 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.StringDEFAULT_SERVICE_ID_DUPLICATEDefault next Service ID to set if the message metadata value does appear in the store of previously received values.static java.lang.StringDEFAULT_SERVICE_ID_UNIQUEDefault 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 voidcloseService()voiddoService(AdaptrisMessage msg)Apply the service to the message.java.lang.StringgetMetadataKeyToCheck()Returns the metadata key whose value should be checked.java.lang.StringgetNextServiceIdIfDuplicate()Returns the ID of the nextServiceto apply if the metadata exists if the store of previous values.java.lang.StringgetNextServiceIdIfUnique()Returns the ID of the nextServiceto apply if the metadata does not exist if the store of previous values.intgetNumberOfPreviousValuesToStore()Returns the number of previous values to keep.java.lang.StringgetStoreFileUrl()Returns the persistent store for previously received values in the form of a file URL.protected voidinitService()voidprepare()Prepare for initialisation.voidsetMetadataKeyToCheck(java.lang.String s)Sets the metadata key whose value should be checked.voidsetNextServiceIdIfDuplicate(java.lang.String s)Sets the ID of the nextServiceto apply if the metadata exists if the store of previous values.voidsetNextServiceIdIfUnique(java.lang.String s)Sets the ID of the nextServiceto apply if the metadata does not exist if the store of previous values.voidsetNumberOfPreviousValuesToStore(int i)Sets the number of previous values to keep.voidsetStoreFileUrl(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:
initServicein classServiceImp- Throws:
CoreException
-
closeService
protected void closeService()
- Specified by:
closeServicein classServiceImp
-
doService
public void doService(AdaptrisMessage msg) throws ServiceException
Description copied from interface:ServiceApply the service to the message.
- Parameters:
msg- theAdaptrisMessageto process- Throws:
ServiceException- wrapping any underlyingExceptions- 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
Serviceto apply if the metadata exists if the store of previous values.- Returns:
- the ID of the next
Serviceto 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
Serviceto apply if the metadata exists if the store of previous values. May not be null or empty.- Parameters:
s- the ID of the nextServiceto apply if the metadata exists if the store of previous values
-
getNextServiceIdIfUnique
public java.lang.String getNextServiceIdIfUnique()
Returns the ID of the next
Serviceto apply if the metadata does not exist if the store of previous values.- Returns:
- the ID of the next
Serviceto 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
Serviceto 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 nextServiceto apply if the metadata does not exist if the store of previous values
-
prepare
public void prepare() throws CoreExceptionDescription copied from interface:ComponentLifecycleExtensionPrepare for initialisation.- Throws:
CoreException
-
-