com.infoengine.procunit.adapter
Class Adapter

java.lang.Object
  extended bycom.infoengine.procunit.adapter.Adapter

public class Adapter
extends Object

This class supports communication between Info*Engine components. It establishes network connections, transmits requests, and receives results. The Info*Engine servlet uses it to create connections and send requests to the template and task processors, and the task processor uses it to create connections and send requests to adapters.


Nested Class Summary
private  class Adapter.AdapterInputStream
          The following inner classes wrap InputStream and OutputStream in order to prevent their close() methods from closing the sockets from which they are derived.
private  class Adapter.AdapterOutputStream
           
 
Field Summary
private static HashMap adapterInstances
           
private static Map busyConnections
           
private static Map freeConnections
           
private static Map freeConnectionsLastUse
           
private  IeRequest ieResponse
           
protected  IeMultipartInputStream inputStream
           
private  com.infoengine.log.LogWriter logWriter
           
private  int maxConnectionAge
           
private  int maxConnectionCacheSize
           
private static String myHostName
           
private  IeRequest originalRequest
           
protected  IeMultipartOutputStream outputStream
           
private  IeProcessor processor
           
private  String requestContentType
           
private static String RESOURCE
           
private  String runtimeServiceName
           
private  String serviceName
           
private  Socket socket
           
 
Constructor Summary
Adapter(Enumeration serviceNames, com.infoengine.log.LogWriter logWriter)
          Constructs an instance initialized to support communication with a component identified in an enumeration.
Adapter(String serviceName, com.infoengine.log.LogWriter logWriter)
          Constructs an instance initialized to support communication with a named component.
 
Method Summary
 void close()
          Releases the connection.
private  void closeConnection(Socket connection, boolean force)
           
private  void createConnection(String serviceName, com.infoengine.log.LogWriter logWriter)
          Creates a connection to a named component.
private  Socket getConnection(String serviceName)
           
private  Socket getFreeConnection(String serviceName)
           
 InputStream getInputStream()
          Returns the input stream associated with the connection established by this object.
 OutputStream getOutputStream()
          Returns the output stream currently associated with the connection established by this object.
 String getServiceName()
          Returns the name of the service currently associated with the object instance.
private  void initialize()
          Initializes the object instance.
 boolean isInProcess()
          Indicates whether the service currently associated with the object instance will be executed in-process.
 IeRequest receive()
          Reads and returns a response to a request previously sent across the established connection.
 void send(IeRequest request)
          Sends an Info*Engine request object across the established connection.
 void send(IeRequest request, IeMultipartInputStream in)
          Sends an Info*Engine request object across the established connection, and copies BLOB's from a specified servlet input stream to the connection too.
 void setInputStream(IeMultipartInputStream is)
          Sets the multipart input stream associated with the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ieResponse

private IeRequest ieResponse

logWriter

private com.infoengine.log.LogWriter logWriter

myHostName

private static String myHostName

originalRequest

private IeRequest originalRequest

processor

private IeProcessor processor

socket

private Socket socket

serviceName

private String serviceName

runtimeServiceName

private String runtimeServiceName

requestContentType

private String requestContentType

RESOURCE

private static String RESOURCE

outputStream

protected IeMultipartOutputStream outputStream

inputStream

protected IeMultipartInputStream inputStream

adapterInstances

private static HashMap adapterInstances

busyConnections

private static Map busyConnections

freeConnections

private static Map freeConnections

freeConnectionsLastUse

private static Map freeConnectionsLastUse

maxConnectionAge

private int maxConnectionAge

maxConnectionCacheSize

private int maxConnectionCacheSize
Constructor Detail

Adapter

public Adapter(String serviceName,
               com.infoengine.log.LogWriter logWriter)
        throws IEException
Constructs an instance initialized to support communication with a named component. The Info*Engine naming service is used to look up the address of the named component, and a connection is established.

Parameters:
serviceName - The name of the component with which to establish a connection.
logWriter - The LogWriter on which to write messages related to this network connection.
Throws:
IEException - if a connection can not be established to the named component, perhaps because the component is unknown or it is not accepting connections.

Adapter

public Adapter(Enumeration serviceNames,
               com.infoengine.log.LogWriter logWriter)
        throws IEException
Constructs an instance initialized to support communication with a component identified in an enumeration. The enumeration is traversed one element at a time. Each element is assumed to be the name of a service. The Info*Engine naming service is used to look up the address of the named service, and a connection is attempted. If the connection attempt fails, the next name in the enumeration is attempted. As soon as a connection is established successfully, construction of the object instance is complete.

Parameters:
serviceNames - The enumeration of service names with which to establish a connection.
logWriter - The LogWriter on which to write messages related to this network connection.
Throws:
IEException - if a connection can not be established to any of the named services, perhaps because none of the services are known, or none are accepting connections.
Method Detail

getServiceName

public String getServiceName()
Returns the name of the service currently associated with the object instance.

Returns:
The current service name

isInProcess

public boolean isInProcess()
Indicates whether the service currently associated with the object instance will be executed in-process.

Returns:
true if the service is in-process

setInputStream

public void setInputStream(IeMultipartInputStream is)
                    throws IEException
Sets the multipart input stream associated with the object. Use this to establish a stream from which BLOB's will be copied.

Parameters:
is - The multipart input stream from which BLOB's will be copied to the component at the other end of the connection.
Throws:
IEException - if the input stream can not be associated with this object.

getInputStream

public InputStream getInputStream()
                           throws IEException
Returns the input stream associated with the connection established by this object.

Throws:
IEException - if the input stream can not be obtained.

getOutputStream

public OutputStream getOutputStream()
                             throws IEException
Returns the output stream currently associated with the connection established by this object.

Throws:
IEException - if the output stream can not be pbtained.

send

public void send(IeRequest request,
                 IeMultipartInputStream in)
          throws IEException
Sends an Info*Engine request object across the established connection, and copies BLOB's from a specified servlet input stream to the connection too.

Parameters:
request - The Info*Engine request object to be sent across the connection.
in - The servlet input stream possibly containing BLOB's to be sent across the connection.
Throws:
IEException - if the request and/or BLOB's can not be sent successfully.

send

public void send(IeRequest request)
          throws IEException
Sends an Info*Engine request object across the established connection.

Parameters:
request - The Info*Engine request object to be sent across the connection.
Throws:
IEException - if the request can not be sent successfully.

receive

public IeRequest receive()
                  throws IEException,
                         AdapterException
Reads and returns a response to a request previously sent across the established connection.

Returns:
The response to a request previously sent across the connection.
Throws:
IEException - if an I/O error prevents the response from being received successfully.
AdapterException - if the peer on the other end of the connection returns an exception.

close

public void close()
Releases the connection.


createConnection

private void createConnection(String serviceName,
                              com.infoengine.log.LogWriter logWriter)
                       throws IEException
Creates a connection to a named component. The Info*Engine naming service is used to look up the address of the named component, and a connection is established.

Parameters:
serviceName - The name of the component with which to establish a connection.
logWriter - The log writer to which to write log messages
Throws:
IEException - if a connection can not be established to the named component, perhaps because the component is unknown or it is not accepting connections.

initialize

private void initialize()
                 throws IEException
Initializes the object instance.

Throws:
IEException

getConnection

private Socket getConnection(String serviceName)
                      throws IEException
Throws:
IEException

getFreeConnection

private Socket getFreeConnection(String serviceName)

closeConnection

private void closeConnection(Socket connection,
                             boolean force)