• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java WorkerExecutor类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中io.vertx.core.WorkerExecutor的典型用法代码示例。如果您正苦于以下问题:Java WorkerExecutor类的具体用法?Java WorkerExecutor怎么用?Java WorkerExecutor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



WorkerExecutor类属于io.vertx.core包,在下文中一共展示了WorkerExecutor类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testThreadPoolMetricsOnClose

import io.vertx.core.WorkerExecutor; //导入依赖的package包/类
@Test
public void testThreadPoolMetricsOnClose() throws Exception {
  WorkerExecutor exec = vertx.createSharedWorkerExecutor("the-executor", 10);
  assertTrue(metricsService.getMetricsSnapshot(exec).size() > 0);
  assertTrue(metricsService.getMetricsSnapshot("vertx.pools.worker.vert.x-worker-thread").size() > 0);
  assertTrue(metricsService.getMetricsSnapshot("vertx.pools.worker.vert.x-internal-blocking").size() > 0);
  exec.close();
  assertTrue(metricsService.getMetricsSnapshot(exec).size() == 0);
  assertTrue(metricsService.getMetricsSnapshot("vertx.pools.worker.vert.x-worker-thread").size() > 0);
  assertTrue(metricsService.getMetricsSnapshot("vertx.pools.worker.vert.x-internal-blocking").size() > 0);
  CountDownLatch latch = new CountDownLatch(1);
  vertx.close(ar -> latch.countDown());
  awaitLatch(latch);
  assertEquals(new JsonObject(), metricsService.getMetricsSnapshot("vertx.pools.worker.vert.x-worker-thread"));
  assertEquals(new JsonObject(), metricsService.getMetricsSnapshot("vertx.pools.worker.vert.x-internal-blocking"));
}
 
开发者ID:vert-x3,项目名称:vertx-dropwizard-metrics,代码行数:17,代码来源:MetricsTest.java


示例2: main

import io.vertx.core.WorkerExecutor; //导入依赖的package包/类
public static void main(String[] args) {
	Vertx vertx = Vertx.vertx();
	CountDownLatch completion = new CountDownLatch(2);
	
	WorkerExecutor sharedWorker = vertx.createSharedWorkerExecutor("my-shared-pool", 20);
	sharedWorker.executeBlocking(successfulBlockingTask(), responseHandler(completion));
	sharedWorker.executeBlocking(failedBlockingTask(), responseHandler(completion));
	vertx.close();
}
 
开发者ID:gauravrmazra,项目名称:gauravbytes,代码行数:10,代码来源:VertxWorkExecutorExample.java


示例3: testWithBlockingWithWorker

import io.vertx.core.WorkerExecutor; //导入依赖的package包/类
@Test
public void testWithBlockingWithWorker() throws Exception {
  AtomicBoolean calledSpy = new AtomicBoolean();
  AtomicBoolean startedSpy = new AtomicBoolean();
  vertx.createHttpServer().requestHandler(request -> {
    calledSpy.set(true);
    request.response().end("Alright");
  }).listen(8081, ar -> {
    startedSpy.set(ar.succeeded());
  });

  await().atMost(DEFAULT_TIMEOUT).untilAtomic(startedSpy, is(true));

  camel.addRoutes(new RouteBuilder() {
    @Override
    public void configure() throws Exception {
      from("direct:my-route")
        .process(exchange -> Thread.sleep(3000))
        .to("http://localhost:8081");
    }
  });

  WorkerExecutor pool = vertx.createSharedWorkerExecutor("some-fancy-name");

  bridge = CamelBridge.create(vertx, new CamelBridgeOptions(camel)
    .addOutboundMapping(fromVertx("camel-route").toCamel("direct:my-route").setBlocking(true)
      .setWorkerExecutor(pool)));

  camel.start();
  BridgeHelper.startBlocking(bridge);

  vertx.eventBus().send("camel-route", "hello");

  await().atMost(DEFAULT_TIMEOUT).untilAtomic(calledSpy, is(true));
}
 
开发者ID:vert-x3,项目名称:vertx-camel-bridge,代码行数:36,代码来源:OutboundEndpointTest.java


示例4: ContextScheduler

import io.vertx.core.WorkerExecutor; //导入依赖的package包/类
public ContextScheduler(WorkerExecutor workerExecutor, boolean ordered) {
  Objects.requireNonNull(workerExecutor, "workerExecutor is null");
  this.vertx = ((WorkerExecutorInternal) workerExecutor).vertx();
  this.context = null;
  this.workerExecutor = workerExecutor;
  this.blocking = true;
  this.ordered = ordered;
}
 
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:9,代码来源:ContextScheduler.java


示例5: createSharedWorkerExecutor

import io.vertx.core.WorkerExecutor; //导入依赖的package包/类
@Override
public WorkerExecutor createSharedWorkerExecutor(String name) {
    return vertx.createSharedWorkerExecutor(name);
}
 
开发者ID:pitchpoint-solutions,项目名称:sfs,代码行数:5,代码来源:SfsVertxImpl.java


示例6: testThreadPoolMetrics

