Tabnine Logo
Engine.run
Code IndexAdd Tabnine to your IDE (free)

How to use
run
method
in
com.linkedin.parseq.Engine

Best Java code snippets using com.linkedin.parseq.Engine.run (Showing top 20 results out of 315)

origin: linkedin/parseq

/**
 * Runs the given task. Task passed in as a parameter becomes a root on a new Plan.
 * All tasks created and started as a consequence of a root task will belong to that plan and will share a Trace.
 * <p>
 * This method throws {@code IllegalStateException} if Engine does not have capacity to run the task.
 * Engine's capacity is specified by a {@value #MAX_CONCURRENT_PLANS} configuration property. Use
 * {@link EngineBuilder#setEngineProperty(String, Object)} to set this property.
 * For the sake of backwards compatibility default value for a {@value #MAX_CONCURRENT_PLANS} is
 * {@value #DEFUALT_MAX_CONCURRENT_PLANS} which essentially means "unbounded capacity".
 *
 * @param task the task to run
 * @throws IllegalStateException
 */
public void run(final Task<?> task) {
 run(task, defaultPlanClass(task));
}
origin: linkedin/parseq

@Override
protected void doRunExample(final Engine engine) throws Exception {
 final int[] toSort = createRandomArray(10, new Random());
 final Task<int[]> mergeSort = mergeSort(toSort, new Range(0, toSort.length));
 engine.run(mergeSort);
 mergeSort.await();
 System.out.println("Before sort: " + Arrays.toString(toSort));
 System.out.println("After  sort: " + Arrays.toString(mergeSort.get()));
 Arrays.sort(toSort);
 System.out.println("Java   sort: " + Arrays.toString(toSort));
 ExampleUtil.printTracingResults(mergeSort);
}
origin: linkedin/parseq

 /** Task collections */

 //---------------------------------------------------------------

 @Override
 protected void doRunExample(final Engine engine) throws Exception {
  Task<?> task = createExtendedSummary(1);
//    Task<?> task = Task.par(createExtendedSummary(1), createExtendedSummary(2));

  engine.run(task);

  runTaskAndPrintResults(engine, task);
 }

origin: linkedin/parseq

@Override
public void runTask(Engine engine, Task<?> t) throws InterruptedException {
 initArrivalProcess();
 if (lastNano == 0) {
  lastNano = System.nanoTime();
 }
 long nextNano = lastNano + arrivalProcess.nanosToNextEvent();
 long actualNano = waitUntil(nextNano);
 planExecutionAccuracy.recordValue(Math.abs(actualNano - nextNano));
 engine.run(t);
 lastNano = nextNano;
}
origin: linkedin/parseq

@Override
protected void doRunExample(final Engine engine) throws Exception
{
 final int[] toSort = createRandomArray(10, new Random());
 final Task<int[]> mergeSort = new MergeSortPlan(toSort);
 engine.run(mergeSort);
 mergeSort.await();
 System.out.println("Before sort: " + Arrays.toString(toSort));
 System.out.println("After sort:  " + Arrays.toString(mergeSort.get()));
 ExampleUtil.printTracingResults(mergeSort);
}
origin: linkedin/parseq

private void runTaskAndPrintResults(final Engine engine, Task<?> task) throws InterruptedException {
 engine.run(task);
 task.await();
 System.out.println(task.get());
 ExampleUtil.printTracingResults(task);
}
origin: linkedin/parseq

@Override
protected void doRunExample(final Engine engine) throws Exception {
 final Task<?> nonBatchable = plan(this::nonBatchableTask);
 engine.run(nonBatchable);
 nonBatchable.await();
 System.out.println("not batched:");
 ExampleUtil.printTracingResults(nonBatchable);
 System.out.println("batched:");
 final Task<?> batchable = plan(this::batchableTask);
 engine.run(batchable);
 batchable.await();
 ExampleUtil.printTracingResults(batchable);
}
origin: linkedin/parseq

