Class 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 a AsynchronousSocketChannel.
    • 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 boolean performAsyncOperation​(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 void performBlockingOperation​(java.nio.channels.AsynchronousSocketChannel channel, java.nio.ByteBuffer data)
      Must be implemented for the blocking execution of a step.
      static SocketSend sendTo​(java.net.SocketAddress socketAddress)  
      static SocketSend sendTo​(java.util.function.Function<Continuation<?>,​java.net.SocketAddress> getSocketAddress)
      Suspends until all data from the input ByteBuffer has been sent to a network socket.The buffer must be initialized for sending, i.e. if necessary a call to Buffer.flip() must have been performed.
      • Methods inherited from class org.obrel.core.RelatedObject

        deleteRelation, get, getRelation, getRelations, notifyRelationListeners, readRelations, relationsEqual, relationsHashCode, relationsString, set, set, transform, writeRelations
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface de.esoco.lib.property.Fluent

        _with
      • Methods inherited from interface org.obrel.core.FluentRelatable

        with, with, with
      • Methods inherited from interface org.obrel.core.Relatable

        deleteRelation, deleteRelation, deleteRelations, get, getAll, getOption, getRelation, getRelationCount, getRelations, getRelations, hasFlag, hasRelation, hasRelations, init, set, set, set, set, set, setOption, streamRelations, transform
    • 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 input ByteBuffer has been sent to a network socket.The buffer must be initialized for sending, i.e. if necessary a call to Buffer.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 following SocketReceive to implement a request-response scheme.

        Parameters:
        getSocketAddress - A function that provides the target socket address from the current continuation
        Returns:
        A new step instance
      • performBlockingOperation

        protected void performBlockingOperation​(java.nio.channels.AsynchronousSocketChannel channel,
                                                java.nio.ByteBuffer data)
                                         throws java.lang.InterruptedException,
                                                java.util.concurrent.ExecutionException
        Must be implemented for the blocking execution of a step. It receives an AsynchronousSocketChannel which must be accessed through the blocking API (like Future.get()).
        Specified by:
        performBlockingOperation in class AsynchronousSocketStep
        Parameters:
        channel - The channel to perform the operation on
        data - The byte buffer for the operation data
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException