I think I got the gist of it.  As a test I modified the Stripes action bean 
that handles my first page and added the following to its @DefaultHandler 
method:

  final Queue queue = QueueFactory.getDefaultQueue();
  queue.add(TaskOptions.Builder.url("/zugzug.zug")); // web.xml maps *.zug to 
stripes

It's adding a task to the queue.

Then I created an action bean for the gae task queue automaton to poke:

  @UrlBinding("/zugzug.zug")
  public class TaskQueueActionBean implements ActionBean { ...

and its @DefaultHandler method contains:

  @SuppressWarnings("unchecked")
  final List headerNames =
          Collections.list(getContext().getRequest().getHeaderNames());
  this.log.debug("header names: {}", headerNames);

And then the log received:

  header names: [Content-Type, User-Agent, Referer, Host, 
X-AppEngine-QueueName, X-AppEngine-TaskName, X-AppEngine-TaskRetryCount, 
Content-Length]

The first time I tried it I forgot to create the corresponding jsp view file, 
zugzug.jsp (which is essentially empty), and the task queue automaton kept 
retrying because stripes was returning an error because the jsp file was 
missing; lots of those log.debug lines in the log file.  After I fixed that 
then it was only in there once for each time I went to my first page.

The first page action bean enqueued the task, the task queue automaton sent an 
http request to the url zugzug.zug, then the TaskQueueActionBean was invoked 
and its success caused the automaton to dequeue the task (but not if it 
returned an error; then the automaton retries).


Rusty Wright wrote:
> The docs say "The default queue will call the request handler at the URL 
> /worker ..."  So it sounds to me that if you were, for example, using 
> Spring MVC, and had a Spring controller with
> 
> @Controller
> @RequestMapping("/worker")
> public final class WorkerController {
>    @RequestMapping(method = RequestMethod.GET)
>    public String handleGetRequest(final ModelMap model) {
>        this.log.debug("called");
> 
>        return (null);
>    }
> }
> 
> then it would call your handleGetRequest() method 5 times a second, by 
> sending an http GET (or POST?) request to your /worker url each time.
> 
> Similarly, with Stripes (and for Struts 2 probably something similar) it 
> would be something like
> 
> @UrlBinding("/worker")
> public class WorkerActionBean implements ActionBean {
>    @DefaultHandler
>    public Resolution handleRequest() {
>        this.log.debug("called");
> 
>        return (null);
>    }
> }
> 
> I'm returning null because I don't know what the task queue thing does 
> with what it gets back (I didn't read much of their docs; to tell the 
> truth, I stopped at that sentence I quoted at the top because it sounds 
> very similar to their cron thing, which docs I did read most of).  I'm 
> undoubtedly also lacking the code needed to pull the next task off the 
> queue and do something with it.
> 
> I'm assuming that you have some web framework in front of everything and 
> thus don't need a servlet mapping in your web.xml for the /worker url 
> since the web framework is handling the url mapping.
> 
> So they're "pinging" your /worker url using a plain old http request to 
> initiate running each task; your controller or action bean is what 
> performs the task.  Think of it like you typed in your browser's address 
> box http://your-gae-app.appspot.com/worker?task_queue_params_go_here or 
> you used the command line programs cURL or wget.
> 
> If I understand this correctly then I would say that their sentence I 
> quoted isn't as clear as it could be.  Given the way it's stated, is the 
> task queue really able to bypass all of the http request processing and 
> directly invoke my handler method?  How would it know which class+method 
> handles that url?  I would think that the servlet container calls the 
> request method, as a result of their task queue automaton diddling the url.
> 
> 
> John V Denley wrote:
>> Yes, I would like a "real" example of how to do this too, I get that
>> we need to use a URL to accept the request to do something, but where
>> does the URL start executing code. obviously its not going to be at
>> the "onModuleLoad" entry point.
>>
>> Thanks,
>> John
>>
>> On Nov 11, 1:23 am, edarroyo <[email protected]> wrote:
>>> Is there any gae samples usingtaskqueues that we can look at?
>>> I am having a really hard time understanding how to useTaskQueues.
>>>
>>> Thanks!
>>>
>>> On Oct 27, 6:18 pm, Vincent <[email protected]> wrote:
>>>
>>>
>>>
>>>> Thanks , Jason. It's very helpful for me to understand how to use this
>>>> new API.
>>
>> -- 
>>
>> You received this message because you are subscribed to the Google 
>> Groups "Google App Engine for Java" 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-appengine-java?hl=en.
>>
>>

--

You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" 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-appengine-java?hl=en.


Reply via email to