本文整理汇总了Java中storm.trident.state.map.MapState类的典型用法代码示例。如果您正苦于以下问题:Java MapState类的具体用法?Java MapState怎么用?Java MapState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MapState类属于storm.trident.state.map包,在下文中一共展示了MapState类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: updateState
import storm.trident.state.map.MapState; //导入依赖的package包/类
@Override
public void updateState(MapState<Map<String, Object>> state, List<TridentTuple> tuples, TridentCollector collector) {
List<Map<String, Object>> events = Lists.newArrayList();
List<List<Object>> keys = Lists.newArrayList();
for (TridentTuple t : tuples) {
if(t!=null) {
List<Object> l = Lists.newArrayList();
l.add(_generalKey + t.getValueByField(_key));
keys.add(l);
events.add((Map<String, Object>) t.getValueByField(_value));
//System.out.println("SAVED TO MEMCACHED KEY: " + _generalKey +t.getValueByField(_key) +
// " VALUE: " + t.getValueByField(_value));
}
}
try {
state.multiPut(keys, events);
} catch (ReportedFailedException e) {
Logger.getLogger(MemcachedUpdater.class.getName()).log(Level.WARNING, null, e);
}
}
开发者ID:redBorder,项目名称:rb-bi,代码行数:23,代码来源:MemcachedUpdater.java
示例2: updateState
import storm.trident.state.map.MapState; //导入依赖的package包/类
@Override
public void updateState(MapState<Map<String, Object>> state, List<TridentTuple> tuples, TridentCollector collector) {
List<Map<String, Object>> events = new ArrayList<>();
List<List<Object>> keys = new ArrayList<>();
for (TridentTuple t : tuples) {
if (t != null) {
List<Object> l = new ArrayList<>();
l.add(_generalKey + t.getValueByField(_key));
keys.add(l);
if (t.getValueByField(_value) != null)
events.add((Map<String, Object>) t.getValueByField(_value));
if (_debug) {
System.out.println("SAVED TO RIAK KEY: " + _generalKey + t.getValueByField(_key)
+ " VALUE: " + t.getValueByField(_value));
}
}
}
try {
if (!events.isEmpty())
state.multiPut(keys, events);
} catch (ReportedFailedException e) {
Logger.getLogger(RiakUpdater.class.getName()).log(Level.WARNING, null, e);
}
}
开发者ID:redBorder,项目名称:rb-bi,代码行数:27,代码来源:RiakUpdater.java
示例3: updateState
import storm.trident.state.map.MapState; //导入依赖的package包/类
@Override
public void updateState(MapState<Map<String, Map<String, Object>>> state, List<TridentTuple> tuples, TridentCollector collector) {
Map<String, Map<String, Object>> keyValue = new HashMap<>();
List<Map<String, Map<String, Object>>> events = new ArrayList<>();
List<List<Object>> keys = new ArrayList<>();
for (TridentTuple t : tuples) {
if (t != null) {
List<Object> l = new ArrayList<>();
l.add(_generalKey + t.getValueByField(_key));
keys.add(l);
keyValue.put(_generalKey + t.getValueByField(_key), (Map<String, Object>) t.getValueByField(_value));
if (_debug) {
System.out.println("SAVED TO GRIDGAIN, KEY: " + _generalKey + t.getValueByField(_key)
+ " VALUE: " + t.getValueByField(_value));
}
}
}
events.add(keyValue);
try {
logger.fine("Calling gridgain multiput");
state.multiPut(keys, events);
logger.fine("Back from gridgain multiput");
} catch (Exception e) {
Logger.getLogger(GridGainUpdater.class.getName()).log(Level.SEVERE, null, e);
e.printStackTrace();
}
}
开发者ID:redBorder,项目名称:rb-bi,代码行数:32,代码来源:GridGainUpdater.java
示例4: makeState
import storm.trident.state.map.MapState; //导入依赖的package包/类
@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));
}
开发者ID:hpcc-systems,项目名称:storm-cassandra-cql,代码行数:33,代码来源:CassandraCqlMapStateFactory.java
示例5: makeState
import storm.trident.state.map.MapState; //导入依赖的package包/类
@Override
public State makeState(Map conf, IMetricsContext iMetricsContext, int i, int i2) {
Options options = new Options(conf);
ESIndexMapState<OpaqueValue<T>> mapState = new ESIndexMapState<>(clientFactory.makeClient(conf), serializer, new BulkResponseHandler.LoggerResponseHandler(), options.reportError());
MapState ms = OpaqueMap.build(new CachedMap(mapState, options.getCachedMapSize()));
return new SnapshottableMap<OpaqueValue<T>>(ms, new Values(options.getGlobalKey()));
}
开发者ID:fhussonnois,项目名称:storm-trident-elasticsearch,代码行数:8,代码来源:ESIndexMapState.java
示例6: updateState
import storm.trident.state.map.MapState; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void updateState(MapState<LofDataSet> state, List<TridentTuple> tuples,
TridentCollector collector)
{
// Get model
List<LofDataSet> dataSets = state.multiGet(Arrays.asList(Arrays.asList((Object) this.stateName)));
LofDataSet dataSet = null;
if (dataSets != null && !dataSets.isEmpty())
{
dataSet = dataSets.get(0);
}
else
{
dataSet = this.initialState;
}
for (TridentTuple targetTuple : tuples)
{
this.receiveCount++;
LofPoint recievedPoint = (LofPoint) targetTuple.get(0);
double lofScore = receivePoint(recievedPoint, dataSet);
if (this.dataNotifier != null)
{
this.dataNotifier.notifyResult(new LofResult(lofScore, recievedPoint));
}
}
// Save model
state.multiPut(Arrays.asList(Arrays.asList((Object) this.stateName)),
Arrays.asList(dataSet));
if (this.batchNotifier != null)
{
this.batchNotifier.notifyResult(dataSet);
}
}
开发者ID:acromusashi,项目名称:acromusashi-stream-ml,代码行数:41,代码来源:LofUpdater.java
示例7: batchRetrieve
import storm.trident.state.map.MapState; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public List<String> batchRetrieve(MapState<KmeansDataSet> state, List<TridentTuple> args)
{
if (this.objectMapper == null)
{
this.objectMapper = new ObjectMapper();
}
// 学習データモデルを取得
List<KmeansDataSet> dataSets = state.multiGet(Arrays.asList(Arrays.asList((Object) this.baseStateName)));
KmeansDataSet dataSet = null;
if (dataSets != null && !dataSets.isEmpty())
{
dataSet = dataSets.get(0);
}
List<String> resultStrList = new ArrayList<>();
// 受信したデータ毎にクラスタリングを行い、結果を返す。
for (TridentTuple targetTuple : args)
{
KmeansPoint recievedPoint = (KmeansPoint) targetTuple.get(0);
// 状態が取得できなかった場合は空文字を結果として設定する。
if (dataSet == null)
{
resultStrList.add("");
continue;
}
KmeansResult result = KmeansCalculator.classify(recievedPoint, dataSet);
String resultStr = null;
try
{
resultStr = this.objectMapper.writeValueAsString(result);
}
catch (IOException ex)
{
logger.warn("Received data is invalid. skip this data. ReceivedData="
+ recievedPoint, ex);
}
if (resultStr != null)
{
resultStrList.add(resultStr);
}
else
{
resultStrList.add("");
}
}
return resultStrList;
}
开发者ID:acromusashi,项目名称:acromusashi-stream-ml,代码行数:58,代码来源:KmeansQuery.java
示例8: updateState
import storm.trident.state.map.MapState; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void updateState(MapState<KmeansDataSet> state, List<TridentTuple> tuples,
TridentCollector collector)
{
// データが流れてきていない場合はupdateStateメソッドが呼ばれないため、本メソッド内ではデータが存在するとして扱う。
List<KmeansDataSet> dataSets = state.multiGet(Arrays.asList(Arrays.asList((Object) this.stateName)));
KmeansDataSet dataSet = null;
if (dataSets != null && !dataSets.isEmpty())
{
dataSet = dataSets.get(0);
}
// TupleからKMeans用データを抽出する。
List<KmeansPoint> receiveList = new ArrayList<>();
for (TridentTuple targetTuple : tuples)
{
KmeansPoint recievedPoint = (KmeansPoint) targetTuple.get(0);
receiveList.add(recievedPoint);
}
// 投入されたKMeans用点から学習モデルを生成する。
KmeansDataSet generatedDataSet = KmeansCalculator.createDataModel(receiveList,
this.clusterNum, this.maxIteration, this.convergenceThreshold);
if (generatedDataSet != null)
{
dataSet = generatedDataSet;
}
// 元々データモデルが存在せず、かつ投入された点が不足しており学習モデルが生成できなかった場合、以後の処理は行わない。
if (dataSet == null)
{
return;
}
// データ通知拡張ポイントに値が設定されていた場合、クラスタリング結果を算出し、通知を行う。
if (this.dataNotifier != null)
{
for (KmeansPoint targetPoint : receiveList)
{
KmeansResult result = KmeansCalculator.classify(targetPoint, dataSet);
this.dataNotifier.notifyResult(result);
}
}
// Save model
state.multiPut(Arrays.asList(Arrays.asList((Object) this.stateName)),
Arrays.asList(dataSet));
if (this.batchNotifier != null)
{
this.batchNotifier.notifyResult(dataSet);
}
}
开发者ID:acromusashi,项目名称:acromusashi-stream-ml,代码行数:57,代码来源:KmeansUpdater.java
示例9: batchRetrieve
import storm.trident.state.map.MapState; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public List<String> batchRetrieve(MapState<LofDataSet> state, List<TridentTuple> tuples)
{
if (this.objectMapper == null)
{
this.objectMapper = new ObjectMapper();
}
// Get model
List<LofDataSet> dataSets = state.multiGet(Arrays.asList(Arrays.asList((Object) this.baseStateName)));
LofDataSet dataSet = null;
if (dataSets != null && !dataSets.isEmpty())
{
dataSet = dataSets.get(0);
}
List<String> resultStrList = new ArrayList<>();
// 受信したデータ毎にLOFスコアの算出を行い、結果のJSON文字列を返す
for (TridentTuple targetTuple : tuples)
{
LofPoint recievedPoint = (LofPoint) targetTuple.get(0);
// データモデルが取得できなかった場合は空文字を結果として設定
if (dataSet == null)
{
resultStrList.add("");
continue;
}
double lofScore = 0.0d;
if (this.hasIntermediate)
{
lofScore = LofCalculator.calculateLofWithoutUpdate(this.kn, recievedPoint, dataSet);
}
else
{
lofScore = LofCalculator.calculateLofNoIntermediate(this.kn, recievedPoint, dataSet);
}
LofResult result = new LofResult(lofScore, recievedPoint);
String resultStr = null;
try
{
resultStr = this.objectMapper.writeValueAsString(result);
}
catch (IOException ex)
{
logger.warn("Received data is invalid. skip this data. ReceivedData="
+ recievedPoint, ex);
}
if (resultStr != null)
{
resultStrList.add(resultStr);
}
else
{
resultStrList.add("");
}
}
return resultStrList;
}
开发者ID:acromusashi,项目名称:acromusashi-stream-ml,代码行数:69,代码来源:LofQuery.java
注:本文中的storm.trident.state.map.MapState类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论