@Override
protected void doRunExample(final Engine engine) throws Exception {
 final Task<?> nonBatchable = plan(this::nonBatchableTask);
 engine.run(nonBatchable);
 nonBatchable.await();
 System.out.println("not batched:");
 ExampleUtil.printTracingResults(nonBatchable);
 System.out.println("batched:");
 final Task<?> batchable = plan(this::batchableTask);
 engine.run(batchable);
 batchable.await();
 ExampleUtil.printTracingResults(batchable);
}
origin: linkedin/parseq

 @Override
 protected void doRunExample(final Engine engine) throws Exception {
  final MockService<String> httpClient = getService();

  final Task<Integer> fetchAndLength =
    fetch404Url(httpClient, "http://www.google.com")
     .map("length", x -> x.length());

  engine.run(fetchAndLength);

  fetchAndLength.await();

  System.out.println("Error while fetching url: " + fetchAndLength.getError());

  ExampleUtil.printTracingResults(fetchAndLength);
 }
}
origin: linkedin/parseq

 @Override
 protected void doRunExample(final Engine engine) throws Exception {
  final MockService<String> httpClient = getService();

  final Task<Integer> fetchAndLength =
    fetch404Url(httpClient, "http://www.google.com")
     .recover("default", t -> "")
     .map("length", s -> s.length());

  engine.run(fetchAndLength);

  fetchAndLength.await();

  System.out.println("Response length: " + fetchAndLength.get());

  ExampleUtil.printTracingResults(fetchAndLength);
 }
}
origin: linkedin/parseq

 @Override
 protected void doRunExample(final Engine engine) throws Exception {
  final MockService<String> httpClient = getService();

  final Task<Integer> fetchAndLength =
    fetchUrl(httpClient, "http://www.google.com", 100)
     .withTimeout(50, TimeUnit.MILLISECONDS)
     .recover("default", t -> "")
     .map("length", s -> s.length());

  engine.run(fetchAndLength);

  fetchAndLength.await();

  System.out.println("Response length: " + fetchAndLength.get());

  ExampleUtil.printTracingResults(fetchAndLength);
 }
}
origin: linkedin/parseq

 @Override
 public void run() {
  engine.run(task);
  try {
   assertTrue(task.await(5, TimeUnit.SECONDS));
  } catch (InterruptedException e) {
   // Ignore.
  }
 }
});
origin: linkedin/parseq

 @Override
 protected void doRunExample(final Engine engine) throws Exception {
  final MockService<String> httpClient = getService();
  final Task<String> fetchBing = fetchUrl(httpClient, "http://www.bing.com");
  final Task<String> fetchYahoo = fetchUrl(httpClient, "http://www.yahoo.com");
  final Task<String> fetchGoogle = fetchUrl(httpClient, "http://www.google.com");

  final Task<?> parFetch = Task.par(fetchBing, fetchGoogle, fetchYahoo);
  engine.run(parFetch);

  parFetch.await();

  System.out.println("Bing   => " + fetchBing.get());
  System.out.println("Yahoo  => " + fetchYahoo.get());
  System.out.println("Google => " + fetchGoogle.get());

  ExampleUtil.printTracingResults(parFetch);
 }
}
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 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

 @Override
 protected void doRunExample(final Engine engine) throws Exception {
  final MockService<String> httpClient = getService();

  final Task<String> fetchWithTimeout =
    fetchUrl(httpClient, "http://www.google.com")
     .withTimeout(50, TimeUnit.MILLISECONDS);

  engine.run(fetchWithTimeout);

  fetchWithTimeout.await();

  System.out.println(!fetchWithTimeout.isFailed() ? "Received result: " + fetchWithTimeout.get()
    : "Error: " + fetchWithTimeout.getError());

  ExampleUtil.printTracingResults(fetchWithTimeout);
 }
}
origin: linkedin/parseq

 @Override
 protected void doRunExample(final Engine engine) throws Exception
 {
  final MockService<String> httpClient = getService();

  final Task<String> fetch = fetchUrl(httpClient, "http://www.google.com");
  final Task<String> fetchWithTimeout =
    timeoutWithError(50, TimeUnit.MILLISECONDS, fetch);

  engine.run(fetchWithTimeout);

  fetchWithTimeout.await();

  System.out.println(!fetchWithTimeout.isFailed()
              ? "Received result: " + fetchWithTimeout.get()
              : "Error: " + fetchWithTimeout.getError());

  ExampleUtil.printTracingResults(fetchWithTimeout);
 }
}
origin: linkedin/parseq

