Package tutorial.storm.trident.example.elasticsearch

Source Code of tutorial.storm.trident.example.elasticsearch.ElasticSearchStateFactory

package tutorial.storm.trident.example.elasticsearch;

import backtype.storm.task.IMetricsContext;
import org.elasticsearch.client.Client;
import storm.trident.state.State;
import storm.trident.state.StateFactory;

import java.util.Map;

/**
* This implementation is basically what Trident needs to build your custom
* {@link State} implementation.
*
* @author Davide Palmisano (davide.palmisano@peerindex.com)
*/
public class ElasticSearchStateFactory implements StateFactory {

    @Override
    public State makeState(Map map, IMetricsContext iMetricsContext, int partitionIndex, int numPartitions) {
        /**
         * Here, we're using a singleton because we're connecting to a local in-memory ES-cluster.
         * In a real world application, you should just instantiate a client to connect
         * to your production database.
         */
        Client client = ElasticSearchSingleton.getInstance();
        return new ElasticSearchState(client);
    }
}
TOP

Related Classes of tutorial.storm.trident.example.elasticsearch.ElasticSearchStateFactory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.