org.rapidoid.job.Jobs类的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(5.0k)|赞(0)|评价(0)|浏览(107)

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

Jobs介绍

暂无

代码示例

代码示例来源:origin: rapidoid/rapidoid

public static <T> void call(Callback<T> callback, T result, Throwable error) {
  Jobs.execute(new CallbackExecutorJob<>(callback, result, error));
}

代码示例来源:origin: rapidoid/rapidoid

@Override
public void onError(Throwable error) {
  Jobs.call(bodyCallback, null, error);
}

代码示例来源:origin: rapidoid/rapidoid

public ScheduledFuture<Void> days(Runnable action) {
  return Jobs.after(delay, TimeUnit.DAYS).run(action);
}

代码示例来源:origin: rapidoid/rapidoid

public static <T> ScheduledFuture<?> scheduleWithFixedDelay(Callable<T> job, long initialDelay, long delay,
                              TimeUnit unit, Callback<T> callback) {
  return scheduleWithFixedDelay(callbackJob(job, callback), initialDelay, delay, unit);
}

代码示例来源:origin: rapidoid/rapidoid

public static <T> ScheduledFuture<?> scheduleAtFixedRate(Callable<T> job, long initialDelay, long period,
                             TimeUnit unit, Callback<T> callback) {
  return scheduleAtFixedRate(callbackJob(job, callback), initialDelay, period, unit);
}

代码示例来源:origin: rapidoid/rapidoid

public static <T> void execute(Callable<T> job, Callback<T> callback) {
  execute(callbackJob(job, callback));
}

代码示例来源:origin: rapidoid/rapidoid

public static void haltSoon() {
    new Thread(() -> {
      U.sleep(1000);
      Jobs.shutdownNow();
      Setups.haltAll();
      System.exit(0);
    }).start();
  }
}

代码示例来源:origin: rapidoid/rapidoid

public static <T> ScheduledFuture<?> schedule(Callable<T> job, long delay, TimeUnit unit, Callback<T> callback) {
  return schedule(callbackJob(job, callback), delay, unit);
}

代码示例来源:origin: rapidoid/rapidoid

@SuppressWarnings("unchecked")
public ScheduledFuture<Void> run(Runnable action) {
  if (after >= 0) {
    return (ScheduledFuture<Void>) Jobs.schedule(action, after, timeUnit);
  } else if (every >= 0) {
    return (ScheduledFuture<Void>) Jobs.scheduleAtFixedRate(action, 0, every, timeUnit);
  } else {
    throw Err.notExpected();
  }
}

代码示例来源:origin: rapidoid/rapidoid

public static void bootstrap() {
    if (!once.go()) return;

    Log.info("Bootstraping metrics");

    os = ManagementFactory.getOperatingSystemMXBean();
    sysCpuM = Cls.findMethod(os.getClass(), "getSystemCpuLoad");
    procCpuM = Cls.findMethod(os.getClass(), "getProcessCpuLoad");
    openFileDescriptorCount = Cls.findMethod(os.getClass(), "getOpenFileDescriptorCount");

    threads = ManagementFactory.getThreadMXBean();

    register("cpu/system", SYSTEM_CPU);
    register("cpu/process", PROCESS_CPU);

    register("mem/used", MEM_USED);
    register("mem/total", MEM_TOTAL);

    register("threads", NUM_THREADS);
    register("descriptors", NUM_FILE_DESC);

    // FIXME there are too many metrics
//        JMXMetrics.bootstrap();

    Metrics updateMetrics = new Metrics();
    updateMetrics.run();
    Jobs.scheduleAtFixedRate(updateMetrics, 1, 1, TimeUnit.SECONDS);
  }

代码示例来源:origin: org.rapidoid/rapidoid-ctx

public static <T> void execute(Callable<T> job, Callback<T> callback) {
  execute(callbackJob(job, callback));
}

代码示例来源:origin: rapidoid/rapidoid

private static void init() {
  if (Ctxs.getPersisterProvider() == null) {
    Ctxs.setPersisterProvider(new CustomizableSetupAwarePersisterProvider());
  }
  JSON.warmUp();
  Runtime.getRuntime().addShutdownHook(new Thread(() -> {
    shutdownAll();
    Jobs.shutdownNow();
  }));
}

代码示例来源:origin: org.rapidoid/rapidoid-ctx

public static <T> ScheduledFuture<?> scheduleWithFixedDelay(Callable<T> job, long initialDelay, long delay,
    TimeUnit unit, Callback<T> callback) {
  return scheduleWithFixedDelay(callbackJob(job, callback), initialDelay, delay, unit);
}

代码示例来源:origin: org.rapidoid/rapidoid-ctx

public static <T> ScheduledFuture<?> scheduleAtFixedRate(Callable<T> job, long initialDelay, long period,
    TimeUnit unit, Callback<T> callback) {
  return scheduleAtFixedRate(callbackJob(job, callback), initialDelay, period, unit);
}

代码示例来源:origin: org.rapidoid/rapidoid-ctx

public static <T> ScheduledFuture<?> schedule(Callable<T> job, long delay, TimeUnit unit, Callback<T> callback) {
  return schedule(callbackJob(job, callback), delay, unit);
}

代码示例来源:origin: rapidoid/rapidoid

Jobs.execute(new Runnable() {
  @Override
  public void run() {

代码示例来源:origin: rapidoid/rapidoid

public ScheduledFuture<Void> microseconds(Runnable action) {
  return Jobs.after(delay, TimeUnit.MICROSECONDS).run(action);
}

代码示例来源:origin: rapidoid/rapidoid

private static <T> Runnable callbackJob(final Callable<T> job, final Callback<T> callback) {
  return () -> {
    T result;
    try {
      result = job.call();
    } catch (Throwable e) {
      call(callback, null, e);
      return;
    }
    call(callback, result, null);
  };
}

代码示例来源:origin: org.rapidoid/rapidoid-http-server

public void run() {
    shutdownAll();
    Jobs.shutdownNow();
  }
});

代码示例来源:origin: rapidoid/rapidoid

HttpStatus errorAndDone(final Req req, final Throwable error, final LogLevel logLevel) {
  req.revert();
  req.async();
  Runnable errorHandler = () -> {
    error(req, error, logLevel);
    // the Req object will do the rendering
    req.done();
  };
  Ctx ctx = Ctxs.get();
  if (ctx == null) {
    With.exchange(req).run(errorHandler);
  } else {
    Jobs.execute(errorHandler);
  }
  return HttpStatus.ASYNC;
}

相关文章