Java Code Examples for backtype.storm.tuple.Tuple#getLong()

The following examples show how to use backtype.storm.tuple.Tuple#getLong() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RequestBolt.java    From StormCV with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(Tuple tuple) {
	try{
		long requestId = tuple.getLong(0);
		List<? extends CVParticle> result = operation.execute(requestId, tuple.getString(1));
		for(CVParticle particle : result){
			particle.setRequestId(requestId);
			collector.emit(tuple, operation.getSerializer().toTuple(particle));
		}
		collector.ack(tuple);
	}catch(IOException ioe){
		logger.error("Unable to serialize result to tuple", ioe );
		collector.fail(tuple);
	}catch(Exception e){
		logger.error("Unable to proces tuple", e );
		collector.fail(tuple);
	}
}
 
Example 2
Source File: SequenceTestSplitRecord.java    From jstorm with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example 3
Source File: WindowTestCountAggBolt.java    From jstorm with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(Tuple input) {
    Object obj = input.getValue(0);
    long count = input.getLong(1);
    int source = input.getSourceTask();

    System.out.println("### obj = " + obj + " count = " + count + " src = " + source);

    Map<Integer, Long> subCounts = counts.get(obj);
    if (subCounts == null) {
        subCounts = new HashMap<Integer, Long>();
        counts.put(obj, subCounts);
    }
    // Update the current count for this object
    subCounts.put(source, count);
    // Output the sum of all the known counts so for this key
    long sum = 0;
    for (Long val : subCounts.values()) {
        sum += val;
    }
    collector.emit(new Values(obj, sum));
}
 
Example 4
Source File: RollingCountAggBolt.java    From jstorm with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(Tuple tuple) {
    Object obj = tuple.getValue(0);
    long count = tuple.getLong(1);
    int source = tuple.getSourceTask();
    Map<Integer, Long> subCounts = counts.get(obj);
    if (subCounts == null) {
        subCounts = new HashMap<Integer, Long>();
        counts.put(obj, subCounts);
    }
    // Update the current count for this object
    subCounts.put(source, count);
    // Output the sum of all the known counts so for this key
    long sum = 0;
    for (Long val : subCounts.values()) {
        sum += val;
    }
    collector.emit(new Values(obj, sum));
}
 
Example 5
Source File: SplitRecord.java    From jstorm with Apache License 2.0 6 votes vote down vote up
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 ");
    }
}
 
Example 6
Source File: ForwardThroughput.java    From flink-perf with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Tuple input) {
	Matcher m = threeDigitAbbr.matcher(input.getString(0));
	if (m.matches()) {
		matches++;
	}

	if(start == 0) {
		start = System.currentTimeMillis();
	}
	received++;
	if(received % logfreq == 0) {
		long now = System.currentTimeMillis();


		// throughput for the last "logfreq" elements
		if(lastLog == -1) {
			// init (the first)
			lastLog = now;
			lastElements = received;
		} else {
			long timeDiff = now - lastLog;
			long elementDiff = received - lastElements;
			double ex = (1000/(double)timeDiff);
			LOG.info("During the last {} ms, we received {} elements. That's {} elements/second/core", timeDiff, elementDiff, elementDiff*ex);
			// reinit
			lastLog = now;
			lastElements = received;
		}
	}

	if(input.getLong(1) != 0) {
		long lat = System.currentTimeMillis() - input.getLong(1);
		LOG.info("Latency {} ms from same machine", lat);
	}

	if(withFT) {
		collector.ack(input);
	}
}
 
Example 7
Source File: SequenceTestPairCount.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Tuple input, BasicOutputCollector collector) {
    Long tupleId = input.getLong(0);
    Pair pair = (Pair) input.getValue(1);
    emitCounter.inc();
    collector.emit(new Values(tupleId, pair));
}
 
Example 8
Source File: Latency.java    From flink-perf with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Tuple input) {
	if(start == 0) {
		start = System.currentTimeMillis();
	}
	received++;
	if(received % logfreq == 0) {
		long now = System.currentTimeMillis();

		// throughput for the last "logfreq" elements
		if(lastLog == -1) {
			// init (the first)
			lastLog = now;
			lastElements = received;
		} else {
			long timeDiff = now - lastLog;
			long elementDiff = received - lastElements;
			double ex = (1000/(double)timeDiff);
			LOG.info("During the last {} ms, we received {} elements. That's {} elements/second/core", timeDiff, elementDiff, elementDiff*ex);
			// reinit
			lastLog = now;
			lastElements = received;
		}
	}

	if(input.getLong(2) != 0 && input.getString(1).equals(host)) {
		long lat = System.currentTimeMillis() - input.getLong(2);
		LOG.info("Latency {} ms from machine "+input.getString(1), lat);
	}
	if(withFT) {
		collector.ack(input);
	}
}
 
