Class PersistenceBackend

  • Direct Known Subclasses:
    FallbackPersistenceBackend

    public abstract class PersistenceBackend
    extends Object
    Author:
    Luca Frosini (ISTI - CNR), Alessandro Pieve (ISTI - CNR)
    • Field Detail

      • MAX_TIME_TO_FALLBACK

        public static final long MAX_TIME_TO_FALLBACK
        Max Time Period Used during while the usage of FallbackPersistenceBackend is forced
        See Also:
        Constant Field Values
      • MAX_FALLBACK_RETRY

        public static final int MAX_FALLBACK_RETRY
        Max Times of Retry before forcing the usage of FallbackPersistenceBackend
        See Also:
        Constant Field Values
      • forceFallbackUse

        protected boolean forceFallbackUse
      • fallbackUseCounter

        protected int fallbackUseCounter
      • fallbackUseStartTime

        protected long fallbackUseStartTime
      • persistenceBackendMonitor

        protected FallbackMonitor persistenceBackendMonitor
    • Constructor Detail

      • PersistenceBackend

        protected PersistenceBackend()
    • Method Detail

      • getAggregationScheduler

        public AggregationScheduler getAggregationScheduler()
        Returns:
        the aggregationScheduler
      • setAggregationScheduler

        protected void setAggregationScheduler​(AggregationScheduler aggregationScheduler)
        Parameters:
        aggregationScheduler - the aggregationScheduler to set
      • prepareConnection

        protected abstract void prepareConnection​(PersistenceBackendConfiguration configuration)
                                           throws Exception
        Prepare the connection to persistence. This method must be used by implementation class to prepare the connection with the persistence storage, DB, file etc.
        Parameters:
        configuration - The configuration to create the connection
        Throws:
        Exception - if fails
      • openConnection

        protected abstract void openConnection()
                                        throws Exception
        This method is used to open db connection
        Throws:
        Exception
      • closeConnection

        protected abstract void closeConnection()
                                         throws Exception
        This method is used to close db connection
        Throws:
        Exception
      • close

        public void close()
                   throws Exception
        This method is used to close
        Throws:
        Exception
      • clean

        protected abstract void clean()
                               throws Exception
        This method is used to allow PersistenceBackend implementations to clean a global status if any (or to renew it) when to much exceptions occurs trying to persist Records.
        Throws:
        Exception
      • isConnectionActive

        public abstract boolean isConnectionActive()
                                            throws Exception
        Check the Connection state
        Returns:
        true if the connection is active, false otherwise
        Throws:
        Exception
      • reallyAccount

        protected abstract void reallyAccount​(Record record)
                                       throws Exception
        This method contains the code to save the Record
        Throws:
        Exception
      • accountWithFallback

        protected void accountWithFallback​(Record... records)
                                    throws Exception
        Parameters:
        records -
        Throws:
        Exception
      • accountValidateAggregate

        protected void accountValidateAggregate​(Record record,
                                                boolean validate,
                                                boolean aggregate)
        Parameters:
        record -
        validate -
        aggregate -
      • account

        public void account​(Record record)
                     throws InvalidValueException
        Persist the Record. The Record is validated first, then accounted, in a separated thread. So that the program can continue the execution. If the persistence fails the class write that the record in a local file so that the Record can be recorder later.
        Parameters:
        record - the Record to persist
        Throws:
        InvalidValueException - if the Record Validation Fails