org.apache.ignite.Ignite.compute()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(250)

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

Ignite.compute介绍

[英]Gets compute facade over all cluster nodes started in server mode.
[中]获取在服务器模式下启动的所有群集节点上的计算外观。

代码示例

代码示例来源:origin: apache/ignite

/**
 * Roulette Wheel selection 
 *
 * @param map Map of keys/fitness scores
 * @return List of primary Keys for respective chromosomes that will breed
 */
private List<Long> selectByRouletteWheel(LinkedHashMap map) {
  List<Long> populationKeys = this.ignite.compute().execute(new RouletteWheelSelectionTask(this.cfg), map);
  
  return populationKeys;
}

代码示例来源:origin: apache/ignite

/**
 * @param prj Projection.
 * @return {@link org.apache.ignite.IgniteCompute} for given projection.
 */
protected IgniteCompute compute(ClusterGroup prj) {
  return prj.ignite().compute(prj);
}

代码示例来源:origin: apache/ignite

/**
 * @param ignite Grid.
 * @param taskName Task name.
 * @return {@code True} if task is not deployed.
 */
private boolean checkUndeployed(Ignite ignite, String taskName) {
  return ignite.compute().localTasks().get(taskName) == null;
}

代码示例来源:origin: apache/ignite

/**
   * @throws Exception If test failed.
   */
  @Test
  public void testMany() throws Exception {
    ignite1.compute().execute(GridCacheLoadPopulationTask.class, null);
  }
}

代码示例来源:origin: apache/ignite

@Override public void test(Factory factory, Ignite ignite) throws Exception {
    Collection<Object> results = new ArrayList<>(MAX_JOB_COUNT);
    for (int i = 0; i < MAX_JOB_COUNT; ++i) {
      // value(i - 1): use negative argument of the value method to generate nullong value.
      results.add(ignite.compute().apply((IgniteClosure<Object, Object>)factory.create(), value(i - 1)));
    }
    checkResultsClassCount(MAX_JOB_COUNT - 1, results, value(0).getClass());
    assertCollectionsEquals("Results value mismatch", createGoldenResults(), results);
  }
});

代码示例来源:origin: apache/ignite

/**
 * Called to remove object from cache without regard to transaction.
 *
 * @param ignite Grid.
 * @param cache Cache.
 * @param key Key.
 */
public static void evict(Ignite ignite, HibernateCacheProxy cache, Object key) {
  key = cache.keyTransformer().transform(key);
  ignite.compute(ignite.cluster()).call(new ClearKeyCallable(key, cache.name()));
}

代码示例来源:origin: apache/ignite

@Override public void test(Factory factory, Ignite ignite) throws Exception {
    Collection<EchoCallable> jobs = new ArrayList<>(MAX_JOB_COUNT);
    for (int i = 0; i < MAX_JOB_COUNT; ++i) {
      EchoCallable job = (EchoCallable)factory.create();
      job.setArg(value(i - 1));
      jobs.add(job);
    }
    Collection<Object> results = ignite.compute().call(jobs);
    checkResultsClassCount(MAX_JOB_COUNT - 1, results, value(0).getClass());
    assertCollectionsEquals("Results value mismatch", createGoldenResults(), results);
  }
});

代码示例来源:origin: apache/ignite

@Override public void test(Factory factory, Ignite ignite) throws Exception {
    Collection<Object> results = new ArrayList<>(MAX_JOB_COUNT);
    for (int i = 0; i < MAX_JOB_COUNT; ++i) {
      EchoCallable job = (EchoCallable)factory.create();
      job.setArg(value(i - 1));
      results.add(ignite.compute().call(job));
    }
    checkResultsClassCount(MAX_JOB_COUNT - 1, results, value(0).getClass());
    assertCollectionsEquals("Results value mismatch", createGoldenResults(), results);
  }
});

代码示例来源:origin: apache/ignite

/**
 * @param num Number.
 */
private void checkTask(int num) {
  Ignite ignite = G.ignite(getTestIgniteInstanceName());
  ComputeTaskFuture<?> fut = ignite.compute().executeAsync(GridTaskSessionTestTask.class.getName(), num);
  Object res = fut.get();
  assert (Integer)res == SPLIT_COUNT : "Invalid result [num=" + num + ", fut=" + fut + ']';
}

代码示例来源:origin: apache/ignite

@Override public void test(Factory factory, Ignite ignite) throws Exception {
    Collection<EchoCallable> jobs = new ArrayList<>(MAX_JOB_COUNT);
    for (int i = 0; i < MAX_JOB_COUNT; ++i) {
      EchoCallable job = (EchoCallable)factory.create();
      job.setArg(value(i - 1));
      jobs.add(job);
    }
    IgniteFuture<Collection<Object>> fut = ignite.compute().callAsync(jobs);
    checkResultsClassCount(MAX_JOB_COUNT - 1, fut.get(), value(0).getClass());
    assertCollectionsEquals("Results value mismatch", createGoldenResults(), fut.get());
  }
});

