Beispiel #1
0
  /**
   * Creates a RPC server with a thread-pool used to process requests.
   *
   * @param threads number of threads in a thread-pool.
   * @param queueSize thread-pool request queue size.
   */
  public RPCServer(int threads, int queueSize) {
    if (threads < 0) throw new IllegalArgumentException("threads < 0");

    if (threads > 0 && queueSize < 1) throw new IllegalArgumentException("queueSize < 1");

    if (threads > 0) {
      threadPoll =
          new ThreadPoolExecutor(
              threads, threads, 0, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(queueSize));
      threadPoll.prestartAllCoreThreads();
    } else threadPoll = null; // sync processing

    channelProviderImpl = new RPCChannelProvider(threadPoll);

    serverContext = new ServerContextImpl();
    serverContext.setBeaconServerStatusProvider(new DefaultBeaconServerDataProvider(serverContext));

    try {
      serverContext.initialize(channelProviderImpl);
    } catch (Throwable th) {
      throw new RuntimeException("Failed to initialize pvAccess RPC server.", th);
    }
  }