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 ServiceImp
Simple sequence number generator that uses a file to store the next sequence number.Rather than using a database to store sequence numbers (c.f.
MetadataIdentitySequenceNumberService
orStaticIdentitySequenceNumberService
) , 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 aProperties
object. 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 class
SimpleSequenceNumberService.OverflowBehaviour
The 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 void
closeService()
void
doService(AdaptrisMessage msg)
Apply the service to the message.java.lang.Boolean
getAlwaysReplaceMetadata()
java.lang.Long
getMaximumSequenceNumber()
java.lang.String
getMetadataKey()
java.lang.String
getNumberFormat()
SimpleSequenceNumberService.OverflowBehaviour
getOverflowBehaviour()
java.lang.String
getSequenceNumberFile()
protected void
initService()
void
prepare()
Prepare for initialisation.void
setAlwaysReplaceMetadata(java.lang.Boolean t)
Whether or not to always replace the metadata key.void
setMaximumSequenceNumber(java.lang.Long l)
Set the maximum sequence number which will reset the count when reached.void
setMetadataKey(java.lang.String key)
Set the metadata key where the resulting sequence number will be stored.void
setNumberFormat(java.lang.String format)
Metadata will be formatted using the pattern specified.void
setOverflowBehaviour(SimpleSequenceNumberService.OverflowBehaviour s)
Set the behaviour when the sequence number exceeds that specified by the number format.void
setSequenceNumberFile(java.lang.String s)
Set the file that will contain the sequence number.void
start()
Starts the component.void
stop()
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:
initService
in classServiceImp
- Throws:
CoreException
-
closeService
protected void closeService()
- Specified by:
closeService
in classServiceImp
-
start
public void start() throws CoreException
Description copied from interface:ComponentLifecycle
Starts 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:
start
in interfaceComponentLifecycle
- Overrides:
start
in classServiceImp
- Throws:
CoreException
- wrapping any underlyingException
s
-
stop
public void stop()
Description copied from interface:ComponentLifecycle
Stop 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 aRuntimeException
may cause unintended consequences- Specified by:
stop
in interfaceComponentLifecycle
- Overrides:
stop
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:
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 CoreException
Description copied from interface:ComponentLifecycleExtension
Prepare for initialisation.- Throws:
CoreException
-
-