代码示例来源:origin: apache/ignite

/**
 * @throws Exception If failed.
 */
@Test
public void testTaskMap() throws Exception {
  Ignite ignite = G.ignite(getTestIgniteInstanceName());
  info("Executing sync mapped task.");
  ignite.compute().execute(SyncMappedTask.class, null);
  info("Executing async mapped task.");
  ignite.compute().execute(AsyncMappedTask.class, null);
}

代码示例来源:origin: apache/ignite

@Override public void test(Factory factory, Ignite ignite) throws Exception {
    ignite.getOrCreateCache("test0");
    ignite.getOrCreateCache("test1");
    final IgniteCompute comp = ignite.compute();
    for (int i = 0; i < MAX_JOB_COUNT; ++i) {
      IgniteRunnable job = (IgniteRunnable)factory.create();
      IgniteFuture<Void> fut = comp.affinityRunAsync(Arrays.asList("test0", "test1"), 0, job);
      fut.get();
    }
  }
});

代码示例来源:origin: apache/ignite

/**
 * @param ignite Grid.
 * @param taskName Task name.
 * @return {@code true} if task has been deployed on passed grid.
 */
private boolean checkDeployed(Ignite ignite, String taskName) {
  Map<String, Class<? extends ComputeTask<?, ?>>> locTasks = ignite.compute().localTasks();
  if (log().isInfoEnabled())
    log().info("Local tasks found: " + locTasks);
  return locTasks.get(taskName) != null;
}

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
@Override protected void beforeTestsStarted() throws Exception {
  ignite = G.ignite(getTestIgniteInstanceName());
  long tstamp = startTimestamp();
  ignite.compute().localDeployTask(GridAllEventsTestTask.class, GridAllEventsTestTask.class.getClassLoader());
  List<Event> evts = pullEvents(tstamp, 1);
  assertEvent(evts.get(0).type(), EVT_TASK_DEPLOYED, evts);
}

代码示例来源:origin: apache/ignite

/** */
private void checkExecuteException(IgniteException resE) throws Exception {
  try (Ignite ignite = startGrid()) {
    IgniteCompute compute = ignite.compute();
    try {
      compute.execute(new ResultExceptionTask(resE), null);
    } catch (IgniteException e) {
      assertSame(resE, e);
    }
  }
}

代码示例来源:origin: apache/ignite

/**
 * @throws Exception if failed.
 */
@Test
public void testSetAttribute() throws Exception {
  Ignite ignite = G.ignite(getTestIgniteInstanceName());
  ignite.compute().localDeployTask(GridTaskSessionTestTask.class, GridTaskSessionTestTask.class.getClassLoader());
  refreshInitialData();
  for (int i = 0; i < EXEC_COUNT; i++)
    checkTask(i);
}

代码示例来源:origin: apache/ignite

@Override public void test(Factory factory, Ignite ignite) throws Exception {
    ignite.getOrCreateCache("test0");
    ignite.getOrCreateCache("test1");
    final IgniteCompute comp = ignite.compute();
    for (int i = 0; i < MAX_JOB_COUNT; ++i) {
      IgniteRunnable job = (IgniteRunnable)factory.create();
      IgniteFuture<Void> fut = comp.affinityRunAsync(Arrays.asList("test0", "test1"), key(0), job);
      fut.get();
    }
  }
});

代码示例来源:origin: apache/ignite

/**
 * Starts computation job.
 *
 * @param idx Grid index on which computation job should start.
 * @param restartIdx The index of the node to be restarted.
 * @param workersCntr The current number of computation threads.
 */
private void startComputation(int idx, AtomicInteger restartIdx, AtomicInteger workersCntr) {
  Ignite ignite = grid(idx);
  ClusterGroup cg = ignite.cluster().forLocal();
  ignite.compute(cg).callAsync(new BinaryObjectAdder(startLatch, idx, updatesQueue, restartIdx, workersCntr));
}

代码示例来源:origin: apache/ignite

/**
 * @throws Exception If failed.
 */
@Test
public void testNoCacheResultMethodUsage() throws Exception {
  Ignite ignite = G.ignite(getTestIgniteInstanceName());
  ignite.compute().withNoResultCache()
      .execute(GridResultNoCacheResultMethodTestTask.class, "Grid Result No Cache Method Test Argument");
}

代码示例来源:origin: apache/ignite

@Override public void run() {
    doSleep(1000);
    //spi1.failSend = false;
    cnt.getAndAdd(c1.compute(c1.cluster().forNodeId(c2.cluster().localNode().id())).call(new TestClosure()));
  }
}, 1, "hang-thread");

相关文章