@ComponentProfile(summary="Generate a sequence number from a simple text file", tag="service,sequence") public class SimpleSequenceNumberService extends ServiceImp
Rather than using a database to store sequence numbers (c.f.
MetadataIdentitySequenceNumberService
or
StaticIdentitySequenceNumberService
) , 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 a Properties
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 (using File.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.
Modifier and Type | Class and Description |
---|---|
static class |
SimpleSequenceNumberService.OverflowBehaviour
The behaviour of the sequence number generator when the number exceeds that specified by the number format.
|
log
CONFIRMATION_ID_KEY
Constructor and Description |
---|
SimpleSequenceNumberService() |
Modifier and Type | Method and 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
|
changeState, close, continueOnFailure, createName, createQualifier, getContinueOnFail, getIsTrackingEndpoint, getLookupName, getUniqueId, init, isBranching, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, setContinueOnFail, setIsTrackingEndpoint, setLookupName, setUniqueId
protected 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 doService(AdaptrisMessage msg) throws ServiceException
Service
Apply the service to the message.
msg
- the AdaptrisMessage
to processServiceException
- wrapping any underlying Exception
sService.doService(com.adaptris.core.AdaptrisMessage)
public java.lang.String getMetadataKey()
public void setMetadataKey(java.lang.String key)
key
- the metadataKey to setpublic java.lang.String getNumberFormat()
public void setNumberFormat(java.lang.String format)
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
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.DecimalFormat
public java.lang.Boolean getAlwaysReplaceMetadata()
public void setAlwaysReplaceMetadata(java.lang.Boolean t)
t
- the alwaysReplaceMetadata to set, default is true.public SimpleSequenceNumberService.OverflowBehaviour getOverflowBehaviour()
public void setOverflowBehaviour(SimpleSequenceNumberService.OverflowBehaviour s)
s
- the behaviour to set (default is SimpleSequenceNumberService.OverflowBehaviour.Continue
)SimpleSequenceNumberService.OverflowBehaviour
public java.lang.String getSequenceNumberFile()
public void setSequenceNumberFile(java.lang.String s)
s
- the file.public java.lang.Long getMaximumSequenceNumber()
public void setMaximumSequenceNumber(java.lang.Long l)
l
- the maximum sequence number, a value of null means there is no maximum (default).public void prepare() throws CoreException
ComponentLifecycleExtension
CoreException