com.linkedin.parseq.Task.action()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(168)

本文整理了Java中com.linkedin.parseq.Task.action()方法的一些代码示例,展示了Task.action()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Task.action()方法的具体详情如下:
包路径:com.linkedin.parseq.Task
类名称:Task
方法名:action

Task.action介绍

[英]Equivalent to action("action", action).
[中]相当于动作(“动作”,动作)。

代码示例

代码示例来源:origin: linkedin/parseq

private Task<?> addResponse(final Promise<Integer> response) {
  return Task.action("addResponse", new Action() {
   @Override
   public void run() {
    _responses.add(response.get());
   }
  });
 }
}

代码示例来源:origin: linkedin/parseq

private Task<?> networkClassifyTask(final Task<Network> network) {
 return Task.action("NetworkClassifier", new Action() {
  @Override
  public void run() {
   doClassify(new NetworkClassifier(network.get()));
  }
 });
}

代码示例来源:origin: linkedin/parseq

private Task<?> truthMapClassifyTask(final String name, final Classification classification,
  final Promise<Map<Long, Boolean>> result) {
 return Task.action(name + "Classifier", new Action() {
  @Override
  public void run() {
   doClassify(new TruthMapClassifier(classification, result.get()));
  }
 });
}

代码示例来源:origin: linkedin/parseq

private Task<?> connectedClassifyTask(final Task<Network> network) {
 return Task.action("ConnectedClassifier", new Action() {
  @Override
  public void run() {
   doClassify(new ConnectedClassifier(network.get()));
  }
 });
}

代码示例来源:origin: linkedin/parseq

private Task<?> checkDone() {
 return Task.action("checkDone", new Action() {
  @Override
  public void run() {
   final int index = Math.min(WAIT_TIMES.length - 1, _responses.size());
   if (WAIT_TIMES[index] + _startMillis <= System.currentTimeMillis()) {
    _result.done(_responses);
   }
  }
 });
}

代码示例来源:origin: linkedin/parseq

private Task<?> classifyTask(final Classifier classifier) {
 return Task.action(classifier.getClass().getSimpleName(), new Action() {
  @Override
  public void run() {
   doClassify(classifier);
  }
 });
}

代码示例来源:origin: linkedin/parseq

/**
 * Creates a new {@link Task} that have a value of type Void. Because the
 * returned task has no value, it is typically used to produce side-effects.
 *
 * @deprecated  As of 2.0.0, replaced by {@link Task#action(String, com.linkedin.parseq.function.Action) Task.action}
 * @param name a name that describes the action
 * @param runnable the action that will be executed when the task is run
 * @return the new task
 * @see Task#action(String, com.linkedin.parseq.function.Action) Task.action
 */
@Deprecated
public static Task<Void> action(final String name, final Runnable runnable) {
 return Task.action(name, runnable::run);
}

代码示例来源:origin: linkedin/parseq

/**
 * Equivalent to {@code action("action", action)}.
 * @see #action(String, Action)
 */
public static Task<Void> action(final Action action) {
 return action("action: " + _taskDescriptor.getDescription(action.getClass().getName()), action);
}

代码示例来源:origin: linkedin/parseq

public static Task<?> noop() {
 return Task.action("noop", () -> {
 } );
}

代码示例来源:origin: linkedin/parseq

private static <T> Task<?> enqueueTask(final Queue<T> queue, final T value) {
  return Task.action("enqueue", () -> queue.add(value));
 }
}

代码示例来源:origin: linkedin/parseq

@Test
public void testAction() {
 final AtomicReference<String> variable = new AtomicReference<String>();
 Task<Void> task = Task.action(() -> variable.set("value"));
 runAndWait("TestTaskFactoryMethods.testAction", task);
 assertEquals(variable.get(), "value");
 assertEquals(countTasks(task.getTrace()), 1);
}

代码示例来源:origin: linkedin/parseq

@Test
public void testRunWithinCapacity() throws InterruptedException {
 final AtomicInteger counter = new AtomicInteger(0);
 Task<?>[] tasks = new Task<?>[10];
 for (int i = 0; i < 10; i++) {
  tasks[i] = Task.action(counter::incrementAndGet);
 }
 for (int i = 0; i < 10; i++) {
  _engine.run(tasks[i]);
 }
 assertTrue(awaitAll(tasks));
 assertEquals(10, counter.get());
}

代码示例来源:origin: linkedin/parseq

