本文整理汇总了Java中storm.trident.tuple.TridentTuple类的典型用法代码示例。如果您正苦于以下问题:Java TridentTuple类的具体用法?Java TridentTuple怎么用?Java TridentTuple使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TridentTuple类属于storm.trident.tuple包,在下文中一共展示了TridentTuple类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateState
import storm.trident.tuple.TridentTuple; //导入依赖的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: execute
import storm.trident.tuple.TridentTuple; //导入依赖的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));
}
示例3: execute
import storm.trident.tuple.TridentTuple; //导入依赖的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));
}
}
示例4: execute
import storm.trident.tuple.TridentTuple; //导入依赖的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"));
}
}
}
示例5: execute
import storm.trident.tuple.TridentTuple; //导入依赖的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));
}
}
示例6: updateState
import storm.trident.tuple.TridentTuple; //导入依赖的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);
}
}
示例7: updateState
import storm.trident.tuple.TridentTuple; //导入依赖的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);
}
}
示例8: isKeep
import storm.trident.tuple.TridentTuple; //导入依赖的package包/类
@Override
public boolean isKeep(TridentTuple tuple) {
String mac = tuple.getStringByField("src_mac");
boolean status = true;
if(mac!=null) {
String macSplit[] = mac.split(":");
String macHex = macSplit[0];
// if (_debug)
// System.out.println("HEX: " + macHex);
String binary = hexToBin(macHex);
if (binary.endsWith("10") || binary.endsWith("11"))
status = false;
// if (_debug) {
// System.out.println("BIN: " + binary);
// System.out.println("TRUE/FALSE: " + status);
// }
}
return status;
}
示例9: execute
import storm.trident.tuple.TridentTuple; //导入依赖的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.tuple.TridentTuple; //导入依赖的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: batchRetrieve
import storm.trident.tuple.TridentTuple; //导入依赖的package包/类
public List<List<Values>> batchRetrieve(List<TridentTuple> tridentTuples) {
List<List<Values>> batchRetrieveResult = Lists.newArrayList();
List<Get> gets = Lists.newArrayList();
for (TridentTuple tuple : tridentTuples) {
byte[] rowKey = options.mapper.rowKey(tuple);
gets.add(hBaseClient.constructGetRequests(rowKey, options.projectionCriteria));
}
try {
Result[] results = hBaseClient.batchGet(gets);
for(Result result : results) {
List<Values> values = options.rowToStormValueMapper.toValues(result);
batchRetrieveResult.add(values);
}
} catch (Exception e) {
LOG.warn("Batch get operation failed. Triggering replay.", e);
throw new FailedException(e);
}
return batchRetrieveResult;
}
示例12: finishBatch
import storm.trident.tuple.TridentTuple; //导入依赖的package包/类
@Override
public void finishBatch(ProcessorContext processorContext) {
BatchState state = (BatchState) processorContext.state[_context.getStateIndex()];
if (!state.tuples.isEmpty()) {
List<Object> results = _function.batchRetrieve(_state, state.args);
if (results.size() != state.tuples.size()) {
throw new RuntimeException("Results size is different than argument size: " + results.size() + " vs " + state.tuples.size());
}
for (int i = 0; i < state.tuples.size(); i++) {
TridentTuple tuple = state.tuples.get(i);
Object result = results.get(i);
_collector.setContext(processorContext, tuple);
_function.execute(_projection.create(tuple), result, _collector);
}
}
}
示例13: execute
import storm.trident.tuple.TridentTuple; //导入依赖的package包/类
@Override
public void execute(TridentTuple tridentTuple, TridentCollector tridentCollector) {
String url = tridentTuple.getString(0);
Readability readability = null;
Integer timeoutMillis = 5000;
try {
readability = new Readability(new URL(url), timeoutMillis); // URL
readability.init();
} catch (Exception e) {
System.out.println(e.getMessage());
return;
}
String webPageString = readability.content; //readability.outerHtml();
String webPageTitle = readability.title;
String hrefString = readability.hrefString.toString();
//System.out.println("GetAdFreeWebPage: hrefString: \""+ hrefString+"\"");
tridentCollector.emit(new Values(webPageString, webPageTitle, hrefString));
}
示例14: execute
import storm.trident.tuple.TridentTuple; //导入依赖的package包/类
@Override
public void execute(TridentTuple tridentTuple, TridentCollector tridentCollector) {
String hrefList = tridentTuple.getString(0);
Integer depth = Integer.parseInt(tridentTuple.getString(1));
if(hrefList == null || hrefList.trim().length() == 0 || depth == 0)
return;
depth--;
// System.out.println("PrepareHrefKafka: \""+hrefList+"\"");
String[] hrefArray = hrefList.split(" ");
for(String href : hrefArray) {
tridentCollector.emit(new Values(href, depth.toString()));
}
}
示例15: finishBatch
import storm.trident.tuple.TridentTuple; //导入依赖的package包/类
@Override
public void finishBatch(ProcessorContext processorContext) {
BatchState state = (BatchState) processorContext.state[_context.getStateIndex()];
if(!state.tuples.isEmpty()) {
List<Object> results = _function.batchRetrieve(_state, state.args);
if(results.size()!=state.tuples.size()) {
throw new RuntimeException("Results size is different than argument size: " + results.size() + " vs " + state.tuples.size());
}
for(int i=0; i<state.tuples.size(); i++) {
TridentTuple tuple = state.tuples.get(i);
Object result = results.get(i);
_collector.setContext(processorContext, tuple);
_function.execute(_projection.create(tuple), result, _collector);
}
}
}