org.elasticsearch.common.collect.MapBuilder Java Examples

The following examples show how to use org.elasticsearch.common.collect.MapBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FsBlobContainer.java    From Elasticsearch with Apache License 2.0 7 votes vote down vote up
@Override
public ImmutableMap<String, BlobMetaData> listBlobsByPrefix(String blobNamePrefix) throws IOException {
    // using MapBuilder and not ImmutableMap.Builder as it seems like File#listFiles might return duplicate files!
    MapBuilder<String, BlobMetaData> builder = MapBuilder.newMapBuilder();

    blobNamePrefix = blobNamePrefix == null ? "" : blobNamePrefix;
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(path, blobNamePrefix + "*")) {
        for (Path file : stream) {
            final BasicFileAttributes attrs = Files.readAttributes(file, BasicFileAttributes.class);
            if (attrs.isRegularFile()) {
                builder.put(file.getFileName().toString(), new PlainBlobMetaData(file.getFileName().toString(), attrs.size()));
            }
        }
    }
    return builder.immutableMap();
}
 
Example #2
Source File: CreateIndexRequest.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
/**
 * Adds mapping that will be added when the index gets created.
 *
 * @param type   The mapping type
 * @param source The mapping source
 */
@SuppressWarnings("unchecked")
public CreateIndexRequest mapping(String type, Map source) {
    if (mappings.containsKey(type)) {
        throw new IllegalStateException("mappings for type \"" + type + "\" were already defined");
    }
    // wrap it in a type map if its not
    if (source.size() != 1 || !source.containsKey(type)) {
        source = MapBuilder.<String, Object>newMapBuilder().put(type, source).map();
    }
    try {
        XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
        builder.map(source);
        return mapping(type, builder.string());
    } catch (IOException e) {
        throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
    }
}
 
Example #3
Source File: CodecService.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
private CodecService(Index index, Settings indexSettings, MapperService mapperService) {
    super(index, indexSettings);
    this.mapperService = mapperService;
    MapBuilder<String, Codec> codecs = MapBuilder.<String, Codec>newMapBuilder();
    if (mapperService == null) {
        codecs.put(DEFAULT_CODEC, new Lucene54Codec());
        codecs.put(BEST_COMPRESSION_CODEC, new Lucene54Codec(Mode.BEST_COMPRESSION));
    } else {
        codecs.put(DEFAULT_CODEC, 
                new PerFieldMappingPostingFormatCodec(Mode.BEST_SPEED, mapperService, logger));
        codecs.put(BEST_COMPRESSION_CODEC, 
                new PerFieldMappingPostingFormatCodec(Mode.BEST_COMPRESSION, mapperService, logger));
    }
    codecs.put(LUCENE_DEFAULT_CODEC, Codec.getDefault());
    for (String codec : Codec.availableCodecs()) {
        codecs.put(codec, Codec.forName(codec));
    }
    this.codecs = codecs.immutableMap();
}
 
Example #4
Source File: TransportProxyClient.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Inject
public TransportProxyClient(Settings settings, TransportService transportService, TransportClientNodesService nodesService, Map<String, GenericAction> actions) {
    this.nodesService = nodesService;
    MapBuilder<Action, TransportActionNodeProxy> actionsBuilder = new MapBuilder<>();
    for (GenericAction action : actions.values()) {
        if (action instanceof Action) {
            actionsBuilder.put((Action) action, new TransportActionNodeProxy(settings, action, transportService));
        }
    }
    this.proxies = actionsBuilder.immutableMap();
}
 
Example #5
Source File: PutIndexTemplateRequest.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * Adds mapping that will be added when the index gets created.
 *
 * @param type   The mapping type
 * @param source The mapping source
 */
public PutIndexTemplateRequest mapping(String type, Map<String, Object> source) {
    // wrap it in a type map if its not
    if (source.size() != 1 || !source.containsKey(type)) {
        source = MapBuilder.<String, Object>newMapBuilder().put(type, source).map();
    }
    try {
        XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
        builder.map(source);
        return mapping(type, builder.string());
    } catch (IOException e) {
        throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
    }
}
 
