本文整理汇总了Java中backtype.storm.task.TopologyContext.getThisTaskIndex方法的典型用法代码示例。如果您正苦于以下问题:Java TopologyContext.getThisTaskIndex方法的具体用法?Java TopologyContext.getThisTaskIndex怎么用?Java TopologyContext.getThisTaskIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类backtype.storm.task.TopologyContext
的用法示例。
在下文中一共展示了TopologyContext.getThisTaskIndex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: open
import backtype.storm.task.TopologyContext; //导入方法依赖的package包/类
@Override
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
MessageDigest md;
int counter;
this.thisTaskIndex = context.getThisTaskIndex();
this.numSpouts = context.getComponentTasks(context.getThisComponentId()).size();
counter = 0;
try {
md = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("Couldn't find MD5 algorithm.", e);
}
// we want to create a message that hashes to exacly one of the following spouts. As there are the same number
// of bolts on each level as there are spouts, we just keep looking until we find a uuid whose hash code would
// be assigned to the id of this spout (if it were a bolt).
do {
if (++counter > 1000 * 1000) {
throw new RuntimeException("Unable to generate required UUID in 1 mio tries.");
}
byte[] bytes = md.digest(UUID.randomUUID().toString().getBytes());
this.uuid = new String(bytes);
} while (this.uuid.hashCode() % this.numSpouts != this.thisTaskIndex);
this.collector = collector;
if (!this.disableAniello) {
// this will create/configure the worker monitor once per worker
WorkerMonitor.getInstance().setContextInfo(context);
// this object is used in the emit/execute method to compute the number of inter-node messages
this.taskMonitor = new TaskMonitor(context.getThisTaskId());
}
}
示例2: open
import backtype.storm.task.TopologyContext; //导入方法依赖的package包/类
@Override
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
this.collector = collector;
LinkedHashMap copy = new LinkedHashMap(conf);
copy.putAll(spoutConfig);
StormSettings settings = new StormSettings(copy);
InitializationUtils.setValueReaderIfNotSet(settings, JdkValueReader.class, log);
ackReads = settings.getStormSpoutReliable();
if (ackReads) {
inTransitQueue = new LinkedHashMap<Object, Object>();
replayQueue = new LinkedList<Object[]>();
retries = new HashMap<Object, Integer>();
queueSize = settings.getStormSpoutReliableQueueSize();
tupleRetries = settings.getStormSpoutReliableRetriesPerTuple();
tupleFailure = settings.getStormSpoutReliableTupleFailureHandling();
}
int totalTasks = context.getComponentTasks(context.getThisComponentId()).size();
int currentTask = context.getThisTaskIndex();
// match the partitions based on the current topology
List<PartitionDefinition> partitions = RestService.findPartitions(settings, log);
List<PartitionDefinition> assigned = RestService.assignPartitions(partitions, currentTask, totalTasks);
iterator = RestService.multiReader(settings, assigned, log);
}