本文整理匯總了Java中com.google.appengine.api.taskqueue.QueueFactory.getDefaultQueue方法的典型用法代碼示例。如果您正苦於以下問題:Java QueueFactory.getDefaultQueue方法的具體用法?Java QueueFactory.getDefaultQueue怎麽用?Java QueueFactory.getDefaultQueue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.appengine.api.taskqueue.QueueFactory
的用法示例。
在下文中一共展示了QueueFactory.getDefaultQueue方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: queueToIndex
import com.google.appengine.api.taskqueue.QueueFactory; //導入方法依賴的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);
}
示例2: enqueueTask
import com.google.appengine.api.taskqueue.QueueFactory; //導入方法依賴的package包/類
@Override
public void enqueueTask(String taskName, Map<String, String[]> paramMap) {
checkNotNull(taskName);
final Queue queue = QueueFactory.getDefaultQueue();
final TaskOptions options = TaskOptions.Builder.withUrl(String.format(PATH_ADMIN_TASK, taskName));
for (Map.Entry<String, String[]> param : paramMap.entrySet()) {
for (String value : param.getValue()) {
options.param(param.getKey(), value);
}
}
try {
queue.add(options);
LOGGER.info("Added admin task to queue {}", taskName);
} catch (TransientFailureException tfe) {
LOGGER.error("Run admin task fail {} ", tfe.getMessage());
}
}
示例3: doGet
import com.google.appengine.api.taskqueue.QueueFactory; //導入方法依賴的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);
}
示例4: 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());
}
示例5: watchFolderChanges
import com.google.appengine.api.taskqueue.QueueFactory; //導入方法依賴的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();
}
示例6: spoonPollEndTask
import com.google.appengine.api.taskqueue.QueueFactory; //導入方法依賴的package包/類
private void spoonPollEndTask(Meeting meeting) {
String taskName = "pollEnd_"+meeting.getKey();
this.removePollEndTask(meeting);
if (meeting.getPoll().getEndDate() != null && !meeting.getPoll().isEnded()) {
Queue queue = QueueFactory.getDefaultQueue();
TaskOptions task = TaskOptions.Builder
.withUrl(AppHelper.getTaskBaseUrl()+"/pollEnd")
.etaMillis(meeting.getPoll().getEndDate().getTime())
.param("meeting", meeting.getKey())
.method(Method.POST)
.taskName(taskName)
;
queue.add(task);
}
}
示例7: testTaskHandleContainsAllNecessaryProperties
import com.google.appengine.api.taskqueue.QueueFactory; //導入方法依賴的package包/類
@Test
public void testTaskHandleContainsAllNecessaryProperties() throws Exception {
String name = "testTaskHandleContainsAllNecessaryProperties-" + System.currentTimeMillis();
Queue queue = QueueFactory.getDefaultQueue();
TaskOptions options = withTaskName(name).payload("payload");
options.etaMillis(0); // TODO -- remove this once NPE is fixewd
TaskHandle handle = waitOnFuture(queue.addAsync(options));
assertEquals("default", handle.getQueueName());
assertEquals(name, handle.getName());
assertEquals("payload", new String(handle.getPayload(), "UTF-8"));
assertNotNull(handle.getEtaMillis());
assertEquals(0, (int) handle.getRetryCount());
}
示例8: 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();
waitOnFuture(defaultQueue.addAsync(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");
waitOnFuture(testQueue.addAsync(withTaskName(name2)));
sync();
request = TestQueueServlet.getLastRequest();
assertEquals("test", request.getHeader(QUEUE_NAME));
assertEquals(name2, request.getHeader(TASK_NAME));
}
示例9: testTaskHandleContainsAllNecessaryProperties
import com.google.appengine.api.taskqueue.QueueFactory; //導入方法依賴的package包/類
@Test
public void testTaskHandleContainsAllNecessaryProperties() throws Exception {
String name = "testTaskHandleContainsAllNecessaryProperties-" + System.currentTimeMillis();
Queue queue = QueueFactory.getDefaultQueue();
TaskOptions options = withTaskName(name).payload("payload");
options.etaMillis(0); // TODO -- remove this once NPE is fixewd
TaskHandle handle = queue.add(options);
assertEquals("default", handle.getQueueName());
assertEquals(name, handle.getName());
assertEquals("payload", new String(handle.getPayload(), "UTF-8"));
assertNotNull(handle.getEtaMillis());
assertEquals(0, (int) handle.getRetryCount());
}
示例10: 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));
}
示例11: testRetry
import com.google.appengine.api.taskqueue.QueueFactory; //導入方法依賴的package包/類
@Test
public void testRetry() throws Exception {
long numTimesToFail = 1;
String key = "testRetry-" + System.currentTimeMillis();
Queue queue = QueueFactory.getDefaultQueue();
queue.add(withUrl("/_ah/retryTest")
.param("testdata-key", key)
.param("times-to-fail", String.valueOf(numTimesToFail))
.retryOptions(RetryOptions.Builder.withTaskRetryLimit(5)));
String countKey = RetryTestServlet.getInvocationCountKey(key);
long expectedAttempts = (numTimesToFail + 1);
long actualAttempts = waitForTestData(countKey, expectedAttempts);
assertEquals(expectedAttempts, actualAttempts);
String requestKey1 = RetryTestServlet.getRequestDataKey(key, 1);
RequestData request1 = waitForTestDataToExist(requestKey1);
assertEquals("0", request1.getHeader(TASK_RETRY_COUNT));
assertEquals("0", request1.getHeader(TASK_EXECUTION_COUNT));
String requestKey2 = RetryTestServlet.getRequestDataKey(key, 2);
RequestData request2 = waitForTestDataToExist(requestKey2);
assertEquals("1", request2.getHeader(TASK_RETRY_COUNT));
assertEquals("1", request2.getHeader(TASK_EXECUTION_COUNT));
}
示例12: testRetryLimitIsHonored
import com.google.appengine.api.taskqueue.QueueFactory; //導入方法依賴的package包/類
@Test
public void testRetryLimitIsHonored() throws Exception {
long numTimesToFail = 10;
int retryLimit = 2;
String key = "testRetryLimitIsHonored-" + System.currentTimeMillis();
Queue queue = QueueFactory.getDefaultQueue();
queue.add(withUrl("/_ah/retryTest")
.param("testdata-key", key)
.param("times-to-fail", String.valueOf(numTimesToFail))
.retryOptions(RetryOptions.Builder.withTaskRetryLimit(retryLimit)));
long expectedAttempts = (long) (retryLimit + 1);
String countKey = RetryTestServlet.getInvocationCountKey(key);
Long actualAttempts = waitForTestData(countKey, expectedAttempts);
// Ideally this would be the assert, but when a task fails with 500, the test framework
// cannot capture it for the attempt count.
// assertEquals(expectedAttempts, actualAttempts);
// Allow room for one task to fail with 500.
assertTrue("Task retries lower than specified via withTaskRetryLimit()",
actualAttempts == expectedAttempts || actualAttempts == expectedAttempts - 1);
}
示例13: enqueue
import com.google.appengine.api.taskqueue.QueueFactory; //導入方法依賴的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);
}
示例14: transactionalTaskEnqueuing
import com.google.appengine.api.taskqueue.QueueFactory; //導入方法依賴的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]
}
示例15: doGet
import com.google.appengine.api.taskqueue.QueueFactory; //導入方法依賴的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!");
}