Пример #1
0
  private void putDynamicEvent(Map<String, List<DBObject>> eventMap, Event event) {
    String eventCollection;
    Map<String, String> headers = event.getHeaders();
    String eventDb = headers.get(DB_NAME);
    eventCollection = headers.get(COLLECTION);

    if (!StringUtils.isEmpty(eventDb)) {
      eventCollection = eventDb + NAMESPACE_SEPARATOR + eventCollection;
    } else {
      eventCollection = dbName + NAMESPACE_SEPARATOR + eventCollection;
    }

    if (!eventMap.containsKey(eventCollection)) {
      eventMap.put(eventCollection, new ArrayList<DBObject>());
    }

    List<DBObject> documents = eventMap.get(eventCollection);
    addEventToList(documents, event);
  }
Пример #2
0
  private List<DBObject> addEventToList(List<DBObject> documents, Event event) {
    if (documents == null) {
      documents = new ArrayList<DBObject>(batchSize);
    }

    DBObject eventJson;
    byte[] body = event.getBody();
    if (autoWrap) {
      eventJson = new BasicDBObject(wrapField, new String(body));
    } else {
      try {
        eventJson = (DBObject) JSON.parse(new String(body));
      } catch (Exception e) {
        logger.error("Can't parse events: " + new String(body), e);
        return documents;
      }
    }
    documents.add(eventJson);

    return documents;
  }