Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
package com.presidentio.testdatagenerator.output;
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