Example 9
Source File: FastWordCountSessionEventTimeWindowTopology.java    From jstorm with Apache License 2.0 4 votes vote down vote up
@Override
public long extractTimestamp(Tuple element) {
    return element.getLong(1);
}
 
Example 10
Source File: TotalCount.java    From jstorm with Apache License 2.0 4 votes vote down vote up
@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);
    }

}
 
Example 11
Source File: PerformanceTestTopology.java    From jstorm with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(Tuple input) {
    long count = input.getLong(0);
    collector.ack(input);
}
 
Example 12
Source File: FastWordCountEventTimeWindowTopology.java    From jstorm with Apache License 2.0 4 votes vote down vote up
@Override
public long extractTimestamp(Tuple element) {
    return element.getLong(1);
}
 
Example 13
Source File: MergeRecord.java    From jstorm with Apache License 2.0 4 votes vote down vote up
@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));
}
 
Example 14
Source File: Throughput.java    From flink-perf with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(Tuple input) {
	if(host == -1) {
		try {
			this.host = com.github.projectflink.streaming.Throughput.convertHostnameToInt(InetAddress.getLocalHost().getHostName());
		} catch (UnknownHostException e) {
			e.printStackTrace();
		}
	}
	if(start == 0) {
		start = System.currentTimeMillis();
	}
	received++;
	if(received % logfreq == 0) {
		long now = System.currentTimeMillis();

		/*long sinceSec = ((now - start)/1000);
		if(sinceSec == 0) return;
		LOG.info("Received {} elements since {}. Elements per second {}, GB received {}",
				received,
				sinceSec,
				received/sinceSec ,
				(received * (8 + 8 + 4 + pt.getInt("payload")))/1024/1024/1024 ); */

		// throughput for the last "logfreq" elements
		if(lastLog == -1) {
			// init (the first)
			lastLog = now;
			lastElements = received;
		} else {
			long timeDiff = now - lastLog;
			long elementDiff = received - lastElements;
			double ex = (1000/(double)timeDiff);
			LOG.info("During the last {} ms, we received {} elements. That's {} elements/second/core", timeDiff, elementDiff, elementDiff*ex);
			// reinit
			lastLog = now;
			lastElements = received;
		}
	}

	if(input.getLong(2) != 0 /* && input.getInteger(1).equals(host) */) {
		long lat = System.currentTimeMillis() - input.getLong(2);
		LOG.info("Latency {} ms from machine "+host, lat);
	}

	if(withFT) {
		collector.ack(input);
	}
}
 
Example 15
Source File: SequenceTestMergeRecord.java    From jstorm with Apache License 2.0 4 votes vote down vote up
@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();
}
 
Example 16
Source File: ThroughputHostsTracking.java    From flink-perf with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(Tuple input) {
	if(start == 0) {
		start = System.currentTimeMillis();
	}
	received++;
	if(received % logfreq == 0) {
		long now = System.currentTimeMillis();

		/*long sinceSec = ((now - start)/1000);
		if(sinceSec == 0) return;
		LOG.info("Received {} elements since {}. Elements per second {}, GB received {}",
				received,
				sinceSec,
				received/sinceSec ,
				(received * (8 + 8 + 4 + pt.getInt("payload")))/1024/1024/1024 ); */

		// throughput for the last "logfreq" elements
		if(lastLog == -1) {
			// init (the first)
			lastLog = now;
			lastElements = received;
		} else {
			long timeDiff = now - lastLog;
			long elementDiff = received - lastElements;
			double ex = (1000/(double)timeDiff);
			LOG.info("During the last {} ms, we received {} elements. That's {} elements/second/core", timeDiff, elementDiff, elementDiff*ex);
			// reinit
			lastLog = now;
			lastElements = received;
		}
	}

	if(input.getLong(2) != 0 && input.getString(1).equals(host)) {
		long lat = System.currentTimeMillis() - input.getLong(2);
		((List<String>)input.getValues().get(4)).add(host);
		LOG.info("Latency {} ms from machine "+host+" after hosts "+input.getValues().get(4), lat);
	}

	if(withFT) {
		collector.ack(input);
	}
}
 
Example 17
Source File: SimpleBatchTestBolt.java    From jstorm with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(Tuple tuple, BasicOutputCollector basicOutputCollector) {
    BatchId id = (BatchId) tuple.getValue(0);
    Long value = tuple.getLong(1);
    System.out.println("SimpleBatchTestBolt #execute id = " + id + " value = " + value);
}
 
Example 18
Source File: PerformanceTestTopology.java    From jstorm with Apache License 2.0 4 votes vote down vote up
public void execute(Tuple input) {
    long count = input.getLong(0);
    collector.ack(input);
}
 
Example 19
Source File: PerformanceTestTopology.java    From jstorm with Apache License 2.0 4 votes vote down vote up
public void execute(Tuple input) {
    long count = input.getLong(0);
    collector.ack(input);
}
 
Example 20
Source File: PairCount.java    From jstorm with Apache License 2.0 3 votes vote down vote up
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));
}