Package io.activej.net.socket.tcp
Class TcpSocket
java.lang.Object
io.activej.reactor.AbstractNioReactive
io.activej.net.socket.tcp.TcpSocket
- All Implemented Interfaces:
AsyncCloseable,ITcpSocket,io.activej.reactor.nio.NioChannelEventHandler,io.activej.reactor.NioReactive,io.activej.reactor.Reactive
public final class TcpSocket
extends io.activej.reactor.AbstractNioReactive
implements ITcpSocket, io.activej.reactor.nio.NioChannelEventHandler
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intFields inherited from class io.activej.reactor.AbstractNioReactive
reactorFields inherited from interface io.activej.async.process.AsyncCloseable
STATIC -
Method Summary
Modifier and TypeMethodDescriptionvoidconnect(io.activej.reactor.nio.NioReactor reactor, InetSocketAddress address) connect(io.activej.reactor.nio.NioReactor reactor, InetSocketAddress address, long timeout, @Nullable io.activej.reactor.net.SocketSettings socketSettings) connect(io.activej.reactor.nio.NioReactor reactor, InetSocketAddress address, @Nullable Duration duration, @Nullable io.activej.reactor.net.SocketSettings socketSettings) static int@Nullable SocketChannel@Nullable ObjectbooleanisClosed()booleanvoidvoidread()Operation to read some data from network.voidsetInspector(@Nullable TcpSocket.Inspector inspector) voidsetUserData(@Nullable Object userData) Sets an arbitrary object as a user-defined context for this sockettoString()static TcpSocketwrapChannel(io.activej.reactor.nio.NioReactor reactor, SocketChannel socketChannel, @Nullable io.activej.reactor.net.SocketSettings socketSettings) static TcpSocketwrapChannel(io.activej.reactor.nio.NioReactor reactor, SocketChannel socketChannel, InetSocketAddress remoteAddress, @Nullable io.activej.reactor.net.SocketSettings socketSettings) Operation to write some data to network.Methods inherited from class io.activej.reactor.AbstractNioReactive
getReactorMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface io.activej.async.process.AsyncCloseable
close
-
Field Details
-
DEFAULT_READ_BUFFER_SIZE
public static final int DEFAULT_READ_BUFFER_SIZE -
NO_TIMEOUT
public static final int NO_TIMEOUT- See Also:
-
-
Method Details
-
wrapChannel
public static TcpSocket wrapChannel(io.activej.reactor.nio.NioReactor reactor, SocketChannel socketChannel, InetSocketAddress remoteAddress, @Nullable @Nullable io.activej.reactor.net.SocketSettings socketSettings) throws IOException - Throws:
IOException
-
wrapChannel
public static TcpSocket wrapChannel(io.activej.reactor.nio.NioReactor reactor, SocketChannel socketChannel, @Nullable @Nullable io.activej.reactor.net.SocketSettings socketSettings) throws IOException - Throws:
IOException
-
connect
public static Promise<TcpSocket> connect(io.activej.reactor.nio.NioReactor reactor, InetSocketAddress address) -
connect
public static Promise<TcpSocket> connect(io.activej.reactor.nio.NioReactor reactor, InetSocketAddress address, @Nullable @Nullable Duration duration, @Nullable @Nullable io.activej.reactor.net.SocketSettings socketSettings) -
connect
public static Promise<TcpSocket> connect(io.activej.reactor.nio.NioReactor reactor, InetSocketAddress address, long timeout, @Nullable @Nullable io.activej.reactor.net.SocketSettings socketSettings) -
setInspector
-
getConnectionCount
public static int getConnectionCount() -
getRemoteAddress
-
getUserData
-
setUserData
Sets an arbitrary object as a user-defined context for this socketIt may be used e.g. by socket inspector for collecting statistics per socket.
-
read
Description copied from interface:ITcpSocketOperation to read some data from network. Returns a promise of a bytebuf that represents some data received from network.It is allowed to call read before previous read was completed. However, each consecutive call will cancel all the previous calls (they will not be completed).
- Specified by:
readin interfaceITcpSocket- Returns:
- promise of ByteBuf that represents data received from network
-
onReadReady
public void onReadReady()- Specified by:
onReadReadyin interfaceio.activej.reactor.nio.NioChannelEventHandler
-
write
Description copied from interface:ITcpSocketOperation to write some data to network. Returns a promise of void that represents successful write.Many write operations may be called. However, when some write is successful, all the promises received from write calls before it will be completed at once.
- Specified by:
writein interfaceITcpSocket- Parameters:
buf- data to be sent to network- Returns:
- promise that represents successful write operation
-
isReadAvailable
public boolean isReadAvailable()- Specified by:
isReadAvailablein interfaceITcpSocket
-
onWriteReady
public void onWriteReady()- Specified by:
onWriteReadyin interfaceio.activej.reactor.nio.NioChannelEventHandler
-
closeEx
- Specified by:
closeExin interfaceAsyncCloseable
-
isClosed
public boolean isClosed()- Specified by:
isClosedin interfaceITcpSocket
-
getSocketChannel
-
toString
-