public class Environment extends Object implements Closeable
| Constructor and Description |
|---|
Environment()
Construct environment which uses up to 1000 threads.
|
Environment(int maxThreads)
Construct environment with the given maximum number of threads.
|
Environment(int maxThreads,
String threadNamePrefix,
Thread.UncaughtExceptionHandler handler)
Construct environment with the given maximum number of threads, thread
name prefix, and uncaught exception handler.
|
Environment(ScheduledExecutorService executor)
Construct environment with a custom executor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes all existing sessions and then shuts down the thread pool.
|
ScheduledExecutorService |
executor()
Returns the executor used by this environment.
|
Session |
newSession(ChannelBroker broker)
Attempts to connect using given broker, blocking until session is
established.
|
Session |
newSession(ChannelBroker broker,
long timeout,
TimeUnit unit)
Attempts to connect using given broker, blocking until session is
established.
|
SessionAcceptor |
newSessionAcceptor(int port)
Returns an acceptor of sessions.
|
SessionAcceptor |
newSessionAcceptor(SocketAddress localAddress)
Returns an acceptor of sessions.
|
SessionConnector |
newSessionConnector(SocketAddress remoteAddress)
Returns a session connector for a remote endpoint.
|
SessionConnector |
newSessionConnector(SocketAddress remoteAddress,
SocketAddress localAddress)
Returns a session connector for a remote endpoint.
|
SessionConnector |
newSessionConnector(String host,
int port)
Returns a session connector for a remote endpoint.
|
Session[] |
newSessionPair()
Returns two locally connected sessions.
|
Environment |
withClassLoader(ClassLoader classLoader)
Returns an environment instance which uses the provided classloader
for all established sessions.
|
Environment |
withClientSocketFactory(SocketFactory sf)
Returns an environment instance which connects using the given client
socket factory.
|
Environment |
withServerSocketFactory(ServerSocketFactory ssf)
Returns an environment instance which accepts using the given server
socket factory.
|
Environment |
withSocketSelector()
Returns an environment instance which uses selectable sockets, reducing
the amount of idle threads.
|
public Environment()
public Environment(int maxThreads)
maxThreads - maximum number of threads in poolpublic Environment(int maxThreads,
String threadNamePrefix,
Thread.UncaughtExceptionHandler handler)
maxThreads - maximum number of threads in poolthreadNamePrefix - prefix given to thread name; pass null for defaulthandler - handler for uncaught exceptions; pass null for defaultpublic Environment(ScheduledExecutorService executor)
ThreadPoolpublic Environment withClientSocketFactory(SocketFactory sf)
IllegalStateException - if environment uses a selectorpublic Environment withServerSocketFactory(ServerSocketFactory ssf)
IllegalStateException - if environment uses a selectorpublic Environment withSocketSelector() throws IOException
Overall performance is lower with selectable sockets, but scalability is improved. Remote call overhead is about 2 to 4 times higher, which is largely due to the inefficient design of the nio library.
IllegalStateException - if environment uses a socket factoryIOExceptionpublic Environment withClassLoader(ClassLoader classLoader)
public SessionConnector newSessionConnector(String host, int port)
connect to immediately establish a session.host - required name of remote endpointport - remote portpublic SessionConnector newSessionConnector(SocketAddress remoteAddress)
connect to immediately establish a session.remoteAddress - required address of remote endpointpublic SessionConnector newSessionConnector(SocketAddress remoteAddress, SocketAddress localAddress)
connect to immediately establish a session.remoteAddress - required address of remote endpointlocalAddress - optional address of local bindpointpublic SessionAcceptor newSessionAcceptor(int port) throws IOException
acceptAll to start automatically accepting sessions.port - port for accepting socket connections; pass zero to choose
any available portIOExceptionpublic SessionAcceptor newSessionAcceptor(SocketAddress localAddress) throws IOException
acceptAll to start automatically accepting sessions.localAddress - address for accepting socket connections; use null to
automatically select a local address and any available portIOExceptionpublic Session newSession(ChannelBroker broker) throws IOException
broker - required broker for establishing connections; must always
connect to same remote endpointIOExceptionpublic Session newSession(ChannelBroker broker, long timeout, TimeUnit unit) throws IOException
broker - required broker for establishing connections; must always
connect to same remote endpointRemoteTimeoutExceptionIOExceptionpublic Session[] newSessionPair() throws RejectedException
RejectedException - if thread pool is full or shutdownpublic ScheduledExecutorService executor()
public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionCopyright © 2006–2015 Cojen. All rights reserved.