Google App Engine Task Queue on GWT

萝らか妹 提交于 2019-12-19 03:46:08

问题


I'm looking at Google App Engine's new task queue API for Java and I'm having a hard time relating that to my GWT application. If I wanted to use a task queue to do some asynchronous processing, how should I do that using GWT.

The way I see it is, I'd have to send a server request that would then do the submission to the task queue API. If I understand task queues properly, I'd have to create yet another servlet to do the processing from the task queue (be the worker).

I'm looking for 2 things:

  1. Would the worker be a Servlet (i.e. extends HttpServlet)? If not, can someone give me an example of a "worker"?
  2. Does it really make sense to use a task queue if I just want to submit an asynchronous response to be executed immediately? It seems GWT's built-in RPC mechanism is enough.

回答1:


Yes, worker would be a servlet which can handle a request with POST parameters. If you want an asynchronous call from client's point of view then RPC is enough (from server's point of view it is still synchronous). If you want to do "delayed" jobs which don't talk to your client, you can use a task queue.




回答2:


Deferred.Deferable

Any plans for deferred.defer in Java?

import static com.google.appengine.api.labs.taskqueue.TaskOptions.Builder.taskName;

import java.io.IOException;

import javax.servlet.ServletException;

import com.newatlanta.appengine.taskqueue.Deferred;
import com.newatlanta.appengine.taskqueue.Deferred.Deferrable;

@SuppressWarnings("serial")
public class SampleTask implements Deferrable {

    private String arg1;
    private String arg2;

    public SampleTask() {
    }

    public SampleTask(String arg1, String arg2) {
        // save information to use later
        this.arg1 = arg1;
        this.arg2 = arg2;
    }

    @Override
    public void doTask() throws ServletException, IOException {
        // TODO do work here

        // this is how you 'schedule' a task
        // doing this here is recursive;
        // you most likely want to call this from
        // a server rpc endpoint
        SampleTask task = new SampleTask("arg1", "arg2");
        Deferred.defer(task, "queue-name", taskName("task-name"));
    }
}


来源:https://stackoverflow.com/questions/1759387/google-app-engine-task-queue-on-gwt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!