Package org.apache.commons.javaflow

Examples of org.apache.commons.javaflow.Continuation


import swarm.javaflow.ContTest;

public class Main {
  public static void main(String[] args) {
    Continuation c = Continuation.startWith(new ContTest());
    System.out.println("returned a continuation");
    Continuation d = Continuation.continueWith(c);
    System.out.println("returned another continuation");
  }
View Full Code Here


  private static Hashtable<String,Continuation> portals = new Hashtable<String,Continuation>();
 
  public static String open(Runnable runnable) {
   
    String pid = Long.toString(System.currentTimeMillis());
    Continuation c = Continuation.startWith(runnable);   
    if (c!=null) {
      portals.put(pid,c);
      System.out.println("Portal.open("+pid+")");
    }
    else System.err.println("ERROR : Can't open portal "+pid);
View Full Code Here

    return pid;
  }
 
  public static void enter(String pid) {
   
    Continuation c = portals.get(pid);
    System.out.println("Enter ("+pid+")");
    Continuation.continueWith(c);
  }
View Full Code Here

  }
 
  public static void next(String pid) {
   
    System.out.println("Portal.next("+pid+")");
    Continuation c = portals.get(pid);
    Continuation c2 = Continuation.continueWith(c);
   
    if (c2!=null) portals.put(pid, c2);
    else portals.remove(pid);
  }
View Full Code Here

  }

  public static void exit(String pid) {
   
    if (pid==null) pid = "";
    Continuation c = portals.get(pid)
    System.out.println("Portal.exit("+pid+")");
    if (c==null) Continuation.suspend();   
    else
      Continuation.suspend(c)
  }
View Full Code Here

  }
 
  public static void close(String pid) {
    if (pid!=null && portals.containsKey(pid)) {
      System.out.println("Portal.close("+pid+") ");
      Continuation c = portals.remove(pid);
      if (c!=null) c.exit();
    }
  }
View Full Code Here

            }

        }

        // Continuations case
        Continuation continuation = (Continuation) Http.Request.current().args.get(C);
        if (continuation == null) {
            continuation = new Continuation(new StackRecorder((Runnable) null));
        }

        StackRecorder pStackRecorder = new StackRecorder(continuation.stackRecorder);
        Object result = null;

        final StackRecorder old = pStackRecorder.registerThread();
        try {
            pStackRecorder.isRestoring = !pStackRecorder.isEmpty();

            // Execute code
            result = method.invoke(instance, realArgs);

            if (pStackRecorder.isCapturing) {
                if (pStackRecorder.isEmpty()) {
                    throw new IllegalStateException("stack corruption. Is " + method + " instrumented for javaflow?");
                }
                Object trigger = pStackRecorder.value;
                Continuation nextContinuation = new Continuation(pStackRecorder);
                Http.Request.current().args.put(C, nextContinuation);

                if (trigger instanceof Long) {
                    throw new Suspend((Long) trigger);
                }
View Full Code Here

                    beforeExecute(w.thread, task);
                    Throwable thrown = null;
                    try
                    {                                
                        /* start in suspended mode to get a handle to the continuation */
                        Continuation c = Continuation.startSuspendedWith(task);                                             
                        /* resume the damn continuation */                                                   
                        c = Continuation.continueWith(c, new ContinuationContext(c));
                        /* post process the call if need be */                       
                        ContinuationsExecutor.doPostProcessing(c);
                    }
View Full Code Here

            }

        }

        // Continuations case
        Continuation continuation = (Continuation) Http.Request.current().args.get(C);
        if (continuation == null) {
            continuation = new Continuation(new StackRecorder((Runnable) null));
        }

        StackRecorder pStackRecorder = new StackRecorder(continuation.stackRecorder);
        Object result = null;

        final StackRecorder old = pStackRecorder.registerThread();
        try {
            pStackRecorder.isRestoring = !pStackRecorder.isEmpty();

            // Execute code
            result = method.invoke(instance, realArgs);

            if (pStackRecorder.isCapturing) {
                if (pStackRecorder.isEmpty()) {
                    throw new IllegalStateException("stack corruption. Is " + method + " instrumented for javaflow?");
                }
                Object trigger = pStackRecorder.value;
                Continuation nextContinuation = new Continuation(pStackRecorder);
                Http.Request.current().args.put(C, nextContinuation);

                if (trigger instanceof Long) {
                    throw new Suspend((Long) trigger);
                }
View Full Code Here

            }

        }

        // Continuations case
        Continuation continuation = (Continuation) Http.Request.current().args.get(C);
        if (continuation == null) {
            continuation = new Continuation(new StackRecorder((Runnable) null));
        }

        StackRecorder pStackRecorder = new StackRecorder(continuation.stackRecorder);
        Object result = null;

        final StackRecorder old = pStackRecorder.registerThread();
        try {
            pStackRecorder.isRestoring = !pStackRecorder.isEmpty();

            // Execute code
            result = method.invoke(instance, realArgs);

            if (pStackRecorder.isCapturing) {
                if (pStackRecorder.isEmpty()) {
                    throw new IllegalStateException("stack corruption. Is " + method + " instrumented for javaflow?");
                }
                Object trigger = pStackRecorder.value;
                Continuation nextContinuation = new Continuation(pStackRecorder);
                Http.Request.current().args.put(C, nextContinuation);

                if (trigger instanceof Long) {
                    throw new Suspend((Long) trigger);
                }
View Full Code Here

TOP

Related Classes of org.apache.commons.javaflow.Continuation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.