public final class ConnectionManager extends Object
A ConnectionManager
is created by a
connection-based Endpoint
implemention to manage
connections to a particular ConnectionEndpoint
. The newRequest
method is used to send a request to the
connection endpoint.
Each request attempt is mapped to a new session of the
Jini ERI multiplexing protocol on an established connection chosen
by the ConnectionEndpoint
. Request data is written as
the data sent for the session, and response data is read as the
data recdeived for the session.
Logger
named
net.jini.jeri.connection.ConnectionManager
to log
information at the following levels:
Level | Description |
---|---|
FINEST | connection opened or reused |
This implementation uses the Logger
named
net.jini.jeri.connection.mux
to log information at the
following levels:
Level | Description |
---|---|
WARNING | unexpected exception during asynchronous I/O processing, or thread creation failure |
HANDLED | I/O exception during asynchronous I/O processing |
FINEST | detailed implementation activity |
This implementation recognizes the following system properties:
com.sun.jini.jeri.connectionTimeout
- Time in
milliseconds to leave idle client-side connections around before
closing them. The default value is 15000 milliseconds (15 seconds).
com.sun.jini.jeri.handshakeTimeout
- Time in
milliseconds for client-side connections to wait for the server to
acknowledge an opening handshake. The default value is 15000 milliseconds (15 seconds).
Modifier and Type | Class and Description |
---|---|
private static class |
ConnectionManager.Outbound
Outbound request wrapper around the outbound request created by the mux.
|
private class |
ConnectionManager.OutboundMux
Subclass wrapper around MuxClient for outbound connections.
|
private static class |
ConnectionManager.Reaper
Records idle times in muxes and shuts down muxes that have been
idle for at least TIMEOUT milliseconds.
|
private class |
ConnectionManager.ReqIterator
Outbound request iterator returned by newRequest.
|
Modifier and Type | Field and Description |
---|---|
private List |
active
The active muxes (during connect).
|
private ConnectionEndpoint |
ep
The endpoint.
|
private static long |
HANDSHAKE_TIMEOUT
How long to wait for a server to respond to an initial client message.
|
private List |
idle
The idle muxes (during connect).
|
private static Logger |
logger
ConnectionManager logger.
|
private List |
muxes
The OutboundMuxes.
|
private int |
pendingConnects
Number of pending connect calls.
|
private static Set |
reaperSet
Set of connection managers with open or pending muxes
(connections), for consideration by the reaper thread.
|
private Collection |
roactive
Unmodifiable view of active.
|
private Collection |
roidle
Unmodifiable view of idle.
|
private static Executor |
systemThreadPool
Executor that executes tasks in pooled system threads.
|
private static long |
TIMEOUT
How long to leave idle muxes around before closing them.
|
Constructor and Description |
---|
ConnectionManager(ConnectionEndpoint ep)
Creates a new
ConnectionManager that manages
client-side connections to the specified connection endpoint. |
Modifier and Type | Method and Description |
---|---|
(package private) boolean |
checkIdle(long now,
List idle)
For each mux, calls checkIdle on the mux, and if checkIdle returns
true, removes the mux and adds it to the idle list.
|
(package private) ConnectionManager.OutboundMux |
connect(OutboundRequestHandle handle)
Calls connect on the connection endpoint with the active and idle
muxes and the specified handle.
|
private ConnectionManager.OutboundMux |
newOutboundMux(Connection c)
Constructs an OutboundMux instance from the connection.
|
OutboundRequestIterator |
newRequest(OutboundRequestHandle handle)
Returns an
OutboundRequestIterator to use to send
a new request for the specified handle to this connection
manager's ConnectionEndpoint . |
(package private) void |
remove(ConnectionManager.OutboundMux mux)
Removes and shuts down a mux.
|
private static final long TIMEOUT
private static final long HANDSHAKE_TIMEOUT
private static final Logger logger
private static final Executor systemThreadPool
private static final Set reaperSet
private final ConnectionEndpoint ep
private final List muxes
private final List active
private final Collection roactive
private final List idle
private final Collection roidle
private int pendingConnects
public ConnectionManager(ConnectionEndpoint ep)
ConnectionManager
that manages
client-side connections to the specified connection endpoint.ep
- the connection endpointConnectionManager.OutboundMux connect(OutboundRequestHandle handle) throws IOException
IOException
boolean checkIdle(long now, List idle)
void remove(ConnectionManager.OutboundMux mux)
private ConnectionManager.OutboundMux newOutboundMux(Connection c) throws IOException
IOException
public OutboundRequestIterator newRequest(OutboundRequestHandle handle)
OutboundRequestIterator
to use to send
a new request for the specified handle to this connection
manager's ConnectionEndpoint
.
If the hasNext
method of the returned iterator
returns true
, the next
method behaves
as follows:
The connection endpoint'sconnect
method is invoked with any active connections that have not reached their maximum number of in-progress requests, any idle connections, andhandle
. If that returnsnull
, the endpoint'sconnect
method is invoked withhandle
. In either case, if a new connection is returned, the Jini ERI multiplexing protocol is started on the connection (as the client). Finally, thewriteRequestData
method of the connection is invoked withhandle
and the request output stream of theOutboundRequest
that is created for the request. If any exception is thrown while obtaining a connection from the endpoint or writing the request data, that exception is thrown to the caller. TheOutboundRequest
returned bynext
will invoke thereadResponseData
method of the connection with the specified handle and the response input stream before any other data is read from the response input stream. ThepopulateContext
andgetUnfulfilledConstraints
methods of theOutboundRequest
are implemented by delegating to the corresponding method of the connection passinghandle
and the other arguments (if any).
The returned iterator might allow continued iteration if the connection used for the most recent request attempt was shut down gracefully by the server.
handle
- a handle to identify the request in later
invocations on the connection endpoint and its connectionsOutboundRequestIterator
to use to send
a new request for the specified handle to this connection
manager's ConnectionEndpoint
NullPointerException
- if handle
is
null
Copyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.