storm.trident.state.map.NonTransactionalMap Java Examples

The following examples show how to use storm.trident.state.map.NonTransactionalMap. 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: ESIndexMapState.java    From storm-trident-elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public State makeState(Map conf, IMetricsContext iMetricsContext, int i, int i2) {
    Options options = new Options(conf);
    ESIndexMapState<T> mapState = new ESIndexMapState<>(clientFactory.makeClient(conf), serializer, new BulkResponseHandler.LoggerResponseHandler(), options.reportError());
    MapState<T> ms  = NonTransactionalMap.build(new CachedMap<>(mapState, options.getCachedMapSize()));
    return new SnapshottableMap<>(ms, new Values(options.getGlobalKey()));
}
 
Example #2
Source File: CassandraCqlMapStateFactory.java    From storm-cassandra-cql with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"rawtypes", "unchecked"})
public State makeState(Map configuration, IMetricsContext metrics, int partitionIndex, int numPartitions) {

    if (clientFactory == null) {
        clientFactory = new MapConfiguredCqlClientFactory(configuration);
    }

    Session session;
    if(options.keyspace != null) {
        session = clientFactory.getSession(options.keyspace);
    } else {
        session = clientFactory.getSession();
    }

    CassandraCqlMapState state = new CassandraCqlMapState(session, mapper, options, configuration);
    state.registerMetrics(configuration, metrics, options.mapStateMetricName);

    CachedMap cachedMap = new CachedMap(state, options.localCacheSize);

    MapState mapState;
    if (stateType == StateType.NON_TRANSACTIONAL) {
        mapState = NonTransactionalMap.build(cachedMap);
    } else if (stateType == StateType.OPAQUE) {
        mapState = OpaqueMap.build(cachedMap);
    } else if (stateType == StateType.TRANSACTIONAL) {
        mapState = TransactionalMap.build(cachedMap);
    } else {
        throw new RuntimeException("Unknown state type: " + stateType);
    }

    return new SnapshottableMap(mapState, new Values(options.globalKey));
}