@Test
public void testRunWithinCapacity() throws InterruptedException {
 final AtomicInteger counter = new AtomicInteger(0);
 Task<?>[] tasks = new Task<?>[10];
 for (int i = 0; i < 10; i++) {
  tasks[i] = Task.action(counter::incrementAndGet);
 }
 for (int i = 0; i < 10; i++) {
  _engine.run(tasks[i], (i % 2 == 0) ? "evenPlan" : "oddPlan");
 }
 assertTrue(awaitAll(tasks));
 assertEquals(10, counter.get());
}

代码示例来源:origin: linkedin/parseq

@Test
public void testBlockingRunWithinCapacity() throws InterruptedException {
 final AtomicInteger counter = new AtomicInteger(0);
 Task<?>[] tasks = new Task<?>[10];
 for (int i = 0; i < 10; i++) {
  tasks[i] = Task.action(counter::incrementAndGet);
 }
 for (int i = 0; i < 10; i++) {
  _engine.blockingRun(tasks[i], (i % 2 == 0) ? "evenPlan" : "oddPlan");
 }
 assertTrue(awaitAll(tasks));
 assertEquals(10, counter.get());
}

代码示例来源:origin: linkedin/parseq

@Test
public void testBlockingRunWithinCapacity() throws InterruptedException {
 final AtomicInteger counter = new AtomicInteger(0);
 Task<?>[] tasks = new Task<?>[10];
 for (int i = 0; i < 10; i++) {
  tasks[i] = Task.action(counter::incrementAndGet);
 }
 for (int i = 0; i < 10; i++) {
  _engine.blockingRun(tasks[i]);
 }
 assertTrue(awaitAll(tasks));
 assertEquals(10, counter.get());
}

代码示例来源:origin: linkedin/parseq

@Test
public void testTimeBoundedTryRunWithinCapacity() throws InterruptedException {
 final AtomicInteger counter = new AtomicInteger(0);
 Task<?>[] tasks = new Task<?>[10];
 for (int i = 0; i < 10; i++) {
  tasks[i] = Task.action(counter::incrementAndGet);
 }
 for (int i = 0; i < 10; i++) {
  assertTrue(_engine.tryRun(tasks[i], 10, TimeUnit.MILLISECONDS));
 }
 assertTrue(awaitAll(tasks));
 assertEquals(10, counter.get());
}

代码示例来源:origin: linkedin/parseq

@Test
public void testTryRunWithinCapacity() throws InterruptedException {
 final AtomicInteger counter = new AtomicInteger(0);
 Task<?>[] tasks = new Task<?>[10];
 for (int i = 0; i < 10; i++) {
  tasks[i] = Task.action(counter::incrementAndGet);
 }
 for (int i = 0; i < 10; i++) {
  assertTrue(_engine.tryRun(tasks[i]));
 }
 assertTrue(awaitAll(tasks));
 assertEquals(10, counter.get());
}

代码示例来源:origin: linkedin/parseq

@Test
public void testTryRunWithinCapacity() throws InterruptedException {
 final AtomicInteger counter = new AtomicInteger(0);
 Task<?>[] tasks = new Task<?>[10];
 for (int i = 0; i < 10; i++) {
  tasks[i] = Task.action(counter::incrementAndGet);
 }
 for (int i = 0; i < 10; i++) {
  assertTrue(_engine.tryRun(tasks[i], (i % 2 == 0) ? "evenPlan" : "oddPlan"));
 }
 assertTrue(awaitAll(tasks));
 assertEquals(10, counter.get());
}

代码示例来源:origin: linkedin/parseq

@Test
public void testTimeBoundedTryRunWithinCapacity() throws InterruptedException {
 final AtomicInteger counter = new AtomicInteger(0);
 Task<?>[] tasks = new Task<?>[10];
 for (int i = 0; i < 10; i++) {
  tasks[i] = Task.action(counter::incrementAndGet);
 }
 for (int i = 0; i < 10; i++) {
  assertTrue(_engine.tryRun(tasks[i], (i % 2 == 0) ? "evenPlan" : "oddPlan",
    10, TimeUnit.MILLISECONDS));
 }
 assertTrue(awaitAll(tasks));
 assertEquals(10, counter.get());
}

代码示例来源:origin: linkedin/parseq

@Override
 public Promise<Queue<Integer>> run(final Context context) throws Exception {
  final SettablePromise<Queue<Integer>> promise = Promises.settable();
  final Queue<Integer> queue = new LinkedList<Integer>();
  final Task<?> t1 = enqueueTask(queue, 1);
  t1.setPriority(-5);
  final Task<?> t2 = enqueueTask(queue, 2);
  t2.setPriority(10);
  final Task<?> t3 = enqueueTask(queue, 3);
  t3.setPriority(0);
  context.run(t1, t2, t3);
  context.after(t1, t2, t3).run(Task.action("done", () -> promise.done(queue)));
  return promise;
 }
};

相关文章