Interface ModificationTracker
- All Superinterfaces:
ExclusiveSessionProvider, SessionTaskDispatcher, TaskDispatcher, Terminatable
Tracks global changes.
The tracker is a SessionTaskDispatcher that maintains its own session and periodically
polls for modifications, notifying the registered ModificationListeners.
Remote clients poll the server's tracker instead of the database, which may also push
MasterSerialEvents along.
The application can request an exclusive use of the tracker's session for a
(short) period of time and release it afterward.
- Author:
- harald
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddDeletion(Session session, String name, long id, long tableSerial) Adds a deletion to the previously counted modifications.voidaddModificationListener(ModificationListener listener) Adds a modification listener.voidaddShutdownRunnable(Runnable runnable) Registers a runnable to be executed once when the tracker thread terminates.
This applies to an orderly termination as well as to a termination due to severe errors.longcountModification(Session session, String name) Counts the modification for a given name.
Used to trigger modification events.getIdSerialForClass(Class<?> clazz) Gets the pair of id/serial for a given class.
The modification name is determined from the class's table name.getIdSerialForName(String name) Gets the pair of id/serial for a given modification name.
Used in remote connections.static ModificationTrackerThe tracker singleton.voidInvalidates the tracker.
Forces the tracking info to be rebuilt.booleanReturns whether the tracker runs in local client mode.
In this mode, there is no middle-tier server and the clients are directly connected to the database.
Although this mode isn't recommended, it is an option for simple desktop applications with only very few parallel users.booleanRemoves a modification listener.booleanremoveShutdownRunnable(Runnable runnable) Unregisters a shutdown runnable.voidrollbackModification(Session session, long txNumber) Invoked whenever a transaction is rolled back.
Allows the tracker to adjust the pending counts.static voidSubmits a task invoking given runnable.static voidtransaction(Runnable runnable) Submits a session task invoking the given runnable within a transaction of the tracker's session.static voidtransaction(String txName, Runnable runnable) Submits a session task invoking the given runnable within a transaction of the tracker's session.Methods inherited from interface ExclusiveSessionProvider
releaseSession, requestSessionMethods inherited from interface SessionTaskDispatcher
getSession, isSessionClosedOnTermination, isSessionKeptAlive, setSession, setSessionClosedOnTermination, setSessionKeptAliveMethods inherited from interface TaskDispatcher
addTask, addTaskAndWait, addTaskListener, getAllTasks, getDeadInterval, getQueueSize, getShutdownIdleTimeout, getSleepInterval, getTask, getWaitInterval, isAlive, isInstanceOfTaskPending, isQueueEmpty, isTaskPending, isUsingMutexLocking, lock, removeTask, removeTaskListener, setDeadInterval, setShutdownIdleTimeout, setSleepInterval, setUsingMutexLocking, setWaitInterval, start, toDiagnosticString, unlock, waitForTaskMethods inherited from interface Terminatable
isTerminationRequested, requestTermination, terminate
-
Method Details
-
getInstance
-
submit
Submits a task invoking given runnable.- Parameters:
runnable- the runnable to be executed once
-
transaction
-
transaction
Submits a session task invoking the given runnable within a transaction of the tracker's session.- Parameters:
runnable- the runnable to be executed once
-
addModificationListener
Adds a modification listener.- Parameters:
listener- the listener to add
-
removeModificationListener
Removes a modification listener.- Parameters:
listener- to remove- Returns:
- true if removed
-
countModification
Counts the modification for a given name.
Used to trigger modification events.- Parameters:
session- the session persisting the modification, null if thread-local session (never remote)name- a unique name to track modifications- Returns:
- the modification serial assigned to this modification, unique per name (the counter could be higher already)
-
addDeletion
Adds a deletion to the previously counted modifications.- Parameters:
session- the session persisting the modification, null if thread-local session (never remote)name- a unique name to track modificationsid- the ID of the object that was deletedtableSerial- the modification serial obtained fromcountModification(Session, String)
-
rollbackModification
Invoked whenever a transaction is rolled back.
Allows the tracker to adjust the pending counts.- Parameters:
session- the transaction's session (never remote)txNumber- the transaction number
-
addShutdownRunnable
Registers a runnable to be executed once when the tracker thread terminates.
This applies to an orderly termination as well as to a termination due to severe errors.- Parameters:
runnable- the runnable
-
removeShutdownRunnable
Unregisters a shutdown runnable.- Parameters:
runnable- the runnable- Returns:
- true if runnable removed
-
getIdSerialForClass
Gets the pair of id/serial for a given class.
The modification name is determined from the class's table name.- Parameters:
clazz- the tracked class- Returns:
- the id/serial pair, never null
-
getIdSerialForName
Gets the pair of id/serial for a given modification name.
Used in remote connections.- Parameters:
name- the name to look up- Returns:
- the id/serial pair for the name, never null
-
invalidate
void invalidate()Invalidates the tracker.
Forces the tracking info to be rebuilt. -
isLocalClientMode
boolean isLocalClientMode()Returns whether the tracker runs in local client mode.
In this mode, there is no middle-tier server and the clients are directly connected to the database.
Although this mode isn't recommended, it is an option for simple desktop applications with only very few parallel users.- Returns:
- true if in local client mode, false for regular mode
-