Search in sources :

Example 1 with OutputCollector

use of backtype.storm.task.OutputCollector in project storm by nathanmarz.

the class TridentBoltExecutor method prepare.

@Override
public void prepare(Map conf, TopologyContext context, OutputCollector collector) {
    _messageTimeoutMs = context.maxTopologyMessageTimeout() * 1000L;
    _lastRotate = System.currentTimeMillis();
    _batches = new RotatingMap(2);
    _context = context;
    _collector = collector;
    _coordCollector = new CoordinatedOutputCollector(collector);
    _coordOutputCollector = new BatchOutputCollectorImpl(new OutputCollector(_coordCollector));
    _coordConditions = (Map) context.getExecutorData("__coordConditions");
    if (_coordConditions == null) {
        _coordConditions = new HashMap();
        for (String batchGroup : _coordSpecs.keySet()) {
            CoordSpec spec = _coordSpecs.get(batchGroup);
            CoordCondition cond = new CoordCondition();
            cond.commitStream = spec.commitStream;
            cond.expectedTaskReports = 0;
            for (String comp : spec.coords.keySet()) {
                CoordType ct = spec.coords.get(comp);
                if (ct.equals(CoordType.single())) {
                    cond.expectedTaskReports += 1;
                } else {
                    cond.expectedTaskReports += context.getComponentTasks(comp).size();
                }
            }
            cond.targetTasks = new HashSet<Integer>();
            for (String component : Utils.get(context.getThisTargets(), COORD_STREAM(batchGroup), new HashMap<String, Grouping>()).keySet()) {
                cond.targetTasks.addAll(context.getComponentTasks(component));
            }
            _coordConditions.put(batchGroup, cond);
        }
        context.setExecutorData("_coordConditions", _coordConditions);
    }
    _bolt.prepare(conf, context, _coordOutputCollector);
}
Also used : BatchOutputCollector(backtype.storm.coordination.BatchOutputCollector) IOutputCollector(backtype.storm.task.IOutputCollector) OutputCollector(backtype.storm.task.OutputCollector) HashMap(java.util.HashMap) BatchOutputCollectorImpl(backtype.storm.coordination.BatchOutputCollectorImpl) RotatingMap(backtype.storm.utils.RotatingMap)

Example 2 with OutputCollector

use of backtype.storm.task.OutputCollector in project jstorm by alibaba.

the class CoordinatedBolt method prepare.

public void prepare(Map config, TopologyContext context, OutputCollector collector) {
    TimeCacheMap.ExpiredCallback<Object, TrackingInfo> callback = null;
    if (_delegate instanceof TimeoutCallback) {
        callback = new TimeoutItems();
    }
    _tracked = new TimeCacheMap<Object, TrackingInfo>(context.maxTopologyMessageTimeout(), callback);
    _collector = collector;
    _delegate.prepare(config, context, new OutputCollector(new CoordinatedOutputCollector(collector)));
    for (String component : Utils.get(context.getThisTargets(), Constants.COORDINATED_STREAM_ID, new HashMap<String, Grouping>()).keySet()) {
        for (Integer task : context.getComponentTasks(component)) {
            _countOutTasks.add(task);
        }
    }
    if (!_sourceArgs.isEmpty()) {
        _numSourceReports = 0;
        for (Entry<String, SourceArgs> entry : _sourceArgs.entrySet()) {
            if (entry.getValue().singleCount) {
                _numSourceReports += 1;
            } else {
                _numSourceReports += context.getComponentTasks(entry.getKey()).size();
            }
        }
    }
}
Also used : IOutputCollector(backtype.storm.task.IOutputCollector) OutputCollector(backtype.storm.task.OutputCollector) HashMap(java.util.HashMap) TimeCacheMap(backtype.storm.utils.TimeCacheMap)

Example 3 with OutputCollector

use of backtype.storm.task.OutputCollector in project jstorm by alibaba.

the class TransactionBolt method prepare.

