Example #1
0
 /**
  * Destroy (shutdown) the server.
  *
  * @throws PVAException exception thrown in case of an unexpected error.
  */
 public void destroy() throws PVAException {
   if (threadPoll == null) serverContext.destroy();
   else {
     // notify to shutdown and do not accept any new requests
     threadPoll.shutdown();
     serverContext.destroy();
     threadPoll.shutdownNow();
   }
 }
Example #2
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);
    }
  }
  /* (non-Javadoc)
   * @see org.epics.pvaccess.server.plugins.BeaconServerStatusProvider#getServerStatusData()
   */
  public PVField getServerStatusData() {

    status
        .getIntField("connections")
        .put(context.getTransportRegistry().numberOfActiveTransports());
    status.getLongField("allocatedMemory").put(Runtime.getRuntime().totalMemory());
    status.getLongField("freeMemory").put(Runtime.getRuntime().freeMemory());

    ThreadMXBean threadMBean = ManagementFactory.getThreadMXBean();
    status.getIntField("threads").put(threadMBean.getThreadCount());

    final long[] deadlocks =
        threadMBean.isSynchronizerUsageSupported()
            ? threadMBean.findDeadlockedThreads()
            : threadMBean.findMonitorDeadlockedThreads();
    status.getIntField("deadlocks").put((deadlocks != null) ? deadlocks.length : 0);

    OperatingSystemMXBean osMBean = ManagementFactory.getOperatingSystemMXBean();
    status.getDoubleField("averageSystemLoad").put(osMBean.getSystemLoadAverage());

    return status;
  }
Example #4
0
 /**
  * Run the server for a given amount of time.
  *
  * @param seconds time (in seconds) to run the server, if <code>0</code> server is run until
  *     destroyed.
  * @throws PVAException exception thrown in case of an unexpected error.
  */
 public void run(int seconds) throws PVAException {
   serverContext.run(seconds);
 }
Example #5
0
 /** Display basic information about the context. */
 public void printInfo() {
   System.out.println(serverContext.getVersion().getVersionString());
   serverContext.printInfo();
 }