Ejemplo n.º 1
0
  /**
   * Combine the metadata from various sources and return the latest copy.
   *
   * @return
   */
  @Override
  public HashMap<String, String> getLatestMetadata() {
    HashMap<String, String> retVal = new HashMap<String, String>();
    // The totalMetaInfo is updated once every 24hours...
    MetaInfo metaInfo = this.getTotalMetaInfo();
    if (metaInfo != null) {
      metaInfo.addToDict(retVal);
    }
    // Add the latest value of the fields we are monitoring.
    if (allarchiveFieldsData != null) {
      retVal.putAll(allarchiveFieldsData);
    }
    if (runTimeFieldsData != null) {
      retVal.putAll(runTimeFieldsData);
    }

    return retVal;
  }
Ejemplo n.º 2
0
 /** PV is connected. Get meta info, or subscribe right away. */
 private void handleConnected(final Channel channel) {
   try {
     if (channel.getConnectionState() != Channel.CONNECTED) {
       return;
     }
   } catch (Exception ex) {
     logger.warn("Exception handling connection state change for " + this.name, ex);
     return;
   }
   if (state == PVConnectionState.Connected) return;
   state = PVConnectionState.Connected;
   hostName = channel_ref.getChannel().getHostName();
   totalMetaInfo.setHostName(hostName);
   for (final PVListener listener : listeners) {
     listener.pvConnected(this);
   }
   // If we're "running", we need to get the meta data and
   // then subscribe.
   // Otherwise, we're done.
   if (!running) {
     connected = true;
     // meta = null;
     synchronized (this) {
       this.notifyAll();
     }
     return;
   }
   // else: running, get meta data, then subscribe
   try {
     DBRType type = channel.getFieldType();
     if (!(plain || type.isSTRING())) {
       state = PVConnectionState.GettingMetadata;
       if (type.isDOUBLE() || type.isFLOAT()) type = DBRType.CTRL_DOUBLE;
       else if (type.isENUM()) type = DBRType.LABELS_ENUM;
       else if (type.isINT()) type = DBRType.CTRL_INT;
       else type = DBRType.CTRL_SHORT;
       channel.get(type, 1, meta_get_listener);
       return;
     }
   } catch (final Exception ex) {
     logger.error("exception when handleConnect " + name, ex);
     return;
   }
   // Meta info is not requested, not available for this type,
   // or there was an error in the get call.
   // So reset it, then just move on to the subscription.
   // meta = null;
   subscribe();
 }
Ejemplo n.º 3
0
 /** Subscribe for value updates. */
 private void subscribe() {
   synchronized (this) {
     // Prevent multiple subscriptions.
     if (subscription != null) {
       return;
     }
     // Late callback, channel already closed?
     final RefCountedChannel ch_ref = channel_ref;
     if (ch_ref == null) {
       return;
     }
     final Channel channel = ch_ref.getChannel();
     // final Logger logger = Activator.getLogger();
     try {
       if (channel.getConnectionState() != Channel.CONNECTED) {
         return;
       }
       //
       // the RefCountedChannel should maintain a single
       // subscription to the underlying CAJ/JCA channel.
       // So even with N PVs for the same channel, it's
       // only one subscription on the network instead of
       // N subscriptions.
       final DBRType type = DBR_Helper.getTimeType(plain, channel.getFieldType());
       state = PVConnectionState.Subscribing;
       totalMetaInfo.setStartTime(System.currentTimeMillis());
       // isnotTimestampDBR
       if (this.name.endsWith(".RTYP")) {
         subscription = channel.addMonitor(MonitorMask.ARCHIVE.getMask(), this);
       } else {
         subscription =
             channel.addMonitor(
                 type, channel.getElementCount(), MonitorMask.ARCHIVE.getMask(), this);
       }
     } catch (final Exception ex) {
       logger.error("exception when subscribing pv " + name, ex);
     }
   }
 }
