当前位置: 首页>>代码示例>>Java>>正文


Java TopologyContext.getThisTaskIndex方法代码示例

本文整理汇总了Java中org.apache.storm.task.TopologyContext.getThisTaskIndex方法的典型用法代码示例。如果您正苦于以下问题:Java TopologyContext.getThisTaskIndex方法的具体用法?Java TopologyContext.getThisTaskIndex怎么用?Java TopologyContext.getThisTaskIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.storm.task.TopologyContext的用法示例。


在下文中一共展示了TopologyContext.getThisTaskIndex方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: open

import org.apache.storm.task.TopologyContext; //导入方法依赖的package包/类
@Override
public void open(final Map<String, Object> spoutConfig, final TopologyContext topologyContext) {
    // Load configuration items.

    // Determine our time bucket window, in seconds, defaulted to 60.
    int timeBucketSeconds = 60;
    if (spoutConfig.containsKey(SpoutConfig.METRICS_RECORDER_TIME_BUCKET)) {
        final Object timeBucketCfgValue = spoutConfig.get(SpoutConfig.METRICS_RECORDER_TIME_BUCKET);
        if (timeBucketCfgValue instanceof Number) {
            timeBucketSeconds = ((Number) timeBucketCfgValue).intValue();
        }
    }

    // Conditionally enable prefixing with taskId
    if (spoutConfig.containsKey(SpoutConfig.METRICS_RECORDER_ENABLE_TASK_ID_PREFIX)) {
        final Object taskIdCfgValue = spoutConfig.get(SpoutConfig.METRICS_RECORDER_ENABLE_TASK_ID_PREFIX);
        if (taskIdCfgValue instanceof Boolean && (Boolean) taskIdCfgValue) {
            this.metricPrefix = "task-" + topologyContext.getThisTaskIndex();
        }
    }

    // Log how we got configured.
    logger.info("Configured with time window of {} seconds and using taskId prefixes?: {}",
        timeBucketSeconds, Boolean.toString(metricPrefix.isEmpty()));

    // Register the top level metrics.
    assignedValues = topologyContext.registerMetric("GAUGES", new MultiAssignableMetric(), timeBucketSeconds);
    timers = topologyContext.registerMetric("TIMERS", new MultiReducedMetric(new MeanReducer()), timeBucketSeconds);
    counters = topologyContext.registerMetric("COUNTERS", new MultiCountMetric(), timeBucketSeconds);
}
 
开发者ID:salesforce,项目名称:storm-dynamic-spout,代码行数:31,代码来源:StormRecorder.java

示例2: onSpoutOpen

import org.apache.storm.task.TopologyContext; //导入方法依赖的package包/类
/**
 * Handler called when the dynamic spout opens, this method is responsible for creating and setting triggers for
 * handling the spinning up and down of sidelines.
 * @param spout Dynamic spout instance.
 * @param topologyConfig Topology configuration.
 * @param topologyContext Topology context.
 */
@Override
public void onSpoutOpen(
    final DynamicSpout spout,
    final Map topologyConfig,
    final TopologyContext topologyContext
) {
    this.spout = spout;

    createSidelineTriggers();

    Preconditions.checkArgument(
        spoutConfig.containsKey(SidelineConfig.REFRESH_INTERVAL_SECONDS)
        && spoutConfig.get(SidelineConfig.REFRESH_INTERVAL_SECONDS) != null,
        "Configuration value for " + SidelineConfig.REFRESH_INTERVAL_SECONDS + " is required."
    );

    final long refreshIntervalSeconds = ((Number) spoutConfig.get(SidelineConfig.REFRESH_INTERVAL_SECONDS)).longValue();

    final long refreshIntervalMillis = TimeUnit.SECONDS.toMillis(refreshIntervalSeconds);

    // Why not just start the timer at 0? Because we want to block onSpoutOpen() until the first run of loadSidelines()
    loadSidelines();

    // Repeat our sidelines check periodically
    final String threadName = "[" + DynamicSpout.class.getSimpleName() + ":" + getClass().getSimpleName() + "] Timer on "
        + topologyContext.getThisComponentId() + ":" + topologyContext.getThisTaskIndex();

    timer = new Timer(threadName);
    timer.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            // Catch this so that it doesn't kill the recurring task
            try {
                loadSidelines();
            } catch (Exception ex) {
                logger.error("Attempting to loadSidelines() failed {}", ex);
            }
        }
    }, refreshIntervalMillis, refreshIntervalMillis);

    for (final SidelineTrigger sidelineTrigger : sidelineTriggers) {
        sidelineTrigger.open(getSpoutConfig());
    }
}
 
