Class AbstractConnection
- Direct Known Subclasses:
ClientConnection,ServerConnection
- Author:
- Martin Gwerder
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionAbstractConnection(InetSocketAddress remoteAddress, SecurityContext context) AbstractConnection(SocketChannel sock, SecurityContext context) Create a connection with the given context.AbstractConnection(SocketChannel sock, SecurityContext context, boolean isClient) Create a connection with the given context.This copy constructor enables duplication of a connection. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidvoidconnect()Connects to the remote host with respective security context.protected voiddo_handshake(long timeout) protected voiddo_teardown(long timeout) protected ByteBufferenlargeApplicationBuffer(SSLEngine engine, ByteBuffer buffer) protected ByteBufferenlargeBuffer(ByteBuffer buffer, int sessionProposedCapacity) protected ByteBufferenlargePacketBuffer(SSLEngine engine, ByteBuffer buffer) static longGets the default timeout for all connections not having an own timeout.protected SSLEngineGet the hostname of the remote host.intgetPort()Gets the port of the remote host.Gets the protocol name used.Gets the security context used with the socket channel.Returns the socket channel in use for this connection.longGets the default timeout for this connection.protected ByteBufferhandleBufferUnderflow(SSLEngine engine, ByteBuffer buffer) protected voidbooleanbooleanisTls()returns true if a TLS handshake has been successfully done.read()read(long timeout) Read a string from the socket channel.readln()readln(long timeout) Read a string up until CRLF from the socket channel.static longsetDefaultTimeout(long timeout) Sets the default timeout for all connections not having an own timeout.protected final SSLEnginesetProtocol(String protocol) Sets the protocol to be used (mainly for logger messages).final SecurityContextsetSecurityContext(SecurityContext context) Sets the security context to be used with the socket channel.protected final SocketChannellongsetTimeout(long timeout) Sets the default timeout for this connection.voidshutdown()voidstartTls()Make a TLS handshake on the connection with the default timeout.voidstartTls(long timeout) Make a TLS handshake on the connection with a specified timeout.voidvoidWrite a message string to the peer partner.voidvoid
-
Field Details
-
CRLF
- See Also:
-
-
Constructor Details
-
AbstractConnection
-
AbstractConnection
This copy constructor enables duplication of a connection.
- Parameters:
ac- A connection to be copied
-
AbstractConnection
Create a connection with the given context.
- Parameters:
sock- the channel to connect tocontext- the predefined security contextisClient- true if the connection is a client connection
-
AbstractConnection
Create a connection with the given context.
- Parameters:
sock- the channel to connect tocontext- the predefined security context
-
-
Method Details
-
getHostName
Get the hostname of the remote host.
- Returns:
- the hostname
-
getPort
public int getPort()Gets the port of the remote host.
- Returns:
- the remote port number (if known; otherwise -1)
-
setSocketChannel
-
getSocketChannel
Returns the socket channel in use for this connection.
- Returns:
- the socket channel of this connection
- Throws:
IOException- if socket is not connected
-
setSecurityContext
Sets the security context to be used with the socket channel.
- Parameters:
context- the security context to be used- Returns:
- the previously set security context
-
getSecurityContext
Gets the security context used with the socket channel.
- Returns:
- the security context
-
getEngine
-
setEngine
-
connect
Connects to the remote host with respective security context.
- Throws:
IOException- if connecting fails
-
startTls
Make a TLS handshake on the connection with the default timeout.
- Throws:
IOException- if handshake fails
-
startTls
Make a TLS handshake on the connection with a specified timeout.
- Parameters:
timeout- the timeout in milliseconds- Throws:
IOException- if handshake fails
-
setProtocol
Sets the protocol to be used (mainly for logger messages).
- Parameters:
protocol- the protocol name or abbreviation- Returns:
- the previously set protocol name
-
getProtocol
Gets the protocol name used.
- Returns:
- the protocol name
-
do_handshake
- Throws:
IOException
-
do_teardown
- Throws:
IOException
-
isTls
public boolean isTls()returns true if a TLS handshake has been successfully done.
- Returns:
- the TLS state
-
setDefaultTimeout
public static long setDefaultTimeout(long timeout) Sets the default timeout for all connections not having an own timeout.
- Parameters:
timeout- the timeout in milliseconds- Returns:
- the previously set timeout
-
getDefaultTimeout
public static long getDefaultTimeout()Gets the default timeout for all connections not having an own timeout.
- Returns:
- the previously set timeout
-
setTimeout
public long setTimeout(long timeout) Sets the default timeout for this connection.
- Parameters:
timeout- the timeout in milliseconds- Returns:
- the previously set timeout
-
getTimeout
public long getTimeout()Gets the default timeout for this connection.
- Returns:
- the timeout in milliseconds
-
writeln
- Throws:
IOException
-
writeln
- Throws:
IOException
-
write
- Throws:
IOException
-
write
Write a message string to the peer partner.
- Parameters:
message- the message string to be senttimeout- the timeout in milliseconds- Throws:
IOException- if communication or encryption fails
-
read
- Throws:
IOExceptionTimeoutException
-
read
Read a string from the socket channel.
- Parameters:
timeout- the timeout to be applied before unblocking- Returns:
- the string read
- Throws:
IOException- if decryption fails or host is unexpectedly disconnectedTimeoutException- if reaching a timeout while reading
-
readln
- Throws:
IOExceptionTimeoutException
-
readln
Read a string up until CRLF from the socket channel.
- Parameters:
timeout- the timeout to be applied before unblocking- Returns:
- the string read
- Throws:
IOException- if decryption fails or host is unexpectedly disconnectedTimeoutException- if reaching a timeout while reading
-
enlargePacketBuffer
-
enlargeApplicationBuffer
-
enlargeBuffer
-
handleBufferUnderflow
-
closeConnection
- Throws:
IOException
-
handleEndOfStream
- Throws:
IOException
-
shutdown
- Throws:
IOException
-
isShutdown
public boolean isShutdown()
-