• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java TaskHandle类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.google.appengine.api.taskqueue.TaskHandle的典型用法代码示例。如果您正苦于以下问题:Java TaskHandle类的具体用法?Java TaskHandle怎么用?Java TaskHandle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TaskHandle类属于com.google.appengine.api.taskqueue包,在下文中一共展示了TaskHandle类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: loadAllTasks

import com.google.appengine.api.taskqueue.TaskHandle; //导入依赖的package包/类
/** Leases and returns all tasks from the queue with the specified tag tld, in batches. */
public static List<TaskHandle> loadAllTasks(Queue queue, String tld) {
  ImmutableList.Builder<TaskHandle> allTasks = new ImmutableList.Builder<>();
  int numErrors = 0;
  long backOff = backOffMillis;
  while (true) {
    try {
      List<TaskHandle> tasks = queue.leaseTasks(LeaseOptions.Builder
          .withTag(tld)
          .leasePeriod(LEASE_PERIOD.getMillis(), TimeUnit.MILLISECONDS)
          .countLimit(BATCH_SIZE));
      allTasks.addAll(tasks);
      if (tasks.isEmpty()) {
        return allTasks.build();
      }
    } catch (TransientFailureException | DeadlineExceededException e) {
      if (++numErrors >= 3) {
        throw new RuntimeException("Error leasing tasks", e);
      }
      Uninterruptibles.sleepUninterruptibly(backOff, TimeUnit.MILLISECONDS);
      backOff *= 2;
    }
  }
}
 
开发者ID:google,项目名称:nomulus,代码行数:25,代码来源:LordnTask.java


示例2: deleteTasksWithRetry

import com.google.appengine.api.taskqueue.TaskHandle; //导入依赖的package包/类
/** Deletes a list of tasks from the given queue using a retrier. */
private static void deleteTasksWithRetry(
    final List<DnsRefreshRequest> refreshRequests,
    final Queue queue,
    AsyncFlowMetrics asyncFlowMetrics,
    Retrier retrier,
    OperationResult result) {
  if (refreshRequests.isEmpty()) {
    return;
  }
  final List<TaskHandle> tasks =
      refreshRequests.stream().map(DnsRefreshRequest::task).collect(toImmutableList());
  retrier.callWithRetry(() -> queue.deleteTask(tasks), TransientFailureException.class);
  refreshRequests.forEach(
      r -> asyncFlowMetrics.recordAsyncFlowResult(DNS_REFRESH, result, r.requestedTime()));
}
 
开发者ID:google,项目名称:nomulus,代码行数:17,代码来源:RefreshDnsOnHostRenameAction.java


示例3: createFromTask

import com.google.appengine.api.taskqueue.TaskHandle; //导入依赖的package包/类
/**
 * Returns a packaged-up {@link DnsRefreshRequest} parsed from a task queue task.
 */
static DnsRefreshRequest createFromTask(TaskHandle task, DateTime now) throws Exception {
  ImmutableMap<String, String> params = ImmutableMap.copyOf(task.extractParams());
  Key<HostResource> hostKey =
      Key.create(checkNotNull(params.get(PARAM_HOST_KEY), "Host to refresh not specified"));
  HostResource host =
      checkNotNull(ofy().load().key(hostKey).now(), "Host to refresh doesn't exist");
  boolean isHostDeleted =
      isDeleted(host, latestOf(now, host.getUpdateAutoTimestamp().getTimestamp()));
  if (isHostDeleted) {
    logger.infofmt("Host %s is already deleted, not refreshing DNS.", hostKey);
  }
  return new AutoValue_RefreshDnsOnHostRenameAction_DnsRefreshRequest.Builder()
      .setHostKey(hostKey)
      .setLastUpdateTime(host.getUpdateAutoTimestamp().getTimestamp())
      .setRequestedTime(
          DateTime.parse(
              checkNotNull(params.get(PARAM_REQUESTED_TIME), "Requested time not specified")))
      .setIsRefreshNeeded(!isHostDeleted)
      .setTask(task)
      .build();
}
 
