@ComponentProfile(summary="Set Metadata based on whether the message is considered a duplicate or not", tag="service,duplicate") public class DuplicateMessageRoutingService extends ServiceImp
Class which checks the value of a configured metadata key against a list of previously received values. If the value appears in
the list, the value of getDuplicateDestination
is stored against the value of getDestinationKey
, if it
does not the value of getUniqueDestination
is used.
This class should really just set an isDuplicate
metadata key to true and leave the destination selection to
MetadataBranchingService
.
In the adapter configuration file this class is aliased as duplicate-message-routing-service which is the preferred alternative to the fully qualified classname when building your configuration.
Modifier and Type | Class and Description |
---|---|
protected static interface |
DuplicateMessageRoutingService.Operator |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_CHECK_KEY
Metadata key against which the value to check for uniqueness is stored.
|
log
Constructor and Description |
---|
DuplicateMessageRoutingService() |
Modifier and Type | Method and Description |
---|---|
protected void |
closeService() |
void |
doService(AdaptrisMessage msg)
Method which checks to see if the message is unique (based on a metadata
element) and sets a new metadata element with a value which is dependant
upon the uniqueness or otherwise of the received element.
|
java.lang.String |
getConfigLocation()
Gets the location for the file that will contain the persisted list of
received ids.
|
java.lang.String |
getDestinationKey()
Gets the Key for the output MetadataElement which will contain the output
destination.
|
java.lang.String |
getDuplicateDestination()
Sets the output destination String which will be stored as the value of the
MetadataElement if the id is not unique.
|
int |
getHistorySize()
Gets the number of elements to keep in the previously received IDs list.
|
java.lang.String |
getKeyToCheck()
Gets the key for the MetadataElement to check for uniqueness.
|
java.lang.String |
getUniqueDestination()
Gets the output destination String which will be stored as the value of the
MetadataElement if the id is unique.
|
protected void |
initService() |
void |
prepare()
Prepare for initialisation.
|
void |
setConfigLocation(java.lang.String s)
Sets the location for the file that will contain the persisted list of
received ids.
|
void |
setDestinationKey(java.lang.String key)
Sets the Key for the output MetadataElement which will contain the output
destination.
|
void |
setDuplicateDestination(java.lang.String destination)
Sets the output destination String which will be stored as the value of the
MetadataElement if the id is not unique.
|
void |
setHistorySize(int i)
Sets the number of elements to keep in the previously received IDs list.
|
void |
setKeyToCheck(java.lang.String key)
Sets the key for the MetadataElement to check for uniqueness.
|
void |
setUniqueDestination(java.lang.String destination)
Sets the output destination String which will be stored as the value of the
MetadataElement if the id is unique.
|
void |
start()
Starts the component.
|
void |
stop()
Stop the component
|
protected static void |
tryAndLog(java.lang.String logMsg,
DuplicateMessageRoutingService.Operator l) |
protected static void |
tryAndWrap(DuplicateMessageRoutingService.Operator l) |
changeState, close, continueOnFailure, createName, createQualifier, getContinueOnFail, getIsTrackingEndpoint, getUniqueId, init, isBranching, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, setContinueOnFail, setIsTrackingEndpoint, setUniqueId
public static final java.lang.String DEFAULT_CHECK_KEY
Metadata key against which the value to check for uniqueness is stored.
public void setHistorySize(int i)
Sets the number of elements to keep in the previously received IDs list. Default is 100
i
- the number of message ids to retainpublic int getHistorySize()
Gets the number of elements to keep in the previously received IDs list. Default is 100
public void setKeyToCheck(java.lang.String key)
Sets the key for the MetadataElement to check for uniqueness. Default is "DuplicateCheck".
key
- the Key to checkpublic java.lang.String getKeyToCheck()
Gets the key for the MetadataElement to check for uniqueness.
public void setConfigLocation(java.lang.String s)
Sets the location for the file that will contain the persisted list of received ids.
s
- a URI which must be in the form "file:///filepath"public java.lang.String getConfigLocation()
Gets the location for the file that will contain the persisted list of received ids.
public void setDestinationKey(java.lang.String key)
Sets the Key for the output MetadataElement which will contain the output destination.
key
- the Key to set againstpublic java.lang.String getDestinationKey()
Gets the Key for the output MetadataElement which will contain the output destination.
public void setUniqueDestination(java.lang.String destination)
Sets the output destination String which will be stored as the value of the MetadataElement if the id is unique.
destination
- the String to set on the output MetadataElementpublic java.lang.String getUniqueDestination()
Gets the output destination String which will be stored as the value of the MetadataElement if the id is unique.
public void setDuplicateDestination(java.lang.String destination)
Sets the output destination String which will be stored as the value of the MetadataElement if the id is not unique.
destination
- the String to set on the output MetadataElementpublic java.lang.String getDuplicateDestination()
Sets the output destination String which will be stored as the value of the MetadataElement if the id is not unique.
public void doService(AdaptrisMessage msg) throws ServiceException
Method which checks to see if the message is unique (based on a metadata element) and sets a new metadata element with a value which is dependant upon the uniqueness or otherwise of the received element.
msg
- the input AdaptrisMessageServiceException
- wrapping any underlying Exceptionprotected void initService() throws CoreException
initService
in class ServiceImp
CoreException
protected void closeService()
closeService
in class ServiceImp
public 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
start
in class ServiceImp
CoreException
- wrapping any underlying Exception
spublic 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
stop
in class ServiceImp
public void prepare() throws CoreException
ComponentLifecycleExtension
CoreException
protected static void tryAndLog(java.lang.String logMsg, DuplicateMessageRoutingService.Operator l)
protected static void tryAndWrap(DuplicateMessageRoutingService.Operator l) throws CoreException
CoreException