Class SessionUtilities
java.lang.Object
org.tentackle.session.SessionUtilities
- Direct Known Subclasses:
DbSessionUtilities
Utility methods for session-related stuff.
Provides:
- the mappings between class names, table names and class IDs, built from the
TableNameandClassIdmapped services, - the
SessionKeepAliveDaemon, started on demand and restarted if it died, - hooks for the
PersistenceExceptions, overridden by the database layer to handle JDBC-specific exceptions.
@Service(SessionUtilities.class).- Author:
- harald
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReplaces an exception cause that is probably not in the classpath of another (usually remote) JVM when the exception gets deserialized there.
Invoked by the constructors ofPersistenceExceptionwith a cause.voidSets the temporary flag according to the exception's cause and the session.
Invoked by the constructors ofPersistenceExceptionwith a cause and a session or identifiable.protected SessionKeepAliveDaemonCreates the session keep alive daemon.createLazyExceptionMessage(String msg, Throwable cause, Identifiable identifiable, Session session) Creates the lazy exception message for aPersistenceException.intdetermineClassId(Class<?> clazz) Determines the class id from the @ClassIdannotation.determineTablename(Class<?> clazz) Determines the tablename from the @TableNameannotation.
AppliesTableName.mapSchema()andTableName.prefix().intgetClassId(String pdoClassName) Gets the class id of a pdo class.getClassName(int classId) Gets the classname for a class id.getClassName(String tableName) Gets the classname for tablename.static SessionUtilitiesThe singleton.getTableName(String className) Gets the table name of a pdo class.
The table name is taken from the mapped services, i.e. with the build-time options of @TableNamealready applied.protected booleanisMultiLineExceptionMessage(String msg, Throwable cause, Identifiable identifiable, Session session) Returns whether the exception message spans multiple lines.booleanReturns whether a rollback should log all statements or not.
The rollback should not be logged if the root-cause is not aPersistenceException, orTentackleRuntimeException.isTemporary()or there is another temporary exception in the exception chain.voidkeepAliveIntervalChanged(Session session) Handles the change of a keep alive interval of a session.
Starts the keep-alive daemon if not running.voidStarts the keep alive thread if not already running.voidStops all helper threads.
-
Constructor Details
-
SessionUtilities
public SessionUtilities()Creates a utility instance.
-
-
Method Details
-
getInstance
-
getTableName
-
getClassName
-
getClassId
-
getClassName
Gets the classname for a class id.- Parameters:
classId- the class id- Returns:
- the name of the class, null if no such class id
-
getClassNames
- Returns:
- the class names
-
determineTablename
Determines the tablename from the @TableNameannotation.
AppliesTableName.mapSchema()andTableName.prefix().- Parameters:
clazz- the class- Returns:
- the tablename, null if no such annotation or empty (e.g. SINGLE-table inheritance)
-
determineClassId
-
startKeepAliveDaemonIfNotRunning
public void startKeepAliveDaemonIfNotRunning()Starts the keep alive thread if not already running.If the daemon died on its own -- due to a severe error or the dead-dispatcher detection -- its registrations are handed over to the replacement. Without that, every session registered so far would silently stop being pinged and be timed out by the remote server, while only the sessions changing their interval afterwards would recover.
-
terminateHelperThreads
public void terminateHelperThreads()Stops all helper threads. -
keepAliveIntervalChanged
Handles the change of a keep alive interval of a session.
Starts the keep-alive daemon if not running.- Parameters:
session- the session
-
alignExceptionCause
Replaces an exception cause that is probably not in the classpath of another (usually remote) JVM when the exception gets deserialized there.
Invoked by the constructors ofPersistenceExceptionwith a cause.- Parameters:
t- the throwable- Returns:
- the probably replaced throwable
-
alignTemporaryExceptionStatus
Sets the temporary flag according to the exception's cause and the session.
Invoked by the constructors ofPersistenceExceptionwith a cause and a session or identifiable.- Parameters:
exception- the exception
-
isSilentRollbackSufficient
Returns whether a rollback should log all statements or not.
The rollback should not be logged if the root-cause is not aPersistenceException, orTentackleRuntimeException.isTemporary()or there is another temporary exception in the exception chain.Notice that
LockExceptions are usually temporary.- Parameters:
t- the head of the exception chain causing the rollback- Returns:
- true if rollback silently, false if all statements that were rolled back are logged
-
createLazyExceptionMessage
public StringBuilder createLazyExceptionMessage(String msg, Throwable cause, Identifiable identifiable, Session session) Creates the lazy exception message for aPersistenceException.- Parameters:
msg- the original messagecause- the causeidentifiable- the identifiablesession- the session- Returns:
- the extended message string builder
-
isMultiLineExceptionMessage
protected boolean isMultiLineExceptionMessage(String msg, Throwable cause, Identifiable identifiable, Session session) Returns whether the exception message spans multiple lines.- Parameters:
msg- the original messagecause- the causeidentifiable- the identifiablesession- the session- Returns:
- true if multiple lines
-
createKeepAliveDaemon
Creates the session keep alive daemon.- Returns:
- the daemon (not started yet!)
-