Search in sources :

Example 1 with Factory

use of storm.trident.tuple.TridentTuple.Factory in project storm by nathanmarz.

the class SubtopologyBolt method prepare.

@Override
public void prepare(Map conf, TopologyContext context, BatchOutputCollector batchCollector) {
    int thisComponentNumTasks = context.getComponentTasks(context.getThisComponentId()).size();
    for (Node n : _nodes) {
        if (n.stateInfo != null) {
            State s = n.stateInfo.spec.stateFactory.makeState(conf, context, context.getThisTaskIndex(), thisComponentNumTasks);
            context.setTaskData(n.stateInfo.id, s);
        }
    }
    DirectedSubgraph<Node, Object> subgraph = new DirectedSubgraph(_graph, _nodes, null);
    TopologicalOrderIterator it = new TopologicalOrderIterator<Node, Object>(subgraph);
    int stateIndex = 0;
    while (it.hasNext()) {
        Node n = (Node) it.next();
        if (n instanceof ProcessorNode) {
            ProcessorNode pn = (ProcessorNode) n;
            String batchGroup = _batchGroups.get(n);
            if (!_myTopologicallyOrdered.containsKey(batchGroup)) {
                _myTopologicallyOrdered.put(batchGroup, new ArrayList());
            }
            _myTopologicallyOrdered.get(batchGroup).add(pn.processor);
            List<String> parentStreams = new ArrayList();
            List<Factory> parentFactories = new ArrayList();
            for (Node p : TridentUtils.getParents(_graph, n)) {
                parentStreams.add(p.streamId);
                if (_nodes.contains(p)) {
                    parentFactories.add(_outputFactories.get(p));
                } else {
                    if (!_roots.containsKey(p.streamId)) {
                        _roots.put(p.streamId, new InitialReceiver(p.streamId, getSourceOutputFields(context, p.streamId)));
                    }
                    _roots.get(p.streamId).addReceiver(pn.processor);
                    parentFactories.add(_roots.get(p.streamId).getOutputFactory());
                }
            }
            List<TupleReceiver> targets = new ArrayList();
            boolean outgoingNode = false;
            for (Node cn : TridentUtils.getChildren(_graph, n)) {
                if (_nodes.contains(cn)) {
                    targets.add(((ProcessorNode) cn).processor);
                } else {
                    outgoingNode = true;
                }
            }
            if (outgoingNode) {
                targets.add(new BridgeReceiver(batchCollector));
            }
            TridentContext triContext = new TridentContext(pn.selfOutFields, parentFactories, parentStreams, targets, pn.streamId, stateIndex, batchCollector);
            pn.processor.prepare(conf, context, triContext);
            _outputFactories.put(n, pn.processor.getOutputFactory());
        }
        stateIndex++;
    }
// TODO: get prepared one time into executor data... need to avoid the ser/deser
// for each task (probably need storm to support boltfactory)
}
Also used : DirectedSubgraph(org.jgrapht.graph.DirectedSubgraph) ArrayList(java.util.ArrayList) TopologicalOrderIterator(org.jgrapht.traverse.TopologicalOrderIterator) Factory(storm.trident.tuple.TridentTuple.Factory) ProjectionFactory(storm.trident.tuple.TridentTupleView.ProjectionFactory) RootFactory(storm.trident.tuple.TridentTupleView.RootFactory) State(storm.trident.state.State) TridentContext(storm.trident.planner.processor.TridentContext)

Example 2 with Factory

use of storm.trident.tuple.TridentTuple.Factory in project storm by nathanmarz.

the class AggregateProcessor method prepare.

@Override
public void prepare(Map conf, TopologyContext context, TridentContext tridentContext) {
    List<Factory> parents = tridentContext.getParentTupleFactories();
    if (parents.size() != 1) {
        throw new RuntimeException("Aggregate operation can only have one parent");
    }
    _context = tridentContext;
    _collector = new FreshCollector(tridentContext);
    _projection = new ProjectionFactory(parents.get(0), _inputFields);
    _agg.prepare(conf, new TridentOperationContext(context, _projection));
}
Also used : ProjectionFactory(storm.trident.tuple.TridentTupleView.ProjectionFactory) ProjectionFactory(storm.trident.tuple.TridentTupleView.ProjectionFactory) Factory(storm.trident.tuple.TridentTuple.Factory) TridentOperationContext(storm.trident.operation.TridentOperationContext)