@Test
public void testShutdownThenRunTask() throws InterruptedException {
 _engine.shutdown();
 final Task<String> task = Task.value("task executed");
 _engine.run(task);
 // Task should be cancelled immediately
 assertTrue(task.await(50, TimeUnit.MILLISECONDS));
 assertTrue(task.isFailed());
}
origin: linkedin/parseq

@Test
public void testTimeoutTaskWithError() throws InterruptedException {
 final Exception error = new Exception();
 final Task<String> task = Task.callable("task", () -> {
  throw error;
 } );
 final Task<String> timeoutTask = task.withTimeout(2000, TimeUnit.MILLISECONDS);
 getEngine().run(timeoutTask);
 // We should complete with an error almost immediately
 assertTrue(timeoutTask.await(100, TimeUnit.MILLISECONDS));
 assertTrue(timeoutTask.isFailed());
 assertEquals(error, timeoutTask.getError());
}
origin: linkedin/parseq

@Override
protected void doRunExample(final Engine engine) throws Exception {
 final MockService<String> httpClient = getService();
 Task<String> stage1 = Task.par(fetchAndMap("http://www.bing.com", httpClient),
                 fetchAndMap("http://www.yahoo.com", httpClient))
                .map((a, b) -> a + b);
 Task<String> stage2 = Task.par(fetchAndMap("http://www.google.com", httpClient),
                 fetchAndMap("https://duckduckgo.com", httpClient))
                .map((a, b) -> a + b);
 Task<String> plan = stage1.flatMap("combine", s1 -> stage2.map(s2 -> s1 + s2));
 engine.run(plan);
 plan.await();
 printTracingResults(plan);
}
com.linkedin.parseqEnginerun

Javadoc

Runs the given task. Task passed in as a parameter becomes a root on a new Plan. All tasks created and started as a consequence of a root task will belong to that plan and will share a Trace.

This method throws IllegalStateException if Engine does not have capacity to run the task. Engine's capacity is specified by a #MAX_CONCURRENT_PLANS configuration property. Use EngineBuilder#setEngineProperty(String,Object) to set this property. For the sake of backwards compatibility default value for a #MAX_CONCURRENT_PLANS is #DEFUALT_MAX_CONCURRENT_PLANS which essentially means "unbounded capacity".

Popular methods of Engine

  • shutdown
    If the engine is currently running, this method will initiate an orderly shutdown. No new tasks will
  • blockingRun
    Runs the given task. Task passed in as a parameter becomes a root on a new Plan. All tasks created a
  • tryRun
    Runs the given task if Engine has a capacity to start new plan as specified by #MAX_CONCURRENT_PLANS
  • <init>
  • acquirePermit
  • createTaskQueueFactory
  • defaultPlanClass
  • getProperty
  • runWithPermit
    Runs the given task with its own context. Use Tasks.seq and Tasks.par to create and run composite ta
  • tryAcquirePermit
  • tryTransitionShutdown
  • tryTransitionTerminate
  • tryTransitionShutdown,
  • tryTransitionTerminate,
  • awaitTermination,
  • isShutdown,
  • isTerminated

Popular in Java

  • Reactive rest calls using spring rest template
  • startActivity (Activity)
  • putExtra (Intent)
  • setRequestProperty (URLConnection)
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • Runnable (java.lang)
    Represents a command that can be executed. Often used to run code in a different Thread.
  • TimeZone (java.util)
    TimeZone represents a time zone offset, and also figures out daylight savings. Typically, you get a
  • Annotation (javassist.bytecode.annotation)
    The annotation structure.An instance of this class is returned bygetAnnotations() in AnnotationsAttr
  • ImageIO (javax.imageio)
  • LogFactory (org.apache.commons.logging)
    Factory for creating Log instances, with discovery and configuration features similar to that employ
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now