Class 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 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.

    • Constructor Detail

      • SimpleSequenceNumberService

        public SimpleSequenceNumberService()
    • Method Detail

      • stop

        public void stop()
        Description copied from interface: ComponentLifecycle
        Stop the component

        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

        Specified by:
        stop in interface ComponentLifecycle
        Overrides:
        stop in class ServiceImp
      • 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.
      • 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).