Example 3 with Factory

use of storm.trident.tuple.TridentTuple.Factory in project storm by nathanmarz.

the class EachProcessor method prepare.

@Override
public void prepare(Map conf, TopologyContext context, TridentContext tridentContext) {
    List<Factory> parents = tridentContext.getParentTupleFactories();
    if (parents.size() != 1) {
        throw new RuntimeException("Each operation can only have one parent");
    }
    _context = tridentContext;
    _collector = new AppendCollector(tridentContext);
    _projection = new ProjectionFactory(parents.get(0), _inputFields);
    _function.prepare(conf, new TridentOperationContext(context, _projection));
}
Also used : ProjectionFactory(storm.trident.tuple.TridentTupleView.ProjectionFactory) ProjectionFactory(storm.trident.tuple.TridentTupleView.ProjectionFactory) Factory(storm.trident.tuple.TridentTuple.Factory) TridentOperationContext(storm.trident.operation.TridentOperationContext)

Example 4 with Factory

use of storm.trident.tuple.TridentTuple.Factory in project storm by nathanmarz.

the class MultiReducerProcessor method prepare.

@Override
public void prepare(Map conf, TopologyContext context, TridentContext tridentContext) {
    List<Factory> parents = tridentContext.getParentTupleFactories();
    _context = tridentContext;
    _streamToIndex = new HashMap<String, Integer>();
    List<String> parentStreams = tridentContext.getParentStreams();
    for (int i = 0; i < parentStreams.size(); i++) {
        _streamToIndex.put(parentStreams.get(i), i);
    }
    _projectionFactories = new ProjectionFactory[_projectFields.size()];
    for (int i = 0; i < _projectFields.size(); i++) {
        _projectionFactories[i] = new ProjectionFactory(parents.get(i), _projectFields.get(i));
    }
    _collector = new FreshCollector(tridentContext);
    _reducer.prepare(conf, new TridentMultiReducerContext((List) Arrays.asList(_projectionFactories)));
}
Also used : ProjectionFactory(storm.trident.tuple.TridentTupleView.ProjectionFactory) Factory(storm.trident.tuple.TridentTuple.Factory) ProjectionFactory(storm.trident.tuple.TridentTupleView.ProjectionFactory) List(java.util.List) TridentMultiReducerContext(storm.trident.operation.TridentMultiReducerContext)

Example 5 with Factory

use of storm.trident.tuple.TridentTuple.Factory in project storm by nathanmarz.

the class PartitionPersistProcessor method prepare.

@Override
public void prepare(Map conf, TopologyContext context, TridentContext tridentContext) {
    List<Factory> parents = tridentContext.getParentTupleFactories();
    if (parents.size() != 1) {
        throw new RuntimeException("Partition persist operation can only have one parent");
    }
    _context = tridentContext;
    _state = (State) context.getTaskData(_stateId);
    _projection = new ProjectionFactory(parents.get(0), _inputFields);
    _collector = new FreshCollector(tridentContext);
    _updater.prepare(conf, new TridentOperationContext(context, _projection));
}
Also used : ProjectionFactory(storm.trident.tuple.TridentTupleView.ProjectionFactory) Factory(storm.trident.tuple.TridentTuple.Factory) ProjectionFactory(storm.trident.tuple.TridentTupleView.ProjectionFactory) TridentOperationContext(storm.trident.operation.TridentOperationContext)

Aggregations

Factory (storm.trident.tuple.TridentTuple.Factory)12 ProjectionFactory (storm.trident.tuple.TridentTupleView.ProjectionFactory)12 TridentOperationContext (storm.trident.operation.TridentOperationContext)8 List (java.util.List)2 DirectedSubgraph (org.jgrapht.graph.DirectedSubgraph)2 TopologicalOrderIterator (org.jgrapht.traverse.TopologicalOrderIterator)2 TridentMultiReducerContext (storm.trident.operation.TridentMultiReducerContext)2 TridentContext (storm.trident.planner.processor.TridentContext)2 State (storm.trident.state.State)2 RootFactory (storm.trident.tuple.TridentTupleView.RootFactory)2 ArrayList (java.util.ArrayList)1