Package com.offbynull.coroutines.user
Class CoroutineWriter
- java.lang.Object
-
- com.offbynull.coroutines.user.CoroutineWriter
-
public final class CoroutineWriter extends java.lang.Object
Writes out (serializes) the current state of aCoroutineRunner
object.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
CoroutineWriter.CoroutineSerializer
Coroutine serializer.static class
CoroutineWriter.DefaultCoroutineSerializer
Default implementation ofCoroutineWriter.CoroutineSerializer
(uses Java's built-in serialization mechanism).
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map
interceptersMap
private CoroutineWriter.CoroutineSerializer
serializer
private java.util.Map
updatersMap
-
Constructor Summary
Constructors Constructor Description CoroutineWriter()
Construct aCoroutineWriter
object.CoroutineWriter(CoroutineWriter.CoroutineSerializer serializer, SerializedState.FrameUpdatePoint[] frameUpdatePoints, SerializedState.FrameInterceptPoint[] frameInterceptPoints)
Constructs aCoroutineWriter
object.CoroutineWriter(SerializedState.FrameInterceptPoint[] frameInterceptPoints)
Constructs aCoroutineWriter
.CoroutineWriter(SerializedState.FrameUpdatePoint[] frameUpdatePoints)
Constructs aCoroutineWriter
.CoroutineWriter(SerializedState.FrameUpdatePoint[] frameUpdatePoints, SerializedState.FrameInterceptPoint[] frameInterceptPoints)
Constructs aCoroutineWriter
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private int[]
clearContinuationReferences(java.lang.Object[] objects, Continuation cn)
SerializedState
deconstruct(CoroutineRunner runner)
Deconstructs aCoroutineRunner
object to a serializable state.byte[]
write(CoroutineRunner runner)
Serializes aCoroutineRunner
object as a byte array.
-
-
-
Field Detail
-
serializer
private final CoroutineWriter.CoroutineSerializer serializer
-
updatersMap
private final java.util.Map updatersMap
-
interceptersMap
private final java.util.Map interceptersMap
-
-
Constructor Detail
-
CoroutineWriter
public CoroutineWriter()
Construct aCoroutineWriter
object. Equivalent to callingnew CoroutineWriter(new DefaultCoroutineSerializer(), new FrameUpdatePoint[0], new FrameInterceptPoint[0])
.
-
CoroutineWriter
public CoroutineWriter(SerializedState.FrameUpdatePoint[] frameUpdatePoints)
Constructs aCoroutineWriter
. Equivalent to callingnew CoroutineWriter(new DefaultCoroutineSerializer(), frameUpdatePoints, new FrameInterceptPoint[0])
.- Parameters:
frameUpdatePoints
- frame update points- Throws:
java.lang.IllegalArgumentException
- ifframeUpdatePoints
contains more than one entry for the same identifier (className/oldMethodId/newMethodId/continuationPoint)java.lang.NullPointerException
- if any argument isnull
-
CoroutineWriter
public CoroutineWriter(SerializedState.FrameInterceptPoint[] frameInterceptPoints)
Constructs aCoroutineWriter
. Equivalent to callingnew CoroutineWriter(new DefaultCoroutineSerializer(), new FrameUpdatePoint[0], frameInterceptPoints)
.- Parameters:
frameInterceptPoints
- frame intercept points- Throws:
java.lang.IllegalArgumentException
- ifframeInterceptPoints
contains more than one entry for the same identifier (className/methodId/continuationPoint)java.lang.NullPointerException
- if any argument isnull
-
CoroutineWriter
public CoroutineWriter(SerializedState.FrameUpdatePoint[] frameUpdatePoints, SerializedState.FrameInterceptPoint[] frameInterceptPoints)
Constructs aCoroutineWriter
. Equivalent to callingnew CoroutineWriter(new DefaultCoroutineSerializer(), frameUpdatePoints, frameInterceptPoints)
.- Parameters:
frameUpdatePoints
- frame update pointsframeInterceptPoints
- frame intercept points- Throws:
java.lang.IllegalArgumentException
- ifframeUpdatePoints
contains more than one entry for the same identifier (className/oldMethodId/newMethodId/continuationPoint), or ifframeInterceptPoints
contains more than one entry for the same identifier (className/methodId/continuationPoint)java.lang.NullPointerException
- if any argument isnull
-
CoroutineWriter
public CoroutineWriter(CoroutineWriter.CoroutineSerializer serializer, SerializedState.FrameUpdatePoint[] frameUpdatePoints, SerializedState.FrameInterceptPoint[] frameInterceptPoints)
Constructs aCoroutineWriter
object.- Parameters:
serializer
- serializer to write out the coroutine stateframeUpdatePoints
- frame update pointsframeInterceptPoints
- frame intercept points- Throws:
java.lang.NullPointerException
- if any argument isnull
or containsnull
java.lang.IllegalArgumentException
- ifframeUpdatePoints
contains more than one entry for the same identifier (className/oldMethodId/newMethodId/continuationPoint), or ifframeInterceptPoints
contains more than one entry for the same identifier (className/methodId/continuationPoint)
-
-
Method Detail
-
write
public byte[] write(CoroutineRunner runner)
Serializes aCoroutineRunner
object as a byte array.- Parameters:
runner
- coroutine runner to serialize- Returns:
runner
serialized to byte array- Throws:
java.lang.NullPointerException
- if any argument isnull
java.lang.IllegalArgumentException
- if failed to serialize
-
deconstruct
public SerializedState deconstruct(CoroutineRunner runner)
Deconstructs aCoroutineRunner
object to a serializable state.- Parameters:
runner
- coroutine runner to deconstruct- Returns:
- deconstructed representation of
CoroutineRunner
- Throws:
java.lang.NullPointerException
- if any argument isnull
java.lang.IllegalArgumentException
- if failed to deconstruct
-
clearContinuationReferences
private int[] clearContinuationReferences(java.lang.Object[] objects, Continuation cn)
-
-