Class DBPoll

  • All Implemented Interfaces:
    java.lang.Runnable
    Direct Known Subclasses:
    SequencePoll

    public abstract class DBPoll
    extends java.lang.Object
    implements java.lang.Runnable
    Thread-friendly class to create a new connection and invoke a subclass' doRun() method for any processing.

    Any user of this class is responsible for calling the init() and close() methods. The class implements the Runnable interface and as such can be used in a new thread. the derived class doRun() method is called repeatedly at given intervals until it returns false, at which time, the thread ends.

    Author:
    Laurent Hasson
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected Connection _C  
      protected static org.apache.logging.log4j.Logger LOG  
    • Constructor Summary

      Constructors 
      Constructor Description
      DBPoll​(java.lang.String PoolName, long PauseMillis)
      Constructor for the class, taking a pool name and pause amount in millis seconds in between calls to doRun()
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected abstract void close()
      Called when the thread is closing
      protected abstract boolean doRun​(Connection C, int Count)  
      java.lang.String getConnectionId()  
      void init()
      Initializes the connection.
      void run()  
      void terminate()
      If launched as a thread, attempts to terminate is asap.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOG

        protected static final org.apache.logging.log4j.Logger LOG
    • Constructor Detail

      • DBPoll

        public DBPoll​(java.lang.String PoolName,
                      long PauseMillis)
        Constructor for the class, taking a pool name and pause amount in millis seconds in between calls to doRun()
        Parameters:
        PoolName - The name of the pool the new connection must be taken from.
        PauseMillis - The amount of time in milliseconds between calls to the doRun() method.
    • Method Detail

      • init

        public void init()
                  throws java.lang.Exception
        Initializes the connection. Must be called before the class is used either directly by calling the run() method, or through a Thread.
        Throws:
        java.lang.Exception - if the connection couldn't be instanciated.
      • getConnectionId

        public java.lang.String getConnectionId()
                                         throws java.lang.Exception
        Throws:
        java.lang.Exception
      • terminate

        public void terminate()
        If launched as a thread, attempts to terminate is asap.
      • run

        public void run()
        Specified by:
        run in interface java.lang.Runnable
      • doRun

        protected abstract boolean doRun​(Connection C,
                                         int Count)
                                  throws java.lang.Exception
        Parameters:
        C -
        Count -
        Returns:
        Throws:
        java.lang.Exception
      • close

        protected abstract void close()
                               throws java.lang.Exception
        Called when the thread is closing
        Throws:
        java.lang.Exception