本文整理匯總了Java中storm.trident.operation.TridentCollector類的典型用法代碼示例。如果您正苦於以下問題:Java TridentCollector類的具體用法?Java TridentCollector怎麽用?Java TridentCollector使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
TridentCollector類屬於storm.trident.operation包,在下文中一共展示了TridentCollector類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: updateState
import storm.trident.operation.TridentCollector; //導入依賴的package包/類
public void updateState(List<TridentTuple> tuples, TridentCollector collector) {
String topic = null;
for (TridentTuple tuple : tuples) {
try {
topic = topicSelector.getTopic(tuple);
if(topic != null) {
producer.send(new KeyedMessage(topic, mapper.getKeyFromTuple(tuple),
mapper.getMessageFromTuple(tuple)));
} else {
LOG.warn("skipping key = " + mapper.getKeyFromTuple(tuple) + ", topic selector returned null.");
}
} catch (Exception ex) {
String errorMsg = "Could not send message with key = " + mapper.getKeyFromTuple(tuple)
+ " to topic = " + topic;
LOG.warn(errorMsg, ex);
throw new FailedException(errorMsg, ex);
}
}
}
示例2: emitNewPartitionBatch
import storm.trident.operation.TridentCollector; //導入依賴的package包/類
private Map emitNewPartitionBatch(TransactionAttempt attempt, TridentCollector collector, Partition partition, Map lastMeta) {
try {
return failFastEmitNewPartitionBatch(attempt, collector, partition, lastMeta);
} catch (FailedFetchException e) {
e.printStackTrace();
}
Map ret = new HashMap();
if (lastMeta != null && partition != null) {
ret.put("offset", lastMeta.get("nextOffset"));
ret.put("nextOffset", lastMeta.get("nextOffset"));
ret.put("partition", partition.partition);
ret.put("broker", ImmutableMap.of("host", partition.host.host, "port", partition.host.port));
ret.put("topic", _config.topic);
ret.put("topology", ImmutableMap.of("name", _topologyName, "id", _topologyInstanceId));
}
return ret;
}
示例3: execute
import storm.trident.operation.TridentCollector; //導入依賴的package包/類
/**
* <p>This function get the radius client from radius event.</p>
* @author Andres Gomez
*/
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
Map<String, Object> radiusData = (Map<String, Object>) tuple.getValue(0);
String clientMac = radiusData.get("Calling-Station-Id").toString();
clientMac = clientMac.replace("-", ":");
Map<String, Object> radiusMap = new HashMap<>();
radiusMap.put("client_mac", clientMac);
if (_debug) {
System.out.println(GetRadiusClient.class +" - Radius client to query: " + clientMac);
}
collector.emit(new Values(radiusMap));
}
示例4: execute
import storm.trident.operation.TridentCollector; //導入依賴的package包/類
/**
* <p>This function converts a JSON events to JAVA Map.</p>
*/
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
String jsonEvent = tuple.getString(0);
if (jsonEvent != null && jsonEvent.length() > 0) {
Map<String, Object> event = null;
try {
event = _mapper.readValue(jsonEvent, Map.class);
_metric.incrEvent();
} catch (IOException | NullPointerException ex) {
Logger.getLogger(MapperFunction.class.getName()).log(Level.SEVERE, "Failed converting a JSON tuple to a Map class [ " + _metricName + " ] \n"
+ " JSON tuple: " + jsonEvent, ex);
}
if (event != null)
collector.emit(new Values(event));
}
}
示例5: execute
import storm.trident.operation.TridentCollector; //導入依賴的package包/類
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
Map<String , Object> mseData = (Map<String, Object>) tuple.get(0);
List<Map<String, Object>> notifications = (List<Map<String, Object>>) mseData.get("notifications");
for (Map<String, Object> notification : notifications){
if(notification.get("notificationType").equals("association")){
logger.fine("Mse10 event this event is a association, emitting: [" + notification.size() + ", " + "null]");
collector.emit(new Values(notification, null));
}else if(notification.get("notificationType").equals("locationupdate")){
logger.fine("Mse10 event this event is a locationupdate, emitting: [null" + ", " + notification.size() + "]");
collector.emit(new Values(null, notification));
}else{
Logger.getLogger(SplitMSE10Data.class.getName()).log(Level.WARNING, "MSE version 10 notificationType is unknown: " + notification.get("notificationType"));
}
}
}
示例6: execute
import storm.trident.operation.TridentCollector; //導入依賴的package包/類
@Override
public void execute(TridentTuple tuple, Map<String, Object> result, TridentCollector collector) {
if (result == null) {
Map<String, Object> empty = new HashMap<>();
collector.emit(new Values(empty));
} else {
result.remove("client_rssi");
result.remove("client_rssi_num");
result.remove("client_snr");
result.remove("client_snr_num");
result.remove("dot11_status");
result.remove("wireless_id");
collector.emit(new Values(result));
}
}
示例7: updateState
import storm.trident.operation.TridentCollector; //導入依賴的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);
}
}
示例8: updateState
import storm.trident.operation.TridentCollector; //導入依賴的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);
}
}
示例9: execute
import storm.trident.operation.TridentCollector; //導入依賴的package包/類
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
String currentValue;
int newHashModValue;
String newValue;
int currentTry;
currentTry = 0;
currentValue = tuple.getString(0);
newHashModValue = (currentValue.hashCode() % this.numPartitions) + 1;
newHashModValue = newHashModValue % this.numPartitions; // rotate back to 0 if necessary
do {
newValue = UUID.randomUUID().toString();
if (currentTry++ >= maxTry) {
throw new RuntimeException("Couldn't find a value for hash/mod " + newHashModValue +
" in " + maxTry + " attempts. Current value is " + newValue +
" Number of partitions: " + this.numPartitions);
}
} while ((newValue.hashCode() % this.numPartitions) != newHashModValue);
collector.emit(new Values(newValue));
}
示例10: updateState
import storm.trident.operation.TridentCollector; //導入依賴的package包/類
public void updateState(List<TridentTuple> tuples, TridentCollector collector) {
List<Mutation> mutations = Lists.newArrayList();
for (TridentTuple tuple : tuples) {
byte[] rowKey = options.mapper.rowKey(tuple);
ColumnList cols = options.mapper.columns(tuple);
mutations.addAll(hBaseClient.constructMutationReq(rowKey, cols, options.durability));
}
try {
hBaseClient.batchMutate(mutations);
} catch (Exception e) {
LOG.warn("Batch write failed but some requests might have succeeded. Triggering replay.", e);
throw new FailedException(e);
}
}
示例11: execute
import storm.trident.operation.TridentCollector; //導入依賴的package包/類
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
String file = tuple.getString(0).replaceAll("\\s+","");
String task = tuple.getString(1);
String user = tuple.getString(2);
String content = JSONObject.escape(tuple.getString(3));
JSONObject json = new JSONObject();
json.put("file",file);
json.put("task",task);
json.put("user",user);
json.put("content",content);
collector.emit(new Values(esIndex,task,file,json.toJSONString()));
}
示例12: emitCrossJoin
import storm.trident.operation.TridentCollector; //導入依賴的package包/類
private void emitCrossJoin(JoinState state, TridentCollector collector, int overrideIndex, TridentTuple overrideTuple) {
List<List>[] sides = state.sides;
int[] indices = state.indices;
for(int i=0; i<indices.length; i++) {
indices[i] = 0;
}
boolean keepGoing = true;
//emit cross-join of all emitted tuples
while(keepGoing) {
List[] combined = new List[sides.length+1];
combined[0] = state.group;
for(int i=0; i<sides.length; i++) {
if(i==overrideIndex) {
combined[i+1] = overrideTuple;
} else {
combined[i+1] = sides[i].get(indices[i]);
}
}
collector.emit(_factory.create(combined));
keepGoing = increment(sides, indices, indices.length - 1, overrideIndex);
}
}
示例13: execute
import storm.trident.operation.TridentCollector; //導入依賴的package包/類
@Override
public void execute(Map<TridentTuple, Object> state, int streamIndex, TridentTuple full, TridentCollector collector) {
ProjectionFactory groupFactory = _groupFactories.get(streamIndex);
ProjectionFactory inputFactory = _inputFactories.get(streamIndex);
TridentTuple group = groupFactory.create(full);
TridentTuple input = inputFactory.create(full);
Object curr;
if (!state.containsKey(group)) {
curr = _reducer.init(collector, group);
state.put(group, curr);
} else {
curr = state.get(group);
}
_reducer.execute(curr, streamIndex, group, input, collector);
}
示例14: aggregate
import storm.trident.operation.TridentCollector; //導入依賴的package包/類
@Override
public void aggregate(Object[] arr, TridentTuple tuple, TridentCollector collector) {
GroupCollector groupColl = (GroupCollector) arr[0];
Map<List, Object> val = (Map) arr[1];
TridentTuple group = _groupFactory.create(tuple);
TridentTuple input = _inputFactory.create(tuple);
Object curr;
if(!val.containsKey(group)) {
curr = _agg.init(arr[2], groupColl);
val.put(group, curr);
} else {
curr = val.get(group);
}
groupColl.currGroup = group;
_agg.aggregate(curr, input, groupColl);
}
示例15: updateState
import storm.trident.operation.TridentCollector; //導入依賴的package包/類
@Override
public void updateState(MapState map, List<TridentTuple> tuples, TridentCollector collector) {
List<List<Object>> groups = new ArrayList<List<Object>>(tuples.size());
List<ValueUpdater> updaters = new ArrayList<ValueUpdater>(tuples.size());
for(TridentTuple t: tuples) {
groups.add(_groupFactory.create(t));
updaters.add(new CombinerValueUpdater(_agg,_inputFactory.create(t).getValue(0)));
}
List<Object> newVals = map.multiUpdate(groups, updaters);
for(int i=0; i<tuples.size(); i++) {
List<Object> key = groups.get(i);
Object result = newVals.get(i);
collector.emit(_factory.create(new List[] {key, new Values(result) }));
}
}