Ejemplo n.º 4
0
 @Override
 public void getCompleted(final GetEvent event) { // This runs in a CA
   // thread
   if (event.getStatus().isSuccessful()) {
     state = PVConnectionState.GotMetaData;
     final DBR dbr = event.getDBR();
     totalMetaInfo.applyBasicInfo(
         EPICS_V3_PV.this.name, dbr, EPICS_V3_PV.this.configservice);
   } else {
     logger.error("The meta get listener was not successful for EPICS_V3_PV " + name);
   }
   PVContext.scheduleCommand(
       EPICS_V3_PV.this.name,
       EPICS_V3_PV.this.jcaCommandThreadId,
       EPICS_V3_PV.this.channel_ref,
       "getCompleted",
       new Runnable() {
         @Override
         public void run() {
           subscribe();
         }
       });
 }
Ejemplo n.º 5
0
  /** MonitorListener interface. */
  @Override
  public void monitorChanged(final MonitorEvent ev) {
    // final Logger log = Activator.getLogger();
    // This runs in a CA thread.
    // Ignore values that arrive after stop()
    if (!running) {
      return;
    }
    if (subscription == null) {
      return;
    }
    if (ev.getStatus() == null || !ev.getStatus().isSuccessful()) {
      return;
    }
    if (controlledPVList != null) {
      // this pv is control pv.
      try {
        updateAllControlPVEnablMent(ev);
      } catch (Exception e) {
        logger.error(
            "exception in monitor changed function when updatinng controlled pvs' enablement for "
                + this.name,
            e);
      }
      return;
    }
    state = PVConnectionState.GotMonitor;
    if (!connected) connected = true;
    try {
      try {
        DBR dbr = ev.getDBR();
        if (dbr == null) {
          return;
        }
        if (this.name.endsWith(".RTYP")) {
          String rtypName = (((DBR_String) dbr).getStringValue())[0];
          dbrtimeevent =
              new POJOEvent(
                  ArchDBRTypes.DBR_SCALAR_STRING,
                  TimeUtils.now(),
                  new ScalarStringSampleValue(rtypName),
                  0,
                  0);
          return;
        }
        // dbr.printInfo();

        ArchDBRTypes generatedDBRType = JCA2ArchDBRType.valueOf(dbr);
        if (archDBRType == null) {
          archDBRType = generatedDBRType;
          con = configservice.getArchiverTypeSystem().getJCADBRConstructor(archDBRType);
        } else {
          assert (con != null);
          if (generatedDBRType != archDBRType) {
            logger.warn(
                "The type of PV "
                    + this.name
                    + " has changed from "
                    + archDBRType
                    + " to "
                    + generatedDBRType);
            fireDroppedSample(PVListener.DroppedReason.TYPE_CHANGE);
            return;
          }
        }
        dbrtimeevent = con.newInstance(dbr);
        totalMetaInfo.computeRate(dbrtimeevent);
        dbr = null;
      } catch (Exception e) {
        logger.error(
            "exception in monitor changed function when converting DBR to dbrtimeevent for pv "
                + this.name,
            e);
      }

      updataMetaDataInParentPV(dbrtimeevent);
      // if this pv has meta data , handle here
      if (hasMetaField) {
        // //////////handle the field value when it
        // changes//////////////
        if (changedarchiveFieldsData.size() > 0) {
          logger.debug(
              "Adding changed field for pv " + name + " with " + changedarchiveFieldsData.size());
          HashMap<String, String> tempHashMap = new HashMap<String, String>();
          tempHashMap.putAll(changedarchiveFieldsData);
          // dbrtimeevent.s
          dbrtimeevent.setFieldValues(tempHashMap, true);
          changedarchiveFieldsData.clear();
        }
        // //////////////////////////
        // ////////////save all the fields once every day//////////////
        if (this.lastTimeStampWhenSavingarchiveFields == null) {
          if (allarchiveFieldsData.size() != 0) {
            saveMetaDataOnceEveryDay();
          }
        } else {
          Calendar currentCalendar = Calendar.getInstance();
          currentCalendar.add(Calendar.DAY_OF_MONTH, -1);
          if (currentCalendar.after(lastTimeStampWhenSavingarchiveFields)) {
            // Calendar currentCalendar2=Calendar.getInstance();
            saveMetaDataOnceEveryDay();
          }
        }
        // //////////////////////////////
      }
      fireValueUpdate();
    } catch (final Exception ex) {
      logger.error("exception in monitor changed for pv " + this.name, ex);
    }
  }