Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.presidentio.testdatagenerator.output;
 
 
 import java.util.Map;

Created by Vitalii_Gergel on 2/19/2015.
public abstract class AbstractEsSink extends AbstractBufferedSink {
    private Client client;
    @Override
    public void init(Map<StringStringprops) {
        String host = props.get(.);
        if (host == null) {
            throw new IllegalArgumentException("Host does not specified");
        }
        String port = props.get(.);
        if (port == null) {
            throw new IllegalArgumentException("Port does not specified");
        }
        String clusterName = props.get(.);
        if (clusterName == null) {
            throw new IllegalArgumentException("Cluster name does not specified");
        }
         = (new TransportClient(ImmutableSettings.settingsBuilder().put("cluster.name"clusterName).build()))
                .addTransportAddress(new InetSocketTransportAddress(host, Integer.valueOf(port)));
    }
    @Override
    public void write(String query) {
        try {
            byte[] bytes = query.getBytes();
            .prepareBulk().add(bytes, 0, bytes.lengthfalse).execute().actionGet();
        } catch (Exception e) {
            throw new IllegalStateException("Failed to save: " + querye);
        }
    }
    @Override
    public void close() {
        super.close();
        .close();
    }
New to GrepCode? Check out our FAQ X