当前位置: 首页>>代码示例>>Java>>正文


Java JsonArray.addObject方法代码示例

本文整理汇总了Java中org.vertx.java.core.json.JsonArray.addObject方法的典型用法代码示例。如果您正苦于以下问题:Java JsonArray.addObject方法的具体用法?Java JsonArray.addObject怎么用?Java JsonArray.addObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.vertx.java.core.json.JsonArray的用法示例。


在下文中一共展示了JsonArray.addObject方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getEvent

import org.vertx.java.core.json.JsonArray; //导入方法依赖的package包/类
private JsonObject getEvent() {

            JsonObject event = m_event; // The original/first event
            JsonArray segArray = new JsonArray();
            StringBuilder lines = new StringBuilder();

            for (MultiLineSegment segment : m_segments) {
                lines.append(segment.getLines());
                segArray.addObject(segment.getFields());
            }

            event.putString(m_outputField, lines.toString());
            event.putArray(m_groupField, segArray);

            return event;
        }
 
开发者ID:clidev,项目名称:spike.x,代码行数:17,代码来源:Grok.java

示例2: handleEvent

import org.vertx.java.core.json.JsonArray; //导入方法依赖的package包/类
@Override
protected void handleEvent(final JsonObject batchEvent) {
    try {
        //
        // Operate on arrays only (batches)
        //
        JsonArray batch = batchEvent.getArray(EVENT_FIELD_BATCH_EVENTS, new JsonArray());
        if (!batchEvent.containsField(EVENT_FIELD_BATCH_EVENTS)) {
            batch.addObject(batchEvent);
        }
        for (int i = 0; i < batch.size(); i++) {

            JsonObject event = batch.get(i);

            // Simply log the event using the specified MDC
            String mdcKey = event.getString(FIELD_MDC_KEY, DEF_MDC_KEY);
            String mdcValue = event.getString(FIELD_MDC_VALUE, m_mdcValue);
            MDC.put(mdcKey, String.valueOf(variables().translate(event, mdcValue)));
            eventLogger().info(event.toString());
        }
    } catch (Exception e) {
        logger().error("Failed to log event: {}",
                batchEvent.getString(EVENT_FIELD_ID), e);
    }
}
 
开发者ID:clidev,项目名称:spike.x,代码行数:26,代码来源:Logback.java

示例3: createBatch

import org.vertx.java.core.json.JsonArray; //导入方法依赖的package包/类
public static JsonObject createBatch(
        final String testName,
        final Map<String, Object> otherFields) {

    Map<String, Object> fields = standardFields(testName);
    JsonObject batch = create(testName, fields);
    JsonArray batchEvents = new JsonArray();
    int n = RND.nextInt(100) + 1;
    for (int i = 0; i < n; i++) {
        batchEvents.addObject(create(testName, otherFields));
    }
    batch.putArray(EVENT_FIELD_BATCH_EVENTS, batchEvents);
    batch.putNumber(EVENT_FIELD_BATCH_SIZE, n);
    return batch;
}
 
开发者ID:clidev,项目名称:spike.x,代码行数:16,代码来源:EventCreator.java

示例4: groupEventsPerTopic

import org.vertx.java.core.json.JsonArray; //导入方法依赖的package包/类
private Map<String, List<JsonObject>> groupEventsPerTopic(
        final JsonObject batchEvent,
        final String topicSelector) {
    //
    // Operate on arrays only (batches)
    //
    JsonArray batch = batchEvent.getArray(EVENT_FIELD_BATCH_EVENTS, new JsonArray());
    if (!batchEvent.containsField(EVENT_FIELD_BATCH_EVENTS)) {
        batch.addObject(batchEvent);
    }
    Map<String, List<JsonObject>> topics = new HashMap();

    for (int i = 0; i < batch.size(); i++) {

        JsonObject event = batch.get(i);
        String topic = String.valueOf(variables().translate(event, topicSelector));
        List<JsonObject> events = topics.get(topic);

        if (events == null) {
            events = new ArrayList();
        }

        events.add(event);
        topics.put(topic, events);
    }
    return topics;
}
 
