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();
while (handleCounter.get() >= MAX_PENDING_COUNTER - 1) {
try {
Thread.sleep(1);
} catch (InterruptedException ignored) {
}
}
tpsCounter.count();
}
use of com.alipay.dw.jstorm.example.sequence.bean.TradeCustomer in project jstorm by alibaba.
the class SequenceTestSplitRecord method execute.
@Override
public void execute(Tuple input, BasicOutputCollector collector) {
Long tupleId = input.getLong(0);
Object object = input.getValue(1);
if (object instanceof TradeCustomer) {
TradeCustomer tradeCustomer = (TradeCustomer) object;
Pair trade = tradeCustomer.getTrade();
Pair customer = tradeCustomer.getCustomer();
collector.emit(SequenceTopologyDef.TRADE_STREAM_ID, new Values(tupleId, trade));
collector.emit(SequenceTopologyDef.CUSTOMER_STREAM_ID, new Values(tupleId, customer));
emitCounter.update(2);
}
}
use of com.alipay.dw.jstorm.example.sequence.bean.TradeCustomer 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));
}
use of com.alipay.dw.jstorm.example.sequence.bean.TradeCustomer in project jstorm by alibaba.
the class SplitRecord method execute.
public void execute(Tuple tuple, BasicOutputCollector collector) {
tpsCounter.count();
Long tupleId = tuple.getLong(0);
Object obj = tuple.getValue(1);
if (obj instanceof TradeCustomer) {
TradeCustomer tradeCustomer = (TradeCustomer) obj;
Pair trade = tradeCustomer.getTrade();
Pair customer = tradeCustomer.getCustomer();
collector.emit(SequenceTopologyDef.TRADE_STREAM_ID, new Values(tupleId, trade));
collector.emit(SequenceTopologyDef.CUSTOMER_STREAM_ID, new Values(tupleId, customer));
} else if (obj != null) {
LOG.info("Unknow type " + obj.getClass().getName());
} else {
LOG.info("Nullpointer ");
}
}
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;
}
Aggregations