@Override
public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
    this.conf = stormConf;
    this.topologyContext = context;
    this.topologyId = topologyContext.getTopologyId();
    this.taskId = topologyContext.getThisTaskId();
    this.componentId = topologyContext.getThisComponentId();
    this.upstreamTasks = TransactionCommon.getUpstreamTasks(componentId, topologyContext);
    this.downstreamTasks = TransactionCommon.getDownstreamTasks(componentId, topologyContext);
    this.topologyMasterId = context.getTopologyMasterId();
    LOG.info("TransactionBolt: upstreamTasks=" + upstreamTasks + ", downstreamTasks=" + downstreamTasks);
    this.outputCollector = new TransactionOutputCollector(this, collector);
    this.boltExecutor.prepare(conf, context, new OutputCollector(outputCollector));
    this.boltStatus = State.INIT;
    if (sysTopology == null) {
        try {
            sysTopology = Common.system_topology(stormConf, context.getRawTopology());
        } catch (InvalidTopologyException e) {
            LOG.error("Failed to build system topology", e);
            throw new RuntimeException(e);
        }
    }
    this.lastSuccessfulBatch = new ConcurrentHashMap<Integer, Long>();
    this.processingBatches = new HashMap<Integer, Map<Long, BatchTracker>>();
    Set<String> upstreamSpoutNames = TransactionCommon.getUpstreamSpouts(componentId, topologyContext);
    for (String spoutName : upstreamSpoutNames) {
        int groupId = TransactionCommon.groupIndex(topologyContext.getRawTopology(), spoutName);
        lastSuccessfulBatch.put(groupId, TransactionCommon.INIT_BATCH_ID);
        processingBatches.put(groupId, new HashMap<Long, BatchTracker>());
    }
    this.batchCache = new BatchCache(context, upstreamSpoutNames, sysTopology);
    this.kryoInput = new Input(1);
    this.streamIds = new SerializationFactory.IdDictionary(sysTopology);
    this.inputStreamIds = new HashSet<Integer>();
    Set<GlobalStreamId> inputs = topologyContext.getThisSources().keySet();
    for (GlobalStreamId stream : inputs) {
        inputStreamIds.add(streamIds.getStreamId(stream.get_componentId(), stream.get_streamId()));
    }
    for (String upstreamComponentId : TransactionCommon.getUpstreamComponents(componentId, topologyContext)) {
        inputStreamIds.add(streamIds.getStreamId(upstreamComponentId, TransactionCommon.BARRIER_STREAM_ID));
    }
    //LOG.info("Stream info prepare: streamIds={}, inputStreams={}, inputStreamIds={}", streamIds, inputs, inputStreamIds);
    startInitState();
}
Also used : OutputCollector(backtype.storm.task.OutputCollector) InvalidTopologyException(backtype.storm.generated.InvalidTopologyException) SerializationFactory(backtype.storm.serialization.SerializationFactory) BatchCache(com.alibaba.jstorm.transactional.BatchCache) Input(com.esotericsoftware.kryo.io.Input) GlobalStreamId(backtype.storm.generated.GlobalStreamId) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 4 with OutputCollector

use of backtype.storm.task.OutputCollector in project pulsar by yahoo.

the class PulsarBoltTest method testSharedProducer.

@Test
public void testSharedProducer() throws Exception {
    PersistentTopicStats topicStats = admin.persistentTopics().getStats(topic);
    Assert.assertEquals(topicStats.publishers.size(), 1);
    PulsarBolt otherBolt = new PulsarBolt(pulsarBoltConf, new ClientConfiguration());
    MockOutputCollector otherMockCollector = new MockOutputCollector();
    OutputCollector collector = new OutputCollector(otherMockCollector);
    TopologyContext context = mock(TopologyContext.class);
    when(context.getThisComponentId()).thenReturn("test-bolt-" + methodName);
    when(context.getThisTaskId()).thenReturn(1);
    otherBolt.prepare(Maps.newHashMap(), context, collector);
    topicStats = admin.persistentTopics().getStats(topic);
    Assert.assertEquals(topicStats.publishers.size(), 1);
    otherBolt.close();
    topicStats = admin.persistentTopics().getStats(topic);
    Assert.assertEquals(topicStats.publishers.size(), 1);
}
Also used : OutputCollector(backtype.storm.task.OutputCollector) PersistentTopicStats(com.yahoo.pulsar.common.policies.data.PersistentTopicStats) TopologyContext(backtype.storm.task.TopologyContext) ClientConfiguration(com.yahoo.pulsar.client.api.ClientConfiguration) Test(org.testng.annotations.Test)

