java.lang.Object
io.helidon.common.socket.NioSocket
- All Implemented Interfaces:
HelidonSocket,SocketContext,Supplier<byte[]>
- Direct Known Subclasses:
TlsNioSocket
Plain socket based on NIO
SocketChannel.
This socket uses ByteBuffer for reading and writing.-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedNioSocket(SocketChannel delegate, String childSocketId, String socketId) Plain socket. -
Method Summary
Modifier and TypeMethodDescriptionChild socket id.static NioSocketclient(SocketChannel delegate, String channelId) Create a new client socket.voidclose()Close the underlying socket.byte[]get()voididle()Sets the socket to idle mode.booleanCheck if socket is connected.booleanisSecure()Whether the request is secure.Local peer information.intread(BufferData buffer) Read bytes from the socket.protected intread(ByteBuffer buffer) Read from the underlying socket/channel into the provided buffer.Remote peer information.static NioSocketserver(SocketChannel delegate, String channelId, String serverChannelId) Create a new server socket.socketId()Main socket id.voidwrite(BufferData buffer) Write teh buffer to the underlying socket.protected intwrite(ByteBuffer buffer) Write to the underlying socket/channel from the provided buffer.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.helidon.common.socket.HelidonSocket
protocol, protocolNegotiatedMethods inherited from interface io.helidon.common.socket.SocketContext
log, log
-
Constructor Details
-
NioSocket
Plain socket.- Parameters:
delegate- delegate socketchildSocketId- channel idsocketId- server channel id
-
-
Method Details
-
server
Create a new server socket.- Parameters:
delegate- underlying socketchannelId- channel idserverChannelId- server channel id- Returns:
- a new plain socket
-
client
Create a new client socket.- Parameters:
delegate- underlying socketchannelId- channel id- Returns:
- a new plain socket
-
remotePeer
Description copied from interface:SocketContextRemote peer information.- Specified by:
remotePeerin interfaceSocketContext- Returns:
- peer info
-
localPeer
Description copied from interface:SocketContextLocal peer information.- Specified by:
localPeerin interfaceSocketContext- Returns:
- peer info
-
isSecure
public boolean isSecure()Description copied from interface:SocketContextWhether the request is secure.- Specified by:
isSecurein interfaceSocketContext- Returns:
- whether secure
-
socketId
Description copied from interface:SocketContextMain socket id. This is the server socket id for server side, connection id for client side.- Specified by:
socketIdin interfaceSocketContext- Returns:
- socket id
-
childSocketId
Description copied from interface:SocketContextChild socket id. This is the connection socket id for server side. For client side, this may be additional identification of a request (pipeline id, stream id).- Specified by:
childSocketIdin interfaceSocketContext- Returns:
- child socket id, never null
-
close
public void close()Description copied from interface:HelidonSocketClose the underlying socket.- Specified by:
closein interfaceHelidonSocket
-
idle
public void idle()Description copied from interface:HelidonSocketSets the socket to idle mode. Idle mode expects no bytes coming over the socket but keeps reading exactly one byte in case connection is severed. Idle mode should be used in case of client side connection caching.- Specified by:
idlein interfaceHelidonSocket
-
isConnected
public boolean isConnected()Description copied from interface:HelidonSocketCheck if socket is connected.- Specified by:
isConnectedin interfaceHelidonSocket- Returns:
- true if connected
-
read
Description copied from interface:HelidonSocketRead bytes from the socket. This method blocks until at least 1 byte is available.- Specified by:
readin interfaceHelidonSocket- Parameters:
buffer- buffer to read to- Returns:
- number of bytes read
-
write
Description copied from interface:HelidonSocketWrite teh buffer to the underlying socket. This method blocks until all bytes are written.- Specified by:
writein interfaceHelidonSocket- Parameters:
buffer- buffer to write
-
get
public byte[] get() -
write
Write to the underlying socket/channel from the provided buffer. The buffer is not flipped.- Parameters:
buffer- buffer to write- Returns:
- number of bytes written
-
read
Read from the underlying socket/channel into the provided buffer. The buffer is not flipped.- Parameters:
buffer- buffer to read to- Returns:
- number of bytes read
-