开发者ID:google,项目名称:nomulus,代码行数:25,代码来源:RefreshDnsOnHostRenameAction.java


示例4: processTasks

import com.google.appengine.api.taskqueue.TaskHandle; //导入依赖的package包/类
private static String processTasks(List<TaskHandle> tasks, Queue q) {
  String payload;
  int numberOfDeletedTasks = 0;
  for (TaskHandle task : tasks) {
    payload = new String(task.getPayload());
    output = String.format("Processing: taskName='%s'  payload='%s'", task.getName(), payload);
    log.info(output);
    output = String.format("Deleting taskName='%s'", task.getName());
    log.info(output);
    // [START delete_task]
    q.deleteTask(task);
    // [END delete_task]
    numberOfDeletedTasks++;
  }
  if (numberOfDeletedTasks > 0) {
    message = "Processed and deleted " + numberOfTasksToLease + " tasks from the "
        + " task queue.";
  } else {
    message = "Task Queue has no tasks available for lease.";
  }
  return message;
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:23,代码来源:TaskqueueServlet.java


示例5: processTasks

import com.google.appengine.api.taskqueue.TaskHandle; //导入依赖的package包/类
private static String processTasks(List<TaskHandle> tasks, Queue q) {
  String payload;
  int numberOfDeletedTasks = 0;
  for (TaskHandle task : tasks) {
    payload = new String(task.getPayload());
    output =
        String.format(
            "Processing: taskName='%s'  payload='%s'",
            task.getName().toString(), payload.toString());
    log.info(output.toString());
    output = String.format("Deleting taskName='%s'", task.getName().toString());
    log.info(output.toString());
    // [START delete_task]
    q.deleteTask(task);
    // [END delete_task]
    numberOfDeletedTasks++;
  }
  if (numberOfDeletedTasks > 0) {
    message =
        "Processed and deleted " + numberOfTasksToLease + " tasks from the " + " task queue.";
  } else {
    message = "Task Queue has no tasks available for lease.";
  }
  return message;
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:26,代码来源:TaskqueueServlet.java


示例6: addToQueue

import com.google.appengine.api.taskqueue.TaskHandle; //导入依赖的package包/类
List<TaskHandle> addToQueue(final Collection<Task> tasks) {
  List<TaskHandle> handles = new ArrayList<>();
  Map<String, List<TaskOptions>> queueNameToTaskOptions = new HashMap<>();
  for (Task task : tasks) {
    logger.finest("Enqueueing: " + task);
    String queueName = task.getQueueSettings().getOnQueue();
    TaskOptions taskOptions = toTaskOptions(task);
    List<TaskOptions> taskOptionsList = queueNameToTaskOptions.get(queueName);
    if (taskOptionsList == null) {
      taskOptionsList = new ArrayList<>();
      queueNameToTaskOptions.put(queueName, taskOptionsList);
    }
    taskOptionsList.add(taskOptions);
  }
  for (Map.Entry<String, List<TaskOptions>> entry : queueNameToTaskOptions.entrySet()) {
    Queue queue = getQueue(entry.getKey());
    handles.addAll(addToQueue(queue, entry.getValue()));
  }
  return handles;
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-pipelines,代码行数:21,代码来源:AppEngineTaskQueue.java


示例7: testEnqueueBatchTasks

import com.google.appengine.api.taskqueue.TaskHandle; //导入依赖的package包/类
public void testEnqueueBatchTasks() {
  AppEngineTaskQueue queue = new AppEngineTaskQueue();
  List<Task> tasks = new ArrayList<>(AppEngineTaskQueue.MAX_TASKS_PER_ENQUEUE);
  for (int i = 0; i < AppEngineTaskQueue.MAX_TASKS_PER_ENQUEUE; i++) {
    Task task = createTask();
    tasks.add(task);
  }
  List<TaskHandle> handles = queue.addToQueue(tasks);
  assertEquals(AppEngineTaskQueue.MAX_TASKS_PER_ENQUEUE, handles.size());
  for (int i = 0; i < AppEngineTaskQueue.MAX_TASKS_PER_ENQUEUE; i++) {
    assertEquals(tasks.get(i).getName(), handles.get(i).getName());
  }

  handles = queue.addToQueue(tasks);
  assertEquals(0, handles.size());
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-pipelines,代码行数:17,代码来源:AppEngineTaskQueueTest.java


示例8: testEnqueueLargeBatchTasks

import com.google.appengine.api.taskqueue.TaskHandle; //导入依赖的package包/类
public void testEnqueueLargeBatchTasks() {
  AppEngineTaskQueue queue = new AppEngineTaskQueue();
  int batchSize = AppEngineTaskQueue.MAX_TASKS_PER_ENQUEUE * 2 + 10;
  List<Task> tasks = new ArrayList<>(batchSize);
  for (int i = 0; i < batchSize; i++) {
    Task task = createTask();
    tasks.add(task);
  }
  List<TaskHandle> handles = queue.addToQueue(tasks);
  assertEquals(tasks.size(), handles.size());
  for (int i = 0; i < tasks.size(); i++) {
    assertEquals(tasks.get(i).getName(), handles.get(i).getName());
  }

  handles = queue.addToQueue(tasks);
  assertEquals(0, handles.size());
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-pipelines,代码行数:18,代码来源:AppEngineTaskQueueTest.java


示例9: testEnqueueBatchTwoStages

import com.google.appengine.api.taskqueue.TaskHandle; //导入依赖的package包/类
public void testEnqueueBatchTwoStages() {
  AppEngineTaskQueue queue = new AppEngineTaskQueue();
  int batchSize = AppEngineTaskQueue.MAX_TASKS_PER_ENQUEUE * 2;
  List<Task> tasks = new ArrayList<>(batchSize);
  for (int i = 0; i < batchSize; i++) {
    Task task = createTask();
    tasks.add(task);
  }

  int firstBatchSize = AppEngineTaskQueue.MAX_TASKS_PER_ENQUEUE;
  List<TaskHandle> handles = queue.addToQueue(tasks.subList(0, firstBatchSize));

  assertEquals(firstBatchSize, handles.size());
  for (int i = 0; i < firstBatchSize; i++) {
    assertEquals(tasks.get(i).getName(), handles.get(i).getName());
  }

  handles = queue.addToQueue(tasks);

  // Duplicate is rejected (not counted) per batch.
  int expected = tasks.size() - firstBatchSize;
  assertEquals(expected, handles.size());
  for (int i = 0; i < expected; i++) {
    assertEquals(tasks.get(firstBatchSize + i).getName(), handles.get(i).getName());
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-pipelines,代码行数:27,代码来源:AppEngineTaskQueueTest.java


示例10: deferredTask

import com.google.appengine.api.taskqueue.TaskHandle; //导入依赖的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());
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:25,代码来源:TaskQueueServlet.java


示例11: leaseAndDeleteTasks

import com.google.appengine.api.taskqueue.TaskHandle; //导入依赖的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());
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:18,代码来源:TaskQueueServlet.java


示例12: testBasicLease

import com.google.appengine.api.taskqueue.TaskHandle; //导入依赖的package包/类
@Test
public void testBasicLease() {
    String taskGroupTag = "testBasicLease";
    String taskBaseName = taskGroupTag + "_" + getTimeStampRandom();
    int count = 10;

    addTasks(count, taskBaseName, taskGroupTag, payload);

    // lease 1 task from pull queue
    List<TaskHandle> handleList = leaseTasksByTag60Secs(taskGroupTag, 1, false);
    assertEquals(1, handleList.size());
    deleteTaskByName(handleList.get(0).getName());

    // lease the rest from pull queue
    handleList = leaseTasksByTag60Secs(taskGroupTag, MAX_LEASE_COUNT, false);
    assertEquals(count - 1, handleList.size());

    for (TaskHandle t : handleList) {
        assertTrue(t.getName().startsWith(taskBaseName));
        assertEquals(E2E_TESTING_PULL, t.getQueueName());
        assertEquals(payload, new String(t.getPayload()));
        deleteTaskByName(t.getName());
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:25,代码来源:PullQueueTest.java


示例13: testLeaseExpiration

import com.google.appengine.api.taskqueue.TaskHandle; //导入依赖的package包/类
@Test
public void testLeaseExpiration() {
    String groupTag = "testLeaseExpiration";
    String taskBaseName = groupTag + "_" + getTimeStampRandom();
    deleteOnTearDownTags.add(taskBaseName);

    int count = 1;
    List<TaskHandle> taskList = addTasks(count, taskBaseName, groupTag, "nada");
    long leaseDuration = 1000;
    LeaseOptions options = LeaseOptions.Builder
        .withTag(groupTag)
        .countLimit(count)
        .leasePeriod(leaseDuration, TimeUnit.MILLISECONDS);

    List<TaskHandle> tasks = queue.leaseTasks(options);
    assertEquals(count, tasks.size());

    sync(leaseDuration + 1000); // wait for lease to expire
    List<TaskHandle> tasksAfterExpire = queue.leaseTasks(options);

    // expired, so it should be available for lease.
    assertEquals(count, tasksAfterExpire.size());

    deleteMultipleTasks(tasksAfterExpire);
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:26,代码来源:PullQueueTest.java


示例14: testLeaseTasksByTagBytes

import com.google.appengine.api.taskqueue.TaskHandle; //导入依赖的package包/类
@Test
public void testLeaseTasksByTagBytes() {
    String groupTag = "testLeaseTasksByTagBytes";
    String taskBaseName = groupTag + "_" + getTimeStampRandom();
    taskTags.add(taskBaseName);
    byte[] tagBytes = taskBaseName.getBytes();

    TaskOptions options =
        withMethod(TaskOptions.Method.PULL)
            .taskName(taskBaseName + "_0")
            .tag(tagBytes)
            .payload("");
    queue.add(options);
    sync(5000);  // Give tasks a chance to become available.

    List<TaskHandle> tasks = queue.leaseTasksByTagBytes(1, TimeUnit.SECONDS, 10, tagBytes);
    assertEquals(1, tasks.size());
    queue.deleteTask(tasks);
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:20,代码来源:PullQueueTest.java


示例15: testPullMultipleWithSameTag

import com.google.appengine.api.taskqueue.TaskHandle; //导入依赖的package包/类
@Test
public void testPullMultipleWithSameTag() throws Exception {
    String groupTag = "testLeaseTasksByTagBytes";
    String taskBaseName = groupTag + "_" + getTimeStampRandom();
    TaskHandle th1 = queue.add(withMethod(PULL).tag(taskBaseName).payload("foobar", "UTF-8"));
    TaskHandle th2 = queue.add(withMethod(PULL).tag(taskBaseName).payload("foofoo".getBytes(), "UTF-8"));
    sync();
    try {
        int numTasksToLease = 100;
        List<TaskHandle> handles = queue.leaseTasksByTag(30, TimeUnit.MINUTES, numTasksToLease, taskBaseName);
        assertEquals(2, handles.size());

        Set<String> createdHandles = new HashSet<>();
        createdHandles.add(th1.getName());
        createdHandles.add(th2.getName());

        Set<String> returnedHandles = new HashSet<>();
        returnedHandles.add(handles.get(0).getName());
        returnedHandles.add(handles.get(1).getName());

        assertEquals(createdHandles, returnedHandles);
    } finally {
        queue.deleteTask(th1);
        queue.deleteTask(th2);
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:27,代码来源:PullQueueTest.java


示例16: testPullMultipleWithDiffTag

import com.google.appengine.api.taskqueue.TaskHandle; //导入依赖的package包/类
@Test
public void testPullMultipleWithDiffTag() throws Exception {
    String groupTag = "testPullMultipleWithDiffTag";
    String taskBaseName = groupTag + "_" + getTimeStampRandom();

    TaskHandle th1 = queue.add(withMethod(PULL).tag(taskBaseName).payload("foobar"));
    TaskHandle th2 = queue.add(withMethod(PULL).tag(taskBaseName + "other").payload("foofoo".getBytes()));
    TaskHandle th3 = queue.add(withMethod(PULL).tag(taskBaseName).payload("foofoo".getBytes()));
    sync();
    try {
        List<TaskHandle> handles = queue.leaseTasksByTag(30, TimeUnit.MINUTES, 100, taskBaseName);
        assertEquals(2, handles.size());

        handles = queue.leaseTasksByTag(30, TimeUnit.MINUTES, 100, taskBaseName + "other");
        assertEquals(1, handles.size());
        assertEquals(th2.getName(), handles.get(0).getName());
    } finally {
        queue.deleteTask(th1);
        queue.deleteTask(th2);
        queue.deleteTask(th3);
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:23,代码来源:PullQueueTest.java


示例17: testEtaMillis

import com.google.appengine.api.taskqueue.TaskHandle; //导入依赖的package包/类
@Test
public void testEtaMillis() {
    String tag = "testEtaMillis_" + getTimeStampRandom();
    queue.add(withMethod(PULL).etaMillis(System.currentTimeMillis() + 10000).tag(tag));
    sync(5000);  // Give tasks a chance to become available.

    List<TaskHandle> tasks = queue.leaseTasks(LeaseOptions.Builder.withTag(tag).leasePeriod(1, TimeUnit.SECONDS).countLimit(1));
    assertEquals(0, tasks.size());

    sync(10000);

    tasks = queue.leaseTasks(LeaseOptions.Builder.withTag(tag.getBytes()).leasePeriod(1, TimeUnit.SECONDS).countLimit(1));
    assertEquals(1, tasks.size());

    queue.deleteTask(tasks);
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:17,代码来源:PullQueueTest.java


示例18: testCountdownMillis

import com.google.appengine.api.taskqueue.TaskHandle; //导入依赖的package包/类
@Test
public void testCountdownMillis() {
    String tag = "testCountdownMillis_" + getTimeStampRandom();
    queue.add(withMethod(PULL).countdownMillis(10000).tag(tag));
    sync(5000);  // Give tasks a chance to become available.

    List<TaskHandle> tasks = queue.leaseTasks(LeaseOptions.Builder.withTag(tag.getBytes()).leasePeriod(1, TimeUnit.SECONDS).countLimit(1));
    assertEquals(0, tasks.size());

    sync(10000);

    tasks = queue.leaseTasks(LeaseOptions.Builder.withTag(tag).leasePeriod(1, TimeUnit.SECONDS).countLimit(1));
    assertEquals(1, tasks.size());

    queue.deleteTask(tasks);
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:17,代码来源:PullQueueTest.java


示例19: addTasks

import com.google.appengine.api.taskqueue.TaskHandle; //导入依赖的package包/类
/**
 * @param count        Number of tasks to create.
 * @param taskBaseName add count to this name to create task name.
 * @param groupTag     will be used during tearDown to delete tasks.
 * @param payload      to be used by task.
 * @return List of TaskHandles from queue.add()
 */
private List<TaskHandle> addTasks(int count, String taskBaseName,
                                  String groupTag, String payload) {
    ArrayList<TaskOptions> optionList = new ArrayList<>();
    for (int i = 0; i < count; i++) {
        TaskOptions options =
            withMethod(TaskOptions.Method.PULL)
                .taskName(taskBaseName + "_" + i)
                .tag(groupTag)
                .payload(payload);
        optionList.add(options);
    }
    taskTags.add(groupTag);
    List<TaskHandle> taskHandles = queue.add(optionList);
    sync(5000);  // Give tasks a chance to become available.

    return taskHandles;
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:25,代码来源:PullQueueTest.java


示例20: testTaskHandleContainsAllNecessaryProperties

import com.google.appengine.api.taskqueue.TaskHandle; //导入依赖的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());
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:17,代码来源:AsyncTasksTest.java



注:本文中的com.google.appengine.api.taskqueue.TaskHandle类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java StringObservable类代码示例发布时间:2022-05-22
下一篇:
Java SocketIOClient类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap