Class RemoteDbSessionImpl
java.lang.Object
org.tentackle.dbms.trip.RemoteDbSessionImpl
- All Implemented Interfaces:
RemoteDbSession, Remote, RemoteRoot
User session within the application server.
- Author:
- harald
-
Constructor Summary
ConstructorsConstructorDescriptionRemoteDbSessionImpl(RemoteDbConnectionImpl con, SessionInfo clientInfo, SessionInfo serverInfo) Creates a session on a given connection. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddMasterSerialEvent(MasterSerialEvent masterSerialEvent) Adds a master serial event.protected voidcleanup(boolean crashed) Clean up the session.voidclose()Closes a session.protected voidcloseDb(boolean cleanup) Closes the database connection (and thus rolls back any pending transaction).voidcountMethodInvocation(Method method, Class<?> servicedClass, TimeKeeper timeKeeper) Counts the invocation of a delegate method.<T extends RemoteDbDelegate, I extends RemoteDbDelegateImpl<?>>
TcreateRemoteDelegate(Class<T> delegateClass, Class<I> delegateImplClass, Class<?> clazz, Class<?> effectiveClass, Object... configArgs) Creates a remote delegate for the given class.
Same ascreateRemoteDelegateInstance(Class, Class, Class, Class, Object...)but with dynamic proxy to allow intercepting.<T extends RemoteDbDelegate, I extends RemoteDbDelegateImpl<?>>
TcreateRemoteDelegateInstance(Class<T> delegateClass, Class<I> delegateImplClass, Class<?> clazz, Class<?> effectiveClass, Object... configArgs) Creates a remote delegate for the given class.protected intdetermineTimeout(Session session, SessionInfo clientInfo, SessionInfo serverInfo) Determines the session timeout count.
The default implementation returnsTripServer.getSessionTimeout().protected voiddoLogStatistics(Logger.Level level, boolean clear) Logs the TRIP-statistics.protected voidForces a cleanup if the regular cleanup and closing failed.Gets the string representation of the client host connected to this session.Gets the client session info.longGets the epochal time when the session was closed.Gets the server connection.Gets the invocation filter.Gets a string useful for mapped diagnostic context info.static Collection<RemoteDbSessionImpl> Returns a list of all open sessions.Returns an application-specific option string.
For diagnostic purposes only.Gets the delegate for the remote session.<T extends Remote>
TgetRemoteDelegate(String classname) Gets the delegate for a given interface name.
If the implementation isn't annotated withRemoteService, it will be located according to theNamingRules.Gets the server session info.Gets the session.longGets the unique session number.intGets the session timeout.protected intGets the current timeout counter.protected booleanChecks for timeout.booleanReturns whether this is the remote session of the modification tracker.booleanisOpen()Determines whether the session is open.static SessionInfoisUserLoggedIn(SessionInfo sessionInfo) Checks if the user is already logged in.voidlog(String name, Logger.Level level, String message) Sends text based logging infos to the TRIP-Server.voidlogStatistics(Logger.Level level, boolean clear) Logs the TRIP-statistics.protected DbopenDb()Gets an open db session for this remote client session.protected voidpolled()Sets this session as being polled for timeout.Gets the next master serial event.
The method is invoked by theModificationTracker.voidsetInvocationFilter(RemoteDbSessionInvocationFilter invocationFilter) Sets the invocation filter.voidsetModificationTrackerSession(boolean modificationTrackerSession) Sets the modification tracker session flag.voidsetRegistryCoordinates(Registry registry, UUID id) Sets the registry and the delegate ID this object belongs to.voidsetTimeout(int timeout) Sets the session timeout.static voidstartCleanupThread(long checkInterval) Starts the optional cleanup thread that will monitor the sessions for database activity.static voidStops the cleanup thread.toString()voidUnregisters this target object's delegate from the registry.abstract voidverifySessionInfo(SessionInfo sessionInfo) Verifies and updates the client's session info.
Needs to be implemented by the application.
Checks login credentials and sets the user id.
-
Constructor Details
-
RemoteDbSessionImpl
public RemoteDbSessionImpl(RemoteDbConnectionImpl con, SessionInfo clientInfo, SessionInfo serverInfo) Creates a session on a given connection.- Parameters:
con- the connectionclientInfo- the SessionInfo from the clientserverInfo- the SessionInfo to establish the connection to the database server- Throws:
PersistenceException- if the session could not be initiated.
-
-
Method Details
-
startCleanupThread
public static void startCleanupThread(long checkInterval) Starts the optional cleanup thread that will monitor the sessions for database activity.- Parameters:
checkInterval- is the interval in ms
-
stopCleanupThread
public static void stopCleanupThread()Stops the cleanup thread. -
getOpenSessions
Returns a list of all open sessions.- Returns:
- the sessions, never null
-
isUserLoggedIn
Checks if the user is already logged in.- Parameters:
sessionInfo- the user's session info- Returns:
- the session info if already logged in, null if not logged in
-
toString
-
setRegistryCoordinates
Description copied from interface:RemoteRootSets the registry and the delegate ID this object belongs to.- Specified by:
setRegistryCoordinatesin interfaceRemoteRoot- Parameters:
registry- the registryid- the delegate ID
-
unregisterFromRegistry
public void unregisterFromRegistry()Description copied from interface:RemoteRootUnregisters this target object's delegate from the registry.- Specified by:
unregisterFromRegistryin interfaceRemoteRoot
-
setInvocationFilter
Sets the invocation filter.- Parameters:
invocationFilter- the invocation filter, null for none (default)
-
getInvocationFilter
Gets the invocation filter.- Returns:
- the invocation filter, null for none (default)
-
addMasterSerialEvent
Adds a master serial event.- Parameters:
masterSerialEvent- the event
-
pollMasterSerialEvent
Gets the next master serial event.
The method is invoked by theModificationTracker.- Returns:
- the next master serial event, null if none
-
verifySessionInfo
Verifies and updates the client's session info.
Needs to be implemented by the application.
Checks login credentials and sets the user id.Throws LoginFailedException if login is not allowed for whatever reason.
- Parameters:
sessionInfo- the session info
-
getSessionNumber
public long getSessionNumber()Gets the unique session number.- Returns:
- the number of this session
-
getTimeout
public int getTimeout()Gets the session timeout.- Returns:
- the timeout in timeout intervals
-
setTimeout
public void setTimeout(int timeout) Sets the session timeout.- Parameters:
timeout- the timeout in timeout intervals
-
getSession
-
getConnection
-
getClientSessionInfo
Gets the client session info.- Specified by:
getClientSessionInfoin interfaceRemoteDbSession- Returns:
- the client session info
-
getServerSessionInfo
Gets the server session info.- Returns:
- the server session info
-
getClosedSince
public long getClosedSince()Gets the epochal time when the session was closed.- Returns:
- the time when closed, 0 if still open
-
isModificationTrackerSession
public boolean isModificationTrackerSession()Returns whether this is the remote session of the modification tracker.- Returns:
- true if tracker's session
-
setModificationTrackerSession
public void setModificationTrackerSession(boolean modificationTrackerSession) Sets the modification tracker session flag.- Parameters:
modificationTrackerSession- true if tracker's session
-
countMethodInvocation
Counts the invocation of a delegate method.- Parameters:
method- the method invokedservicedClass- the serviced classtimeKeeper- execution duration
-
getClientHostString
Gets the string representation of the client host connected to this session.- Returns:
- the client host string
-
getOptions
Returns an application-specific option string.
For diagnostic purposes only.- Returns:
- null if no options
-
getMdcInfo
Gets a string useful for mapped diagnostic context info.- Returns:
- the MDC info
-
isOpen
public boolean isOpen()Determines whether the session is open.- Returns:
- true if the session is open
-
close
public void close()Description copied from interface:RemoteDbSessionCloses a session.- Specified by:
closein interfaceRemoteDbSession
-
log
Description copied from interface:RemoteDbSessionSends text based logging infos to the TRIP-Server.- Specified by:
login interfaceRemoteDbSession- Parameters:
name- the logger name, null if predefinedlevel- the logging levelmessage- the message
-
logStatistics
Description copied from interface:RemoteDbSessionLogs the TRIP-statistics.- Specified by:
logStatisticsin interfaceRemoteDbSession- Parameters:
level- the logging levelclear- true if clear statistics after dump
-
getRemoteDelegate
Description copied from interface:RemoteDbSessionGets the delegate for a given interface name.
If the implementation isn't annotated withRemoteService, it will be located according to theNamingRules.- Specified by:
getRemoteDelegatein interfaceRemoteDbSession- Type Parameters:
T- the delegate type- Parameters:
classname- is the name of remote interface- Returns:
- the delegate
-
getRemoteDelegate
Description copied from interface:RemoteDbSessionGets the delegate for the remote session.- Specified by:
getRemoteDelegatein interfaceRemoteDbSession- Returns:
- the delegate
-
createRemoteDelegateInstance
public <T extends RemoteDbDelegate, I extends RemoteDbDelegateImpl<?>> T createRemoteDelegateInstance(Class<T> delegateClass, Class<I> delegateImplClass, Class<?> clazz, Class<?> effectiveClass, Object... configArgs) throws InstantiationException, NoSuchMethodException, IllegalAccessException, InvocationTargetException Creates a remote delegate for the given class.If the optional configuration arguments are given, the delegate must provide a method with the following signature:
public void configureDelegate(Object... args) { // whatever args stands for }The optional configuration parameters allow passing additional objects to the delegate without having to declare the setters in the remote interface.- Type Parameters:
T- the delegate classI- the delegate implementation class- Parameters:
delegateClass- the interface classdelegateImplClass- the implementing classclazz- the serviced classeffectiveClass- the optional effective serviced class, null if clazzconfigArgs- optional arguments to configure the delegate- Returns:
- the created delegate
- Throws:
InstantiationException- if delegate could not be instantiatedNoSuchMethodException- if the delegate does not provide the necessary constructorIllegalAccessException- if access deniedIllegalArgumentException- if wrong argumentsInvocationTargetException- if invocation failed
-
createRemoteDelegate
public <T extends RemoteDbDelegate, I extends RemoteDbDelegateImpl<?>> T createRemoteDelegate(Class<T> delegateClass, Class<I> delegateImplClass, Class<?> clazz, Class<?> effectiveClass, Object... configArgs) throws InstantiationException, NoSuchMethodException, IllegalAccessException, InvocationTargetException Creates a remote delegate for the given class.
Same ascreateRemoteDelegateInstance(Class, Class, Class, Class, Object...)but with dynamic proxy to allow intercepting.- Type Parameters:
T- the remote delegate classI- the delegate implementation class- Parameters:
delegateClass- the interface classdelegateImplClass- the implementing classclazz- the serviced classeffectiveClass- the effectively serviced class, null if clazzconfigArgs- optional configuration arguments passed tocreateRemoteDelegateInstance(Class, Class, Class, Class, Object...)- Returns:
- the created
- Throws:
InstantiationException- if delegate could not be instantiatedNoSuchMethodException- if the delegate does not provide the necessary constructorIllegalAccessException- if access deniedIllegalArgumentException- if wrong argumentsInvocationTargetException- if invocation failed
-
determineTimeout
Determines the session timeout count.
The default implementation returnsTripServer.getSessionTimeout().- Parameters:
session- the session attached to theRemoteDbSessionclientInfo- the session info from the clientserverInfo- the session info to establish the connection to the database rmiServer- Returns:
- the timeout
-
openDb
Gets an open db session for this remote client session.- Returns:
- the db session
- Throws:
LoginFailedException- if opening the session failed
-
cleanup
protected void cleanup(boolean crashed) Clean up the session.The method is invoked whenever the session is closed due to an ordinary logout or client crash. The default implementation rolls back any pending transaction.
- Parameters:
crashed- true if the client crashed, else regular logout
-
doLogStatistics
Logs the TRIP-statistics.- Parameters:
level- the logging levelclear- true if clear statistics after dump
-
closeDb
protected void closeDb(boolean cleanup) Closes the database connection (and thus rolls back any pending transaction). If the db is pooled, it will be returned to the pool instead of being closed.- Parameters:
cleanup- true if db must be physically closed even if pooled, due to session cleanup
-
forceCleanup
protected void forceCleanup()Forces a cleanup if the regular cleanup and closing failed.Simply marks the session closed and moves all references to GC.
-
hasTimedOut
protected boolean hasTimedOut()Checks for timeout. Will internally increment a counter until timeout has reached.- Returns:
- true if timed out
-
getTimeoutCount
protected int getTimeoutCount()Gets the current timeout counter.- Returns:
- the timeout counter
-
polled
protected void polled()Sets this session as being polled for timeout.
-