Class DuplicateMessageRoutingService
- java.lang.Object
-
- com.adaptris.core.ServiceImp
-
- com.adaptris.core.services.duplicate.DuplicateMessageRoutingService
-
- All Implemented Interfaces:
AdaptrisComponent,ComponentLifecycle,ComponentLifecycleExtension,MessageEventGenerator,Service,StateManagedComponent
@ComponentProfile(summary="Set Metadata based on whether the message is considered a duplicate or not", tag="service,duplicate") public class DuplicateMessageRoutingService extends ServiceImpClass 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
getDuplicateDestinationis stored against the value ofgetDestinationKey, if it does not the value ofgetUniqueDestinationis used.This class should really just set an
isDuplicatemetadata key to true and leave the destination selection toMetadataBranchingService.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interfaceDuplicateMessageRoutingService.Operator
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_CHECK_KEYMetadata key against which the value to check for uniqueness is stored.-
Fields inherited from class com.adaptris.core.ServiceImp
log
-
-
Constructor Summary
Constructors Constructor Description DuplicateMessageRoutingService()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcloseService()voiddoService(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.StringgetConfigLocation()Gets the location for the file that will contain the persisted list of received ids.java.lang.StringgetDestinationKey()Gets the Key for the output MetadataElement which will contain the output destination.java.lang.StringgetDuplicateDestination()Sets the output destination String which will be stored as the value of the MetadataElement if the id is not unique.intgetHistorySize()Gets the number of elements to keep in the previously received IDs list.java.lang.StringgetKeyToCheck()Gets the key for the MetadataElement to check for uniqueness.java.lang.StringgetUniqueDestination()Gets the output destination String which will be stored as the value of the MetadataElement if the id is unique.protected voidinitService()voidprepare()Prepare for initialisation.voidsetConfigLocation(java.lang.String s)Sets the location for the file that will contain the persisted list of received ids.voidsetDestinationKey(java.lang.String key)Sets the Key for the output MetadataElement which will contain the output destination.voidsetDuplicateDestination(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.voidsetHistorySize(int i)Sets the number of elements to keep in the previously received IDs list.voidsetKeyToCheck(java.lang.String key)Sets the key for the MetadataElement to check for uniqueness.voidsetUniqueDestination(java.lang.String destination)Sets the output destination String which will be stored as the value of the MetadataElement if the id is unique.voidstart()Starts the component.voidstop()Stop the componentprotected static voidtryAndLog(java.lang.String logMsg, DuplicateMessageRoutingService.Operator l)protected static voidtryAndWrap(DuplicateMessageRoutingService.Operator l)-
Methods inherited from class com.adaptris.core.ServiceImp
changeState, close, continueOnFailure, createName, createQualifier, getContinueOnFail, getIsTrackingEndpoint, getUniqueId, init, isBranching, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, setContinueOnFail, setIsTrackingEndpoint, setUniqueId
-
-
-
-
Field Detail
-
DEFAULT_CHECK_KEY
public static final java.lang.String DEFAULT_CHECK_KEY
Metadata key against which the value to check for uniqueness is stored.
- See Also:
- Constant Field Values
-
-
Method Detail
-
setHistorySize
public void setHistorySize(int i)
Sets the number of elements to keep in the previously received IDs list. Default is 100
- Parameters:
i- the number of message ids to retain
-
getHistorySize
public int getHistorySize()
Gets the number of elements to keep in the previously received IDs list. Default is 100
- Returns:
- the number of message ids to retain
-
setKeyToCheck
public void setKeyToCheck(java.lang.String key)
Sets the key for the MetadataElement to check for uniqueness. Default is "DuplicateCheck".
- Parameters:
key- the Key to check
-
getKeyToCheck
public java.lang.String getKeyToCheck()
Gets the key for the MetadataElement to check for uniqueness.
- Returns:
- the Key to check
-
setConfigLocation
public void setConfigLocation(java.lang.String s)
Sets the location for the file that will contain the persisted list of received ids.
- Parameters:
s- a URI which must be in the form "file:///filepath"
-
getConfigLocation
public java.lang.String getConfigLocation()
Gets the location for the file that will contain the persisted list of received ids.
- Returns:
- the location of the file
-
setDestinationKey
public void setDestinationKey(java.lang.String key)
Sets the Key for the output MetadataElement which will contain the output destination.
- Parameters:
key- the Key to set against
-
getDestinationKey
public java.lang.String getDestinationKey()
Gets the Key for the output MetadataElement which will contain the output destination.
- Returns:
- the Key to set against
-
setUniqueDestination
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.
- Parameters:
destination- the String to set on the output MetadataElement
-
getUniqueDestination
public java.lang.String getUniqueDestination()
Gets the output destination String which will be stored as the value of the MetadataElement if the id is unique.
- Returns:
- the String to set on the output MetadataElement
-
setDuplicateDestination
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.
- Parameters:
destination- the String to set on the output MetadataElement
-
getDuplicateDestination
public 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.
- Returns:
- the String to set on the output MetadataElement
-
doService
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.
- Parameters:
msg- the input AdaptrisMessage- Throws:
ServiceException- wrapping any underlying Exception
-
initService
protected void initService() throws CoreException- Specified by:
initServicein classServiceImp- Throws:
CoreException
-
closeService
protected void closeService()
- Specified by:
closeServicein classServiceImp
-
start
public void start() throws CoreExceptionDescription copied from interface:ComponentLifecycleStarts the component.Once a component is started it should be ready to process messages. In the case of
AdaptrisMessageConsumer, calling start will begin message delivery.- Specified by:
startin interfaceComponentLifecycle- Overrides:
startin classServiceImp- Throws:
CoreException- wrapping any underlyingExceptions
-
stop
public void stop()
Description copied from interface:ComponentLifecycleStop the componentA stopped component is not expected to be ready to process messages. In the case of
AdaptrisMessageConsumer, calling stop will pause message delivery. Throwing aRuntimeExceptionmay cause unintended consequences- Specified by:
stopin interfaceComponentLifecycle- Overrides:
stopin classServiceImp
-
prepare
public void prepare() throws CoreExceptionDescription copied from interface:ComponentLifecycleExtensionPrepare for initialisation.- Throws:
CoreException
-
tryAndLog
protected static void tryAndLog(java.lang.String logMsg, DuplicateMessageRoutingService.Operator l)
-
tryAndWrap
protected static void tryAndWrap(DuplicateMessageRoutingService.Operator l) throws CoreException
- Throws:
CoreException
-
-