本文整理汇总了Java中backtype.storm.task.TopologyContext类的典型用法代码示例。如果您正苦于以下问题:Java TopologyContext类的具体用法?Java TopologyContext怎么用?Java TopologyContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TopologyContext类属于backtype.storm.task包,在下文中一共展示了TopologyContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: prepare
import backtype.storm.task.TopologyContext; //导入依赖的package包/类
@Override
public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
//for backward compatibility.
if(mapper == null) {
this.mapper = new FieldNameBasedTupleToKafkaMapper<K,V>();
}
//for backward compatibility.
if(topicSelector == null) {
this.topicSelector = new DefaultTopicSelector((String) stormConf.get(TOPIC));
}
Map configMap = (Map) stormConf.get(KAFKA_BROKER_PROPERTIES);
Properties properties = new Properties();
properties.putAll(configMap);
ProducerConfig config = new ProducerConfig(properties);
producer = new Producer<K, V>(config);
this.collector = collector;
}
示例2: prepare
import backtype.storm.task.TopologyContext; //导入依赖的package包/类
@Override
public void prepare(Map map, Object conf, TopologyContext topologyContext, IErrorReporter iErrorReporter) {
Map<String, Object> config = (Map<String, Object>) conf;
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
client = CuratorFrameworkFactory.newClient(config.get("zookeeper").toString(), retryPolicy);
client.start();
try {
if (client.checkExists().forPath("/consumers/rb-storm") == null) {
client.create().creatingParentsIfNeeded().forPath("/consumers/rb-storm");
System.out.println("Creating /consumers/rb-storm path ...");
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例3: prepare
import backtype.storm.task.TopologyContext; //导入依赖的package包/类
@Override
public void prepare(Map stormConf, Object registrationArgument, TopologyContext context,
final IErrorReporter errorReporter) {
LOG.info("Initializing the " + getClass().getCanonicalName());
this.graphitePath = getConfiguredGraphitBasePath(stormConf);
if (!stormConf.containsKey(CONF_MONITORING_GRAPHITE_SERVER)) {
throw new RuntimeException("Missing graphite configuration. You need to specify the server and the port" +
"under which the graphite server can be reached. Example: " + CONF_MONITORING_GRAPHITE_SERVER
+ "=graphite.yourdomain.com:2003");
}
this.graphiteConnection = (String) stormConf.get(CONF_MONITORING_GRAPHITE_SERVER);
getGraphiteWriter();
this.metricsToProcess = new HashMap<>();
this.metricsToProcess.put(MonitoringMetricsCollectionHook.METRIC_COMPLETE_LATENCY, new AverageAggregator());
this.metricsToProcess.put(MonitoringMetricsCollectionHook.METRIC_THROUGHPUT, new SumAggregator());
this.metricsToProcess.put(MonitoringMetricsCollectionHook.METRIC_WORKER_CPU_LOAD, new SumAggregator());
this.metricsToProcess.put(MonitoringMetricsCollectionHook.METRIC_WORKER_NETWORK_BYTES, new SumAggregator());
}
示例4: prepare
import backtype.storm.task.TopologyContext; //导入依赖的package包/类
public void prepare(Map map, TopologyContext topologyContext, OutputCollector collector) {
this.collector = collector;
final Configuration hbConfig = HBaseConfiguration.create();
Map<String, Object> conf = (Map<String, Object>)map.get(this.configKey);
if(conf == null) {
throw new IllegalArgumentException("HBase configuration not found using key '" + this.configKey + "'");
}
if(conf.get("hbase.rootdir") == null) {
LOG.warn("No 'hbase.rootdir' value found in configuration! Using HBase defaults.");
}
for(String key : conf.keySet()) {
hbConfig.set(key, String.valueOf(conf.get(key)));
}
this.hBaseClient = new HBaseClient(conf, hbConfig, tableName);
}
示例5: prepare
import backtype.storm.task.TopologyContext; //导入依赖的package包/类
@Override
public void prepare(Map stormConf, TopologyContext context) {
mapper = new ObjectMapper();
this.configParams = (JSONObject) new JSONObject(this.config).get("params");
try {
this.configMap = mapper.readValue(this.config,new TypeReference<Map<String, Object>>() {});
mapParams = (Map<String,Object>) configMap.get("params");
} catch (IOException e) {
e.printStackTrace();
}
field = getParam("field1", true);
operator = getParam("operator", true);
field2 = getParam("field2", true);
entity = getParam("entity");
}
示例6: prepare
import backtype.storm.task.TopologyContext; //导入依赖的package包/类
@Override
public void prepare(Map stormConf, TopologyContext context) {
mapper = new ObjectMapper();
this.configParams = (JSONObject) new JSONObject(this.config).get("params");
try {
this.configMap = mapper.readValue(this.config,new TypeReference<Map<String, Object>>() {});
mapParams = (Map<String,Object>) configMap.get("params");
} catch (IOException e) {
e.printStackTrace();
}
field = getParam("field", true);
operator = (String) getParam("operator", true);
value = (String) getParam("value", true);
entity = (String) getParam("value");
if (operator.equals("RegexExpression")) {
pattern = Pattern.compile(value, Pattern.DOTALL);
}
}
示例7: open
import backtype.storm.task.TopologyContext; //导入依赖的package包/类
public void open(Map conf, TopologyContext ctx, SpoutOutputCollector collector) {
this.collector = collector;
this.history = new ProcessedHistory();
this.subreddit = (String) conf.get("subreddit");
try {
this.subredditCommentsfeedURL = new URL((String)conf.get("feedURL"));
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
LOG.info("Spout subreddit:{} feedURL:{}", this.subreddit, this.subredditCommentsfeedURL);
if (conf.containsKey("sentimentData")) {
LOG.info("Spouts can also see sentimentData");
}
}
示例8: prepare
import backtype.storm.task.TopologyContext; //导入依赖的package包/类
public void prepare(Map conf, TopologyContext ctx, OutputCollector collector) {
this.collector = collector;
this.myId = ctx.getThisComponentId() + "-" + ctx.getThisTaskId();
this.summary = new Summary();
this.publisher = new ZkPublisher();
try {
this.publisher.init(conf);
} catch (Exception e) {
throw new RuntimeException(e);
}
this.lastPublishedTimestamp = 0;
}
示例9: open
import backtype.storm.task.TopologyContext; //导入依赖的package包/类
/**
* Open file with stock tick data and read into List object.
*/
@Override
public void open(Map map,
TopologyContext context,
SpoutOutputCollector outputCollector) {
this.outputCollector = outputCollector;
try {
ticks =
IOUtils.readLines(ClassLoader.getSystemResourceAsStream(
"NASDAQ_daily_prices_A.csv"),
Charset.defaultCharset().name());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例10: open
import backtype.storm.task.TopologyContext; //导入依赖的package包/类
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
try {
_collector = collector;
ru = new RedisUtil();
redis = ru.getJedisInstance();
SchedulerFactory schedulerFactory = new StdSchedulerFactory();
Scheduler scheduler = schedulerFactory.getScheduler();
_qManager = new QuartzManager();
_qManager.setScheduler(scheduler);
PlatformUtils.initRegisterProject(_qManager);
scheduler.start();
//init Hbase tables
CreateTable.initHbaseTable();
}catch(Exception ex){
logger.error("error:"+MySysLogger.formatException(ex));
ex.printStackTrace();
}
}
示例11: open
import backtype.storm.task.TopologyContext; //导入依赖的package包/类
public void open(Map conf, TopologyContext context,
SpoutOutputCollector collector) {
queue = new LinkedBlockingQueue<String>(1000);
this.collector = collector;
StatusListener listener = new StatusListener() {
public void onStatus(Status status) {
queue.offer(TwitterObjectFactory.getRawJSON(status));
}
public void onDeletionNotice(StatusDeletionNotice sdn) { }
public void onTrackLimitationNotice(int i) { }
public void onScrubGeo(long l, long l1) { }
public void onStallWarning(StallWarning stallWarning) { }
public void onException(Exception e) { }
};
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setJSONStoreEnabled(true);
TwitterStreamFactory factory = new TwitterStreamFactory(cb.build());
twitterStream = factory.getInstance();
twitterStream.addListener(listener);
twitterStream.filter(new FilterQuery().language("en").track("trump"));
}
示例12: open
import backtype.storm.task.TopologyContext; //导入依赖的package包/类
@Override
public void open(Map arg0, TopologyContext arg1, SpoutOutputCollector arg2) {
/*
* FileReader fileReader; try { fileReader = new
* FileReader("C:/proj/Migration/apache-storm-0.9.4/apache-storm-0.9.4/logs/InPut.txt");
* bufferedReader =new BufferedReader(fileReader); _collector= arg2; } catch
* (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); }
*/
try {
_collector = arg2;
setUpConnection();
} catch (JMSException e) {
LOGGER.error(e);
}
}
示例13: open
import backtype.storm.task.TopologyContext; //导入依赖的package包/类
@Override
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
//fileName = (String) conf.get("file");
this.collector = collector;
try {
reader = new BufferedReader(new FileReader(fileName));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例14: TridentKafkaEmitter
import backtype.storm.task.TopologyContext; //导入依赖的package包/类
public TridentKafkaEmitter(Map conf, TopologyContext context, TridentKafkaConfig config, String topologyInstanceId) {
_config = config;
_topologyInstanceId = topologyInstanceId;
_connections = new DynamicPartitionConnections(_config, KafkaUtils.makeBrokerReader(conf, _config));
_topologyName = (String) conf.get(Config.TOPOLOGY_NAME);
_kafkaOffsetMetric = new KafkaUtils.KafkaOffsetMetric(_config.topic, _connections);
context.registerMetric("kafkaOffset", _kafkaOffsetMetric, _config.metricsTimeBucketSizeInSecs);
_kafkaMeanFetchLatencyMetric = context.registerMetric("kafkaFetchAvg", new MeanReducer(), _config.metricsTimeBucketSizeInSecs);
_kafkaMaxFetchLatencyMetric = context.registerMetric("kafkaFetchMax", new MaxMetric(), _config.metricsTimeBucketSizeInSecs);
}
示例15: prepare
import backtype.storm.task.TopologyContext; //导入依赖的package包/类
@Override
public void prepare(Map stormConf,
Object registrationArgument,
TopologyContext context,
IErrorReporter errorReporter) {
this.stormId = context.getStormId();
this.extemptMetrics = new HashSet<>();
this.extemptMetrics.add(SchedulingMetricsCollectionHook.METRIC_EMITTED_MESSAGES);
}