Exemplo n.º 1
0
 /** save the meta data */
 private void saveMetaDataOnceEveryDay() {
   HashMap<String, String> tempHashMap = new HashMap<String, String>();
   tempHashMap.putAll(allarchiveFieldsData);
   if (runTimeFieldsData != null && !runTimeFieldsData.isEmpty()) {
     // This should store fields like the description at least once every day.
     tempHashMap.putAll(runTimeFieldsData);
   }
   if (this.totalMetaInfo != null) {
     if (this.totalMetaInfo.getUnit() != null) {
       tempHashMap.put("EGU", this.totalMetaInfo.getUnit());
     }
     if (this.totalMetaInfo.getPrecision() != 0) {
       tempHashMap.put("PREC", Integer.toString(this.totalMetaInfo.getPrecision()));
     }
   }
   // dbrtimeevent.s
   dbrtimeevent.setFieldValues(tempHashMap, false);
   lastTimeStampWhenSavingarchiveFields = Calendar.getInstance();
 }
Exemplo n.º 2
0
 /**
  * update the meta field value in the parent pv.
  *
  * @param dbrtimeevent
  */
 private void updataMetaDataInParentPV(final DBRTimeEvent dbrtimeevent) {
   if (isarchiveFieldsField) {
     parentPVForMetaField.updataMetaFieldValue(
         this.name, "" + dbrtimeevent.getSampleValue().toString());
   }
 }
Exemplo n.º 3
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);
    }
  }