Java Code Examples for io.grpc.Context#currentContextExecutor()

The following examples show how to use io.grpc.Context#currentContextExecutor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TriggerManager.java    From styx with Apache License 2.0 5 votes vote down vote up
TriggerManager(TriggerListener triggerListener,
               Time time,
               Storage storage,
               Stats stats) {
  this.triggerListener = requireNonNull(triggerListener);
  this.time = requireNonNull(time);
  this.storage = requireNonNull(storage);
  this.stats = requireNonNull(stats);
  final ForkJoinPool forkJoinPool = register(closer, new ForkJoinPool(TRIGGER_CONCURRENCY), "trigger-manager");
  this.executor = Context.currentContextExecutor(forkJoinPool);
}
 
Example 2
Source File: Scheduler.java    From styx with Apache License 2.0 5 votes vote down vote up
Scheduler(Time time, StateManager stateManager, Storage storage,
          WorkflowResourceDecorator resourceDecorator, Stats stats, RateLimiter dequeueRateLimiter,
          ShardedCounter shardedCounter, Executor executor, Logger log) {
  this.time = Objects.requireNonNull(time);
  this.stateManager = Objects.requireNonNull(stateManager);
  this.storage = Objects.requireNonNull(storage);
  this.resourceDecorator = Objects.requireNonNull(resourceDecorator);
  this.stats = Objects.requireNonNull(stats);
  this.dequeueRateLimiter = Objects.requireNonNull(dequeueRateLimiter, "dequeueRateLimiter");
  this.shardedCounter = Objects.requireNonNull(shardedCounter, "shardedCounter");
  this.executor = Context.currentContextExecutor(Objects.requireNonNull(executor, "executor"));
  this.log = Objects.requireNonNull(log, "log");
}
 
Example 3
Source File: MetadataService.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
public MetadataService(DispatchHandler dispatchHandler, Executor executor, ServerRequestFactory serverRequestFactory) {
    Objects.requireNonNull(dispatchHandler, "dispatchHandler");
    Objects.requireNonNull(executor, "executor");
    Objects.requireNonNull(serverRequestFactory, "serverRequestFactory");

    this.executor = Context.currentContextExecutor(executor);
    this.simpleRequestHandlerAdaptor = new SimpleRequestHandlerAdaptor<>(this.getClass().getName(), dispatchHandler, serverRequestFactory);
}
 
Example 4
Source File: StreamExecutorServerInterceptor.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
public StreamExecutorServerInterceptor(String name, final Executor executor, final int initNumMessages, final ScheduledExecutorService scheduledExecutorService,
                                       final int periodMillis, int recoveryMessagesCount) {
    this.name = Assert.requireNonNull(name, "name");

    Assert.requireNonNull(executor, "executor");
    // Context wrapper
    this.executor = Context.currentContextExecutor(executor);
    Assert.isTrue(initNumMessages > 0, "initNumMessages must be positive");
    this.initNumMessages = initNumMessages;
    Assert.requireNonNull(scheduledExecutorService, "scheduledExecutorService");
    Assert.isTrue(periodMillis > 0, "periodMillis must be positive");

    Assert.isTrue(recoveryMessagesCount > 0, "recoveryMessagesCount must be positive");
    this.scheduler = new StreamExecutorRejectedExecutionRequestScheduler(scheduledExecutorService, periodMillis, recoveryMessagesCount);
}
 
Example 5
Source File: AsyncContext.java    From flo with Apache License 2.0 4 votes vote down vote up
private AsyncContext(Executor executor) {
  this.executor = Context.currentContextExecutor(Objects.requireNonNull(executor));
}
 
Example 6
Source File: AgentService.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
public AgentService(DispatchHandler dispatchHandler, PingEventHandler pingEventHandler, Executor executor, ServerRequestFactory serverRequestFactory) {
    this.simpleRequestHandlerAdaptor = new SimpleRequestHandlerAdaptor<PResult>(this.getClass().getName(), dispatchHandler, serverRequestFactory);
    this.pingEventHandler = Objects.requireNonNull(pingEventHandler, "pingEventHandler");
    Objects.requireNonNull(executor, "executor");
    this.executor = Context.currentContextExecutor(executor);
}
 
Example 7
Source File: GrpcServerImpl.java    From bazel with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
GrpcServerImpl(
    CommandDispatcher dispatcher,
    Clock clock,
    int port,
    String requestCookie,
    String responseCookie,
    Path serverDirectory,
    int maxIdleSeconds,
    boolean shutdownOnLowSysMem,
    boolean doIdleServerTasks)
    throws AbruptExitException {
  Runtime.getRuntime().addShutdownHook(new Thread(() -> shutdownHook()));

  // server.pid was written in the C++ launcher after fork() but before exec().
  // The client only accesses the pid file after connecting to the socket
  // which ensures that it gets the correct pid value.
  pidFile = serverDirectory.getRelative("server.pid.txt");
  try {
    pidInFile = new String(FileSystemUtils.readContentAsLatin1(pidFile));
  } catch (IOException e) {
    throw createFilesystemFailureException(
        "Server pid file read failed: " + e.getMessage(),
        Code.SERVER_PID_TXT_FILE_READ_FAILURE,
        e);
  }
  deleteAtExit(pidFile);

  this.dispatcher = dispatcher;
  this.clock = clock;
  this.serverDirectory = serverDirectory;
  this.port = port;
  this.maxIdleSeconds = maxIdleSeconds;
  this.shutdownOnLowSysMem = shutdownOnLowSysMem;
  this.serving = false;

  this.commandExecutorPool =
      Context.currentContextExecutor(
          Executors.newCachedThreadPool(
              new ThreadFactoryBuilder()
                  .setNameFormat("grpc-command-%d")
                  .setDaemon(true)
                  .build()));

  this.requestCookie = requestCookie;
  this.responseCookie = responseCookie;

  pidFileWatcherThread = new PidFileWatcherThread();
  pidFileWatcherThread.start();
  commandManager = new CommandManager(doIdleServerTasks);
}