Package de.esoco.coroutine.step.nio
Class SocketSend
- java.lang.Object
-
- org.obrel.core.RelatedObject
-
- de.esoco.coroutine.CoroutineStep<I,O>
-
- de.esoco.coroutine.step.nio.AsynchronousChannelStep<java.nio.ByteBuffer,java.nio.ByteBuffer>
-
- de.esoco.coroutine.step.nio.AsynchronousSocketStep
-
- de.esoco.coroutine.step.nio.SocketSend
-
- All Implemented Interfaces:
de.esoco.lib.property.Fluent<CoroutineStep<java.nio.ByteBuffer,java.nio.ByteBuffer>>,org.obrel.core.FluentRelatable<CoroutineStep<java.nio.ByteBuffer,java.nio.ByteBuffer>>,org.obrel.core.Relatable
public class SocketSend extends AsynchronousSocketStep
Implements asynchronous writing to aAsynchronousSocketChannel.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class de.esoco.coroutine.step.nio.AsynchronousChannelStep
AsynchronousChannelStep.ChannelCallback<V,C extends java.nio.channels.AsynchronousChannel>, AsynchronousChannelStep.ChannelOperation<C extends java.nio.channels.AsynchronousChannel>
-
-
Field Summary
-
Fields inherited from class de.esoco.coroutine.step.nio.AsynchronousSocketStep
SOCKET_CHANNEL
-
Fields inherited from class de.esoco.coroutine.step.nio.AsynchronousChannelStep
CHANNEL_GROUP
-
-
Constructor Summary
Constructors Constructor Description SocketSend(java.util.function.Function<Continuation<?>,java.net.SocketAddress> getSocketAddress)Creates a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleanperformAsyncOperation(int bytesProcessed, java.nio.channels.AsynchronousSocketChannel channel, java.nio.ByteBuffer data, AsynchronousChannelStep.ChannelCallback<java.lang.Integer,java.nio.channels.AsynchronousSocketChannel> callback)Implementation of the ChannelOperation functional interface method signature.protected voidperformBlockingOperation(java.nio.channels.AsynchronousSocketChannel channel, java.nio.ByteBuffer data)Must be implemented for the blocking execution of a step.static SocketSendsendTo(java.net.SocketAddress socketAddress)static SocketSendsendTo(java.util.function.Function<Continuation<?>,java.net.SocketAddress> getSocketAddress)Suspends until all data from the inputByteBufferhas been sent to a network socket.The buffer must be initialized for sending, i.e. if necessary a call toBuffer.flip()must have been performed.-
Methods inherited from class de.esoco.coroutine.step.nio.AsynchronousSocketStep
execute, getSocketAddress, getSocketAddressFactory, getSocketChannel, runAsync
-
Methods inherited from class de.esoco.coroutine.step.nio.AsynchronousChannelStep
getChannelGroup
-
Methods inherited from class de.esoco.coroutine.CoroutineStep
runBlocking, terminateCoroutine, toString
-
Methods inherited from class org.obrel.core.RelatedObject
deleteRelation, get, getRelation, getRelations, notifyRelationListeners, readRelations, relationsEqual, relationsHashCode, relationsString, set, set, transform, writeRelations
-
-
-
-
Constructor Detail
-
SocketSend
public SocketSend(java.util.function.Function<Continuation<?>,java.net.SocketAddress> getSocketAddress)
Creates a new instance.- Parameters:
getSocketAddress- A function that provides the target socket address from the current continuation
-
-
Method Detail
-
sendTo
public static SocketSend sendTo(java.util.function.Function<Continuation<?>,java.net.SocketAddress> getSocketAddress)
Suspends until all data from the inputByteBufferhas been sent to a network socket.The buffer must be initialized for sending, i.e. if necessary a call toBuffer.flip()must have been performed.After the data has been fully sent
ByteBuffer.clear()will be invoked on the buffer so that it can be used directly for subsequent writing to it. An example would be a followingSocketReceiveto implement a request-response scheme.- Parameters:
getSocketAddress- A function that provides the target socket address from the current continuation- Returns:
- A new step instance
-
sendTo
public static SocketSend sendTo(java.net.SocketAddress socketAddress)
- See Also:
sendTo(Function)
-
performAsyncOperation
protected boolean performAsyncOperation(int bytesProcessed, java.nio.channels.AsynchronousSocketChannel channel, java.nio.ByteBuffer data, AsynchronousChannelStep.ChannelCallback<java.lang.Integer,java.nio.channels.AsynchronousSocketChannel> callback)Description copied from class:AsynchronousSocketStepImplementation of the ChannelOperation functional interface method signature.
-
performBlockingOperation
protected void performBlockingOperation(java.nio.channels.AsynchronousSocketChannel channel, java.nio.ByteBuffer data) throws java.lang.InterruptedException, java.util.concurrent.ExecutionExceptionMust be implemented for the blocking execution of a step. It receives anAsynchronousSocketChannelwhich must be accessed through the blocking API (likeFuture.get()).- Specified by:
performBlockingOperationin classAsynchronousSocketStep- Parameters:
channel- The channel to perform the operation ondata- The byte buffer for the operation data- Throws:
java.lang.InterruptedExceptionjava.util.concurrent.ExecutionException
-
-