예제 #1
0
 /** Unsubscribe from value updates. */
 private void unsubscribe() {
   Monitor sub_copy;
   // Atomic access
   synchronized (this) {
     sub_copy = subscription;
     subscription = null;
   }
   if (sub_copy == null) {
     return;
   }
   try {
     sub_copy.clear();
   } catch (IllegalStateException ile) {
     logger.warn("Illegal state exception when unsubscribing pv " + name, ile);
   } catch (final Exception ex) {
     logger.error("exception when unsubscribing pv " + name, ex);
   }
 }
예제 #2
0
  /** @param channelName */
  public void execute(String channelName) {

    try {

      // initialize context
      initialize();

      // Create the Channel to connect to the PV.
      Channel channel = context.createChannel(channelName);

      // Send the request and wait 5.0 seconds for the channel to connect to the PV.
      context.pendIO(5.0);

      // If we're here, then everything went fine.
      // Display basic information about the channel.
      channel.printInfo();

      /** ***************************************************************** */
      /** *************************** sync get **************************** */
      /** ***************************************************************** */
      System.out.println("\n------------------------------------------------\n");
      System.out.println("Sync get:");

      // get request w/o callbacks will wait until flush/pendIO is called
      // (channel default 'type' and 'count' is used)
      DBR dbr = channel.get();
      context.pendIO(3.0);
      dbr.printInfo();

      System.out.println();

      dbr = channel.get(DBRType.STRING, 1);
      context.pendIO(3.0);
      String[] value = ((STRING) dbr).getStringValue();
      System.out.println("Read string value: " + value[0]);

      /** ***************************************************************** */
      /** ************************** async get **************************** */
      /** ***************************************************************** */
      System.out.println("\n------------------------------------------------\n");
      System.out.println("Async get:");

      // get request w/ callbacks are always issued immediately
      // not related to pendIO at all, but require pend_event (to be flushed also)
      GetListenerImpl listener = new GetListenerImpl();
      channel.get(listener);
      synchronized (listener) {
        // flush & get event back
        context.flushIO();
        // wait for response...
        listener.wait(3000);
      }

      if (listener.getStatus() == CAStatus.NORMAL) listener.getValue().printInfo();
      else System.err.println("Get error: " + listener.getStatus());

      /** ***************************************************************** */
      /** *************************** Monitors **************************** */
      /** ***************************************************************** */
      System.out.println("\n------------------------------------------------\n");
      System.out.println("Monitors:");
      System.out.println();

      // Create a monitor
      Monitor monitor = channel.addMonitor(Monitor.VALUE, new MonitorListenerImpl());
      context.flushIO();

      // Sleep for 10 seconds (monitors will be printed out).
      Thread.sleep(10000);

      // Clear the monitor
      monitor.clear();

      System.out.println("\n------------------------------------------------");

      /** ***************************************************************** */
      /** ***************************************************************** */
      /** ***************************************************************** */

      // Disconnect the channel.
      channel.destroy();

      // Flush all pending requests...
      context.flushIO();

      System.out.println("Done.");

    } catch (Throwable th) {
      th.printStackTrace();
    } finally {
      // always finalize
      destroy();
    }
  }