Search in sources :

Example 1 with TradeCustomer

use of com.alipay.dw.jstorm.example.sequence.bean.TradeCustomer 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 2 with TradeCustomer

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

the class SequenceSpout method emit.

public void emit() {
    String buffer = null;
    if (bufferLen > 0) {
        byte[] byteBuffer = new byte[bufferLen];
        for (int i = 0; i < bufferLen; i++) {
            byteBuffer[i] = (byte) random.nextInt(200);
        }
        buffer = new String(byteBuffer);
    }
    Pair trade = PairMaker.makeTradeInstance();
    Pair customer = PairMaker.makeCustomerInstance();
    TradeCustomer tradeCustomer = new TradeCustomer();
    tradeCustomer.setTrade(trade);
    tradeCustomer.setCustomer(customer);
    tradeCustomer.setBuffer(buffer);
    tradeSum.addAndGet(trade.getValue());
    customerSum.addAndGet(customer.getValue());
    collector.emit(new Values(idGenerate.nextLong(), tradeCustomer), tupleId);
    tupleId++;
    handleCounter.incrementAndGet();
    tpCounter.inc();
    while (handleCounter.get() >= MAX_PENDING_COUNTER - 1) {
        try {
            Thread.sleep(1);
        } catch (InterruptedException ignored) {
        }
    }
    tpsCounter.count();
}
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 3 with TradeCustomer

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

the class TotalCount method execute.

@Override
public void execute(Tuple input) {
    if (TupleHelpers.isTickTuple(input)) {
        LOG.info("Receive one Ticket Tuple " + input.getSourceComponent());
        return;
    }
    if (input.getSourceStreamId().equals(SequenceTopologyDef.CONTROL_STREAM_ID)) {
        String str = (input.getStringByField("CONTROL"));
        LOG.warn(str);
        return;
    }
    long before = System.currentTimeMillis();
    myCounter.update(1);
    tpCounter.update(1);
    myMeter.update(1);
    if (checkTupleId) {
        Long tupleId = input.getLong(0);
        if (tupleId <= lastTupleId) {
            /**
             * Display warning
             */
            String errorMessage = ("LastTupleId is " + lastTupleId + ", but now:" + tupleId);
            JStormUtils.reportError(context, errorMessage);
        }
        lastTupleId = tupleId;
    }
    TradeCustomer tradeCustomer;
    try {
        tradeCustomer = (TradeCustomer) input.getValue(1);
    } catch (Exception e) {
        LOG.error(input.getSourceComponent() + "  " + input.getSourceTask() + " " + input.getSourceStreamId() + " target " + input);
        throw new RuntimeException(e);
    }
    tradeSum.addAndGet(tradeCustomer.getTrade().getValue());
    customerSum.addAndGet(tradeCustomer.getCustomer().getValue());
    collector.ack(input);
    long now = System.currentTimeMillis();
    long spend = now - tradeCustomer.getTimestamp();
    tpsCounter.count(spend);
    myJStormHistogram.update(now - before);
    if (slowDonw) {
        JStormUtils.sleepMs(20);
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) TradeCustomer(com.alipay.dw.jstorm.example.sequence.bean.TradeCustomer)

Example 4 with TradeCustomer

use of com.alipay.dw.jstorm.example.sequence.bean.TradeCustomer 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 TradeCustomer

use of com.alipay.dw.jstorm.example.sequence.bean.TradeCustomer 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)

Aggregations

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