import io.vertx.core.WorkerExecutor; //导入依赖的package包/类
@Test
public void testThreadPoolMetrics() throws Exception {

  int size = 5;
  CountDownLatch done = new CountDownLatch(6);

  WorkerExecutor exec = vertx.createSharedWorkerExecutor("the-executor", size);
  JsonObject metrics = metricsService.getMetricsSnapshot(exec);

  assertMetricType("counter", metrics.getJsonObject("queue-size"));
  assertMetricType("timer", metrics.getJsonObject("queue-delay"));
  assertMetricType("counter", metrics.getJsonObject("in-use"));
  assertMetricType("timer", metrics.getJsonObject("usage"));
  assertMetricType("gauge", metrics.getJsonObject("pool-ratio"));
  assertMetricType("gauge", metrics.getJsonObject("max-pool-size"));

  assertCount(metrics.getJsonObject("usage"), 0);
  assertCount(metrics.getJsonObject("queue-delay"), 0);
  assertCount(metrics.getJsonObject("queue-size"), 0);
  assertCount(metrics.getJsonObject("in-use"), 0);
  assertEquals(metrics.getJsonObject("pool-ratio").getDouble("value"), (Double)0D);
  assertEquals(metrics.getJsonObject("max-pool-size").getInteger("value"), (Integer)5);

  //
  CountDownLatch gate = new CountDownLatch(1);
  CountDownLatch latch = new CountDownLatch(5);
  for (int i = 0; i < size;i++) {
    exec.<Boolean>executeBlocking(fut -> {
      try {
        latch.countDown();
        fut.complete(gate.await(10, TimeUnit.SECONDS));
      } catch (InterruptedException e) {
        fut.fail(e);
      }
    }, false, ar -> {
      assertTrue(ar.succeeded());
      assertTrue(ar.result());
      vertx.runOnContext(v -> done.countDown());
    });
  }

  awaitLatch(latch);
  metrics = metricsService.getMetricsSnapshot(exec);
  assertCount(metrics.getJsonObject("usage"), 0);
  assertCount(metrics.getJsonObject("queue-delay"), 5);
  assertCount(metrics.getJsonObject("queue-size"), 0);
  assertCount(metrics.getJsonObject("in-use"), size);
  assertEquals(metrics.getJsonObject("pool-ratio").getDouble("value"), (Double)1D);

  exec.executeBlocking(Future::complete, false, ar -> vertx.runOnContext(v -> done.countDown()));
  metrics = metricsService.getMetricsSnapshot(exec);
  assertCount(metrics.getJsonObject("usage"), 0);
  assertCount(metrics.getJsonObject("queue-delay"), 5);
  assertCount(metrics.getJsonObject("queue-size"), 1);
  assertCount(metrics.getJsonObject("in-use"), size);
  assertEquals(metrics.getJsonObject("pool-ratio").getDouble("value"), (Double)1D);

  gate.countDown();
  awaitLatch(done);
  metrics = metricsService.getMetricsSnapshot(exec);
  assertCount(metrics.getJsonObject("usage"), 6);
  assertCount(metrics.getJsonObject("queue-delay"), 6);
  assertCount(metrics.getJsonObject("queue-size"), 0);
  assertCount(metrics.getJsonObject("in-use"), 0);
  assertEquals(metrics.getJsonObject("pool-ratio").getDouble("value"), (Double)0D);
}
 
开发者ID:vert-x3,项目名称:vertx-dropwizard-metrics,代码行数:67,代码来源:MetricsTest.java


示例7: FromVertxToCamelProducer

import io.vertx.core.WorkerExecutor; //导入依赖的package包/类
/**
 * Creates a new instance of producer.
 *
 * @param vertx    the vert.x instance
 * @param producer the underlying producer, must not be {@code null}
 * @param outbound the outbound configuration, must not be {@code null}
 * @param blocking whether or not the processing is blocking and so should not be run on the event
 *                 loop
 * @param pool     the pool on which the blocking code is going to be executed
 */
public FromVertxToCamelProducer(Vertx vertx, Producer producer, OutboundMapping outbound, boolean blocking,
                                WorkerExecutor  pool) {
  this.endpoint = producer.getEndpoint();
  this.producer = AsyncProcessorConverterHelper.convert(producer);
  this.outbound = outbound;
  this.blocking = blocking;
  this.vertx = vertx;
  this.pool = pool;
}
 
开发者ID:vert-x3,项目名称:vertx-camel-bridge,代码行数:20,代码来源:FromVertxToCamelProducer.java


示例8: getWorkerExecutor

import io.vertx.core.WorkerExecutor; //导入依赖的package包/类
/**
 * @return the worker thread worker to use to execute the processing. This option is only used if blocking is set to
 * {@code true}. If not set, it uses the the default worker worker.
 */
public WorkerExecutor getWorkerExecutor() {
  return worker;
}
 
开发者ID:vert-x3,项目名称:vertx-camel-bridge,代码行数:8,代码来源:OutboundMapping.java


示例9: setWorkerExecutor

import io.vertx.core.WorkerExecutor; //导入依赖的package包/类
/**
 * Sets the worker thread worker used to execute the blocking processing. This option is only used if blocking is set to
 * {@code true}. If not set, it uses the the default worker worker.
 *
 * @param pool the worker worker on which the code is executed
 * @return the current instance of {@link OutboundMapping}
 */
public OutboundMapping setWorkerExecutor(WorkerExecutor pool) {
  this.worker = pool;
  return this;
}
 
开发者ID:vert-x3,项目名称:vertx-camel-bridge,代码行数:12,代码来源:OutboundMapping.java


示例10: blockingScheduler

import io.vertx.core.WorkerExecutor; //导入依赖的package包/类
/**
 * Create a scheduler for a {@link io.vertx.core.WorkerExecutor} object, actions are executed on the threads of this executor.
 *
 * @param executor the worker executor object
 * @return the scheduler
 */
public static Scheduler blockingScheduler(WorkerExecutor executor) {
  return new ContextScheduler(executor, false);
}
 
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:10,代码来源:RxHelper.java



注:本文中的io.vertx.core.WorkerExecutor类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java NodeSettingsWO类代码示例发布时间:2022-05-22
下一篇:
Java QName类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap