本文整理汇总了Java中com.google.appengine.api.taskqueue.QueueFactory.getQueue方法的典型用法代码示例。如果您正苦于以下问题:Java QueueFactory.getQueue方法的具体用法?Java QueueFactory.getQueue怎么用?Java QueueFactory.getQueue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.appengine.api.taskqueue.QueueFactory
的用法示例。
在下文中一共展示了QueueFactory.getQueue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scheduleNotificationBuild
import com.google.appengine.api.taskqueue.QueueFactory; //导入方法依赖的package包/类
public static void scheduleNotificationBuild(String objectType, Long id,
String action) {
if (objectType == null || objectType.isEmpty()) {
throw new IllegalArgumentException("No Specified Object Type");
}
if (id == null) {
throw new IllegalArgumentException("No Specified Object Id");
}
if (action == null || action.isEmpty()) {
throw new IllegalArgumentException("No Action Specified");
}
// Execute the servlet to pull from the queue
Queue executionQueue = QueueFactory.getQueue("notification-building");
executionQueue.add(TaskOptions.Builder
.withUrl("/notifications/builder/").method(Method.GET)
.param("objectType", objectType)
.param("id", String.valueOf(id.longValue()))
.param("action", action));
}
示例2: doGet
import com.google.appengine.api.taskqueue.QueueFactory; //导入方法依赖的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"));
}
示例3: reset
import com.google.appengine.api.taskqueue.QueueFactory; //导入方法依赖的package包/类
/**
* Reset reservations in datastore to match those in RTDB. Reservations in RTDB are used
* as the source of truth, corresponding reservations in datastore are updated to match
* those in RTDB. Reservations in RTDB that do not exist in datastore are added to datastore.
* Reservations that exist in datastore and do not exist in RTDB are updated in datastore
* with status DELETED.
*
* Use of this endpoint should be followed by a user data sync.
*
* @param user User making request (injected by Endpoints)
*/
@ApiMethod(name = "reset", path = "reset")
public void reset(User user)
throws UnauthorizedException {
if (user == null) {
throw new UnauthorizedException("Invalid credentials");
}
// Add Sync Reservations worker to queue.
Queue queue = QueueFactory.getQueue("SyncReservationsQueue");
TaskOptions taskOptions = TaskOptions.Builder
.withUrl("/queue/syncres")
.method(Method.GET);
queue.add(taskOptions);
}
示例4: addDeferredTask
import com.google.appengine.api.taskqueue.QueueFactory; //导入方法依赖的package包/类
/**
* Adds the given task, to be run after the specified time, to the specified queue.
*
* @param task the task object containing the details of task to be added
* @param countdownTime the time delay for the task to be executed
*/
public void addDeferredTask(TaskWrapper task, long countdownTime) {
Queue requiredQueue = QueueFactory.getQueue(task.getQueueName());
TaskOptions taskToBeAdded = TaskOptions.Builder.withUrl(task.getWorkerUrl());
if (countdownTime > 0) {
taskToBeAdded.countdownMillis(countdownTime);
}
for (Map.Entry<String, String[]> entry : task.getParamMap().entrySet()) {
String name = entry.getKey();
String[] values = entry.getValue();
for (String value : values) {
taskToBeAdded = taskToBeAdded.param(name, value);
}
}
requiredQueue.add(taskToBeAdded);
}
示例5: deferredTask
import com.google.appengine.api.taskqueue.QueueFactory; //导入方法依赖的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: doPolling
import com.google.appengine.api.taskqueue.QueueFactory; //导入方法依赖的package包/类
private void doPolling() {
Queue notificationQueue = QueueFactory.getQueue("notification-delivery");
Worker worker = new Worker(notificationQueue);
while (!LifecycleManager.getInstance().isShuttingDown()) {
boolean tasksProcessed = worker.processBatchOfTasks();
ApiProxy.flushLogs();
if (!tasksProcessed) {
// Wait before trying to lease tasks again.
try {
Thread.sleep(MILLISECONDS_TO_WAIT_WHEN_NO_TASKS_LEASED);
} catch (InterruptedException e) {
return;
}
}
}
log.info("Instance is shutting down");
}
示例7: leaseAndDeleteTasks
import com.google.appengine.api.taskqueue.QueueFactory; //导入方法依赖的package包/类
private void leaseAndDeleteTasks(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
int numTasks = Integer.parseInt(req.getParameter("numTasks"));
Double lease = Double.parseDouble(req.getParameter("lease"));
String queue = req.getParameter("queue");
Queue q = QueueFactory.getQueue(queue);
Boolean doDelete = Boolean.parseBoolean(req.getParameter("doDelete"));
List<TaskHandle> tasks = q.leaseTasks(lease.intValue() * 1000, TimeUnit.MILLISECONDS, numTasks);
for (TaskHandle task : tasks) {
if (doDelete) {
q.deleteTask(task.getName());
}
}
resp.getWriter().print(queue + "," + tasks.size());
}
示例8: scheduleNotification
import com.google.appengine.api.taskqueue.QueueFactory; //导入方法依赖的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: testPullMultipleWithSameTag
import com.google.appengine.api.taskqueue.QueueFactory; //导入方法依赖的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);
}
}
示例10: testParams
import com.google.appengine.api.taskqueue.QueueFactory; //导入方法依赖的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);
}
示例11: doPolling
import com.google.appengine.api.taskqueue.QueueFactory; //导入方法依赖的package包/类
private void doPolling() {
Queue notificationQueue = QueueFactory.getQueue("notification-delivery");
PushNotificationWorker worker = new PushNotificationWorker(notificationQueue);
while (!LifecycleManager.getInstance().isShuttingDown()) {
boolean tasksProcessed = worker.processBatchOfTasks();
ApiProxy.flushLogs();
if (!tasksProcessed) {
// Wait before trying to lease tasks again.
try {
Thread.sleep(MILLISECONDS_TO_WAIT_WHEN_NO_TASKS_LEASED);
} catch (InterruptedException e) {
return;
}
}
}
log.info("Instance is shutting down");
}
开发者ID:GoogleCloudPlatform,项目名称:solutions-ios-push-notification-sample-backend-java,代码行数:21,代码来源:PushNotificationWorkerServlet.java
示例12: testRequestHeaders
import com.google.appengine.api.taskqueue.QueueFactory; //导入方法依赖的package包/类
@Test
public void testRequestHeaders() throws Exception {
String name = "testRequestHeaders-1-" + System.currentTimeMillis();
Queue defaultQueue = QueueFactory.getDefaultQueue();
defaultQueue.add(withTaskName(name));
sync();
RequestData request = DefaultQueueServlet.getLastRequest();
assertEquals("default", request.getHeader(QUEUE_NAME));
assertEquals(name, request.getHeader(TASK_NAME));
assertNotNull(request.getHeader(TASK_RETRY_COUNT));
assertNotNull(request.getHeader(TASK_EXECUTION_COUNT));
assertNotNull(request.getHeader(TASK_ETA));
String name2 = "testRequestHeaders-2-" + System.currentTimeMillis();
Queue testQueue = QueueFactory.getQueue("test");
testQueue.add(withTaskName(name2));
sync();
request = TestQueueServlet.getLastRequest();
assertEquals("test", request.getHeader(QUEUE_NAME));
assertEquals(name2, request.getHeader(TASK_NAME));
}
示例13: multicastSend
import com.google.appengine.api.taskqueue.QueueFactory; //导入方法依赖的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");
}
示例14: checkUpgrade
import com.google.appengine.api.taskqueue.QueueFactory; //导入方法依赖的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;
}
示例15: createAction
import com.google.appengine.api.taskqueue.QueueFactory; //导入方法依赖的package包/类
private RdeUploadAction createAction(URI uploadUrl) {
try (Keyring keyring = new FakeKeyringModule().get()) {
RdeUploadAction action = new RdeUploadAction();
action.clock = clock;
action.gcsUtils = new GcsUtils(gcsService, BUFFER_SIZE);
action.ghostryde = new Ghostryde(BUFFER_SIZE);
action.lazyJsch =
() ->
JSchModule.provideJSch(
"[email protected]",
keyring.getRdeSshClientPrivateKey(),
keyring.getRdeSshClientPublicKey());
action.jschSshSessionFactory = new JSchSshSessionFactory(standardSeconds(3));
action.response = response;
action.pgpCompressionFactory = compressFactory;
action.pgpEncryptionFactory = encryptFactory;
action.pgpFileFactory = literalFactory;
action.pgpSigningFactory = signFactory;
action.tarFactory = tarFactory;
action.bucket = "bucket";
action.interval = standardDays(1);
action.timeout = standardSeconds(23);
action.tld = "tld";
action.sftpCooldown = standardSeconds(7);
action.uploadUrl = uploadUrl;
action.receiverKey = keyring.getRdeReceiverKey();
action.signingKey = keyring.getRdeSigningKey();
action.stagingDecryptionKey = keyring.getRdeStagingDecryptionKey();
action.reportQueue = QueueFactory.getQueue("rde-report");
action.runner = runner;
action.taskEnqueuer = new TaskEnqueuer(new Retrier(null, 1));
action.retrier = new Retrier(new FakeSleeper(clock), 3);
return action;
}
}