T
- The parent connector type.public abstract class Connection<T extends Connector> extends java.lang.Object implements Notifiable
Constructor and Description |
---|
Connection(BaseHelper<T> helper,
java.net.Socket socket,
java.nio.channels.SocketChannel socketChannel)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addEntityHeaders(Representation entity,
Series<Parameter> headers)
Adds the entity headers for the given response.
|
protected void |
addGeneralHeaders(Message message,
Series<Parameter> headers)
|
boolean |
canRead()
Indicates if the connection's socket can be read for inbound data.
|
boolean |
canWrite()
Indicates if the connection's socket can be written for outbound data.
|
void |
close()
Closes the connection.
|
Representation |
createInboundEntity(Series<Parameter> headers)
Returns the inbound message entity if available.
|
java.lang.String |
getAddress()
Returns the socket IP address.
|
BaseHelper<T> |
getHelper()
Returns the parent connector helper.
|
java.nio.channels.ReadableByteChannel |
getInboundEntityChannel(long size,
boolean chunked)
Returns the inbound message entity channel if it exists.
|
java.io.InputStream |
getInboundEntityStream(long size,
boolean chunked)
Returns the inbound message entity stream if it exists.
|
java.util.Queue<Response> |
getInboundMessages()
Returns the queue of inbound messages.
|
java.io.InputStream |
getInboundStream()
Returns the inbound stream.
|
java.util.logging.Logger |
getLogger()
Returns the logger.
|
java.nio.channels.WritableByteChannel |
getOutboundEntityChannel(boolean chunked)
Returns the response channel if it exists.
|
java.io.OutputStream |
getOutboundEntityStream(boolean chunked)
Returns the response entity stream if it exists.
|
java.util.Queue<Response> |
getOutboundMessages()
Returns the queue of outbound messages.
|
java.io.OutputStream |
getOutboundStream()
Returns the outbound stream.
|
int |
getPort()
Returns the socket port.
|
protected Representation |
getRepresentation(java.io.InputStream stream)
Returns the representation wrapping the given stream.
|
protected Representation |
getRepresentation(java.nio.channels.ReadableByteChannel channel)
Returns the representation wrapping the given channel.
|
java.net.Socket |
getSocket()
Returns the underlying socket.
|
java.nio.channels.SocketChannel |
getSocketChannel()
Returns the underlying NIO socket channel.
|
java.lang.String |
getSslCipherSuite()
Returns the SSL cipher suite.
|
java.util.List<java.security.cert.Certificate> |
getSslClientCertificates()
Returns the list of client SSL certificates.
|
java.lang.Integer |
getSslKeySize()
Returns the SSL key size, if available and accessible.
|
ConnectionState |
getState()
Returns the state of the connection.
|
boolean |
isBusy()
Indicates if the connection is busy.
|
boolean |
isClientSide()
Indicates if it is a client-side connection.
|
boolean |
isInboundBusy()
Indicates if the input of the socket is busy.
|
boolean |
isOutboundBusy()
Indicates if the output of the socket is busy.
|
boolean |
isPersistent()
Indicates if the connection should be persisted across calls.
|
boolean |
isPipelining()
Indicates if idempotent sequences of requests can be pipelined.
|
boolean |
isServerSide()
Indicates if it is a server-side connection.
|
void |
onEndReached()
Set the inbound busy state to false.
|
void |
onError()
Set the inbound busy state to false and the connection state to
ConnectionState.CLOSING . |
void |
open()
Opens the connection.
|
protected abstract void |
readMessage()
Reads the next message received via the inbound stream or channel.
|
void |
readMessages()
Reads inbound messages from the socket.
|
void |
setInboundBusy(boolean inboundBusy)
Indicates if the input of the socket is busy.
|
void |
setOutboundBusy(boolean outboundBusy)
Indicates if the output of the socket is busy.
|
void |
setPersistent(boolean persistent)
Indicates if the connection should be persisted across calls.
|
void |
setPipelining(boolean pipelining)
Indicates if idempotent sequences of requests can be pipelined.
|
void |
setState(ConnectionState state)
Sets the state of the connection.
|
protected boolean |
shouldBeChunked(Representation entity)
Indicates if the entity should be chunked because its length is unknown.
|
protected abstract void |
writeMessage(Response message)
Write the given message on the socket.
|
protected void |
writeMessage(Response message,
Series<Parameter> headers)
Writes the message and its headers.
|
protected void |
writeMessageBody(Representation entity,
java.nio.channels.WritableByteChannel entityChannel,
java.io.OutputStream entityStream)
Effectively writes the message body.
|
protected void |
writeMessageHead(Response message,
java.io.OutputStream headStream,
Series<Parameter> headers)
Writes the message head to the given output stream.
|
protected void |
writeMessageHead(Response message,
Series<Parameter> headers)
Writes the message head.
|
protected abstract void |
writeMessageHeadLine(Response message,
java.io.OutputStream headStream)
Writes the message head line to the given output stream.
|
void |
writeMessages()
Writes outbound messages to the socket.
|
public Connection(BaseHelper<T> helper, java.net.Socket socket, java.nio.channels.SocketChannel socketChannel) throws java.io.IOException
helper
- The parent connector helper.socket
- The underlying BIO socket.socketChannel
- The underlying NIO socket channel.java.io.IOException
protected void addEntityHeaders(Representation entity, Series<Parameter> headers)
entity
- The entity to inspect.public boolean canRead()
java.io.IOException
public boolean canWrite()
java.io.IOException
public void close()
ConnectionState.CLOSED
.public Representation createInboundEntity(Series<Parameter> headers)
headers
- The headers to use.public java.lang.String getAddress()
public BaseHelper<T> getHelper()
public java.nio.channels.ReadableByteChannel getInboundEntityChannel(long size, boolean chunked)
size
- The expected entity size or -1 if unknown.public java.io.InputStream getInboundEntityStream(long size, boolean chunked)
size
- The expected entity size or -1 if unknown.public java.util.Queue<Response> getInboundMessages()
public java.io.InputStream getInboundStream()
public java.util.logging.Logger getLogger()
public java.nio.channels.WritableByteChannel getOutboundEntityChannel(boolean chunked)
public java.io.OutputStream getOutboundEntityStream(boolean chunked)
public java.util.Queue<Response> getOutboundMessages()
public java.io.OutputStream getOutboundStream()
public int getPort()
protected Representation getRepresentation(java.io.InputStream stream)
stream
- The response input stream.protected Representation getRepresentation(java.nio.channels.ReadableByteChannel channel)
channel
- The response channel.public java.net.Socket getSocket()
public java.nio.channels.SocketChannel getSocketChannel()
public java.lang.String getSslCipherSuite()
public java.util.List<java.security.cert.Certificate> getSslClientCertificates()
public java.lang.Integer getSslKeySize()
public ConnectionState getState()
public boolean isBusy()
public boolean isClientSide()
public boolean isInboundBusy()
public boolean isOutboundBusy()
public boolean isPersistent()
public boolean isPipelining()
public boolean isServerSide()
public void onEndReached()
onEndReached
in interface Notifiable
public void onError()
ConnectionState.CLOSING
.onError
in interface Notifiable
public void open()
ConnectionState.OPEN
.protected abstract void readMessage() throws java.io.IOException
java.io.IOException
public void readMessages()
public void setInboundBusy(boolean inboundBusy)
inboundBusy
- True if the input of the socket is busy.public void setOutboundBusy(boolean outboundBusy)
outboundBusy
- True if the output of the socket is busy.public void setPersistent(boolean persistent)
persistent
- True if the connection should be persisted across calls.public void setPipelining(boolean pipelining)
pipelining
- True requests pipelining is enabled.public void setState(ConnectionState state)
state
- The state of the connection.protected boolean shouldBeChunked(Representation entity)
entity
- The entity to analyze.protected abstract void writeMessage(Response message)
message
- The message to write.protected void writeMessage(Response message, Series<Parameter> headers) throws java.io.IOException
message
- The message to write.java.io.IOException
- if the Response could not be written to the network.protected void writeMessageBody(Representation entity, java.nio.channels.WritableByteChannel entityChannel, java.io.OutputStream entityStream) throws java.io.IOException
entity
- The representation to write as entity of the body.entityChannel
- The outbound entity channel or null if a stream is used.entityStream
- The outbound entity stream or null if a channel is used.java.io.IOException
protected void writeMessageHead(Response message, java.io.OutputStream headStream, Series<Parameter> headers) throws java.io.IOException
message
- The source message.headStream
- The target stream.java.io.IOException
protected void writeMessageHead(Response message, Series<Parameter> headers) throws java.io.IOException
message
- The message.headers
- The series of headers to write.java.io.IOException
protected abstract void writeMessageHeadLine(Response message, java.io.OutputStream headStream) throws java.io.IOException
message
- The source message.headStream
- The target stream.java.io.IOException
public void writeMessages()
Copyright © 2005-2012. All Rights Reserved.