Example #6
Source File: TransportGetFieldMappingsAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private GetFieldMappingsResponse merge(AtomicReferenceArray<Object> indexResponses) {
    MapBuilder<String, ImmutableMap<String, ImmutableMap<String, GetFieldMappingsResponse.FieldMappingMetaData>>> mergedResponses = MapBuilder.newMapBuilder();
    for (int i = 0; i < indexResponses.length(); i++) {
        Object element = indexResponses.get(i);
        if (element instanceof GetFieldMappingsResponse) {
            GetFieldMappingsResponse response = (GetFieldMappingsResponse) element;
            mergedResponses.putAll(response.mappings());
        }
    }
    return new GetFieldMappingsResponse(mergedResponses.immutableMap());
}
 
Example #7
Source File: TransportGetFieldMappingsIndexAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private void addFieldMapper(String field, FieldMapper fieldMapper, MapBuilder<String, FieldMappingMetaData> fieldMappings, boolean includeDefaults) {
    if (fieldMappings.containsKey(field)) {
        return;
    }
    try {
        XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
        builder.startObject();
        fieldMapper.toXContent(builder, includeDefaults ? includeDefaultsParams : ToXContent.EMPTY_PARAMS);
        builder.endObject();
        fieldMappings.put(field, new FieldMappingMetaData(fieldMapper.fieldType().names().fullName(), builder.bytes()));
    } catch (IOException e) {
        throw new ElasticsearchException("failed to serialize XContent of field [" + field + "]", e);
    }
}
 
Example #8
Source File: JvmMonitorService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Inject
public JvmMonitorService(Settings settings, ThreadPool threadPool) {
    super(settings);
    this.threadPool = threadPool;

    this.enabled = this.settings.getAsBoolean("monitor.jvm.enabled", true);
    this.interval = this.settings.getAsTime("monitor.jvm.interval", timeValueSeconds(1));

    MapBuilder<String, GcThreshold> gcThresholds = MapBuilder.newMapBuilder();
    Map<String, Settings> gcThresholdGroups = this.settings.getGroups("monitor.jvm.gc");
    for (Map.Entry<String, Settings> entry : gcThresholdGroups.entrySet()) {
        String name = entry.getKey();
        TimeValue warn = entry.getValue().getAsTime("warn", null);
        TimeValue info = entry.getValue().getAsTime("info", null);
        TimeValue debug = entry.getValue().getAsTime("debug", null);
        if (warn == null || info == null || debug == null) {
            logger.warn("ignoring gc_threshold for [{}], missing warn/info/debug values", name);
        } else {
            gcThresholds.put(name, new GcThreshold(name, warn.millis(), info.millis(), debug.millis()));
        }
    }
    if (!gcThresholds.containsKey(GcNames.YOUNG)) {
        gcThresholds.put(GcNames.YOUNG, new GcThreshold(GcNames.YOUNG, 1000, 700, 400));
    }
    if (!gcThresholds.containsKey(GcNames.OLD)) {
        gcThresholds.put(GcNames.OLD, new GcThreshold(GcNames.OLD, 10000, 5000, 2000));
    }
    if (!gcThresholds.containsKey("default")) {
        gcThresholds.put("default", new GcThreshold("default", 10000, 5000, 2000));
    }

    this.gcThresholds = gcThresholds.immutableMap();

    logger.debug("enabled [{}], interval [{}], gc_threshold [{}]", enabled, interval, this.gcThresholds);
}
 
Example #9
Source File: IndexShardRoutingTable.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private AttributesRoutings getInitializingAttribute(AttributesKey key, DiscoveryNodes nodes) {
    AttributesRoutings shardRoutings = initializingShardsByAttributes.get(key);
    if (shardRoutings == null) {
        synchronized (shardsByAttributeMutex) {
            ArrayList<ShardRouting> from = new ArrayList<>(allInitializingShards);
            List<ShardRouting> to = collectAttributeShards(key, nodes, from);
            shardRoutings = new AttributesRoutings(to, Collections.unmodifiableList(from));
            initializingShardsByAttributes = MapBuilder.newMapBuilder(initializingShardsByAttributes).put(key, shardRoutings).immutableMap();
        }
    }
    return shardRoutings;
}
 
