Interface Session<R>
- All Superinterfaces:
AutoCloseable
,Closeable
,Executor
,Link
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enum
Indicates the session's current connection state. -
Method Summary
Modifier and TypeMethodDescriptionstatic Session
<?> Access the session that the given remote object is bound to.void
addStateListener
(BiPredicate<Session<?>, Throwable> listener) Add a listener which is immediately invoked (in the current thread), or when the session state changes, or when a reconnect attempt fails.void
close()
Closes all connections and immediately closes any future connections.default void
Receives new connections from aConnector
.void
connected
(SocketAddress localAddr, SocketAddress remoteAddr, InputStream in, OutputStream out) Receives new connections from aConnector
.default void
Receives new connections from aConnector
.static Session
<?> current()
Returns the current thread-local session, which is available to a remote method implementation when it's invoked.static boolean
Explicitly dispose a client-side remote object.static boolean
disposeServer
(Object server) Explicitly dispose a server-side remote object implementation from the current session.void
Closes all connections and initiates a reconnect.Class
<?> resolveClass
(String name) Resolve a class using the default or customClassResolver
.root()
Returns the root object which was exported or imported.state()
Returns the current session state.void
Pass an uncaught exception directly to the uncaught exception handler.void
Set the handler which is invoked for any uncaught exceptions within this session instance.Methods inherited from interface org.cojen.dirmi.Link
localAddress, remoteAddress
-
Method Details
-
root
R root()Returns the root object which was exported or imported. -
access
Access the session that the given remote object is bound to. This is method is expected to be called on the client-side.- Throws:
IllegalArgumentException
- if not given a remote stubIllegalStateException
- if the object is disposed
-
current
Returns the current thread-local session, which is available to a remote method implementation when it's invoked. This method is expected to be called on the server-side.- Throws:
IllegalStateException
- if no current session
-
dispose
Explicitly dispose a client-side remote object.- Returns:
- false if the object is already disposed
- Throws:
IllegalArgumentException
- if not given a remote stub- See Also:
-
disposeServer
Explicitly dispose a server-side remote object implementation from the current session.- Returns:
- false if the server is already disposed or if it's unknown to the current session
- Throws:
IllegalStateException
- if no current session- See Also:
-
connected
Receives new connections from aConnector
.- Throws:
UnsupportedOperationException
- if not supported by this sessionIOException
-
connected
Receives new connections from aConnector
.- Throws:
UnsupportedOperationException
- if not supported by this sessionIOException
-
connected
void connected(SocketAddress localAddr, SocketAddress remoteAddr, InputStream in, OutputStream out) throws IOException Receives new connections from aConnector
.- Parameters:
localAddr
- local link address, or null if unknown or not applicableremoteAddr
- remote link address, or null if unknown or not applicable- Throws:
UnsupportedOperationException
- if not supported by this sessionIOException
-
resolveClass
Resolve a class using the default or customClassResolver
.- Throws:
IOException
ClassNotFoundException
-
uncaughtExceptionHandler
Set the handler which is invoked for any uncaught exceptions within this session instance. By default, uncaught exceptions are passed to the environment instance.- Parameters:
h
- handler to use; pass null to use the default handler- See Also:
-
uncaught
Pass an uncaught exception directly to the uncaught exception handler. -
state
Session.State state()Returns the current session state. -
addStateListener
Add a listener which is immediately invoked (in the current thread), or when the session state changes, or when a reconnect attempt fails. The listener is invoked in a blocking fashion, preventing any state changes until the listener returns. If it returns false, the listener is removed. -
reconnect
void reconnect()Closes all connections and initiates a reconnect. Operation has no effect if the session is closed. If this is a server-side session, calling reconnect is effectively the same as calling close. The client-side session detects this and performs the reconnect. -
close
void close()Closes all connections and immediately closes any future connections. All remote objects are invalidated as a side effect.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-