public abstract class RemoteDbSessionImpl extends Object implements RemoteDbSession, Exportable
| Constructor and Description |
|---|
RemoteDbSessionImpl(RemoteDbConnectionImpl con,
SessionInfo clientInfo,
SessionInfo serverInfo)
Creates a session on a given connection.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
cleanup(boolean crashed)
Cleanup the session.
|
void |
close()
Closes a session.
|
protected void |
closeDb(boolean cleanup)
Closes the database connection (and thus rolls back any pending transaction).
|
void |
countMethodInvocation(Method method,
Class<?> servicedClass,
Duration duration)
Counts the invocation of a delegate method.
|
<T extends org.tentackle.persist.rmi.RemoteDelegate,I extends org.tentackle.persist.rmi.RemoteDelegateImpl<?>> |
createRemoteDelegate(Class<T> delegateClass,
Class<I> delegateImplClass,
Class<?> clazz,
Class<?> effectiveClass,
Object... configArgs)
Creates a remote delegate for the given class.
Same as createRemoteDelegateInstance(java.lang.Class<T>, java.lang.Class<I>, java.lang.Class<?>, java.lang.Class<?>, java.lang.Object...) but with dynamic proxy to allow intercepting. |
String |
createRemoteDelegateClassName(String className)
Creates the classname of the remote delegate interface from the
serviced classname.
The default implementation returns: packagename + ".rmi." + classbasename + "RemoteDelegate" |
String |
createRemoteDelegateImplClassName(String className)
Creates the classname of the remote delegate implementation from the
serviced classname.
The default implementation returns + "Impl". |
<T extends org.tentackle.persist.rmi.RemoteDelegate,I extends org.tentackle.persist.rmi.RemoteDelegateImpl<?>> |
createRemoteDelegateInstance(Class<T> delegateClass,
Class<I> delegateImplClass,
Class<?> clazz,
Class<?> effectiveClass,
Object... configArgs)
Creates a remote delegate for the given class.
|
protected void |
doLogStatistics(Logger.Level level,
boolean clear)
Logs the statistics.
|
void |
exportMe()
Exports this remote object.
|
void |
exportRemoteDelegate(org.tentackle.persist.rmi.RemoteDelegate delegate)
Exports the given delegate.
|
protected void |
finalize()
Cleanup in case someone forgot to logoff().
|
protected void |
forceCleanup()
Forces a cleanup if all cleanup and closing failed.
|
String |
getClientHostString()
Gets the string representation of the client host connected to this session.
|
SessionInfo |
getClientSessionInfo()
Gets the client user info.
|
RMIClientSocketFactory |
getClientSocketFactory()
Gets the default client socket factory for all delegates.
|
long |
getClosedSince()
Gets the epochal time when the session was closed.
|
RemoteDbConnectionImpl |
getConnection()
Gets the server connection.
|
org.tentackle.persist.rmi.DbRemoteDelegate |
getDbRemoteDelegate()
Gets the delegate for the remote db-connection.
|
static Collection<RemoteDbSessionImpl> |
getOpenSessions()
Returns a list of all open sessions.
|
String |
getOptions()
Returns an application-specific option string.
For diagnostic purposes only. |
int |
getPort()
Gets the port for all delegates.
|
<T extends org.tentackle.persist.rmi.RemoteDelegate> |
getRemoteDelegate(String classname)
Gets the delegate for a given classname.
Per class the rmi-clients request a remote access there must be a RemoteDelegate. |
String |
getServerName()
Gets the application name of the server.
|
SessionInfo |
getServerSessionInfo()
Gets the server user info.
|
RMIServerSocketFactory |
getServerSocketFactory()
Gets the default server socket factory for all delegates.
|
Db |
getSession()
Gets the session db connection
|
long |
getSessionNumber()
Gets the unique session number.
|
int |
getTimeout()
Gets the session timeout.
|
boolean |
hasTimedOut()
Checks for timeout.
|
boolean |
isGrouped()
Returns whether this is grouped session.
By default, user sessions are grouped, i.e. |
boolean |
isOpen()
Determines whether the session is open.
|
static SessionInfo |
isUserLoggedIn(SessionInfo userInfo)
Checks if the user is already logged in.
|
void |
log(Logger.Level level,
String message)
Sends text based logging infos to the RMI-Server.
|
void |
logStatistics(Logger.Level level,
boolean clear)
Logs the statistics.
|
protected Db |
openDb()
Opens a new Db.
The default implementation opens a new Db. |
void |
polled()
Sets this session as being polled for timeout.
|
void |
setClientSocketFactory(RMIClientSocketFactory csf)
Sets the client socket factory for all delegates.
|
void |
setPort(int port)
Sets Gets the port for all delegates.
|
void |
setServerSocketFactory(RMIServerSocketFactory ssf)
Sets the server socket factory for all delegates.
|
void |
setTimeout(int timeout)
Sets the session timeout.
|
static void |
startCleanupThread(long checkInterval)
Starts the optional cleanup thread that will
monitor the sessions for db-activity.
|
static void |
stopCleanupThread()
Stops the cleanup thread.
|
String |
toString() |
void |
unexportMe()
Unexports this remote object.
|
void |
unexportRemoteDelegate(org.tentackle.persist.rmi.RemoteDelegate delegate)
Unexports given remote delegate.
|
abstract void |
verifySessionInfo(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. |
public RemoteDbSessionImpl(RemoteDbConnectionImpl con, SessionInfo clientInfo, SessionInfo serverInfo) throws RemoteException
con - the connectionclientInfo - the SessionInfo from the clientserverInfo - the SessionInfo to establish the connection to the database serverRemoteException - if the session could not initiated.public static void startCleanupThread(long checkInterval)
checkInterval - is the interval in mspublic static void stopCleanupThread()
public static Collection<RemoteDbSessionImpl> getOpenSessions()
public static SessionInfo isUserLoggedIn(SessionInfo userInfo)
userInfo - the user's infopublic void exportMe()
throws RemoteException
ExportableexportMe in interface ExportableRemoteException - if export failedpublic void unexportMe()
throws RemoteException
ExportableunexportMe in interface ExportableRemoteException - if unexport failedpublic void exportRemoteDelegate(org.tentackle.persist.rmi.RemoteDelegate delegate)
throws RemoteException
Notice that the delegate must not extend UnicastRemoteObject!
delegate - the delegateRemoteException - if export failedpublic void unexportRemoteDelegate(org.tentackle.persist.rmi.RemoteDelegate delegate)
throws RemoteException
Notice: when the session is closed, all still exported objects will be unexported. This method is only necessary if a delegate must be explicitly unexported.
delegate - the delegateRemoteException - if object not exportedpublic abstract void verifySessionInfo(SessionInfo sessionInfo) throws LoginFailedException
sessionInfo - the session infoLoginFailedException - if login is not allowed for whatever reasonpublic long getSessionNumber()
public int getTimeout()
public void setTimeout(int timeout)
timeout - the timeout in timeout intervalspublic Db getSession()
public RemoteDbConnectionImpl getConnection()
public SessionInfo getClientSessionInfo()
getClientSessionInfo in interface RemoteDbSessionpublic SessionInfo getServerSessionInfo()
public long getClosedSince()
public int getPort()
public void setPort(int port)
port - the portpublic RMIClientSocketFactory getClientSocketFactory()
public void setClientSocketFactory(RMIClientSocketFactory csf)
csf - the socket factorypublic RMIServerSocketFactory getServerSocketFactory()
public void setServerSocketFactory(RMIServerSocketFactory ssf)
ssf - the socket factorypublic void countMethodInvocation(Method method, Class<?> servicedClass, Duration duration)
method - the method invokedservicedClass - the serviced classduration - execution durationprotected Db openDb() throws LoginFailedException
LoginFailedException - if opening the db failedprotected void cleanup(boolean crashed)
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.
crashed - true if client crashed, else regular logoutprotected void doLogStatistics(Logger.Level level, boolean clear)
level - the logging levelclear - true if clear statistics after dumpprotected void closeDb(boolean cleanup)
cleanup - true if db must be physically closed even if pooled, due to cleanupprotected void forceCleanup()
Simply marks the session closed and moves all references to GC.
public String getClientHostString()
public String getOptions()
public boolean isOpen()
public boolean isGrouped()
protected void finalize()
throws Throwable
public String getServerName() throws RemoteException
RemoteDbSessiongetServerName in interface RemoteDbSessionRemoteExceptionpublic void close()
throws RemoteException
RemoteDbSessionclose in interface RemoteDbSessionRemoteExceptionpublic void log(Logger.Level level, String message) throws RemoteException
RemoteDbSessionlog in interface RemoteDbSessionlevel - the logging levelmessage - the messageRemoteExceptionpublic void logStatistics(Logger.Level level, boolean clear) throws RemoteException
RemoteDbSessionlogStatistics in interface RemoteDbSessionlevel - the logging levelclear - true if clear statistics after dumpRemoteException - if logging failedRemoteDelegateInvocationHandler.collectStatisticspublic <T extends org.tentackle.persist.rmi.RemoteDelegate> T getRemoteDelegate(String classname) throws RemoteException
RemoteDbSessiongetRemoteDelegate in interface RemoteDbSessionclassname - is the name of classRemoteExceptionpublic org.tentackle.persist.rmi.DbRemoteDelegate getDbRemoteDelegate()
throws RemoteException
RemoteDbSessiongetDbRemoteDelegate in interface RemoteDbSessionRemoteExceptionpublic String createRemoteDelegateClassName(String className)
className - the name of the class to look for a delegatepublic String createRemoteDelegateImplClassName(String className)
+ "Impl".className - the name of the class to look for a delegatepublic <T extends org.tentackle.persist.rmi.RemoteDelegate,I extends org.tentackle.persist.rmi.RemoteDelegateImpl<?>> T createRemoteDelegateInstance(Class<T> delegateClass, Class<I> delegateImplClass, Class<?> clazz, Class<?> effectiveClass, Object... configArgs) throws InstantiationException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException
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.T - the delegate classI - the delegate implementation classdelegateClass - the interface classdelegateImplClass - the implementing classclazz - the serviced classeffectiveClass - the optional effective serviced class, null if clazzconfigArgs - optional arguments to configure the delegateInstantiationExceptionNoSuchMethodExceptionIllegalAccessExceptionIllegalArgumentExceptionInvocationTargetExceptionpublic <T extends org.tentackle.persist.rmi.RemoteDelegate,I extends org.tentackle.persist.rmi.RemoteDelegateImpl<?>> T createRemoteDelegate(Class<T> delegateClass, Class<I> delegateImplClass, Class<?> clazz, Class<?> effectiveClass, Object... configArgs) throws InstantiationException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException
createRemoteDelegateInstance(java.lang.Class<T>, java.lang.Class<I>, java.lang.Class<?>, java.lang.Class<?>, java.lang.Object...) but with dynamic proxy to allow intercepting.T - the remote delegate classI - the delegate implementation classdelegateClass - the interface classdelegateImplClass - the implementing classclazz - the serviced classeffectiveClass - the effectively serviced class, null if clazzconfigArgs - optional configuration arguments passed to createRemoteDelegateInstance(java.lang.Class<T>, java.lang.Class<I>, java.lang.Class<?>, java.lang.Class<?>, java.lang.Object...)InstantiationExceptionNoSuchMethodExceptionIllegalAccessExceptionIllegalArgumentExceptionInvocationTargetExceptionpublic boolean hasTimedOut()
public void polled()
Copyright © 2016 Krake Softwaretechnik. All rights reserved.