net.jini.jeri.tcp
Class TcpEndpoint.ConnectionImpl

java.lang.Object
  extended by net.jini.jeri.tcp.TcpEndpoint.ConnectionImpl
All Implemented Interfaces:
Connection
Enclosing class:
TcpEndpoint

private static class TcpEndpoint.ConnectionImpl
extends Object
implements Connection

Connection implementation. Instances of this class should never get exposed to anything other than our ConnectionManager, which we trust to operate correctly, so we do not bother to validate request handles passed in.


Field Summary
private  InetSocketAddress inetSocketAddress
           
private  Socket socket
           
private  int socketPort
           
 
Constructor Summary
TcpEndpoint.ConnectionImpl(Socket socket)
           
 
Method Summary
(package private)  void checkConnectPermission()
           
 void close()
          Closes this connection.
 SocketChannel getChannel()
          Returns a socket channel that performs I/O on this connection, or null if no socket channel is available.
 InputStream getInputStream()
          Returns an input stream that reads data from this connection.
 OutputStream getOutputStream()
          Returns an output stream that writes data to this connection.
(package private)  Socket getSocket()
           
 InvocationConstraints getUnfulfilledConstraints(OutboundRequestHandle handle)
          Implements OutboundRequest.getUnfulfilledConstraints for a request with the specified handle.
 void populateContext(OutboundRequestHandle handle, Collection context)
          Populates the supplied collection with context information representing a request with the specified handle.
 IOException readResponseData(OutboundRequestHandle handle, InputStream in)
          Reads from the specified stream any per-response data required by this connection for a request with the specified handle.
 void writeRequestData(OutboundRequestHandle handle, OutputStream out)
          Writes to the specified stream any per-request data required by this connection for a request with the specified handle.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

socket

private final Socket socket

inetSocketAddress

private final InetSocketAddress inetSocketAddress

socketPort

private final int socketPort
Constructor Detail

TcpEndpoint.ConnectionImpl

TcpEndpoint.ConnectionImpl(Socket socket)
Method Detail

getSocket

Socket getSocket()

getInputStream

public InputStream getInputStream()
                           throws IOException
Description copied from interface: Connection
Returns an input stream that reads data from this connection.

Specified by:
getInputStream in interface Connection
Returns:
an input stream that reads data from this connection
Throws:
IOException - if an I/O exception occurs

getOutputStream

public OutputStream getOutputStream()
                             throws IOException
Description copied from interface: Connection
Returns an output stream that writes data to this connection.

Specified by:
getOutputStream in interface Connection
Returns:
an output stream that writes data to this connection
Throws:
IOException - if an I/O exception occurs

getChannel

public SocketChannel getChannel()
Description copied from interface: Connection
Returns a socket channel that performs I/O on this connection, or null if no socket channel is available. If a non-null socket channel is returned, it is connected.

Specified by:
getChannel in interface Connection
Returns:
a socket channel that performs I/O on this connection, or null

populateContext

public void populateContext(OutboundRequestHandle handle,
                            Collection context)
Description copied from interface: Connection
Populates the supplied collection with context information representing a request with the specified handle. This method is used to implement OutboundRequest.populateContext for such requests; the context may also be populated by the connection manager.

Specified by:
populateContext in interface Connection
Parameters:
handle - the handle for the request
context - the context collection to populate

getUnfulfilledConstraints

public InvocationConstraints getUnfulfilledConstraints(OutboundRequestHandle handle)
Description copied from interface: Connection
Implements OutboundRequest.getUnfulfilledConstraints for a request with the specified handle.

Specified by:
getUnfulfilledConstraints in interface Connection
Parameters:
handle - the handle for the request
Returns:
the constraints for the request that must be partially or fully implemented by higher layers

writeRequestData

public void writeRequestData(OutboundRequestHandle handle,
                             OutputStream out)
Description copied from interface: Connection
Writes to the specified stream any per-request data required by this connection for a request with the specified handle.

This method is invoked by ConnectionManager with the request output stream of the OutboundRequest that it creates for the request. This method can be used, for example, to convey per-request information about delegation, client authentication, or client privileges.

There may be multiple requests in progress concurrently over this connection, and data written to the specified stream may be buffered and multiplexed with data from other requests before being written to this connection's underlying output stream. Therefore, this method should only write data to the specified stream and must not read any data from this connection's underlying input stream; data can, however, be subsequently read with readResponseData.

Specified by:
writeRequestData in interface Connection
Parameters:
handle - the handle for the request
out - the request output stream of the request

readResponseData

public IOException readResponseData(OutboundRequestHandle handle,
                                    InputStream in)
Description copied from interface: Connection
Reads from the specified stream any per-response data required by this connection for a request with the specified handle.

This method returns null if the information read (if any) indicates that the constraints are satisfied, and it returns an exception if the constraints could not be satisfied. If an exception is returned rather than thrown, the delivery status of a corresponding OutboundRequest will be false.

This method is invoked by ConnectionManager with the response input stream of the OutboundRequest that it creates for the request and the same handle that was passed to writeRequestData. This method can be used to read information produced by ServerConnection.processRequestData in response to the information sent by writeRequestData.

There may be multiple requests in progress concurrently over this connection, and data read from the specified stream may have been buffered and multiplexed with data from other requests being read from this connection's underlying input stream. Therefore, this method should only read data from the specified stream and must not write any data to this connection's underlying output stream.

Specified by:
readResponseData in interface Connection
Parameters:
handle - the handle for the request
in - the response input stream of the request
Returns:
null if the constraints are satisfied, or an exception if the constraints could not be satisfied

close

public void close()
Description copied from interface: Connection
Closes this connection.

Specified by:
close in interface Connection

checkConnectPermission

void checkConnectPermission()


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