Search in sources :

Example 1 with Pair

use of com.alipay.dw.jstorm.example.sequence.bean.Pair in project jstorm by alibaba.

the class SequenceTestSpout method emit.

public void emit() {
    emitCounter.inc();
    Pair trade = PairMaker.makeTradeInstance();
    Pair customer = PairMaker.makeCustomerInstance();
    TradeCustomer tradeCustomer = new TradeCustomer();
    tradeCustomer.setTrade(trade);
    tradeCustomer.setCustomer(customer);
    tradeCustomer.setBuffer(null);
    tradeSumCounter.update(trade.getValue());
    customerSumCounter.update(customer.getValue());
    collector.emit(new Values(idGenerator.nextLong(), tradeCustomer), tupleId);
    tupleId++;
    handleCounter.incrementAndGet();
    while (handleCounter.get() >= MAX_PENDING_COUNTER - 1) {
        JStormUtils.sleepMs(1);
    }
}
Also used : Values(backtype.storm.tuple.Values) Pair(com.alipay.dw.jstorm.example.sequence.bean.Pair) TradeCustomer(com.alipay.dw.jstorm.example.sequence.bean.TradeCustomer)

Example 2 with Pair

use of com.alipay.dw.jstorm.example.sequence.bean.Pair in project jstorm by alibaba.

the class PairSerializer method read.

@Override
public Pair read(Kryo kryo, Input input, Class<Pair> arg2) {
    long value = input.readLong();
    String key = input.readString();
    Pair inner = new Pair();
    inner.setKey(key);
    inner.setValue(value);
    return inner;
}
Also used : Pair(com.alipay.dw.jstorm.example.sequence.bean.Pair)

Example 3 with Pair

use of com.alipay.dw.jstorm.example.sequence.bean.Pair in project jstorm by alibaba.

the class TradeCustomerSerializer method read.

@Override
public TradeCustomer read(Kryo kryo, Input input, Class<TradeCustomer> arg2) {
    Pair custormer = kryo.readObject(input, Pair.class);
    Pair trade = kryo.readObject(input, Pair.class);
    long timeStamp = input.readLong();
    String buffer = input.readString();
    TradeCustomer inner = new TradeCustomer(timeStamp, trade, custormer, buffer);
    return inner;
}
Also used : Pair(com.alipay.dw.jstorm.example.sequence.bean.Pair) TradeCustomer(com.alipay.dw.jstorm.example.sequence.bean.TradeCustomer)

Example 4 with Pair

use of com.alipay.dw.jstorm.example.sequence.bean.Pair in project jstorm by alibaba.

the class SequenceTestMergeRecord method execute.

@Override
public void execute(Tuple input) {
    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 {
        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));
    emitCounter.inc();
}
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 5 with Pair

use of com.alipay.dw.jstorm.example.sequence.bean.Pair in project jstorm by alibaba.

the class PairCount method execute.

public void execute(Tuple tuple, BasicOutputCollector collector) {
    tpsCounter.count();
    Long tupleId = tuple.getLong(0);
    Pair pair = (Pair) tuple.getValue(1);
    sum.addAndGet(pair.getValue());
    collector.emit(new Values(tupleId, pair));
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) Values(backtype.storm.tuple.Values) Pair(com.alipay.dw.jstorm.example.sequence.bean.Pair)

Aggregations

Pair (com.alipay.dw.jstorm.example.sequence.bean.Pair)12 Values (backtype.storm.tuple.Values)8 TradeCustomer (com.alipay.dw.jstorm.example.sequence.bean.TradeCustomer)8 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 Tuple (backtype.storm.tuple.Tuple)2