本文整理匯總了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);
}