Example #10
Source File: IndexShardRoutingTable.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private AttributesRoutings getActiveAttribute(AttributesKey key, DiscoveryNodes nodes) {
    AttributesRoutings shardRoutings = activeShardsByAttributes.get(key);
    if (shardRoutings == null) {
        synchronized (shardsByAttributeMutex) {
            ArrayList<ShardRouting> from = new ArrayList<>(activeShards);
            List<ShardRouting> to = collectAttributeShards(key, nodes, from);

            shardRoutings = new AttributesRoutings(to, Collections.unmodifiableList(from));
            activeShardsByAttributes = MapBuilder.newMapBuilder(activeShardsByAttributes).put(key, shardRoutings).immutableMap();
        }
    }
    return shardRoutings;
}
 
Example #11
Source File: TestElasticsearchAppender.java    From karaf-decanter with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 60000L)
public void test() throws Exception {
    Marshaller marshaller = new JsonMarshaller();
    ElasticsearchAppender appender = new ElasticsearchAppender();
    appender.marshaller = marshaller;
    Dictionary<String, Object> config = new Hashtable<>();
    config.put(ElasticsearchAppender.ADDRESSES_PROPERTY, "http://" + HOST + ":" + HTTP_PORT);
    config.put(EventFilter.PROPERTY_NAME_EXCLUDE_CONFIG, ".*refused.*");
    config.put(EventFilter.PROPERTY_VALUE_EXCLUDE_CONFIG, ".*refused.*");
    appender.open(config);
    appender.handleEvent(new Event("testTopic", MapBuilder.<String, String>newMapBuilder().put("a", "b").put("c", "d").map()));
    appender.handleEvent(new Event("testTopic", MapBuilder.<String, String>newMapBuilder().put("a", "b").put("c", "d").map()));
    appender.handleEvent(new Event("testTopic", MapBuilder.<String, String>newMapBuilder().put("a", "b").put("c", "d").map()));
    appender.handleEvent(new Event("testTopic", MapBuilder.<String, String>newMapBuilder().put("refused", "b").put("c", "d").map()));
    appender.handleEvent(new Event("testTopic", MapBuilder.<String, String>newMapBuilder().put("a", "refused").put("c", "d").map()));
    appender.close();

    HttpHost host = new HttpHost(HOST, HTTP_PORT, "http");
    RestClient client = RestClient.builder(new HttpHost[]{ host }).build();

    String responseString = "";
    while (!responseString.contains("\"count\":3")) {
        Thread.sleep(200);
        Request request = new Request("GET", "/_count");
        Response response = client.performRequest(request);
        responseString = EntityUtils.toString(response.getEntity());
    }
}
 
Example #12
Source File: TransportService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
protected <Request extends TransportRequest> void registerRequestHandler(RequestHandlerRegistry<Request> reg) {
    synchronized (requestHandlerMutex) {
        RequestHandlerRegistry replaced = requestHandlers.get(reg.getAction());
        requestHandlers = MapBuilder.newMapBuilder(requestHandlers).put(reg.getAction(), reg).immutableMap();
        if (replaced != null) {
            logger.warn("registered two transport handlers for action {}, handlers: {}, {}", reg.getAction(), reg, replaced);
        }
    }
}
 
Example #13
Source File: ShardSearchStats.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private StatsHolder groupStats(String group) {
    StatsHolder stats = groupsStats.get(group);
    if (stats == null) {
        synchronized (this) {
            stats = groupsStats.get(group);
            if (stats == null) {
                stats = new StatsHolder();
                groupsStats = MapBuilder.newMapBuilder(groupsStats).put(group, stats).immutableMap();
            }
        }
    }
    return stats;
}
 
