net.jini.jeri.connection
Class ConnectionManager

java.lang.Object
  extended by net.jini.jeri.connection.ConnectionManager

public final class ConnectionManager
extends Object

Provides client-side connection management using the Jini extensible remote invocation (Jini ERI) multiplexing protocol to frame and multiplex requests and responses over connections.

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.

Since:
2.0
Author:
Sun Microsystems, Inc.
Implementation Specifics:
This implementation uses the 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:


Nested Class Summary
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.
 
Field Summary
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 Summary
ConnectionManager(ConnectionEndpoint ep)
          Creates a new ConnectionManager that manages client-side connections to the specified connection endpoint.
 
Method Summary
(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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TIMEOUT

private static final long TIMEOUT
How long to leave idle muxes around before closing them.


HANDSHAKE_TIMEOUT

private static final long HANDSHAKE_TIMEOUT
How long to wait for a server to respond to an initial client message.


logger

private static final Logger logger
ConnectionManager logger.


systemThreadPool

private static final Executor systemThreadPool
Executor that executes tasks in pooled system threads.


reaperSet

private static final Set reaperSet
Set of connection managers with open or pending muxes (connections), for consideration by the reaper thread.


ep

private final ConnectionEndpoint ep
The endpoint.


muxes

private final List muxes
The OutboundMuxes.


active

private final List active
The active muxes (during connect).


roactive

private final Collection roactive
Unmodifiable view of active.


idle

private final List idle
The idle muxes (during connect).


roidle

private final Collection roidle
Unmodifiable view of idle.


pendingConnects

private int pendingConnects
Number of pending connect calls.

Constructor Detail

ConnectionManager

public ConnectionManager(ConnectionEndpoint ep)
Creates a new ConnectionManager that manages client-side connections to the specified connection endpoint.

Parameters:
ep - the connection endpoint
Method Detail

connect

ConnectionManager.OutboundMux connect(OutboundRequestHandle handle)
                                throws IOException
Calls connect on the connection endpoint with the active and idle muxes and the specified handle. If no connection is returned, calls connect with the handle. In either case, if a new connection is returned, creates and adds a mux for it. In all cases, bumps the newRequest count for the mux and returns it. Removes any dead muxes along the way.

Throws:
IOException

checkIdle

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. Returns true if no connects are pending and no muxes remain.


remove

void remove(ConnectionManager.OutboundMux mux)
Removes and shuts down a mux.


newOutboundMux

private ConnectionManager.OutboundMux newOutboundMux(Connection c)
                                              throws IOException
Constructs an OutboundMux instance from the connection.

Throws:
IOException

newRequest

public OutboundRequestIterator newRequest(OutboundRequestHandle handle)
Returns an 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's connect method is invoked with any active connections that have not reached their maximum number of in-progress requests, any idle connections, and handle. If that returns null, the endpoint's connect method is invoked with handle. In either case, if a new connection is returned, the Jini ERI multiplexing protocol is started on the connection (as the client). Finally, the writeRequestData method of the connection is invoked with handle and the request output stream of the OutboundRequest 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. The OutboundRequest returned by next will invoke the readResponseData method of the connection with the specified handle and the response input stream before any other data is read from the response input stream. The populateContext and getUnfulfilledConstraints methods of the OutboundRequest are implemented by delegating to the corresponding method of the connection passing handle 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.

Parameters:
handle - a handle to identify the request in later invocations on the connection endpoint and its connections
Returns:
an OutboundRequestIterator to use to send a new request for the specified handle to this connection manager's ConnectionEndpoint
Throws:
NullPointerException - if handle is null


Copyright 2007-2010, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.