开发者ID:salesforce,项目名称:storm-dynamic-spout,代码行数:52,代码来源:SidelineSpoutHandler.java

示例3: open

import org.apache.storm.task.TopologyContext; //导入方法依赖的package包/类
/**
 * Open is called once the spout instance has been deployed to the Storm cluster
 * and is ready to get to work.
 *
 * @param topologyConfig The Storm Topology configuration.
 * @param topologyContext The Storm Topology context.
 * @param spoutOutputCollector The output collector to emit tuples via.
 * @throws IllegalStateException if you attempt to open the spout multiple times.
 */
@Override
public void open(Map topologyConfig, TopologyContext topologyContext, SpoutOutputCollector spoutOutputCollector) {
    if (isOpen) {
        throw new IllegalStateException("This spout has already been opened.");
    }

    // Save references.
    this.topologyContext = topologyContext;
    this.outputCollector = spoutOutputCollector;

    // Ensure a consumer id prefix has been correctly set.
    if (Strings.isNullOrEmpty((String) getSpoutConfigItem(SpoutConfig.VIRTUAL_SPOUT_ID_PREFIX))) {
        throw new IllegalStateException("Missing required configuration: " + SpoutConfig.VIRTUAL_SPOUT_ID_PREFIX);
    }

    // We do not use the getters for things like the metricsRecorder and coordinator here
    // because each of these getters perform a check to see if the spout is open, and it's not yet until we've
    // finished setting all of these things up.

    // Initialize Metric Recorder
    this.metricsRecorder = getFactoryManager().createNewMetricsRecorder();
    this.metricsRecorder.open(getSpoutConfig(), getTopologyContext());

    // Create MessageBuffer
    final MessageBuffer messageBuffer = getFactoryManager().createNewMessageBufferInstance();
    messageBuffer.open(getSpoutConfig());

    // Create MessageBus instance and store into SpoutMessageBus reference reducing accessible scope.
    final MessageBus messageBus = new MessageBus(messageBuffer);
    this.messageBus = messageBus;

    // Define thread context, this allows us to use contextually relevant thread names.
    final ThreadContext threadContext = new ThreadContext(
        topologyContext.getThisComponentId(),
        topologyContext.getThisTaskIndex()
    );

    // Create Coordinator instance and call open.
    spoutCoordinator = new SpoutCoordinator(
        getSpoutConfig(),
        threadContext,
        messageBus,
        metricsRecorder
    );
    spoutCoordinator.open();

    // Define consumer cohort definition.
    final ConsumerPeerContext consumerPeerContext = new ConsumerPeerContext(
        topologyContext.getComponentTasks(topologyContext.getThisComponentId()).size(),
        topologyContext.getThisTaskIndex()
    );

    // TODO: This should be configurable and created dynamically, the problem is that right now we are still tightly
    // coupled to the VirtualSpout implementation.
    this.virtualSpoutFactory = new VirtualSpoutFactory(
        spoutConfig,
        consumerPeerContext,
        factoryManager,
        metricsRecorder
    );

    // Our spout is open, it's not dependent upon the handler to finish opening for us to be 'opened'
    // This is important, because if we waited most of our getters that check the opened state of the
    // spout would throw an exception and make them unusable.
    isOpen = true;

    this.spoutHandler = getFactoryManager().createSpoutHandler();
    this.spoutHandler.open(spoutConfig, virtualSpoutFactory);
    this.spoutHandler.onSpoutOpen(this, topologyConfig, topologyContext);
}
 
开发者ID:salesforce,项目名称:storm-dynamic-spout,代码行数:80,代码来源:DynamicSpout.java

示例4: prepare

import org.apache.storm.task.TopologyContext; //导入方法依赖的package包/类
@Override
public void prepare(Map conf, TopologyContext context, OutputCollector collector) {
    final int thisTaskId = context.getThisTaskIndex();
    this.outputCollector = collector;
}
 
开发者ID:DStream-Storm,项目名称:DStream,代码行数:6,代码来源:WordCounterBolt.java


注:本文中的org.apache.storm.task.TopologyContext.getThisTaskIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。