Package org.omegazero.net.nio.socket
Class NioPlaintextConnection
java.lang.Object
org.omegazero.common.util.SimpleAttachmentContainer
org.omegazero.net.socket.AbstractSocketConnection
org.omegazero.net.nio.socket.ChannelConnection
org.omegazero.net.nio.socket.NioPlaintextConnection
- All Implemented Interfaces:
Closeable
,AutoCloseable
,org.omegazero.common.util.AttachmentContainer
,SocketConnection
A
ChannelConnection
with no encryption.- API Note:
- Before version 2.1.0, this class was in package
org.omegazero.net.socket.impl
and calledPlainConnection
.
-
Field Summary
Fields inherited from class org.omegazero.net.nio.socket.ChannelConnection
readBuf, writeBuf
Fields inherited from class org.omegazero.net.socket.AbstractSocketConnection
EV_CLOSE, EV_CONNECT, EV_DATA, EV_ERROR, EV_TIMEOUT, EV_WRITABLE, eventEmitter, readLock, writeLock
Fields inherited from class org.omegazero.common.util.SimpleAttachmentContainer
attachments
-
Constructor Summary
ConstructorsConstructorDescriptionNioPlaintextConnection
(SelectionKey selectionKey, ChannelProvider provider) NioPlaintextConnection
(SelectionKey selectionKey, ChannelProvider provider, SocketAddress remote) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Must be called by subclass constructors.boolean
flush()
Attempts to flush any queued data after a call toSocketConnection.writeQueue(byte[])
or data that could not be written previously because the socket was busy.byte[]
read()
Reads data received from the peer host on this connection.void
write
(byte[] data, int offset, int length) Writes data to this connection for delivery to the peer host.void
writeQueue
(byte[] data, int offset, int length) Similar toSocketConnection.write(byte[], int, int)
, except that no attempt will be made to immediately flush the data to the socket, if supported by the implementation.Methods inherited from class org.omegazero.net.nio.socket.ChannelConnection
close, close0, connect, destroy, flushWriteBacklog, getLastIOTime, getLocalAddress, getProvider, getRemoteAddress, isConnected, isWritable, readFromSocket, setReadBlock, writeBuffered, writeToSocket
Methods inherited from class org.omegazero.net.socket.AbstractSocketConnection
getApparentRemoteAddress, getReadLock, getWorker, getWriteLock, handleClose, handleConnect, handleData, handleError, handleTimeout, handleWritable, hasConnected, localClose, localConnect, off, on, once, queueWrite, runAsync, runAsync, setApparentRemoteAddress, setDefaultErrorListener, setOnLocalClose, setOnLocalConnect, setWorker
Methods inherited from class org.omegazero.common.util.SimpleAttachmentContainer
getAttachment, hasAttachment, removeAttachment, setAttachment
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.omegazero.common.util.AttachmentContainer
requireAttachment
Methods inherited from interface org.omegazero.net.socket.SocketConnection
hasDisconnected, on, on, setOnClose, setOnConnect, setOnData, setOnError, setOnTimeout, setOnWritable, write, write, writeQueue
-
Constructor Details
-
NioPlaintextConnection
public NioPlaintextConnection(SelectionKey selectionKey, ChannelProvider provider) throws IOException - Throws:
IOException
-
NioPlaintextConnection
public NioPlaintextConnection(SelectionKey selectionKey, ChannelProvider provider, SocketAddress remote) throws IOException - Throws:
IOException
-
-
Method Details
-
createBuffers
protected void createBuffers()Description copied from class:ChannelConnection
Must be called by subclass constructors. This method creates theChannelConnection.readBuf
andChannelConnection.writeBuf
buffers and any additional buffers required.- Specified by:
createBuffers
in classChannelConnection
-
read
public byte[] read()Description copied from interface:SocketConnection
Reads data received from the peer host on this connection.Whether this method is blocking is implementation-defined. If no data was available,
null
is returned, or the method blocks until data is available.- Returns:
- The read data or
null
if no data is available.
-
write
public void write(byte[] data, int offset, int length) Description copied from interface:SocketConnection
Writes data to this connection for delivery to the peer host.Whether this method is blocking is implementation-defined. A call to this method may store data in a temporary write buffer if the underlying socket is busy. An application should try to respect the value of
SocketConnection.isWritable()
to reduce memory consumption by such write buffer if a lot of data is being written (see also:writable
event).If this method is called before the
connect
event, the data is queued in a temporary buffer and written out when the socket connects.- Parameters:
data
- The data to writeoffset
- The start index of the data to write in the data byte arraylength
- The total number of bytes to write from the data byte array, starting at offset- See Also:
-
writeQueue
public void writeQueue(byte[] data, int offset, int length) Description copied from interface:SocketConnection
Similar toSocketConnection.write(byte[], int, int)
, except that no attempt will be made to immediately flush the data to the socket, if supported by the implementation.- Parameters:
data
- The data to writeoffset
- The start index of the data to write in the data byte arraylength
- The total number of bytes to write from the data byte array, starting at offset- See Also:
-
flush
public boolean flush()Description copied from class:ChannelConnection
Attempts to flush any queued data after a call toSocketConnection.writeQueue(byte[])
or data that could not be written previously because the socket was busy.Whether this method is blocking is implementation-defined.
- Specified by:
flush
in interfaceSocketConnection
- Overrides:
flush
in classChannelConnection
- Returns:
true
if all data could be written to the socket- See Also:
-