Interface Session<R>

All Superinterfaces:
AutoCloseable, Closeable, Executor, Link

public interface Session<R> extends Closeable, Link, Executor
Manages a client-side or server-side remote session, which establishes new socket connections as needed. Remote calls over a session are initiated from the root object, which can return additional remote objects.
See Also:
  • Method Details

    • root

      R root()
      Returns the root object which was exported or imported.
    • access

      static Session<?> access(Object obj)
      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 stub
      IllegalStateException - if the object is disposed
    • current

      static Session<?> 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

      static boolean dispose(Object obj)
      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

      static boolean disposeServer(Object server)
      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

      default void connected(Socket s) throws IOException
      Receives new connections from a Connector.
      Throws:
      UnsupportedOperationException - if not supported by this session
      IOException
    • connected

      default void connected(SocketChannel s) throws IOException
      Receives new connections from a Connector.
      Throws:
      UnsupportedOperationException - if not supported by this session
      IOException
    • connected

      void connected(SocketAddress localAddr, SocketAddress remoteAddr, InputStream in, OutputStream out) throws IOException
      Receives new connections from a Connector.
      Parameters:
      localAddr - local link address, or null if unknown or not applicable
      remoteAddr - remote link address, or null if unknown or not applicable
      Throws:
      UnsupportedOperationException - if not supported by this session
      IOException
    • resolveClass

      Class<?> resolveClass(String name) throws IOException, ClassNotFoundException
      Resolve a class using the default or custom ClassResolver.
      Throws:
      IOException
      ClassNotFoundException
    • uncaughtExceptionHandler

      void uncaughtExceptionHandler(BiConsumer<Session<?>, Throwable> h)
      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

      void uncaught(Throwable e)
      Pass an uncaught exception directly to the uncaught exception handler.
    • state

      Session.State state()
      Returns the current session state.
    • addStateListener

      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. 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 interface AutoCloseable
      Specified by:
      close in interface Closeable