Interface Environment
- All Superinterfaces:
- AutoCloseable, Closeable, Executor
- 
Method SummaryModifier and TypeMethodDescriptiondefault CloseableAccept all server-side connections from the givenServerSocket.acceptAll(ServerSocket ss, Predicate<Socket> listener) Accept all server-side connections from the givenServerSocket.default CloseableAccept all server-side connections from the givenServerSocketChannel.acceptAll(ServerSocketChannel ss, Predicate<SocketChannel> listener) Accept all server-side connections from the givenServerSocketChannel.default Session<?> Call when a server-side connection has been explicitly accepted.Session<?> accepted(SocketAddress localAddr, SocketAddress remoteAddr, InputStream in, OutputStream out) Call when a server-side connection has been explicitly accepted.default Session<?> Call when a server-side connection has been explicitly accepted.default voidclassLoader(ClassLoader loader) Convenience method to use aClassLoaderfor resolving classes.voidclassResolver(ClassResolver resolver) Set the class resolver to use for newly established sessions.voidclose()Stops accepting new sessions, closes all acceptors, closes all sessions, and disposes of all exported objects.default <R> Session<R> Call to establish a new client-side session.<R> Session<R> connect(Class<R> type, Object name, SocketAddress addr) Call to establish a new client-side session.Assign a connector for establishing new client-side socket connections.static Environmentcreate()Returns a newEnvironmentinstance which uses a defaultExecutor.static EnvironmentReturns a newEnvironmentinstance which uses the givenExecutor.static EnvironmentReturns a newEnvironmentinstance which uses the givenExecutor.voidcustomSerializers(Serializer... serializers) Provide custom serializers for newly established sessions.Export a named server-side object.voididleConnectionMillis(int millis) Set the maximum idle connection time for newly established sessions (±33%).voidpingTimeoutMillis(int millis) Set the ping timeout for newly established sessions (±33%).voidreconnectDelayMillis(int millis) Set the reconnect delay for newly established client sessions (±10%).voidSet the handler which is invoked for any uncaught exceptions within this environment instance.
- 
Method Details- 
createReturns a newEnvironmentinstance which uses a defaultExecutor. When theEnvironmentis closed, theExecutoris also closed.
- 
createReturns a newEnvironmentinstance which uses the givenExecutor. When theEnvironmentis closed, theExecutoris not closed.
- 
createReturns a newEnvironmentinstance which uses the givenExecutor.- Parameters:
- closeExecutor- when true, the- Executoris closed when the- Environmentis closed
- Throws:
- IllegalArgumentException- if- closeExecutoris true and the given- Executordoesn't implement- Closeableor- ExecutorService
 
- 
exportExport a named server-side object. If replacing an existing object, then the previously exported instance is disposed of. Pass a null object to remove an export completely. Replacing or removing an exported object has no effect on sessions which already exported it.- Parameters:
- name- serializable name
- obj- remote object
- Returns:
- the previously exported object or null if none
- Throws:
- IllegalArgumentException- if the name isn't serializable or if the object to export isn't- remote.
- IOException
 
- 
acceptAllAccept all server-side connections from the givenServerSocket. As long as the acceptor is still running, the JVM won't exit.- Returns:
- an object which can be closed to stop accepting
- Throws:
- IllegalStateException- if already accepting connections from the socket
- IOException
 
- 
acceptAllAccept all server-side connections from the givenServerSocket. As long as the acceptor is still running, the JVM won't exit.- Parameters:
- listener- is called for each accepted socket; return false if socket is rejected
- Returns:
- an object which can be closed to stop accepting
- Throws:
- IllegalStateException- if already accepting connections from the socket
- IOException
 
- 
acceptAllAccept all server-side connections from the givenServerSocketChannel. As long as the acceptor is still running, the JVM won't exit.- Returns:
- an object which can be closed to stop accepting
- Throws:
- IllegalStateException- if already accepting connections from the socket channel
- IOException
 
- 
acceptAllAccept all server-side connections from the givenServerSocketChannel. As long as the acceptor is still running, the JVM won't exit.- Parameters:
- listener- is called for each accepted socket; return false if socket is rejected
- Returns:
- an object which can be closed to stop accepting
- Throws:
- IllegalStateException- if already accepting connections from the socket channel
- IOException
 