Example #14
Source File: ShardSearchStats.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public void clear() {
    totalStats.clear();
    synchronized (this) {
        if (!groupsStats.isEmpty()) {
            MapBuilder<String, StatsHolder> typesStatsBuilder = MapBuilder.newMapBuilder();
            for (Map.Entry<String, StatsHolder> typeStats : groupsStats.entrySet()) {
                if (typeStats.getValue().totalCurrent() > 0) {
                    typeStats.getValue().clear();
                    typesStatsBuilder.put(typeStats.getKey(), typeStats.getValue());
                }
            }
            groupsStats = typesStatsBuilder.immutableMap();
        }
    }
}
 
Example #15
Source File: ShardIndexingService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private StatsHolder typeStats(String type) {
    StatsHolder stats = typesStats.get(type);
    if (stats == null) {
        synchronized (this) {
            stats = typesStats.get(type);
            if (stats == null) {
                stats = new StatsHolder();
                typesStats = MapBuilder.newMapBuilder(typesStats).put(type, stats).immutableMap();
            }
        }
    }
    return stats;
}
 
Example #16
Source File: ShardIndexingService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public void clear() {
    totalStats.clear();
    synchronized (this) {
        if (!typesStats.isEmpty()) {
            MapBuilder<String, StatsHolder> typesStatsBuilder = MapBuilder.newMapBuilder();
            for (Map.Entry<String, StatsHolder> typeStats : typesStats.entrySet()) {
                if (typeStats.getValue().totalCurrent() > 0) {
                    typeStats.getValue().clear();
                    typesStatsBuilder.put(typeStats.getKey(), typeStats.getValue());
                }
            }
            typesStats = typesStatsBuilder.immutableMap();
        }
    }
}
 
Example #17
Source File: CommitStats.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    MapBuilder<String, String> builder = MapBuilder.newMapBuilder();
    for (int i = in.readVInt(); i > 0; i--) {
        builder.put(in.readString(), in.readString());
    }
    userData = builder.immutableMap();
    generation = in.readLong();
    id = in.readOptionalString();
    numDocs = in.readInt();
}
 
Example #18
Source File: CommitStats.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public CommitStats(SegmentInfos segmentInfos) {
    // clone the map to protect against concurrent changes
    userData = MapBuilder.<String, String>newMapBuilder().putAll(segmentInfos.getUserData()).immutableMap();
    // lucene calls the current generation, last generation.
    generation = segmentInfos.getLastGeneration();
    if (segmentInfos.getId() != null) { // id is only written starting with Lucene 5.0
        id = Base64.encodeBytes(segmentInfos.getId());
    }
    numDocs = Lucene.getNumDocs(segmentInfos);
}
 
Example #19
Source File: AggregationStreams.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * Registers the given stream and associate it with the given types.
 *
 * @param stream    The streams to register
 * @param types     The types associated with the streams
 */
public static synchronized void registerStream(Stream stream, BytesReference... types) {
    MapBuilder<BytesReference, Stream> uStreams = MapBuilder.newMapBuilder(streams);
    for (BytesReference type : types) {
        uStreams.put(type, stream);
    }
    streams = uStreams.immutableMap();
}
 
Example #20
Source File: BucketStreams.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * Registers the given stream and associate it with the given types.
 *
 * @param stream    The streams to register
 * @param types     The types associated with the streams
 */
public static synchronized void registerStream(Stream stream, BytesReference... types) {
    MapBuilder<BytesReference, Stream> uStreams = MapBuilder.newMapBuilder(STREAMS);
    for (BytesReference type : types) {
        uStreams.put(type, stream);
    }
    STREAMS = uStreams.immutableMap();
}
 
Example #21
Source File: PipelineAggregatorStreams.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * Registers the given stream and associate it with the given types.
 *
 * @param stream    The streams to register
 * @param types     The types associated with the streams
 */
public static synchronized void registerStream(Stream stream, BytesReference... types) {
    MapBuilder<BytesReference, Stream> uStreams = MapBuilder.newMapBuilder(streams);
    for (BytesReference type : types) {
        uStreams.put(type, stream);
    }
    streams = uStreams.immutableMap();
}
 
