Package tilda.utils.concurrent
Class DBPoll
- java.lang.Object
-
- tilda.utils.concurrent.DBPoll
-
- All Implemented Interfaces:
java.lang.Runnable
- Direct Known Subclasses:
SequencePoll
public abstract class DBPoll extends java.lang.Object implements java.lang.RunnableThread-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_Cprotected static org.apache.logging.log4j.LoggerLOG
-
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 voidclose()Called when the thread is closingprotected abstract booleandoRun(Connection C, int Count)java.lang.StringgetConnectionId()voidinit()Initializes the connection.voidrun()voidterminate()If launched as a thread, attempts to terminate is asap.
-
-
-
Field Detail
-
LOG
protected static final org.apache.logging.log4j.Logger LOG
-
_C
protected Connection _C
-
-
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.ExceptionInitializes 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:
runin interfacejava.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.ExceptionCalled when the thread is closing- Throws:
java.lang.Exception
-
-