On Fri, Aug 13, 2010 at 7:23 AM, Kevin Qiu <[email protected]> wrote:
> Jeff,
>
> is it safe to say the skeleton of your method looks like this?
>
> void execute() {
> // 1
> DeferredCommand.addCommand(new IncrementalCommand() { /* state machine
> logic as posted above */ }
> // 2
> }
>
> The problem is, DeferredCommand isn't blocking, so after
> DeferredCommand.addCommand(...), whatever logic you put inside the
> incremental command won't be executed before the outer execute method
> finishes. e.g., if I put System.out.println("execute() started") at //1
> position and println("execute() finished") at //2 and loads of print()
> inside the incremental command, the output will be:
> execute() started
> execute() finished
> // whatever I put in the incremental command
> Therefore, execute() method isn't blocking.
>
Of course the DeferredCommand isn't blocking. I know that. The SM just loops
at DICTIONARYREAD until the queue empties. Post your entire implementation
of the execute() method.
Do not put code at //1 or //2 Did my example show that? I don't think it
did. //1 and //2 should be inside the SM. Did you code an implementation or
just do a desk check?
The dictionary entries are downloaded one at a time. The UI isn't live until
all downloads complete. Either way, it looks like I've failed to communicate
how this works. If you want to see a live demo, feel free to send an OpenID,
I'll add it to to the authorization and you can watch it using FF and
Firebug.
> I think I need to clarify/reiterate what I need: I have a list of async
> commands, and I want execute() method to execute these commands, either in
> serial or parallel, and execute() method waits until all these commands
> finish and then returns.
>
>
>
> On Thu, Aug 12, 2010 at 6:24 PM, Jeff Chimene <[email protected]> wrote:
>
>> On 08/12/2010 02:23 PM, Kevin Qiu wrote:
>> > Thanks for taking the time. Although it's not clear what action you put
>> > in the timer and what the timer is supposed to do
>>
>> It's a "processing occurring" timer. I think I mentioned it earlier, so
>> I didn't remove it from the example.
>>
>> > (IncrementalCommand is executed by DeferredCommand.CommandExecutor
>> > and it already has a timer with timeslice set to 100ms).
>>
>> Right.
>>
>> > Also, I suppose you need to reset the "busy" flag in the callback of
>> > the asynchronous calls.
>>
>> Yes. You already had that bit sussed. The case statement asynchronously
>> drains the command queue, while providing a structure that synchronously
>> resolves to a "final" command step.
>>
>> > I'm still a bit incredulous but I'll give it a try. Thanks again :)
>>
>> Feel free to ask.
>>
>> >
>> > Cheers,
>> >
>> > On Thu, Aug 12, 2010 at 4:43 PM, Jeff Chimene <[email protected]
>> > <mailto:[email protected]>> wrote:
>> >
>> > On 08/12/2010 12:50 PM, Kevin Qiu wrote:
>> > > After some thought, I don't think putting it in IncrementalCommand
>> and
>> > > execute with DeferredCommand help much here. Jeff, If I understand
>> you
>> > > correctly, my execute method will look like this:
>> > >
>> > > class Executor {
>> > > // declaration of list of commands
>> > > void execute() {
>> > > DeferredCommand.addCommand(new IncrementalCommand() {
>> > > boolean executing;
>> > > int currentIdx;
>> > >
>> > > public boolean execute() {
>> > > if (executing) return true; // executor will keep looping
>> > > // it's my turn now
>> > > executing = true;
>> > > AsyncCommand cmd = commands.get(currentIdx);
>> > > cmd.execute(new AsyncCallback() {
>> > > public void onFailure(Throwable e) { onSuccess(null); }
>> > > public void onSuccess(Object o) {
>> > > executing = false;
>> > > ++currentIdx;
>> > > }
>> > > }
>> > > // return point
>> > > }
>> > > }
>> > >
>> > > The above method is actually still non-blocking. There's no
>> guarantee
>> > > that my incremental command will finish executing before I reach
>> > > //return point. Did I miss anything?
>> >
>> > Looking at your code a bit more closely (and while composing an
>> > example), I see that you want something that requires a bit more
>> > structure.
>> >
>> > You have the IncrementalCommand() correctly implemented. Forget my
>> > previous answer.
>> >
>> > Now that I really understand what you're asking (I think)...
>> >
>> > I solve the problem using a state machine. Notice how the SM loops
>> on
>> > DICTIONARYREAD until the command queue is empty.
>> >
>> > DeferredCommand.addCommand(new IncrementalCommand() {
>> > @Override
>> > public boolean execute() {
>> > switch (startupState) {
>> > case INITIAL:
>> > timer.scheduleRepeating(600);
>> > startupState = StartupState.DICTIONARYREAD;
>> > break;
>> >
>> > case DICTIONARYREAD:
>> > if (dictionaryRequest.getDictionaryPages()) {
>> > break;
>> > }
>> >
>> > startupState = StartupState.FINAL;
>> > break;
>> >
>> > case FINAL: // Kevin's RETURN POINT?
>> > timer.cancel();
>> > return false; // command is complete
>> > }
>> > return true;
>> > });
>> >
>> > public boolean getDictionaryPages() {
>> > while (dictionaryRequestList.size() > 0) {
>> > if (busy) {
>> > return true;
>> > }
>> > dictionaryRequestList.pop().execute(); // RPC and BUSY mutex
>> > }
>> > return false;
>> > }
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups "Google Web Toolkit" group.
>> > To post to this group, send email to
>> > [email protected]
>> > <mailto:[email protected]>.
>> > To unsubscribe from this group, send email to
>> >
>> > [email protected]<google-web-toolkit%[email protected]>
>> >
>> > <mailto:google-web-toolkit%[email protected]<google-web-toolkit%[email protected]>
>> >.
>> > For more options, visit this group at
>> > http://groups.google.com/group/google-web-toolkit?hl=en.
>> >
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups "Google Web Toolkit" group.
>> > To post to this group, send email to
>> [email protected].
>> > To unsubscribe from this group, send email to
>> > [email protected]<google-web-toolkit%[email protected]>
>> .
>> > For more options, visit this group at
>> > http://groups.google.com/group/google-web-toolkit?hl=en.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Google Web Toolkit" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected]<google-web-toolkit%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/google-web-toolkit?hl=en.
>>
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-web-toolkit%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.