Example 5 with OutputCollector

use of backtype.storm.task.OutputCollector in project jstorm by alibaba.

the class TridentBoltExecutor method prepare.

@Override
public void prepare(Map conf, TopologyContext context, OutputCollector collector) {
    _messageTimeoutMs = context.maxTopologyMessageTimeout() * 1000L;
    _lastRotate = System.currentTimeMillis();
    _batches = new RotatingMap<>(2);
    _context = context;
    _collector = collector;
    _coordCollector = new CoordinatedOutputCollector(new OutputCollector(collector));
    _coordOutputCollector = new BatchOutputCollectorImpl(new OutputCollector(_coordCollector));
    _coordConditions = (Map) context.getExecutorData("__coordConditions");
    if (_coordConditions == null) {
        _coordConditions = new HashMap<>();
        for (String batchGroup : _coordSpecs.keySet()) {
            CoordSpec spec = _coordSpecs.get(batchGroup);
            CoordCondition cond = new CoordCondition();
            cond.commitStream = spec.commitStream;
            cond.expectedTaskReports = 0;
            for (String comp : spec.coords.keySet()) {
                CoordType ct = spec.coords.get(comp);
                if (ct.equals(CoordType.single())) {
                    cond.expectedTaskReports += 1;
                } else {
                    cond.expectedTaskReports += context.getComponentTasks(comp).size();
                }
            }
            cond.targetTasks = new HashSet<>();
            for (String component : Utils.get(context.getThisTargets(), COORD_STREAM(batchGroup), new HashMap<String, Grouping>()).keySet()) {
                cond.targetTasks.addAll(context.getComponentTasks(component));
            }
            _coordConditions.put(batchGroup, cond);
        }
        context.setExecutorData("_coordConditions", _coordConditions);
    }
    _bolt.prepare(conf, context, _coordOutputCollector);
}
Also used : OutputCollector(backtype.storm.task.OutputCollector) BatchOutputCollector(backtype.storm.coordination.BatchOutputCollector) IOutputCollector(backtype.storm.task.IOutputCollector) BatchOutputCollectorImpl(backtype.storm.coordination.BatchOutputCollectorImpl)

Aggregations

OutputCollector (backtype.storm.task.OutputCollector)7 IOutputCollector (backtype.storm.task.IOutputCollector)4 HashMap (java.util.HashMap)4 BatchOutputCollector (backtype.storm.coordination.BatchOutputCollector)2 BatchOutputCollectorImpl (backtype.storm.coordination.BatchOutputCollectorImpl)2 TopologyContext (backtype.storm.task.TopologyContext)2 TimeCacheMap (backtype.storm.utils.TimeCacheMap)2 ClientConfiguration (com.yahoo.pulsar.client.api.ClientConfiguration)2 GlobalStreamId (backtype.storm.generated.GlobalStreamId)1 InvalidTopologyException (backtype.storm.generated.InvalidTopologyException)1 SerializationFactory (backtype.storm.serialization.SerializationFactory)1 RotatingMap (backtype.storm.utils.RotatingMap)1 BatchCache (com.alibaba.jstorm.transactional.BatchCache)1 Input (com.esotericsoftware.kryo.io.Input)1 PersistentTopicStats (com.yahoo.pulsar.common.policies.data.PersistentTopicStats)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Test (org.testng.annotations.Test)1