[javaflow] Knowing when there's nothing to continue

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[javaflow] Knowing when there's nothing to continue

Kohsuke Kawaguchi

It looks like the other discussion is going to take longer, so meanwhile
I have a few other simple changes.

- Continuation.getContext() is typed as Object while it can be
   ContinuationContext. I think using a stricter type is desirable, hence
   the change.

- minor javadoc elaboration on the semantics of getContext().
   This is a developer visible 'API' from this method, so it needs better
   javadoc.
   I have a feeling that you might not like it, but I think I need to
   learn your taste by a trial & error process. So bare with me for a
   while...

- Lastly, right now the continueWith method always return a non-null
   Continuation object, even if there's actually nothing to continue.
   Using such a Continuation object next time around causes an error.
   This isn't good. I think the caller needs to be able to tell if the
   continueWith method returned because the "thread" has suspended, or
   because the "thread" has completed.
   I modified the execute method to return null if the latter.

Let me know which change you are OK with and which change you aren't.
I'll commit accordingly.

--
Kohsuke Kawaguchi

Index: Continuation.java
===================================================================
--- Continuation.java (revision 225442)
+++ Continuation.java (working copy)
@@ -37,7 +37,7 @@
     private final static Log log = LogFactory.getLog(Continuation.class);
     
     private final static transient Map continuationsMap = new HashMap();
-    private transient Object context;
+    private transient ContinuationContext context;
 
     private transient boolean restoring = false;
     private transient boolean capturing = false;
@@ -68,12 +68,19 @@
 
 
     /**
-     * get the current contex. only valid
-     * while calling "continueWith"
-     *
-     * @return context object
+     * get the current context.
+     *
+     * <p>
+     * This method returns the same context object given to {@link #startWith(String, ContinuationContext)}
+     * or {@link #continueWith(Continuation, ContinuationContext)}.
+     * This mechanism allows applications to associate application-specific information to
+     * a fiber.
+     *
+     * @return
+     *      null if this method is invoked outside {@link #startWith(String, ContinuationContext)}
+     *      or {@link #continueWith(Continuation, ContinuationContext)} .
      */
-    public Object getContext() {
+    public ContinuationContext getContext() {
         return context;
     }
     
@@ -109,6 +116,7 @@
     }
 
     private static Continuation execute(final Continuation continuation, final ContinuationContext context) {
+        boolean completed = false;
         try {
             continuation.registerThread();
             
@@ -144,6 +152,8 @@
                 if (continuation.stack.hasReference()) {
                     continuation.stack.popReference();
                 }
+            } else {
+                completed = true;
             }
 
             continuation.context = null;
@@ -151,7 +161,8 @@
             continuation.deregisterThread();
         }
 
-        return continuation;        
+        if(completed)   return null;
+        else            return continuation;
     }
     
     /**


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: [javaflow] Knowing when there's nothing to continue

Torsten Curdt
>
> It looks like the other discussion is going to take longer, so  
> meanwhile I have a few other simple changes.

Hehe ...bring it on ;)

Did you have a look into the Cocoon integration?
Looking at javaflow from that standpoint you will
probably understand some of my requirements.

> - Continuation.getContext() is typed as Object while it can be
>   ContinuationContext. I think using a stricter type is desirable,  
> hence
>   the change.

Ok

> - minor javadoc elaboration on the semantics of getContext().
>   This is a developer visible 'API' from this method, so it needs  
> better
>   javadoc.
>   I have a feeling that you might not like it, but I think I need to
>   learn your taste by a trial & error process. So bare with me for a
>   while...

Don't worry ;)

> - Lastly, right now the continueWith method always return a non-null
>   Continuation object, even if there's actually nothing to continue.
>   Using such a Continuation object next time around causes an error.
>   This isn't good. I think the caller needs to be able to tell if the
>   continueWith method returned because the "thread" has suspended, or
>   because the "thread" has completed.
>   I modified the execute method to return null if the latter.

Ok

>      /**
> -     * get the current contex. only valid

The method is already called "getContext"
("get the current context" ;) ...so IMO all
we need to explain is *what* this context is
and what is so special about it.

In fact most of that information should
be given inside ContinuationContext.java
and we could link to it from here.

So in the end information that I think is
important is as you state later on ...it's
the same context object that is being passed
in with start/continue.

IMHO that's it.

Don't want to be too picky ...but just tried
to explain how I see that javadoc thingy ;)

> -     * while calling "continueWith"
> -     *
> -     * @return context object
> +     * get the current context.
> +     *
> +     * <p>
> +     * This method returns the same context object given to {@link  
> #startWith(String, ContinuationContext)}
> +     * or {@link #continueWith(Continuation, ContinuationContext)}.
> +     * This mechanism allows applications to associate application-
> specific information to
> +     * a fiber.
> +     *
> +     * @return
> +     *      null if this method is invoked outside {@link  
> #startWith(String, ContinuationContext)}
> +     *      or {@link #continueWith(Continuation,  
> ContinuationContext)} .
>       */
> -    public Object getContext() {
> +    public ContinuationContext getContext() {
>          return context;
>      }
>
> @@ -109,6 +116,7 @@
>      }
>
>      private static Continuation execute(final Continuation  
> continuation, final ContinuationContext context) {
> +        boolean completed = false;
>          try {
>              continuation.registerThread();
>
> @@ -144,6 +152,8 @@
>                  if (continuation.stack.hasReference()) {
>                      continuation.stack.popReference();
>                  }
> +            } else {
> +                completed = true;
>              }
>
>              continuation.context = null;
> @@ -151,7 +161,8 @@
>              continuation.deregisterThread();
>          }
>
> -        return continuation;
> +        if(completed)   return null;
> +        else            return continuation;
Please always use { } for if/else

Thanks a lot for your help!

cheers
--
Torsten


PGP.sig (193 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [javaflow] Knowing when there's nothing to continue

Kohsuke Kawaguchi
Torsten Curdt wrote:
>>
>> It looks like the other discussion is going to take longer, so  
>> meanwhile I have a few other simple changes.
>
> Hehe ...bring it on ;)
>
> Did you have a look into the Cocoon integration?
> Looking at javaflow from that standpoint you will
> probably understand some of my requirements.

I intend to do so, before I write a response on the MethodLookup thread.
But I couldn't work on it yesterday. This isn'y my day job, unfortunately.

>>      /**
>> -     * get the current contex. only valid
>
> The method is already called "getContext"
> ("get the current context" ;) ...so IMO all
> we need to explain is *what* this context is
> and what is so special about it.
>
> In fact most of that information should
> be given inside ContinuationContext.java
> and we could link to it from here.
>
> So in the end information that I think is
> important is as you state later on ...it's
> the same context object that is being passed
> in with start/continue.
>
> IMHO that's it.
>
> Don't want to be too picky ...but just tried
> to explain how I see that javadoc thingy ;)

I appreciate it. I think I'll remove the part that talks about the point
of context and then you are OK with it.

> Please always use { } for if/else

I will do that.



--
Kohsuke Kawaguchi

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]