reactor.core.scheduler.Schedulers.decorateExecutorService()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(5.2k)|赞(0)|评价(0)|浏览(147)

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

Schedulers.decorateExecutorService介绍

[英]This method is aimed at Scheduler implementors, enabling custom implementations that are backed by a ScheduledExecutorService to also have said executors decorated (ie. for instrumentation purposes).

It applies the decorators added via #addExecutorServiceDecorator(String,BiFunction), so it shouldn't be added as a decorator. Note also that decorators are not guaranteed to be idempotent, so this method should be called only once per executor.
[中]此方法针对调度器实现者,使由ScheduledExecutorService支持的自定义实现也能修饰所述执行者(即,用于检测目的)。
它应用通过#addExecutorServiceDecorator(字符串、双函数)添加的装饰器,因此不应将其作为装饰器添加。还要注意的是,装饰器并不能保证是幂等的,所以每个执行器只能调用一次这个方法。

代码示例

代码示例来源:origin: reactor/reactor-core

DelegateServiceScheduler(ExecutorService executorService) {
    ScheduledExecutorService exec = convert(executorService);
    this.executor = Schedulers.decorateExecutorService(this, exec);
}

代码示例来源:origin: reactor/reactor-core

CachedService(@Nullable ElasticScheduler parent) {
  this.parent = parent;
  if (parent != null) {
    this.exec = Schedulers.decorateExecutorService(parent, parent.get());
  }
  else {
    this.exec = Executors.newSingleThreadScheduledExecutor();
    this.exec.shutdownNow();
  }
}

代码示例来源:origin: reactor/reactor-core

@Override
public void start() {
  //TODO SingleTimedScheduler didn't implement start, check if any particular reason?
  ScheduledExecutorService b = null;
  for (; ; ) {
    ScheduledExecutorService a = executor;
    if (a != TERMINATED) {
      if (b != null) {
        b.shutdownNow();
      }
      return;
    }
    if (b == null) {
      b = Schedulers.decorateExecutorService(this, this.get());
    }
    if (EXECUTORS.compareAndSet(this, a, b)) {
      return;
    }
  }
}

代码示例来源:origin: reactor/reactor-core

@Override
public void start() {
  ScheduledExecutorService[] b = null;
  for (;;) {
    ScheduledExecutorService[] a = executors;
    if (a != SHUTDOWN) {
      if (b != null) {
        for (ScheduledExecutorService exec : b) {
          exec.shutdownNow();
        }
      }
      return;
    }
    if (b == null) {
      b = new ScheduledExecutorService[n];
      for (int i = 0; i < n; i++) {
        b[i] = Schedulers.decorateExecutorService(this, this.get());
      }
    }
    
    if (EXECUTORS.compareAndSet(this, a, b)) {
      return;
    }
  }
}

代码示例来源:origin: reactor/reactor-core

void init(int n) {
  ScheduledExecutorService[] a = new ScheduledExecutorService[n];
  for (int i = 0; i < n; i++) {
    a[i] = Schedulers.decorateExecutorService(this, this.get());
  }
  EXECUTORS.lazySet(this, a);
}

代码示例来源:origin: reactor/reactor-core

private void init() {
  EXECUTORS.lazySet(this, Schedulers.decorateExecutorService(this, this.get()));
}

代码示例来源:origin: reactor/reactor-core

@Test
public void decorateTwiceWithSameSchedulerInstance() {
  Scheduler instance = Schedulers.newElastic("TWICE", 1);
  ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
  Schedulers.decorateExecutorService(instance, service);
  Schedulers.decorateExecutorService(instance, service);
  assertThat(simpleMeterRegistry.getMeters()
                 .stream()
                 .map(m -> m.getId().getTag("name"))
                 .distinct())
      .containsOnly(
          "elastic(\"TWICE\")-0",
          "elastic(\"TWICE\")-1"
      );
}

代码示例来源:origin: reactor/reactor-core

@Test
public void schedulersInstrumentation() {
  try {
    assertThatCode(() -> {
      Schedulers.enableMetrics();
      Scheduler s = Schedulers.newSingle("foo");
      Schedulers.decorateExecutorService(s,
          Executors.newSingleThreadScheduledExecutor());
      s.schedule(() -> System.out.println("schedulers instrumentation no micrometer"));
    })
        .doesNotThrowAnyException();
  }
  finally {
    Schedulers.disableMetrics();
  }
}

代码示例来源:origin: io.projectreactor/reactor-core

DelegateServiceScheduler(ExecutorService executorService) {
    ScheduledExecutorService exec = convert(executorService);
    this.executor = Schedulers.decorateExecutorService(this, exec);
}

代码示例来源:origin: io.projectreactor/reactor-core

CachedService(@Nullable ElasticScheduler parent) {
  this.parent = parent;
  if (parent != null) {
    this.exec = Schedulers.decorateExecutorService(parent, parent.get());
  }
  else {
    this.exec = Executors.newSingleThreadScheduledExecutor();
    this.exec.shutdownNow();
  }
}

代码示例来源:origin: io.projectreactor/reactor-core

@Override
public void start() {
  //TODO SingleTimedScheduler didn't implement start, check if any particular reason?
  ScheduledExecutorService b = null;
  for (; ; ) {
    ScheduledExecutorService a = executor;
    if (a != TERMINATED) {
      if (b != null) {
        b.shutdownNow();
      }
      return;
    }
    if (b == null) {
      b = Schedulers.decorateExecutorService(this, this.get());
    }
    if (EXECUTORS.compareAndSet(this, a, b)) {
      return;
    }
  }
}

代码示例来源:origin: io.projectreactor/reactor-core

@Override
public void start() {
  ScheduledExecutorService[] b = null;
  for (;;) {
    ScheduledExecutorService[] a = executors;
    if (a != SHUTDOWN) {
      if (b != null) {
        for (ScheduledExecutorService exec : b) {
          exec.shutdownNow();
        }
      }
      return;
    }
    if (b == null) {
      b = new ScheduledExecutorService[n];
      for (int i = 0; i < n; i++) {
        b[i] = Schedulers.decorateExecutorService(this, this.get());
      }
    }
    
    if (EXECUTORS.compareAndSet(this, a, b)) {
      return;
    }
  }
}

代码示例来源:origin: io.projectreactor/reactor-core

void init(int n) {
  ScheduledExecutorService[] a = new ScheduledExecutorService[n];
  for (int i = 0; i < n; i++) {
    a[i] = Schedulers.decorateExecutorService(this, this.get());
  }
  EXECUTORS.lazySet(this, a);
}

代码示例来源:origin: io.projectreactor/reactor-core

private void init() {
  EXECUTORS.lazySet(this, Schedulers.decorateExecutorService(this, this.get()));
}

相关文章