예제 #1
0
 @Override
 public long estimateMemoryConsumption(
     String pvName, PVTypeInfo typeInfo, Timestamp start, Timestamp end, HttpServletRequest req) {
   float storageRate = typeInfo.getComputedStorageRate();
   long numSeconds = TimeUtils.convertToEpochSeconds(end) - TimeUtils.convertToEpochSeconds(start);
   // Add a fudge factor of 3; we generate one event for each event
   long estimatedMemoryConsumption = (long) (storageRate * numSeconds * 2);
   return estimatedMemoryConsumption;
 }
  @Override
  public void execute(HttpServletRequest req, HttpServletResponse resp, ConfigService configService)
      throws IOException {
    String pvName = req.getParameter("pv");
    if (pvName == null || pvName.equals("")) {
      resp.sendError(HttpServletResponse.SC_BAD_REQUEST);
      return;
    }

    Event event = configService.getETLLookup().getLatestEventFromDataStores(pvName);
    if (event != null) {
      resp.setContentType(MimeTypeConstants.APPLICATION_JSON);
      HashMap<String, String> result = new HashMap<String, String>();
      result.put("timestamp", TimeUtils.convertToISO8601String(event.getEventTimeStamp()));
      try (PrintWriter out = resp.getWriter()) {
        out.println(JSONValue.toJSONString(result));
      }
    } else {
      resp.sendError(HttpServletResponse.SC_NOT_FOUND);
      return;
    }
  }
예제 #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);
    }
  }
  private void consumeEventStreamAndOutputToMimeResponse(EventStream strm) throws Exception {
    try {
      int eventsInCurrentStream = 0;
      for (Event e : strm) {
        try {
          eventsInCurrentStream++;

          if (!haveIpushedTheFirstEvent && firstEvent == null) {
            logger.debug(
                "Making a copy of the first event "
                    + TimeUtils.convertToHumanReadableString(e.getEventTimeStamp()));
            firstEvent = e.makeClone();
            continue;
          }

          if (!haveIpushedTheFirstEvent) {
            if (e.getEventTimeStamp().before(this.startTimeStamp)) {
              logger.debug(
                  "Making a copy of another event "
                      + TimeUtils.convertToHumanReadableString(e.getEventTimeStamp()));
              firstEvent = e.makeClone();
              continue;
            } else {
              haveIpushedTheFirstEvent = true;
              logger.debug(
                  "Consuming first and current events "
                      + TimeUtils.convertToHumanReadableString(e.getEventTimeStamp()));
              mimeresponse.consumeEvent(firstEvent);
              timestampOfLastEvent = firstEvent.getEventTimeStamp();
              totalEvents++;
              if (!e.getEventTimeStamp().after(timestampOfLastEvent)) {
                logger.debug(
                    "After sending first event, current event is not after the first event. Skipping "
                        + TimeUtils.convertToHumanReadableString(e.getEventTimeStamp()));
                skippedEvents++;
                continue;
              } else {
                mimeresponse.consumeEvent(e);
                totalEvents++;
                timestampOfLastEvent = e.getEventTimeStamp();
                continue;
              }
            }
          }

          if (amIDeduping) {
            comparedEvents++;
            if (!e.getEventTimeStamp().after(timestampOfLastEvent)) {
              skippedEvents++;
              continue;
            } else {
              amIDeduping = false;
              mimeresponse.consumeEvent(e);
              timestampOfLastEvent = e.getEventTimeStamp();
              totalEvents++;
            }
          } else {
            mimeresponse.consumeEvent(e);
            timestampOfLastEvent = e.getEventTimeStamp();
            totalEvents++;
          }
        } catch (InvalidProtocolBufferException | PBParseException ex) {
          logger.warn(ex.getMessage(), ex);
          if (this.mimeresponse instanceof ExceptionCommunicator) {
            ((ExceptionCommunicator) this.mimeresponse).comminucateException(ex);
          }
          skippedEvents++;
        }
      }

      if (eventsInCurrentStream == 0) {
        logger.info(
            "The stream from "
                + ((strm.getDescription() != null) ? strm.getDescription().getSource() : "Unknown")
                + " was an empty stream.");
      }

      // We start deduping at the boundaries of event streams.
      // This does not apply until we have pushed the first event out..
      if (haveIpushedTheFirstEvent) startDeduping();
    } catch (InvalidProtocolBufferException | PBParseException ex) {
      logger.warn(ex.getMessage(), ex);
      if (this.mimeresponse instanceof ExceptionCommunicator) {
        ((ExceptionCommunicator) this.mimeresponse).comminucateException(ex);
      }
      skippedEvents++;
    }
  }