Class SessionUtilities

java.lang.Object
org.tentackle.session.SessionUtilities
Direct Known Subclasses:
DbSessionUtilities

@Service(SessionUtilities.class) public class SessionUtilities extends Object
Utility methods for session-related stuff.
Author:
harald
  • Constructor Details

    • SessionUtilities

      public SessionUtilities()
      Creates a utility instance.
  • Method Details

    • getInstance

      public static SessionUtilities getInstance()
      The singleton.
      Returns:
      the singleton
    • getTableName

      public String getTableName(String className)
      Gets the table name of a pdo class.
      Parameters:
      className - the class name of the object
      Returns:
      the tablename, null if no such class or not annotated with @TableName
    • getClassName

      public String getClassName(String tableName)
      Gets the classname for tablename.
      Parameters:
      tableName - the tablename
      Returns:
      the name of the class, null if no such tablename
    • getClassId

      public int getClassId(String pdoClassName)
      Gets the class id of a pdo class.
      Parameters:
      pdoClassName - the classname of the pdo
      Returns:
      the class id, 0 if no such class or not annotated with @ClassId.
    • getClassName

      public String getClassName(int classId)
      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

      public Collection<String> getClassNames()
      Gets a list of all class names.
      Sorted by name.
      Returns:
      the class names
    • determineTablename

      public String determineTablename(Class<?> clazz)
      Determines the tablename from the @TableName annotation.
      Parameters:
      clazz - the class
      Returns:
      the tablename, null if no such annotation
    • determineClassId

      public int determineClassId(Class<?> clazz)
      Determines the class id from the @ClassId annotation.
      Parameters:
      clazz - the class
      Returns:
      the class ID, 0 if no such annotation (maybe an abstract class)
    • 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

      public void keepAliveIntervalChanged(Session session)
      Handles the change of a keep alive interval of a session.
      Parameters:
      session - the session
    • alignExceptionCause

      public Throwable alignExceptionCause(Throwable t)
      Replaces exception cause probably not in the jvm's classpath when the stacktrace gets deserialized in another (usually remote) jvm.
      Parameters:
      t - the throwable
      Returns:
      the probably replaced throwable
    • alignTemporaryExceptionStatus

      public void alignTemporaryExceptionStatus(PersistenceException exception)
      Sets the temporary flag according to the exception's root cause and the session.
      Parameters:
      exception - the exception
    • isSilentRollbackSufficient

      public boolean isSilentRollbackSufficient(Throwable t)
      Returns whether a rollback should log all statements or not.
      The rollback should not be logged if the root-cause is not a PersistenceException, or TentackleRuntimeException.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 a PersistenceException.
      Parameters:
      msg - the original message
      cause - the cause
      identifiable - the identifiable
      session - 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 message
      cause - the cause
      identifiable - the identifiable
      session - the session
      Returns:
      true if multiple lines
    • createKeepAliveDaemon

      protected SessionKeepAliveDaemon createKeepAliveDaemon()
      Creates the session keep alive daemon.
      Returns:
      the daemon (not started yet!)