Package de.esoco.coroutine.step.nio
Class AsynchronousChannelStep<I,O>
- java.lang.Object
-
- org.obrel.core.RelatedObject
-
- de.esoco.coroutine.CoroutineStep<I,O>
-
- de.esoco.coroutine.step.nio.AsynchronousChannelStep<I,O>
-
- All Implemented Interfaces:
de.esoco.lib.property.Fluent<CoroutineStep<I,O>>,org.obrel.core.FluentRelatable<CoroutineStep<I,O>>,org.obrel.core.Relatable
- Direct Known Subclasses:
AsynchronousFileStep,AsynchronousSocketStep,ServerSocketAccept
public abstract class AsynchronousChannelStep<I,O> extends CoroutineStep<I,O>
The base class for coroutine steps that perform communication through instances ofAsynchronousChannel. It contains the inner classAsynchronousChannelStep.ChannelCallbackthat implements most of theCompletionHandlerinterface needed for asynchonous channel communication. The actual channel operation must be provided to it as an implementation of the function interfaceAsynchronousChannelStep.ChannelOperation.To simplify the generic declaration of subclasses both input and output type are declared as
ByteBuffer, where the returned value will be the input value. Input buffers must be provided by the preceding step in a coroutine and initialize it for the respective channel step implemenation. For a reading step this means that the buffer must have an adequate capacity. For a writing step it must contain the data to write and it must have been flipped if necessary (seeBuffer.flip()for details).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classAsynchronousChannelStep.ChannelCallback<V,C extends java.nio.channels.AsynchronousChannel>ACompletionHandlerimplementation that performs an asynchronous channel operation and resumes a coroutine step afterwards (asynchronously).protected static interfaceAsynchronousChannelStep.ChannelOperation<C extends java.nio.channels.AsynchronousChannel>A functional interface used as argument toAsynchronousChannelStep.ChannelCallback.
-
Field Summary
Fields Modifier and Type Field Description static org.obrel.core.RelationType<java.nio.channels.AsynchronousChannelGroup>CHANNEL_GROUPState: theAsynchronousChannelGroupto associate any new asynchronous channels with.
-
Constructor Summary
Constructors Constructor Description AsynchronousChannelStep()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.nio.channels.AsynchronousChannelGroupgetChannelGroup(Continuation<?> continuation)Returns theAsynchronousChannelGroupfor asynchronous channel operations in the current scope.-
Methods inherited from class de.esoco.coroutine.CoroutineStep
execute, runAsync, runBlocking, terminateCoroutine, toString
-
Methods inherited from class org.obrel.core.RelatedObject
deleteRelation, get, getRelation, getRelations, notifyRelationListeners, readRelations, relationsEqual, relationsHashCode, relationsString, set, set, transform, writeRelations
-
-
-
-
Method Detail
-
getChannelGroup
protected java.nio.channels.AsynchronousChannelGroup getChannelGroup(Continuation<?> continuation)
Returns theAsynchronousChannelGroupfor asynchronous channel operations in the current scope. If no such group exists a new one will be created with theExecutorServiceof theCoroutineContextand stored asCHANNEL_GROUPin the current scope.- Parameters:
continuation- The channel group- Returns:
- The channel group
-
-