public class MapStateFactoryBuilder<T> extends Object
A helper for building a MapState backed by Cassandra. It internalizes some common implementation choices to simplify usage.
In the simplest use case, a map state can be constructed with:
StateFactory mapState = MapStateFactoryBuilder.opaque() .withTable(“mykeyspace”, “year_month_state”) .withKeys(“year”, “month”) .withJSONBinaryState(“state”) .build();
for a cassandra table with: mykeyspace.year_month_state { year: int, month: int, state: blob }
This will use the storm JSON serializers to convert the state to and from binary format. Other binary serializers can be used with the withBinaryState(String, Serializer)
method.
Storing state in explicit fields (e.g. in a field “sum” of type int) is possible by instead calling withStateMapper(StateMapper)
. For instance, you can use NonTransactionalTupleStateMapper
, TransactionalTupleStateMapper
or OpaqueTupleStateMapper
if your state values are tuples.
Constructor and Description |
---|
MapStateFactoryBuilder() |
public static <U> MapStateFactoryBuilder<OpaqueValue<U>> opaque(Map<String,Object> cassandraConf)
public static <U> MapStateFactoryBuilder<TransactionalValue<U>> transactional(Map<String,Object> cassandraConf)
public static <U> MapStateFactoryBuilder<U> nontransactional(Map<String,Object> cassandraConf)
public MapStateFactoryBuilder<T> withTable(String keyspace, String table)
public MapStateFactoryBuilder<T> withKeys(String... keys)
public MapStateFactoryBuilder<T> withMaxParallelism(Integer maxParallelism)
public MapStateFactoryBuilder<T> withJSONBinaryState(String stateField)
public MapStateFactoryBuilder<T> withStateMapper(StateMapper<T> stateMapper)
public MapStateFactoryBuilder<T> withBinaryState(String stateField, Serializer<T> serializer)
protected MapStateFactoryBuilder<T> withStateType(StateType stateType)
protected MapStateFactoryBuilder<T> withCassandraConfig(Map<String,Object> cassandraConf)
public MapStateFactoryBuilder<T> withCache(int cacheSize)
public StateFactory build()
Copyright © 2022 The Apache Software Foundation. All rights reserved.