Search in sources :

Example 41 with Tuple

use of backtype.storm.tuple.Tuple in project jstorm by alibaba.

the class SingleJoinBolt method execute.

@Override
public void execute(Tuple tuple) {
    List<Object> id = tuple.select(_idFields);
    GlobalStreamId streamId = new GlobalStreamId(tuple.getSourceComponent(), tuple.getSourceStreamId());
    if (!_pending.containsKey(id)) {
        _pending.put(id, new HashMap<GlobalStreamId, Tuple>());
    }
    Map<GlobalStreamId, Tuple> parts = _pending.get(id);
    if (parts.containsKey(streamId))
        throw new RuntimeException("Received same side of single join twice");
    parts.put(streamId, tuple);
    if (parts.size() == _numSources) {
        _pending.remove(id);
        List<Object> joinResult = new ArrayList<Object>();
        for (String outField : _outFields) {
            GlobalStreamId loc = _fieldLocations.get(outField);
            joinResult.add(parts.get(loc).getValueByField(outField));
        }
        _collector.emit(new ArrayList<Tuple>(parts.values()), joinResult);
        for (Tuple part : parts.values()) {
            _collector.ack(part);
        }
        SingleJoinTest.receiveCounter.incrementAndGet();
    }
}
Also used : GlobalStreamId(backtype.storm.generated.GlobalStreamId) ArrayList(java.util.ArrayList) Tuple(backtype.storm.tuple.Tuple)

Example 42 with Tuple

use of backtype.storm.tuple.Tuple in project heron by twitter.

the class OutputCollectorImpl method emitDirect.

@Override
public void emitDirect(int taskId, String streamId, Collection<Tuple> anchors, List<Object> tuple) {
    if (anchors != null) {
        ArrayList<com.twitter.heron.api.tuple.Tuple> l = new ArrayList<com.twitter.heron.api.tuple.Tuple>();
        for (Tuple t : anchors) {
            TupleImpl i = (TupleImpl) t;
            l.add(i.getDelegate());
        }
        delegate.emitDirect(taskId, streamId, l, tuple);
    } else {
        delegate.emitDirect(taskId, streamId, (Collection<com.twitter.heron.api.tuple.Tuple>) null, tuple);
    }
}
Also used : ArrayList(java.util.ArrayList) TupleImpl(backtype.storm.tuple.TupleImpl) Tuple(backtype.storm.tuple.Tuple)

Example 43 with Tuple

use of backtype.storm.tuple.Tuple in project heron by twitter.

the class OutputCollectorImpl method emit.

@Override
public List<Integer> emit(String streamId, Collection<Tuple> anchors, List<Object> tuple) {
    if (anchors != null) {
        ArrayList<com.twitter.heron.api.tuple.Tuple> l = new ArrayList<com.twitter.heron.api.tuple.Tuple>();
        for (Tuple t : anchors) {
            TupleImpl i = (TupleImpl) t;
            l.add(i.getDelegate());
        }
        return delegate.emit(streamId, l, tuple);
    } else {
        return delegate.emit(streamId, (Collection<com.twitter.heron.api.tuple.Tuple>) null, tuple);
    }
}
Also used : ArrayList(java.util.ArrayList) TupleImpl(backtype.storm.tuple.TupleImpl) Tuple(backtype.storm.tuple.Tuple)

Example 44 with Tuple

use of backtype.storm.tuple.Tuple in project jstorm by alibaba.

the class MergeRecord method execute.

@Override
public void execute(Tuple input) {
    tpsCounter.count();
    Long tupleId = input.getLong(0);
    Pair pair = (Pair) input.getValue(1);
    Pair trade = null;
    Pair customer = null;
    Tuple tradeTuple = null;
    Tuple customerTuple = null;
    if (input.getSourceComponent().equals(SequenceTopologyDef.CUSTOMER_BOLT_NAME)) {
        customer = pair;
        customerTuple = input;
        tradeTuple = tradeMap.remove(tupleId);
        if (tradeTuple == null) {
            customerMap.put(tupleId, input);
            return;
        }
        trade = (Pair) tradeTuple.getValue(1);
    } else if (input.getSourceComponent().equals(SequenceTopologyDef.TRADE_BOLT_NAME)) {
        trade = pair;
        tradeTuple = input;
        customerTuple = customerMap.remove(tupleId);
        if (customerTuple == null) {
            tradeMap.put(tupleId, input);
            return;
        }
        customer = (Pair) customerTuple.getValue(1);
    } else {
        LOG.info("Unknow source component: " + input.getSourceComponent());
        collector.fail(input);
        return;
    }
    tradeSum.addAndGet(trade.getValue());
    customerSum.addAndGet(customer.getValue());
    collector.ack(tradeTuple);
    collector.ack(customerTuple);
    TradeCustomer tradeCustomer = new TradeCustomer();
    tradeCustomer.setTrade(trade);
    tradeCustomer.setCustomer(customer);
    collector.emit(new Values(tupleId, tradeCustomer));
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) Values(backtype.storm.tuple.Values) Tuple(backtype.storm.tuple.Tuple) Pair(com.alipay.dw.jstorm.example.sequence.bean.Pair) TradeCustomer(com.alipay.dw.jstorm.example.sequence.bean.TradeCustomer)

Example 45 with Tuple

use of backtype.storm.tuple.Tuple in project jstorm by alibaba.

the class SlidingWindowSumBolt method execute.

@Override
public void execute(TupleWindow inputWindow) {
    /*
         * The inputWindow gives a view of (a) all the events in the window (b)
         * events that expired since last activation of the window (c) events
         * that newly arrived since last activation of the window
         */
    List<Tuple> tuplesInWindow = inputWindow.get();
    List<Tuple> newTuples = inputWindow.getNew();
    List<Tuple> expiredTuples = inputWindow.getExpired();
    LOG.debug("Events in current window: " + tuplesInWindow.size());
    /*
         * Instead of iterating over all the tuples in the window to compute the
         * sum, the values for the new events are added and old events are
         * subtracted. Similar optimizations might be possible in other
         * windowing computations.
         */
    for (Tuple tuple : newTuples) {
        sum += (int) tuple.getValue(0);
    }
    for (Tuple tuple : expiredTuples) {
        sum -= (int) tuple.getValue(0);
    }
    collector.emit(new Values(sum));
}
Also used : Values(backtype.storm.tuple.Values) Tuple(backtype.storm.tuple.Tuple)

Aggregations

Tuple (backtype.storm.tuple.Tuple)49 Values (backtype.storm.tuple.Values)11 ArrayList (java.util.ArrayList)10 MessageId (backtype.storm.tuple.MessageId)5 List (java.util.List)5 Test (org.testng.annotations.Test)5 Message (com.yahoo.pulsar.client.api.Message)4 TupleImpl (backtype.storm.tuple.TupleImpl)3 TupleImplExt (backtype.storm.tuple.TupleImplExt)3 Pair (com.alibaba.jstorm.utils.Pair)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 GlobalStreamId (backtype.storm.generated.GlobalStreamId)2 FailedException (backtype.storm.topology.FailedException)2 TupleExt (backtype.storm.tuple.TupleExt)2 TimerTrigger (com.alibaba.jstorm.daemon.worker.timer.TimerTrigger)2 TopoMasterCtrlEvent (com.alibaba.jstorm.task.master.ctrlevent.TopoMasterCtrlEvent)2 RotatingMap (com.alibaba.jstorm.utils.RotatingMap)2 Pair (com.alipay.dw.jstorm.example.sequence.bean.Pair)2 TradeCustomer (com.alipay.dw.jstorm.example.sequence.bean.TradeCustomer)2