Example #22
Source File: CrateComponentLoader.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private CrateComponentLoader(Settings settings) {
    ServiceLoader<CrateComponent> crateComponents = ServiceLoader.load(CrateComponent.class);
    plugins = new ArrayList<>();
    MapBuilder<Plugin, List<OnModuleReference>> onModuleReferences = MapBuilder.newMapBuilder();
    for (CrateComponent crateComponent : crateComponents) {
        logger.trace("Loading crateComponent: {}", crateComponent);
        Plugin plugin = crateComponent.createPlugin(settings);
        plugins.add(plugin);
        List<OnModuleReference> list = Lists.newArrayList();
        for (Method method : plugin.getClass().getDeclaredMethods()) {
            if (!method.getName().equals("onModule")) {
                continue;
            }
            if (method.getParameterTypes().length == 0 || method.getParameterTypes().length > 1) {
                logger.warn("Plugin: {} implementing onModule with no parameters or more than one parameter", plugin.name());
                continue;
            }
            Class moduleClass = method.getParameterTypes()[0];
            if (!Module.class.isAssignableFrom(moduleClass)) {
                logger.warn("Plugin: {} implementing onModule by the type is not of Module type {}", plugin.name(), moduleClass);
                continue;
            }
            method.setAccessible(true);
            //noinspection unchecked
            list.add(new OnModuleReference(moduleClass, method));
        }
        if (!list.isEmpty()) {
            onModuleReferences.put(plugin, list);
        }
    }
    this.onModuleReferences = onModuleReferences.immutableMap();
}
 
Example #23
Source File: TransportClient.java    From elasticsearch-helper with Apache License 2.0 5 votes vote down vote up
@Inject
@SuppressWarnings("unchecked")
public ProxyActionMap(Settings settings, TransportService transportService, Map<String, GenericAction> actions) {
    MapBuilder<Action, TransportActionNodeProxy> actionsBuilder = new MapBuilder<>();
    for (GenericAction action : actions.values()) {
        if (action instanceof Action) {
            actionsBuilder.put((Action) action, new TransportActionNodeProxy(settings, action, transportService));
        }
    }
    this.proxies = actionsBuilder.immutableMap();
}
 
Example #24
Source File: TransportService.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public void removeHandler(String action) {
    synchronized (requestHandlerMutex) {
        requestHandlers = MapBuilder.newMapBuilder(requestHandlers).remove(action).immutableMap();
    }
}
 
Example #25
Source File: IngestYauaaPlugin.java    From yauaa with Apache License 2.0 4 votes vote down vote up
@Override
public Map<String, Processor.Factory> getProcessors(Processor.Parameters parameters) {
    return MapBuilder.<String, Processor.Factory>newMapBuilder()
        .put(YauaaProcessor.TYPE, new YauaaProcessor.Factory())
        .immutableMap();
}
 
Example #26
Source File: IngestCsvPlugin.java    From elasticsearch-ingest-csv with Apache License 2.0 4 votes vote down vote up
@Override
public Map<String, Processor.Factory> getProcessors(Processor.Parameters parameters) {
    return MapBuilder.<String, Processor.Factory>newMapBuilder()
            .put(CsvProcessor.TYPE, new CsvProcessor.Factory())
            .immutableMap();
}
 
Example #27
Source File: NodeService.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public synchronized void removeAttribute(String key) {
    serviceAttributes = new MapBuilder<>(serviceAttributes).remove(key).immutableMap();
}
 
Example #28
Source File: NodeService.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public synchronized void putAttribute(String key, String value) {
    serviceAttributes = new MapBuilder<>(serviceAttributes).put(key, value).immutableMap();
}
 
