Class SimpleSequenceNumberService
- java.lang.Object
-
- com.adaptris.core.ServiceImp
-
- com.adaptris.core.services.metadata.SimpleSequenceNumberService
-
- All Implemented Interfaces:
AdaptrisComponent,ComponentLifecycle,ComponentLifecycleExtension,MessageEventGenerator,Service,StateManagedComponent
@ComponentProfile(summary="Generate a sequence number from a simple text file", tag="service,sequence") public class SimpleSequenceNumberService extends ServiceImpSimple sequence number generator that uses a file to store the next sequence number.Rather than using a database to store sequence numbers (c.f.
MetadataIdentitySequenceNumberServiceorStaticIdentitySequenceNumberService) , this service uses a a plain text file to store the sequence number. Multiple instances of this service should use different files; behaviour is undefined if multiple instances use the same file.The sequence number file consists of a simple key value pair
SimpleSequenceNumberService.next=[the next sequence number]which is accessed using aPropertiesobject. If the property does not exist, then it is defaulted to 1. If you wish to manually modify the file, then the value should always be the next sequence number. If the file does not exist, then a new file is created (usingFile.createNewFile(), and the sequence number defaulted to 1.In the adapter configuration file this class is aliased as simple-sequence-number-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 static classSimpleSequenceNumberService.OverflowBehaviourThe behaviour of the sequence number generator when the number exceeds that specified by the number format.
-
Field Summary
-
Fields inherited from class com.adaptris.core.ServiceImp
log
-
-
Constructor Summary
Constructors Constructor Description SimpleSequenceNumberService()
-
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.BooleangetAlwaysReplaceMetadata()java.lang.LonggetMaximumSequenceNumber()java.lang.StringgetMetadataKey()java.lang.StringgetNumberFormat()SimpleSequenceNumberService.OverflowBehaviourgetOverflowBehaviour()java.lang.StringgetSequenceNumberFile()protected voidinitService()voidprepare()Prepare for initialisation.voidsetAlwaysReplaceMetadata(java.lang.Boolean t)Whether or not to always replace the metadata key.voidsetMaximumSequenceNumber(java.lang.Long l)Set the maximum sequence number which will reset the count when reached.voidsetMetadataKey(java.lang.String key)Set the metadata key where the resulting sequence number will be stored.voidsetNumberFormat(java.lang.String format)Metadata will be formatted using the pattern specified.voidsetOverflowBehaviour(SimpleSequenceNumberService.OverflowBehaviour s)Set the behaviour when the sequence number exceeds that specified by the number format.voidsetSequenceNumberFile(java.lang.String s)Set the file that will contain the sequence number.voidstart()Starts the component.voidstop()Stop the component-
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
-
-
-
-
Method Detail
-
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
-
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:
Service.doService(com.adaptris.core.AdaptrisMessage)
-
getMetadataKey
public java.lang.String getMetadataKey()
- Returns:
- the metadataKey
-
setMetadataKey
public void setMetadataKey(java.lang.String key)
Set the metadata key where the resulting sequence number will be stored.- Parameters:
key- the metadataKey to set
-
getNumberFormat
public java.lang.String getNumberFormat()
- Returns:
- the numberFormat
-
setNumberFormat
public void setNumberFormat(java.lang.String format)
Metadata will be formatted using the pattern specified.This allows you to format the number precisely to the value that is required; e.g if you use "000000000" then the metadata value is always 9 characters long, the number being prefixed by leading zeros
- Parameters:
format- the numberFormat to set. The default is '0'; which coupled with the default overflow behaviour of 'Continue' means it will just use the raw number.- See Also:
DecimalFormat
-
getAlwaysReplaceMetadata
public java.lang.Boolean getAlwaysReplaceMetadata()
-
setAlwaysReplaceMetadata
public void setAlwaysReplaceMetadata(java.lang.Boolean t)
Whether or not to always replace the metadata key.- Parameters:
t- the alwaysReplaceMetadata to set, default is true.
-
getOverflowBehaviour
public SimpleSequenceNumberService.OverflowBehaviour getOverflowBehaviour()
-
setOverflowBehaviour
public void setOverflowBehaviour(SimpleSequenceNumberService.OverflowBehaviour s)
Set the behaviour when the sequence number exceeds that specified by the number format.- Parameters:
s- the behaviour to set (default isSimpleSequenceNumberService.OverflowBehaviour.Continue)- See Also:
SimpleSequenceNumberService.OverflowBehaviour
-
getSequenceNumberFile
public java.lang.String getSequenceNumberFile()
-
setSequenceNumberFile
public void setSequenceNumberFile(java.lang.String s)
Set the file that will contain the sequence number.- Parameters:
s- the file.
-
getMaximumSequenceNumber
public java.lang.Long getMaximumSequenceNumber()
-
setMaximumSequenceNumber
public void setMaximumSequenceNumber(java.lang.Long l)
Set the maximum sequence number which will reset the count when reached.- Parameters:
l- the maximum sequence number, a value of null means there is no maximum (default).
-
prepare
public void prepare() throws CoreExceptionDescription copied from interface:ComponentLifecycleExtensionPrepare for initialisation.- Throws:
CoreException
-
-