开发者ID:clidev,项目名称:spike.x,代码行数:28,代码来源:NsqHttp.java

示例5: createBatchEvent

import org.vertx.java.core.json.JsonArray; //导入方法依赖的package包/类
/**
 * Creates a new batch event based on the given filter.
 *
 * @param filter the filter that created the event
 * @param events the list of events to add to the batch
 * <p>
 * @return the new batch event
 */
public static JsonObject createBatchEvent(
        final AbstractFilter filter,
        final List<String> events) {

    Preconditions.checkNotNull(filter);
    Preconditions.checkNotNull(events);

    JsonObject batch = new JsonObject();
    batch.putString(EVENT_FIELD_ID, new UUID().toString());
    batch.putString(EVENT_FIELD_SOURCE, filter.getName());
    batch.putNumber(EVENT_FIELD_TIMESTAMP, System.currentTimeMillis());
    batch.putString(EVENT_FIELD_TIMEZONE, ZoneId.of("UTC").getId());
    batch.putString(EVENT_FIELD_TYPE, EVENT_TYPE_BATCH);
    batch.putString(EVENT_FIELD_CHAIN, filter.getChainName());
    batch.putString(EVENT_FIELD_PRIORITY, EVENT_PRIORITY_NORMAL); // Default

    JsonArray jsonEvents = new JsonArray();
    for (String event : events) {
        jsonEvents.addObject(new JsonObject(event));
    }

    batch.putString(EVENT_FIELD_TYPE, EVENT_TYPE_BATCH);
    batch.putArray(EVENT_FIELD_BATCH_EVENTS, jsonEvents);
    batch.putNumber(EVENT_FIELD_BATCH_SIZE, events.size());
    return batch;
}
 
开发者ID:clidev,项目名称:spike.x,代码行数:35,代码来源:Events.java

示例6: doRequest

import org.vertx.java.core.json.JsonArray; //导入方法依赖的package包/类
@Override
protected void doRequest(final HttpClient client) {

    String uri = ES_PUBLISH_URI;
    HttpClientRequest request = doPost(uri, new HttpClientResponseAdapter() {

        @Override
        protected void handleFailure(final HttpClientResponse response) {
            if (response.statusCode() != 200) {
                m_logger.error("Failed to index events: {} (host: {} index: {})",
                        m_batchEvent.getString(EVENT_FIELD_ID),
                        getConnection().getAddress(),
                        m_indexSelector,
                        new IllegalStateException("HTTP post failure: "
                                + response.statusCode()
                                + "/"
                                + response.statusMessage()));
            }
        }
    });

    //
    // Operate on arrays only (batches)
    //
    JsonArray batch = m_batchEvent.getArray(EVENT_FIELD_BATCH_EVENTS, new JsonArray());
    if (!m_batchEvent.containsField(EVENT_FIELD_BATCH_EVENTS)) {
        batch.addObject(m_batchEvent);
    }

    //
    // Build bulk of json data to post
    // https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html
    //
    StringBuilder bulk = new StringBuilder();
    for (int i = 0; i < batch.size(); i++) {
        //
        // Translate index name and type from event contents (if needed)
        //
        JsonObject event = batch.get(i);
        String index = String.valueOf(m_variables.translate(event, m_indexSelector));
        String type = String.valueOf(m_variables.translate(event, m_indexType));

        // Action and meta data
        bulk.append("{\"index\":{\"_index\":\"");
        bulk.append(index);
        bulk.append("\",\"_type\":\"");
        bulk.append(type);
        bulk.append("\",\"_id\":\"");
        bulk.append(event.getString(EVENT_FIELD_ID));
        bulk.append("\"}}\n");
        // Index data
        bulk.append(event.toString());
        bulk.append("\n");
    }

    byte[] body = bulk.toString().getBytes();
    request.putHeader(CONTENT_LENGTH, String.valueOf(body.length));
    request.exceptionHandler(new DefaultConnectionExceptionHandler(
            getConnection()));
    request.write(new Buffer(body));
    request.end();
}
 