Example #29
Source File: ElasticSearchJSONEventSerializer.java    From bboss-elasticsearch with Apache License 2.0 4 votes vote down vote up
private   void appendHeaders(Map<String,Object> builder, Event event)
      throws IOException {
//    Map<String, String> headers = Maps.newHashMap(event.getHeaders());
	  MapBuilder mapBuilder = MapBuilder.newMapBuilder();
//	  mapBuilder.putAll(event.getHeaders());
//	  Map<String, String> headers = mapBuilder.map();
    Map<String, String> headers = event.getHeaders();
    if(headers == null || headers.size() == 0){
      return;
    }
    String timestamp = headers.remove("timestamp");
    if (!SimpleStringUtil.isEmpty(timestamp)
        && SimpleStringUtil.isEmpty(headers.get("@timestamp"))) {
      long timestampMs = Long.parseLong(timestamp);
      builder.put("@timestamp", new Date(timestampMs));
    }

    String source = headers.remove("source");
    if (!SimpleStringUtil.isEmpty(source)
        && SimpleStringUtil.isEmpty(headers.get("@source"))) {
      builder.put( "@source",
          source);
    }

    String type = headers.remove("type");
    if (!SimpleStringUtil.isEmpty(type)
        && SimpleStringUtil.isEmpty(headers.get("@type"))) {
      builder.put("@type", type);
    }

    String host = headers.remove("host");
    if (!SimpleStringUtil.isEmpty(host)
        && SimpleStringUtil.isEmpty(headers.get("@source_host"))) {

      builder.put( "beat.host",
          host);
    }

    String srcPath = headers.remove("src_path");
    if (!SimpleStringUtil.isEmpty(srcPath)
        && SimpleStringUtil.isEmpty(headers.get("@source_path"))) {
      builder.put( "@source_path",
          srcPath);
    }


    for (String key : headers.keySet()) {
      String val = headers.get(key);
      builder.put(key, val);
    }

  }
 
Example #30
Source File: ElasticSearchLogStashEventSerializer.java    From bboss-elasticsearch with Apache License 2.0 4 votes vote down vote up
private  void appendHeaders(XContentBuilder builder, Event event)
      throws IOException {
//    Map<String, String> headers = Maps.newHashMap(event.getHeaders());
	  MapBuilder mapBuilder = MapBuilder.newMapBuilder();
//	  mapBuilder.putAll(event.getHeaders());
//	  Map<String, String> headers = mapBuilder.map();
    Map<String, String> headers = event.getHeaders();
    if(headers == null || headers.size() == 0){
      return;
    }
    String timestamp = headers.remove("timestamp");
    if (!SimpleStringUtil.isEmpty(timestamp)
        && SimpleStringUtil.isEmpty(headers.get("@timestamp"))) {
      long timestampMs = Long.parseLong(timestamp);
      builder.field("@timestamp", new Date(timestampMs));
    }

    String source = headers.remove("source");
    if (!SimpleStringUtil.isEmpty(source)
        && SimpleStringUtil.isEmpty(headers.get("@source"))) {
      ContentBuilderUtil.appendField(builder, "@source",
          source.getBytes(charset));
    }

    String type = headers.remove("type");
    if (!SimpleStringUtil.isEmpty(type)
        && SimpleStringUtil.isEmpty(headers.get("@type"))) {
      ContentBuilderUtil.appendField(builder, "@type", type.getBytes(charset));
    }

    String host = headers.remove("host");
    if (!SimpleStringUtil.isEmpty(host)
        && SimpleStringUtil.isEmpty(headers.get("@source_host"))) {
      ContentBuilderUtil.appendField(builder, "@source_host",
          host.getBytes(charset));
    }

    String srcPath = headers.remove("src_path");
    if (!SimpleStringUtil.isEmpty(srcPath)
        && SimpleStringUtil.isEmpty(headers.get("@source_path"))) {
      ContentBuilderUtil.appendField(builder, "@source_path",
          srcPath.getBytes(charset));
    }

    builder.startObject("@fields");
    for (String key : headers.keySet()) {
      byte[] val = headers.get(key).getBytes(charset);
      ContentBuilderUtil.appendField(builder, key, val);
    }
    builder.endObject();
  }