public abstract class AbstractConnection extends Object
Constructor and Description |
---|
AbstractConnection(AbstractConnection ac)
This copy constructor enables duplication of a connection.
|
AbstractConnection(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.
|
Modifier and Type | Method and Description |
---|---|
protected void |
closeConnection() |
void |
connect()
Connects to the remote host with respective security context.
|
protected void |
do_handshake(long timeout) |
protected void |
do_teardown(long timeout) |
protected ByteBuffer |
enlargeApplicationBuffer(SSLEngine engine,
ByteBuffer buffer) |
protected ByteBuffer |
enlargeBuffer(ByteBuffer buffer,
int sessionProposedCapacity) |
protected ByteBuffer |
enlargePacketBuffer(SSLEngine engine,
ByteBuffer buffer) |
static long |
getDefaultTimeout()
Gets the default timeout for all connections not having an own timeout.
|
protected SSLEngine |
getEngine() |
String |
getHostName()
Get the hostname of the remote host.
|
int |
getPort()
Gets the port of the remote host.
|
String |
getProtocol()
Gets the protocol name used.
|
SecurityContext |
getSecurityContext()
Gets the security context used with the socket channel.
|
SocketChannel |
getSocketChannel()
Returns the socket channel in use for this connection.
|
long |
getTimeout()
Gets the default timeout for this connection.
|
protected ByteBuffer |
handleBufferUnderflow(SSLEngine engine,
ByteBuffer buffer) |
protected void |
handleEndOfStream() |
boolean |
isShutdown() |
boolean |
isTls()
returns true if a TLS handshake has been successfully done.
|
String |
read() |
String |
read(long timeout)
Read a string from the socket channel.
|
String |
readln() |
String |
readln(long timeout)
Read a string up until CRLF from the socket channel.
|
static long |
setDefaultTimeout(long timeout)
Sets the default timeout for all connections not having an own timeout.
|
protected SSLEngine |
setEngine(SSLEngine engine) |
String |
setProtocol(String protocol)
Sets the protocol to be used (mainly for logger messages).
|
SecurityContext |
setSecurityContext(SecurityContext context)
Sets the security context to be used with the socket channel.
|
protected SocketChannel |
setSocketChannel(SocketChannel s) |
long |
setTimeout(long timeout)
Sets the default timeout for this connection.
|
void |
shutdown() |
void |
startTls()
Make a TLS handshake on the connection with the default timeout.
|
void |
startTls(long timeout)
Make a TLS handshake on the connection with a specified timeout.
|
void |
write(String message) |
void |
write(String message,
long timeout)
Write a message string to the peer partner.
|
void |
writeln(String message) |
void |
writeln(String message,
long timeout) |
protected static final String CRLF
public AbstractConnection(InetSocketAddress remoteAddress, SecurityContext context)
public AbstractConnection(AbstractConnection ac)
This copy constructor enables duplication of a connection.
ac
- A connection to be copiedpublic AbstractConnection(SocketChannel sock, SecurityContext context, boolean isClient)
Create a connection with the given context.
sock
- the channel to connect tocontext
- the predefined security contextisClient
- true if the connection is a client connectionpublic AbstractConnection(SocketChannel sock, SecurityContext context)
Create a connection with the given context.
sock
- the channel to connect tocontext
- the predefined security contextpublic String getHostName()
Get the hostname of the remote host.
public int getPort()
Gets the port of the remote host.
protected final SocketChannel setSocketChannel(SocketChannel s)
public SocketChannel getSocketChannel() throws IOException
Returns the socket channel in use for this connection.
IOException
- if socket is not connectedpublic final SecurityContext setSecurityContext(SecurityContext context)
Sets the security context to be used with the socket channel.
context
- the security context to be usedpublic SecurityContext getSecurityContext()
Gets the security context used with the socket channel.
protected SSLEngine getEngine()
public void connect() throws IOException
Connects to the remote host with respective security context.
IOException
- if connecting failspublic void startTls() throws IOException
Make a TLS handshake on the connection with the default timeout.
IOException
- if handshake failspublic void startTls(long timeout) throws IOException
Make a TLS handshake on the connection with a specified timeout.
timeout
- the timeout in millisecondsIOException
- if handshake failspublic String setProtocol(String protocol)
Sets the protocol to be used (mainly for logger messages).
protocol
- the protocol name or abbreviationpublic String getProtocol()
Gets the protocol name used.
protected void do_handshake(long timeout) throws IOException
IOException
protected void do_teardown(long timeout) throws IOException
IOException
public boolean isTls()
returns true if a TLS handshake has been successfully done.
public static long setDefaultTimeout(long timeout)
Sets the default timeout for all connections not having an own timeout.
timeout
- the timeout in millisecondspublic static long getDefaultTimeout()
Gets the default timeout for all connections not having an own timeout.
public long setTimeout(long timeout)
Sets the default timeout for this connection.
timeout
- the timeout in millisecondspublic long getTimeout()
Gets the default timeout for this connection.
public void writeln(String message) throws IOException
IOException
public void writeln(String message, long timeout) throws IOException
IOException
public void write(String message) throws IOException
IOException
public void write(String message, long timeout) throws IOException
Write a message string to the peer partner.
message
- the message string to be senttimeout
- the timeout in millisecondsIOException
- if communication or encryption failspublic String read() throws IOException, TimeoutException
IOException
TimeoutException
public String read(long timeout) throws IOException, TimeoutException
Read a string from the socket channel.
timeout
- the timeout to be applied before unblockingIOException
- if decryption fails or host is unexpectedly disconnectedTimeoutException
- if reaching a timeout while readingpublic String readln() throws IOException, TimeoutException
IOException
TimeoutException
public String readln(long timeout) throws IOException, TimeoutException
Read a string up until CRLF from the socket channel.
timeout
- the timeout to be applied before unblockingIOException
- if decryption fails or host is unexpectedly disconnectedTimeoutException
- if reaching a timeout while readingprotected ByteBuffer enlargePacketBuffer(SSLEngine engine, ByteBuffer buffer)
protected ByteBuffer enlargeApplicationBuffer(SSLEngine engine, ByteBuffer buffer)
protected ByteBuffer enlargeBuffer(ByteBuffer buffer, int sessionProposedCapacity)
protected ByteBuffer handleBufferUnderflow(SSLEngine engine, ByteBuffer buffer)
protected void closeConnection() throws IOException
IOException
protected void handleEndOfStream() throws IOException
IOException
public void shutdown() throws IOException
IOException
public boolean isShutdown()
Copyright © 2023. All rights reserved.