开发者ID:clidev,项目名称:spike.x,代码行数:63,代码来源:Elasticsearch.java

示例7: handleEvent

import org.vertx.java.core.json.JsonArray; //导入方法依赖的package包/类
@Override
protected void handleEvent(final JsonObject batchEvent) {
    try {
        if (isStarted()) {

            int available = connections().getAvailableCount();
            logger().trace("Received event: {} batch-size: {} available servers: {}",
                    batchEvent.getString(EVENT_FIELD_ID),
                    batchEvent.getInteger(EVENT_FIELD_BATCH_SIZE, 0),
                    available);

            //
            // Operate on arrays only (batches)
            //
            JsonArray batch = batchEvent.getArray(EVENT_FIELD_BATCH_EVENTS, new JsonArray());
            if (!batchEvent.containsField(EVENT_FIELD_BATCH_EVENTS)) {
                batch.addObject(batchEvent);
            }

            if (available > 0) {
                String precision = m_precision;
                List<String> points = new ArrayList();

                for (int i = 0; i < batch.size(); i++) {
                    //
                    // Does event match any serie definition
                    //
                    JsonObject event = batch.get(i);
                    for (Serie serie : m_series) {
                        if (serie.isMatch(event)) {
                            String point = translateToDataPoint(serie, event, precision);
                            logger().trace("Data point: {}", point);
                            // Ignore empty points (eg. empty value fields)
                            if (point != null) {
                                points.add(point);
                            }
                            break; // Match found, handle next event
                        }
                    }
                }

                //
                // Store events in InfluxDB
                //
                if (points.size() > 0) {
                    IConnection<HttpClient> connection = connections().next();
                    InfluxDbWriter handler = new InfluxDbWriter(
                            connection,
                            m_databaseName,
                            m_consistency,
                            m_precision,
                            points);
                    connection.doRequest(handler);
                }
            }
        }
    } catch (ConnectionException e) {
        logger().error("Failed to publish event: {}",
                batchEvent.getString(EVENT_FIELD_ID), e);
    }
}
 
开发者ID:clidev,项目名称:spike.x,代码行数:62,代码来源:InfluxDb.java

示例8: handleEvent

import org.vertx.java.core.json.JsonArray; //导入方法依赖的package包/类
@Override
protected void handleEvent(final JsonObject batchEvent) {
    
    try {
        if (isStarted()) {
            
            int available = connections().getAvailableCount();
            logger().trace("Received event: {} batch-size: {} available servers: {}",
                    batchEvent.getString(EVENT_FIELD_ID),
                    batchEvent.getInteger(EVENT_FIELD_BATCH_SIZE, 0),
                    available);
            
            if (available > 0) {
                
                IConnection<HttpClient> connection = connections().next();

                //
                // Operate on arrays only (batches)
                //
                JsonArray batch = batchEvent.getArray(EVENT_FIELD_BATCH_EVENTS, new JsonArray());
                if (!batchEvent.containsField(EVENT_FIELD_BATCH_EVENTS)) {
                    batch.addObject(batchEvent);
                }

                // Dweet away
                for (int i = 0; i < batch.size(); i++) {
                    
                    JsonObject event = batch.get(i);

                    // Dweetify dsname and value for easy access in freeboard
                    m_dweets.put(
                            event.getString(EVENT_FIELD_DSNAME),
                            event.getValue(EVENT_FIELD_VALUE));
                    JsonObject dweet = new JsonObject(m_dweets);
                    
                    DweetPublisher handler = new DweetPublisher(
                            connection,
                            m_thingName,
                            m_dweetPath,
                            dweet);

                    connection.doRequest(handler);
                }
            }
        }
    } catch (ConnectionException e) {
        logger().error("Failed to publish event: {}",
                batchEvent.getString(EVENT_FIELD_ID), e);
    }
}
 
开发者ID:clidev,项目名称:spike.x,代码行数:51,代码来源:Dweet.java


注:本文中的org.vertx.java.core.json.JsonArray.addObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。