- 
acceptedCall when a server-side connection has been explicitly accepted. Any exception thrown from this method closes the socket.- Returns:
- new or existing server-side session instance
- Throws:
- IOException- if a communication failure or if the client is requesting an object which isn't exported
 
- 
acceptedCall when a server-side connection has been explicitly accepted. Any exception thrown from this method closes the socket.- Returns:
- new or existing server-side session instance
- Throws:
- IOException- if a communication failure or if the client is requesting an object which isn't exported
 
- 
acceptedSession<?> accepted(SocketAddress localAddr, SocketAddress remoteAddr, InputStream in, OutputStream out) throws IOException Call when a server-side connection has been explicitly accepted. Any exception thrown from this method closes the socket.- Parameters:
- localAddr- local link address, or null if unknown or not applicable
- remoteAddr- remote link address, or null if unknown or not applicable
- Returns:
- new or existing server-side session instance
- Throws:
- IOException- if a communication failure or if the client is requesting an object which isn't exported
 
- 
connectCall to establish a new client-side session. A remote server must be accepting connections, and it must also export the given named object.- Parameters:
- type- the type of the root object which is exported by the remote server
- name- the name of the root object which is exported by the remote server
- addr- server address to connect to
- Returns:
- new or existing client-side session instance
- Throws:
- IllegalArgumentException- if the name isn't serializable or if the type isn't- remote.
- IOException- if a communication failure or if no object is exported by the given type and name
 
- 
connectdefault <R> Session<R> connect(Class<R> type, Object name, String host, int port) throws IOException Call to establish a new client-side session. A remote server must be accepting connections, and it must also export the given named object.- Parameters:
- type- the type of the root object which is exported by the remote server
- name- the name of the root object which is exported by the remote server
- host- server host address to connect to
- port- server port to connect to
- Returns:
- new or existing client-side session instance
- Throws:
- IllegalArgumentException- if the name isn't serializable or if the type isn't- remote.
- IOException- if a communication failure or if no object is exported by the given type and name
 
- 
connectorAssign a connector for establishing new client-side socket connections. By default, thedirectconnector is used.- Parameters:
- c- non-null connector
- Returns:
- the previously assigned connector
- Throws:
- IOException
 
- 
customSerializersProvide custom serializers for newly established sessions. If the set of serializers provided by the client and server sessions don't match, then null is serialized for classes which aren't customized on both sides.- Throws:
- NullPointerException- if any serializers are null
 
- 
reconnectDelayMillisvoid reconnectDelayMillis(int millis) Set the reconnect delay for newly established client sessions (±10%). Client sessions attempt to reconnect when the session is disconnected, and the delay is applied before each attempt. The default reconnect delay is 1 second. Pass a negative delay to disable reconnect, and instead the session is closed when it's disconnected.Disposingtherootobject also disables reconnect.
- 
pingTimeoutMillisvoid pingTimeoutMillis(int millis) Set the ping timeout for newly established sessions (±33%). If no ping response is received from the remote endpoint in time, then the session is disconnected or closed. Server-side sessions are always closed, but client-side sessions are closed only when reconnect is disabled. The default ping timeout is 2 seconds. Pass a negative timeout to disable pings. The session can still close or be disconnected if communication over the control connection fails.
- 
idleConnectionMillisvoid idleConnectionMillis(int millis) Set the maximum idle connection time for newly established sessions (±33%). This defines the maximum amount of time a connection can remain idle before it's automatically closed. The default idle time is 60 seconds. Pass a negative amount to disable the closing of idle connections.
- 
classResolverSet the class resolver to use for newly established sessions. This affects the class loading behavior forSerializedmethods.- Parameters:
- resolver- resolver to use; pass null to use the default resolver
 
- 
classLoaderConvenience method to use aClassLoaderfor resolving classes.- Parameters:
- loader- loader to use to resolve classes; pass null to use the default resolver
 
- 
uncaughtExceptionHandlerSet the handler which is invoked for any uncaught exceptions within this environment instance. The session instance passed to the handler is null when not applicable. By default, uncaught exceptions are passed to the current thread's uncaught exception handler.- Parameters:
- h- handler to use; pass null to use the default handler
- See Also:
 
- 
closevoid close()Stops accepting new sessions, closes all acceptors, closes all sessions, and disposes of all exported objects.- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
 
 
-