com.hazelcast.jet.Job.cancel()方法的使用及代码示例

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

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

Job.cancel介绍

[英]Makes a request to cancel this job and returns. The job will complete after its execution has stopped on all the nodes. If the job is already suspended, Jet will delete its runtime resources and snapshots and it won't be able to resume again.

NOTE: if the cluster becomes unstable (a member leaves or similar) while the job is in the process of cancellation, it may end up getting restarted after the cluster has stabilized and won't be cancelled. Call #getStatus() to find out and possibly try to cancel again.

The job status will be JobStatus#FAILED after cancellation, Job#join() will throw a CancellationException.

See #cancelAndExportSnapshot(String) to cancel with a terminal snapshot.
[中]请求取消此作业并返回。作业将在所有节点上停止执行后完成。如果作业已挂起,Jet将删除其运行时资源和快照,并且无法再次恢复。
注意:如果集群在作业取消过程中变得不稳定(成员离开或类似),则可能在集群稳定后重新启动,并且不会被取消。调用#getStatus()查找,并可能再次尝试取消。
作业状态将为JobStatus#取消后失败,作业#join()将抛出CancellationException。
请参阅#cancelAndExportSnapshot(字符串)以使用终端快照取消。

代码示例

代码示例来源:origin: hazelcast/hazelcast-jet-code-samples

private static void cancel(Job job) {
  job.cancel();
  while (job.getStatus() != JobStatus.COMPLETED) {
    uncheckRun(() -> SECONDS.sleep(1));
  }
}

代码示例来源:origin: hazelcast/hazelcast-code-samples

/**
 * <p>Run a Jet analysis job to examine the journal of updates to
 * HTTP sessions. As we don't want it to run for ever, give it a
 * second or two to do some work then end it.
 * </p>
 */
@ShellMethod(key = "ANALYSIS", value = "Analyse the orders")
public void analyseSessions() throws Exception {
  IMap<String, Integer> sequenceMap = this.hazelcastInstance.getMap(Constants.IMAP_NAME_SEQUENCE);
  sequenceMap.clear();
  Job analysisJob = this.jetInstance.newJob(SequenceAnalysis.build());
  analysisJob.getFuture();
  // Give the job time to do something
  int wait = 2;
  log.info("Sleep {} seconds", wait);
  TimeUnit.SECONDS.sleep(wait);
  if (analysisJob.getStatus() == JobStatus.RUNNING) {
    analysisJob.cancel();
  } else {
    log.error("Job status {}", analysisJob.getStatus());
  }
  System.out.printf("%d sequence%s found%n", sequenceMap.size(), (sequenceMap.size() == 1 ? "" : "s"));
}

代码示例来源:origin: hazelcast/hazelcast-jet-code-samples

private void run() throws Exception {
  JetConfig cfg = new JetConfig();
  cfg.setInstanceConfig(new InstanceConfig().setCooperativeThreadCount(
      Math.max(1, getRuntime().availableProcessors() / 2)));
  try {
    createKafkaCluster();
    fillTopics();
    JetInstance instance = Jet.newJetInstance(cfg);
    Jet.newJetInstance(cfg);
    IMapJet<String, Integer> sinkMap = instance.getMap(SINK_NAME);
    Pipeline p = buildPipeline();
    long start = System.nanoTime();
    Job job = instance.newJob(p);
    while (true) {
      int mapSize = sinkMap.size();
      System.out.format("Received %d entries in %d milliseconds.%n",
          mapSize, NANOSECONDS.toMillis(System.nanoTime() - start));
      if (mapSize == MESSAGE_COUNT_PER_TOPIC * 2) {
        job.cancel();
        break;
      }
      Thread.sleep(100);
    }
  } finally {
    Jet.shutdownAll();
    shutdownKafkaCluster();
  }
}

代码示例来源:origin: hazelcast/hazelcast-jet-code-samples

private void go() throws Exception {
    EventGenerator eventGenerator = new EventGenerator(jet.getMap(TRADES));
    eventGenerator.start();
    try {
      // comment out the code to try the appropriate enrichment method
      Pipeline p = enrichUsingIMap();
//            Pipeline p = enrichUsingReplicatedMap();
//            Pipeline p = enrichUsingHashJoin();
      Job job = jet.newJob(p);
      eventGenerator.generateEventsForFiveSeconds();
      job.cancel();
      Thread.sleep(2000);
    } finally {
      eventGenerator.shutdown();
      Jet.shutdownAll();
    }
  }

代码示例来源:origin: hazelcast/hazelcast-jet-code-samples

public static void main(String[] args) throws Exception {
    System.setProperty("hazelcast.logging.type", "log4j");
    // All IMap partitions must receive updates for the watermark to advance
    // correctly. Since we use just a handful of keys in this sample, we set a
    // low partition count.
    System.setProperty("hazelcast.partition.count", "1");

    JetConfig cfg = new JetConfig();
    cfg.getHazelcastConfig().getMapEventJournalConfig("*").setEnabled(true);
    JetInstance jet = Jet.newJetInstance(cfg);
    ProducerTask producer = new ProducerTask(jet);

    try {
      // uncomment one of these
//            Pipeline p = aggregate();
//            Pipeline p = groupAndAggregate();
      Pipeline p = coGroup();
//            Pipeline p = coGroupWithBuilder();

      System.out.println("Running pipeline " + p);
      Job job = jet.newJob(p);
      Thread.sleep(5000);
      producer.stop();
      job.cancel();
    } finally {
      producer.stop();
      Jet.shutdownAll();
    }
  }

代码示例来源:origin: hazelcast/hazelcast-jet-code-samples

job.cancel();

代码示例来源:origin: hazelcast/hazelcast-jet-code-samples

trackedJob1.cancel();

代码示例来源:origin: hazelcast/hazelcast-jet

@Command(
    description = "Cancels a running job"
)
public void cancel(
    @Parameters(index = "0",
        paramLabel = "<job name or id>",
        description = "Name of the job to terminate"
    ) String name
) throws IOException {
  runWithJet(jet -> {
    Job job = getJob(jet, name);
    assertJobActive(name, job);
    printf("Cancelling job %s...%n", formatJob(job));
    job.cancel();
    waitForJobStatus(job, JobStatus.FAILED);
    println("Job was successfully terminated.");
  });
}

代码示例来源:origin: hazelcast/hazelcast-jet-code-samples

job.cancel();

代码示例来源:origin: hazelcast/hazelcast-jet

@Test
public void test_cancelJob_jobNotActive() {
  // Given
  Job job = newJob();
  job.cancel();
  assertJobStatusEventually(job, JobStatus.FAILED);
  // When
  // Then
  exception.expectMessage("is not active");
  run("cancel", job.getName());
}

代码示例来源:origin: hazelcast/hazelcast-jet

@Test
public void test_suspendJob_jobNotRunning() {
  // Given
  Job job = newJob();
  job.cancel();
  assertJobStatusEventually(job, JobStatus.FAILED);
  // When
  // Then
  exception.expectMessage("is not running");
  run("suspend", job.getName());
}

代码示例来源:origin: hazelcast/hazelcast-jet

@Test
public void test_saveSnapshot_jobNotActive() {
  // Given
  Job job = newJob();
  assertJobStatusEventually(job, JobStatus.RUNNING);
  job.cancel();
  assertJobStatusEventually(job, JobStatus.FAILED);
  // When
  // Then
  exception.expectMessage("is not active");
  run("save-snapshot", job.getIdString(), "my-snapshot");
}

相关文章