Example usage for org.apache.commons.javaflow Continuation isSerializable

List of usage examples for org.apache.commons.javaflow Continuation isSerializable

Introduction

In this page you can find the example usage for org.apache.commons.javaflow Continuation isSerializable.

Prototype

public boolean isSerializable() 

Source Link

Usage

From source file:com.topekalabs.bigmachine.lib.app.ContinuationSerializationTest.java

@Test
public void simpleSerializationTest() throws Exception {
    MutableInt context = new MutableInt();
    Continuation c = Continuation.startWith(new SimpleContinuationRunnable(), context);
    logger.debug("Is serializable: {}", c.isSerializable());

    Assert.assertEquals("The value of the context was not set properly", SimpleContinuationRunnable.FIRST_VALUE,
            context.getValue());/*w  w w .  j  a va 2 s  . co m*/

    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    ObjectOutputStream oos = new ObjectOutputStream(bos);
    oos.writeObject(c);
    oos.close();

    ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()));
    c = (Continuation) ois.readObject();
    ois.close();

    Continuation.continueWith(c, context);

    Assert.assertEquals("The value of the context was not set properly",
            SimpleContinuationRunnable.SECOND_VALUE, context.getValue());
}