@@ -116,19 +116,19 @@ public static Continuation startSuspendedWith(Runnable target) {
116116 *
117117 * @param target
118118 * The object whose <tt>run</tt> method will be executed.
119- * @param optimized
119+ * @param singleShot
120120 * If true then continuation constructed is performance-optimized but
121- * may be resumed only once. Otherwise "restartable " continuation is created that may
121+ * may be resumed only once. Otherwise "multi-shot " continuation is created that may
122122 * be resumed multiple times.
123123 * @return
124124 * always return a non-null valid object.
125125 */
126- public static Continuation startSuspendedWith (Runnable target , boolean optimized ) {
126+ public static Continuation startSuspendedWith (Runnable target , boolean singleShot ) {
127127 if (target == null ) {
128128 throw new IllegalArgumentException ("target is null" );
129129 }
130130 StackRecorder stackRecorder = new StackRecorder (target );
131- return optimized ? new OptimizedContinuation (stackRecorder , null ) : new RestartableContinuation (stackRecorder , null );
131+ return singleShot ? new SingleShotContinuation (stackRecorder , null ) : new MultiShotContinuation (stackRecorder , null );
132132 }
133133
134134 /**
@@ -157,16 +157,16 @@ public static Continuation startWith(Runnable target) {
157157 *
158158 * @param target
159159 * The object whose <tt>run</tt> method will be executed.
160- * @param optimized
160+ * @param singleShot
161161 * If true then continuation constructed is performance-optimized but
162- * may be resumed only once. Otherwise "restartable " continuation is created that may
162+ * may be resumed only once. Otherwise "multi-shot " continuation is created that may
163163 * be resumed multiple times.
164164 * @return
165165 * Continuation object if runnable supplied is supended, otherwise <code>null</code>
166166 * @see #startWith(Runnable, Object)
167167 */
168- public static Continuation startWith (Runnable target , boolean optimized ) {
169- return startWith (target , null , optimized );
168+ public static Continuation startWith (Runnable target , boolean singleShot ) {
169+ return startWith (target , null , singleShot );
170170 }
171171
172172 /**
@@ -201,22 +201,22 @@ public static Continuation startWith(Runnable target, Object context) {
201201 * @param context
202202 * This value can be obtained from {@link #getContext()} until this method returns.
203203 * Can be null.
204- * @param optimized
204+ * @param singleShot
205205 * If true then continuation constructed is performance-optimized but
206- * may be resumed only once. Otherwise "restartable " continuation is created that may
206+ * may be resumed only once. Otherwise "multi-shot " continuation is created that may
207207 * be resumed multiple times.
208208 * @return
209209 * If the execution completes and there's nothing more to continue, return null.
210210 * Otherwise, the execution has been {@link #suspend() suspended}, in which case
211211 * a new non-null continuation is returned.
212212 * @see #getContext()
213213 */
214- public static Continuation startWith (Runnable target , Object context , boolean optimized ) {
214+ public static Continuation startWith (Runnable target , Object context , boolean singleShot ) {
215215 if (log .isDebugEnabled ()) {
216216 log .debug ("starting new flow from " + ReflectionUtils .descriptionOfObject (target ));
217217 }
218218
219- return startSuspendedWith (target , optimized ).resume (context );
219+ return startSuspendedWith (target , singleShot ).resume (context );
220220 }
221221
222222 /**
@@ -344,22 +344,22 @@ public Object value() {
344344 }
345345
346346 /**
347- * <p>View this continuation as a "restartable " continuation that may be resumed multiple times.
348- * <p>Conversion to the restartable continuation is not always possible, i.e. already resumed
349- * optimized continuation may not be converted to the restartable variant.
347+ * <p>View this continuation as a "multi-shot " continuation that may be resumed multiple times.
348+ * <p>Conversion to the multi-shot continuation is not always possible, i.e. already resumed
349+ * single-shot continuation may not be converted to the multi-shot variant.
350350 *
351- * @return self if this is already a restartable continuation or a newly constructed
352- * restartable continuation
351+ * @return self if this is already a multi-shot continuation or a newly constructed
352+ * multi-shot continuation
353353 */
354- abstract public Continuation restartable ();
354+ abstract public Continuation multiShot ();
355355
356356 /**
357357 * <p>View this continuation as a performance-optimized continuation that may be resumed only once.
358- * <p>Conversion to the optimized continuation is always possible
358+ * <p>Conversion to the single-shot continuation is always possible
359359 *
360- * @return self if this is already an optimized continuation or a newly constructed optimized continuation
360+ * @return self if this is already a single-shot continuation or a newly constructed single-shot continuation
361361 */
362- abstract public Continuation optimized ();
362+ abstract public Continuation singleShot ();
363363
364364 /**
365365 * Stops the running continuation.
@@ -494,21 +494,21 @@ public String toString() {
494494
495495 abstract protected Continuation resumeWith (ResumeParameter param );
496496
497- static final class RestartableContinuation extends Continuation {
497+ static final class MultiShotContinuation extends Continuation {
498498 private static final long serialVersionUID = 1L ;
499499
500- RestartableContinuation (StackRecorder stackRecorder , Object value ) {
500+ MultiShotContinuation (StackRecorder stackRecorder , Object value ) {
501501 super (stackRecorder , value );
502502 }
503503
504504 @ Override
505- public Continuation restartable () {
505+ public Continuation multiShot () {
506506 return this ;
507507 }
508508
509509 @ Override
510- public Continuation optimized () {
511- return new OptimizedContinuation (new StackRecorder (stackRecorder ), value ());
510+ public Continuation singleShot () {
511+ return new SingleShotContinuation (new StackRecorder (stackRecorder ), value ());
512512 }
513513
514514 @ Override
@@ -530,31 +530,29 @@ protected Continuation resumeWith(ResumeParameter param) {
530530 continue ;
531531 }
532532
533- return new RestartableContinuation (nextStackRecorder , result .value ());
533+ return new MultiShotContinuation (nextStackRecorder , result .value ());
534534 }
535535 }
536536 }
537537
538- static final class OptimizedContinuation extends Continuation {
538+ static final class SingleShotContinuation extends Continuation {
539539 private static final long serialVersionUID = 1L ;
540540 private boolean isResumed = false ;
541541
542- OptimizedContinuation (StackRecorder stackRecorder , Object value ) {
542+ SingleShotContinuation (StackRecorder stackRecorder , Object value ) {
543543 super (stackRecorder , value );
544544 }
545545
546546 @ Override
547- public Continuation restartable () {
548- synchronized (this ) {
549- if (isResumed ) {
550- throw new IllegalStateException ("Exclusive continuation may not be converted to restartable after resume" );
551- }
552- }
553- return new RestartableContinuation (new StackRecorder (stackRecorder ), value ());
547+ public Continuation multiShot () {
548+ if (isResumed ) {
549+ throw new IllegalStateException ("Exclusive continuation may not be converted to multi-shot after resume" );
550+ }
551+ return new MultiShotContinuation (new StackRecorder (stackRecorder ), value ());
554552 }
555553
556554 @ Override
557- public Continuation optimized () {
555+ public Continuation singleShot () {
558556 return this ;
559557 }
560558
@@ -563,16 +561,14 @@ protected Continuation resumeWith(ResumeParameter param) {
563561 if (log .isDebugEnabled ()) {
564562 log .debug ("continueing with continuation " + ReflectionUtils .descriptionOfObject (this ));
565563 }
566- synchronized (this ) {
567- if (isResumed ) {
568- if (param == ResumeParameter .exit ()) {
569- return null ;
570- } else {
571- throw new IllegalStateException ("Exclusive continuation may be resumed only once" );
572- }
564+ if (isResumed ) {
565+ if (param == ResumeParameter .exit ()) {
566+ return null ;
567+ } else {
568+ throw new IllegalStateException ("Exclusive continuation may be resumed only once" );
573569 }
574- isResumed = true ;
575570 }
571+ isResumed = true ;
576572 StackRecorder nextStackRecorder = stackRecorder ; // Use existing one, don't copy
577573 SuspendResult result = nextStackRecorder .execute (param );
578574 if (SuspendResult .EXIT == result ) {
@@ -586,7 +582,7 @@ protected Continuation resumeWith(ResumeParameter param) {
586582 throw new IllegalStateException ("Exclusive continuation may not be re-tried" );
587583 }
588584
589- return new OptimizedContinuation (nextStackRecorder , result .value ());
585+ return new SingleShotContinuation (nextStackRecorder , result .value ());
590586 }
591587 }
592588
0 commit comments