本文整理匯總了Java中com.google.appengine.api.taskqueue.Queue.add方法的典型用法代碼示例。如果您正苦於以下問題:Java Queue.add方法的具體用法?Java Queue.add怎麽用?Java Queue.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.appengine.api.taskqueue.Queue
的用法示例。
在下文中一共展示了Queue.add方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doGet
import com.google.appengine.api.taskqueue.Queue; //導入方法依賴的package包/類
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) {
Enumeration e = req.getHeaderNames();
while(e.hasMoreElements()) {
String param = (String)e.nextElement();
log.info("header:" + param + req.getHeader(param));
}
String cronHeader = req.getHeader("X-Appengine-Cron");
if(cronHeader == null || !cronHeader.trim().equals("true")) {
resp.setStatus(403);
return;
}
Queue queue = QueueFactory.getQueue("reaper");
queue.add(TaskOptions.Builder.withUrl("/reaper"));
}
示例2: queueToIndex
import com.google.appengine.api.taskqueue.Queue; //導入方法依賴的package包/類
/**
* @param name
* @param id
*/
public static void queueToIndex (String name, Long id) {
Queue queue = QueueFactory.getDefaultQueue();
TaskOptions options = TaskOptions.Builder.withMethod(Method.POST)
.url(INDEX_SEARCH_URL).param(ENTITY_NAME_KEY, name)
.param(ENTITY_ID_KEY, id.toString());
int retry = RETRY_COUNT;
do {
try {
queue.add(options);
// success no need to retry
retry = 0;
} catch (TransientFailureException ex) {
retry--;
}
} while (retry > 0);
}
示例3: watchFolderChanges
import com.google.appengine.api.taskqueue.Queue; //導入方法依賴的package包/類
public Channel watchFolderChanges(Drive driveService, Project project) throws IOException {
Channel channel = new Channel();
channel.setId(java.util.UUID.randomUUID().toString());
channel.setToken(project.getKey());
channel.setType("web_hook");
channel.setAddress(API.getBaseUrl()+"/webhook/receiveFolderChanges");
long expirationMillis = 86400000; // 1day
channel.setExpiration( (new Date()).getTime() + expirationMillis);
// task for renewing watch channel
Queue queue = QueueFactory.getDefaultQueue();
TaskOptions task = TaskOptions.Builder
.withUrl(AppHelper.getTaskBaseUrl()+"/watchFolderChanges")
.countdownMillis(expirationMillis)
.param("project", project.getKey())
.param("user", project.getOwner().getKey().getString())
.method(Method.POST)
;
queue.add(task);
return driveService.files().watch(project.getFolder(),channel).execute();
}
示例4: doGet
import com.google.appengine.api.taskqueue.Queue; //導入方法依賴的package包/類
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String channelKey = getChannelKey();
String filterText = req.getParameter("filterText");
filterText = (filterText == null) ? "" : filterText;
String tag = req.getParameter("tag");
String requestId = req.getParameter("reqId");
String userId = userService.getCurrentUser().getUserId();
Queue queue = QueueFactory.getDefaultQueue();
TaskOptions taskOptions = withUrl("/fetch")
.param("displayStyle", req.getParameter("displayStyle"))
.param("filterText", filterText)
.param("key", channelKey)
.param("networkCode", req.getParameter("networkCode"))
.param("userId", userId)
.param("tag", tag)
.param("reqId", requestId)
.param("typeOverride", req.getParameter("typeOverride"));
queue.add(taskOptions.method(Method.GET));
resp.getWriter().print(channelKey);
}
示例5: deferredTask
import com.google.appengine.api.taskqueue.Queue; //導入方法依賴的package包/類
private static void deferredTask(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
String queue = req.getParameter("queue");
Queue q;
if (queue == null) {
q = QueueFactory.getDefaultQueue();
} else {
q = QueueFactory.getQueue(queue);
}
final String data = req.getParameter("deferredData");
TaskOptions opts =
TaskOptions.Builder.withPayload(
new DeferredTask() {
@Override
public void run() {
gotCalledBack(data);
}
});
latch = new CountDownLatch(1);
TaskHandle handle = q.add(opts);
resp.getWriter().print(handle.getQueueName());
}
示例6: testParams
import com.google.appengine.api.taskqueue.Queue; //導入方法依賴的package包/類
@Test
public void testParams() throws Exception {
class ParamHandler implements PrintServlet.RequestHandler {
private String paramValue;
public void handleRequest(ServletRequest req) {
paramValue = req.getParameter("single_value");
}
}
ParamHandler handler = new ParamHandler();
PrintServlet.setRequestHandler(handler);
final Queue queue = QueueFactory.getQueue("tasks-queue");
queue.add(withUrl(URL).param("single_value", "param_value"));
sync();
assertEquals("param_value", handler.paramValue);
}
示例7: testPullMultipleWithSameTag
import com.google.appengine.api.taskqueue.Queue; //導入方法依賴的package包/類
@Test
public void testPullMultipleWithSameTag() throws Exception {
final Queue queue = QueueFactory.getQueue("pull-queue");
TaskHandle th1 = queue.add(withMethod(PULL).tag("barfoo2").payload("foobar").etaMillis(15000));
TaskHandle th2 = queue.add(withMethod(PULL).tag("barfoo2").payload("foofoo").etaMillis(10000));
try {
List<TaskHandle> handles = waitOnFuture(queue.leaseTasksByTagAsync(30, TimeUnit.MINUTES, 100, "barfoo2"));
assertEquals(2, handles.size());
Set<String> expectedTasks = taskHandlesToNameSet(th1, th2);
Set<String> returnedTasks = taskHandleListToNameSet(handles);
assertEquals(expectedTasks, returnedTasks);
} finally {
queue.deleteTask(th1);
queue.deleteTask(th2);
}
}
示例8: scheduleNotification
import com.google.appengine.api.taskqueue.Queue; //導入方法依賴的package包/類
@POST
@Path("{patientEmail}")
@Produces({MediaType.TEXT_PLAIN})
public String scheduleNotification(@PathParam("patientEmail") String patientEmail,
@FormParam("calendarId") String calendarId,
@FormParam("eventId") String eventId) throws IOException {
verifyPatientEmail(patientEmail);
Event event = getCalendarEvent(patientEmail, calendarId, eventId);
String appointmentTime = event.getStart().getDateTime().toStringRfc3339();
TaskOptions task = withUrl("/tasks/notification/")
.method(TaskOptions.Method.GET)
.param("patientEmail", patientEmail)
.param("appointmentAddress", event.getLocation())
.param("appointmentTime", appointmentTime);
Queue queue = QueueFactory.getQueue(QUEUE_NAME);
queue.add(task);
return "OK";
}
示例9: multicastSend
import com.google.appengine.api.taskqueue.Queue; //導入方法依賴的package包/類
public void multicastSend(List<Device> devices, String action, String extraData) {
Queue queue = QueueFactory.getQueue("MulticastMessagesQueue");
// Split messages into batches for multicast
// GCM limits maximum devices per multicast request. AppEngine also limits the size of
// lists stored in the datastore.
int total = devices.size();
List<String> partialDevices = new ArrayList<String>(total);
int counter = 0;
for (Device device : devices) {
counter ++;
partialDevices.add(device.getGcmId());
int partialSize = partialDevices.size();
if (partialSize == MAX_DEVICES || counter == total) {
// Send multicast message
Long multicastKey = MessageStore.createMulticast(partialDevices,
action,
extraData);
mLogger.fine("Queuing " + partialSize + " devices on multicast " + multicastKey);
TaskOptions taskOptions = TaskOptions.Builder
.withUrl("/queue/send")
.param("multicastKey", Long.toString(multicastKey))
.method(TaskOptions.Method.POST);
queue.add(taskOptions);
partialDevices.clear();
}
}
mLogger.fine("Queued message to " + total + " devices");
}
示例10: checkUpgrade
import com.google.appengine.api.taskqueue.Queue; //導入方法依賴的package包/類
public void checkUpgrade(String userId) {
if (!conversionEnabled) // Unless conversion is enabled...
return;
Objectify datastore = ObjectifyService.begin();
UserData userData = datastore.find(userKey(userId));
if ((userData.upgradedGCS && useGcs) ||
(!userData.upgradedGCS && !useGcs))
return; // All done.
Queue queue = QueueFactory.getQueue("blobupgrade");
queue.add(TaskOptions.Builder.withUrl("/convert").param("user", userId)
.etaMillis(System.currentTimeMillis() + 60000));
return;
}
示例11: enqueue
import com.google.appengine.api.taskqueue.Queue; //導入方法依賴的package包/類
public void enqueue() {
// these tasks run on the background thread...
ModulesService modulesApi = ModulesServiceFactory.getModulesService();
String hostname = modulesApi.getVersionHostname(ServletConsts.BACKEND_GAE_SERVICE, null);
task.header(ServletConsts.HOST, hostname);
Queue queue = QueueFactory.getDefaultQueue();
queue.add(task);
}
示例12: pushPersonalizedOffers
import com.google.appengine.api.taskqueue.Queue; //導入方法依賴的package包/類
/**
* Sends personalized offers to a user that checked in at a place.
* @param placeId the place from which we want to retrieve offers.
* @param user the user to whom we send the personalized offers.
*/
private void pushPersonalizedOffers(final String placeId, final User user) {
// insert a task to a queue
LOG.info("adding a task to recommendations-queue");
Queue queue = QueueFactory.getQueue("recommendations-queue");
try {
String userEmail = user.getEmail();
queue.add(withUrl("/tasks/recommendations")
.param("userEmail", userEmail).param("placeId", placeId));
LOG.info("task added");
} catch (RuntimeException e) {
LOG.severe(e.getMessage());
}
}
示例13: transactionalTaskEnqueuing
import com.google.appengine.api.taskqueue.Queue; //導入方法依賴的package包/類
@Test
public void transactionalTaskEnqueuing() throws Exception {
// [START transactional_task_enqueuing]
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Queue queue = QueueFactory.getDefaultQueue();
Transaction txn = datastore.beginTransaction();
// ...
queue.add(TaskOptions.Builder.withUrl("/path/to/handler"));
// ...
txn.commit();
// [END transactional_task_enqueuing]
}
示例14: doGet
import com.google.appengine.api.taskqueue.Queue; //導入方法依賴的package包/類
/**
* Basic demonstration of adding a deferred task.
* @param request servlet request
* @param resp servlet response
*/
@Override
public void doGet(final HttpServletRequest request,
final HttpServletResponse resp) throws IOException {
// Add the task to the default queue.
Queue queue = QueueFactory.getDefaultQueue();
// Wait 5 seconds to run for demonstration purposes
queue.add(TaskOptions.Builder.withPayload(new ExpensiveOperation())
.etaMillis(System.currentTimeMillis() + DELAY_MS));
resp.setContentType("text/plain");
resp.getWriter().println("Task is backgrounded on queue!");
}
示例15: doPost
import com.google.appengine.api.taskqueue.Queue; //導入方法依賴的package包/類
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String key = request.getParameter("key");
// Add the task to the default queue.
// [START addQueue]
Queue queue = QueueFactory.getDefaultQueue();
queue.add(TaskOptions.Builder.withUrl("/worker").param("key", key));
// [END addQueue]
response.sendRedirect("/");
}