|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.lang.Thread
org.tentackle.db.ModificationThread
public class ModificationThread
Thread to monitor the modification table.
Runs on a separate db connection and invokes runnables if modifications are detected.
| Nested Class Summary | |
|---|---|
class |
ModificationThread.ModificationEntry
Entry for each table (or class) to watch for modifications. |
static interface |
ModificationThread.SerialRunnable
Special runnable invoked from within the ModificationThread whenever a serial on a table has changed. |
| Nested classes/interfaces inherited from class java.lang.Thread |
|---|
Thread.State, Thread.UncaughtExceptionHandler |
| Field Summary |
|---|
| Fields inherited from class java.lang.Thread |
|---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
| Constructor Summary | |
|---|---|
protected |
ModificationThread()
Creates a dummy thread. Will never start and just log what would be registered It is used at startup for db-classes that register runnables before the real modthread is created. |
protected |
ModificationThread(Db db,
long mseconds,
boolean cloneDb)
Creates a modification thread. |
| Method Summary | |
|---|---|
static ModificationThread |
createThread(Db db,
long mseconds)
Creates a modification thread as a singleton with a cloned db connection. |
static ModificationThread |
createThread(Db db,
long mseconds,
boolean cloneDb)
Creates a modification thread as a singleton. |
Db |
getDb()
Gets the db connection for this thread. |
long[] |
getIdSerialForName(String tableName)
Gets the pair of id/serial for a given tablename. |
long |
getInterval()
Gets the polling interval. |
long |
getMasterSerial()
Gets the current master serial. |
protected int |
getRemoteDelegateId()
Gets the remote delegate. |
long[] |
getSerials(long[] ids)
Gets all ModificationEntries (synchronized). |
static ModificationThread |
getThread()
Gets the single modification thread. This is the method applications should refer to the modthread. |
boolean |
isDummy()
Determines whether this is the dummy thread. |
boolean |
isIdle()
Determines whether this is idle. |
void |
poll()
Runs one poll and invokes the ModificationThread.SerialRunnables if a modification is detected. |
long[] |
readSerials(long[] ids)
Reads serials for given ids. |
void |
registerMasterSerialRunnable(Runnable runnable)
Registers a pure runnable to be executed if the master serial has changed |
void |
registerRunnable(Runnable runnable)
Registers a pure runnable to be executed in the modification thread. |
void |
registerShutdownRunnable(Runnable runnable)
Registers a pure runnable to be executed if the ModificationThread is terminated due to severe errors. |
void |
registerTable(String tableName,
ModificationThread.SerialRunnable serialRunnable)
Registers a table with a runnable invoked from the ModificationThread. |
void |
registerTable(String tableName,
Runnable runnable)
Registers a table with a runnable that will be invoked in the GUI-Thread. |
void |
requestToStop()
Request to stop the thread. |
void |
run()
The workhorse. Clones the db connection, sets the db-group and then in loop periodically invokeRunOnce() and poll(). |
void |
runOnce(Runnable runnable)
Runs a runnable within the modification thread's context. |
void |
runOnceAndWait(Runnable runnable)
Runs a runnable within the modification thread's context and waits for completion. |
long[] |
selectIdSerialForName(String tableName)
Selects the pair of id/serial for a given tablename. |
long |
selectMasterSerial()
Reads the master-serial from the database. |
String |
selectNameForId(long id)
Selects the tablename for a given ID. |
void |
setIdle(boolean idle)
Sets the idle state of this thread. Application threads using the primary db-connection (i.e. |
void |
setInterval(long mseconds)
Sets the polling interval. |
void |
terminate()
Terminates this thread. Will request to stop and wait until stopped. |
| Methods inherited from class java.lang.Thread |
|---|
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
protected ModificationThread(Db db,
long mseconds,
boolean cloneDb)
db - the database connectionmseconds - polling interval in millisecondscloneDb - true if clone db connection on startprotected ModificationThread()
| Method Detail |
|---|
public static ModificationThread createThread(Db db,
long mseconds,
boolean cloneDb)
db - the database connectionmseconds - polling interval in millisecondscloneDb - true if clone db connection on start
DbRuntimeException - if already created and was not the dummy thread
public static ModificationThread createThread(Db db,
long mseconds)
db - the database connectionmseconds - polling interval in milliseconds
DbRuntimeException - if already created and was not the dummy threadpublic static ModificationThread getThread()
public Db getDb()
public boolean isDummy()
ModificationThread()public void runOnce(Runnable runnable)
runnable - the runnable to run
public void runOnceAndWait(Runnable runnable)
throws InterruptedException
Notice: if other runnables are already registered but not executed so far, those runnables will be executed *before* the runnable passed by this method.
runnable - the runnable to run
InterruptedExceptionpublic void requestToStop()
terminate() instead.
terminate()public void terminate()
requestToStop()public void run()
invokeRunOnce() and poll().
On requestToStop() closes the db connection and terminates the thread.
run in interface Runnablerun in class ThreadThread.start(),
Thread.stop(),
Thread.Thread(ThreadGroup, Runnable, String)public void poll()
ModificationThread.SerialRunnables if a modification is detected.
The implementation keeps the sync locks as short as possible.
public void registerTable(String tableName,
Runnable runnable)
tableName - is the name of the table to watch forrunnable - to execute if something in table changed (invoked by EventQueue.invokeLater)
public void registerTable(String tableName,
ModificationThread.SerialRunnable serialRunnable)
tableName - is the name of the table to watch forserialRunnable - to execute if something in table changed.public void registerRunnable(Runnable runnable)
runnable - the runnablepublic void registerMasterSerialRunnable(Runnable runnable)
runnable - the runnablepublic void registerShutdownRunnable(Runnable runnable)
runnable - the runnablepublic long getMasterSerial()
public long selectMasterSerial()
public long[] getSerials(long[] ids)
ids - the table IDs to read the serials for
public long[] getIdSerialForName(String tableName)
tableName - the table to lookup
public long[] selectIdSerialForName(String tableName)
tableName - the table to lookup
public String selectNameForId(long id)
id - the table ID
public long[] readSerials(long[] ids)
ids - the table IDs
public void setInterval(long mseconds)
mseconds - the polling interval in millisecondspublic long getInterval()
public boolean isIdle()
public void setIdle(boolean idle)
idle - true if thread should *not* process the modification table.protected int getRemoteDelegateId()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||