Example #1
0
  @Override
  public void preProcessEvent(Map<String, Object> map) {
    // remove entries with null values
    Iterator<String> iter = map.keySet().iterator();
    while (iter.hasNext()) {
      if (map.get(iter.next()) == null) {
        iter.remove();
      }
    }

    // rename attributes that are esper reserved words
    EsperNamingUtils.checkWordsAreLegalEsperNamesInMapKeys(map);
  }
Example #2
0
  // use this method if you only have the input event
  private String registerEventOrDefinition(
      Event event, Map<String, Object> attributes, EventDefinition inputDef) {

    boolean gotInputDef = (inputDef != null);

    String escapedEventType;
    SortedMap<String, Class> map;

    if (gotInputDef) {
      map = inputDef.getProperties();
      escapedEventType = EsperNamingUtils.checkWordIsLegalEsperName(inputDef.getEventType());
    } else if (event == null || attributes == null) {
      log.warn("Got null input event or attributes in registerEventOrDefinition");
      return null;
    } else {
      // create map from attributes, throw out nulls
      map = new TreeMap<String, Class>();
      for (String name : attributes.keySet()) {
        Object attr = attributes.get(name);
        if (attr == null) continue;
        Class propertyClass = attr.getClass();
        map.put(name, propertyClass);
      }
      escapedEventType = EsperNamingUtils.checkWordIsLegalEsperName(event.getEventType());
    }

    // prepare event signature
    String eventSignature = getInputEventSignature(map);

    // see if we've seen this event before at all
    if (!inputEvents.containsKey(escapedEventType)) {

      log.info("registering new event definition: %s", escapedEventType);
      addInputEventSignature(escapedEventType, eventSignature);

      // first see if we have a pre-existing outputEvent, and if so, we need to merge properties
      // in case our new upper level event is narrower than previously registered base event
      // TODO: this is just a guard for the case where we have prevOutputDef one level down
      // TODO: (it won't help in case for multi-level distance, need to replace this with plugin
      // specific handling,
      // TODO:  to possibly find an ancestor prev def to use)
      EventDefinition prevOutputDef = this.getOutputEventDefinition(escapedEventType);
      EventDefinition newDef = null;
      if (prevOutputDef != null) {
        String msg =
            String.format(
                "detected differences with previously registered outputEvent: %s",
                escapedEventType);
        if (logPropertyDifferences(msg, prevOutputDef.getProperties(), map)) {

          if (gotInputDef) {
            // make a copy of def props
            map = new TreeMap<String, Class>();
            map.putAll(inputDef.getProperties());
            updateMapWithPrevOutputProperties(map, prevOutputDef.getProperties());
            newDef =
                new EventDefinition(
                    inputDef.getSourceEventClass(), escapedEventType, inputDef.getEvtClass(), map);
          } else {
            updateMapWithPrevOutputProperties(map, prevOutputDef.getProperties());
            newDef = new EventDefinition(event, escapedEventType, event.getClass(), map);
          }

          String updatedEventSignature = getInputEventSignature(map);
          addInputEventSignature(escapedEventType, updatedEventSignature);
        }
      }

      if (newDef == null) {
        if (!gotInputDef)
          newDef = new EventDefinition(event, escapedEventType, event.getClass(), map);
        else newDef = inputDef;
      }

      inputEvents.put(escapedEventType, newDef);
      registerEventStream(newDef);
    } else if (eventSignature != null
        && !checkInputEventSignatureRegistered(escapedEventType, eventSignature)) {
      log.info("got new signature for event type: %s", escapedEventType);

      // see if we have a new variant signature for a previously registered event
      if (gotInputDef) {
        // make a copy of def props
        map = new TreeMap<String, Class>();
        map.putAll(inputDef.getProperties());
      }

      String combinedEventSignature = null;
      EventDefinition prevDef = inputEvents.get(escapedEventType);
      String msg = String.format("detected updated event definition: %s", escapedEventType);

      if (logPropertyDifferences(msg, prevDef.getProperties(), map)) {
        map.putAll(prevDef.getProperties());
        combinedEventSignature = getInputEventSignature(map);
      } else {
        combinedEventSignature = eventSignature;
      }

      if (!checkInputEventSignatureRegistered(escapedEventType, combinedEventSignature)) {

        log.info("updating event definition registration: %s", escapedEventType);

        addInputEventSignature(escapedEventType, combinedEventSignature);

        EventDefinition combinedDef;
        if (gotInputDef) {
          combinedDef =
              new EventDefinition(
                  inputDef.getSourceEventClass(), escapedEventType, inputDef.getEvtClass(), map);
        } else {
          combinedDef = new EventDefinition(event, escapedEventType, event.getClass(), map);
        }
        inputEvents.put(escapedEventType, combinedDef);

        updateEventStream(combinedDef);
      }
      addInputEventSignature(escapedEventType, eventSignature);
    } else if (!inputEventRegistrationsValid.contains(escapedEventType)) {
      // this is a previously registered stream, but no currently valid EPL statements
      log.info("revalidating event type: %s", escapedEventType);
      inputEventRegistrationsValid.add(escapedEventType);
      notifyEventRegistered(inputEvents.get(escapedEventType));
    }

    return escapedEventType;
  }