Java Code Examples for backtype.storm.tuple.Tuple#getInteger()
The following examples show how to use
backtype.storm.tuple.Tuple#getInteger() .
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: UserDefinedWorkerTopology.java From jstorm with Apache License 2.0 | 6 votes |
@Override public void execute(Tuple tuple) { String sourceIp = tuple.getString(1); Integer sourcePort = tuple.getInteger(2); if (differentNode) { if (ip.equals(sourceIp)) { fail(tuple, _collector); return; } else if (port.equals(sourcePort)) { fail(tuple, _collector); return; } _collector.emit(tuple, new Values(tuple.getValue(0), ip, port)); _collector.ack(tuple); return; } else { if (ip.equals(sourceIp) == false) { fail(tuple, _collector); return; } _collector.emit(tuple, new Values(tuple.getValue(0), ip, port)); _collector.ack(tuple); } }
Example 2
Source File: TransactionalWords.java From jstorm with Apache License 2.0 | 6 votes |
@Override public void execute(Tuple tuple, BasicOutputCollector collector) { TransactionAttempt attempt = (TransactionAttempt) tuple.getValue(0); int curr = tuple.getInteger(2); Integer prev = tuple.getInteger(3); int currBucket = curr / BUCKET_SIZE; Integer prevBucket = null; if (prev != null) { prevBucket = prev / BUCKET_SIZE; } if (prevBucket == null) { collector.emit(new Values(attempt, currBucket, 1)); } else if (currBucket != prevBucket) { collector.emit(new Values(attempt, currBucket, 1)); collector.emit(new Values(attempt, prevBucket, -1)); } }
Example 3
Source File: InOrderTestBolt.java From jstorm with Apache License 2.0 | 6 votes |
@Override public void execute(Tuple input, BasicOutputCollector collector) { Integer c1 = input.getInteger(0); Integer c2 = input.getInteger(1); Integer expect = expected.get(c1); if (expect == null) expect = 0; if (c2.intValue() == expect.intValue()) successCounter.inc(); else failCounter.inc(); expect = c2 + 1; expected.put(c1, expect); }
Example 4
Source File: TransactionalWordsTest.java From jstorm with Apache License 2.0 | 6 votes |
@Override public void execute(Tuple tuple, BasicOutputCollector collector) { TransactionAttempt attempt = (TransactionAttempt) tuple.getValue(0); int curr = tuple.getInteger(2); Integer prev = tuple.getInteger(3); int currBucket = curr / BUCKET_SIZE; Integer prevBucket = null; if (prev != null) { prevBucket = prev / BUCKET_SIZE; } if (prevBucket == null) { collector.emit(new Values(attempt, currBucket, 1)); } else if (currBucket != prevBucket) { collector.emit(new Values(attempt, currBucket, 1)); collector.emit(new Values(attempt, prevBucket, -1)); } }
Example 5
Source File: UniqueVisitorBolt.java From storm-benchmark with Apache License 2.0 | 5 votes |
@Override public void updateCurrentWindow(Tuple tuple) { String url = tuple.getString(0); int userId = tuple.getInteger(1); Set<Integer> users = cached.get(url); if (null == users) { users = new HashSet<Integer>(); cached.put(url, users); } users.add(userId); }
Example 6
Source File: InOrderDeliveryTest.java From jstorm with Apache License 2.0 | 5 votes |
@Override public void execute(Tuple tuple, BasicOutputCollector collector) { Integer c1 = tuple.getInteger(0); Integer c2 = tuple.getInteger(1); Integer exp = expected.get(c1); if (exp == null) exp = 0; if (c2.intValue() != exp.intValue()) { System.out.println(c1 + " " + c2 + " != " + exp); throw new FailedException(c1 + " " + c2 + " != " + exp); } exp = c2 + 1; expected.put(c1, exp); }
Example 7
Source File: TransactionalWords.java From jstorm with Apache License 2.0 | 5 votes |
@Override public void execute(Tuple tuple) { Integer bucket = tuple.getInteger(1); Integer delta = tuple.getInteger(2); Integer curr = _accum.get(bucket); if (curr == null) curr = 0; _accum.put(bucket, curr + delta); }
Example 8
Source File: SlidingTupleTestBolt.java From jstorm with Apache License 2.0 | 5 votes |
@Override public void execute(TupleWindow inputWindow) { List<Tuple> tuplesInWindow = inputWindow.get(); int sum = 0; for(Tuple tuple : tuplesInWindow) sum += tuple.getInteger(0); asmCounter.update(sum); }
Example 9
Source File: TestEventOrderCheckBolt.java From jstorm with Apache License 2.0 | 5 votes |
public void execute(Tuple input) { Integer sourceId = input.getInteger(0); Long eventId = input.getLong(1); Long recentEvent = recentEventId.get(sourceId); if (null != recentEvent && eventId <= recentEvent) { String error = "Error: event id is not in strict order! event source Id: " + sourceId + ", last event Id: " + recentEvent + ", current event Id: " + eventId; _collector.emit(input, new Values(error)); } recentEventId.put(sourceId, eventId); _collector.ack(input); }
Example 10
Source File: TransactionalWordsTest.java From jstorm with Apache License 2.0 | 5 votes |
@Override public void execute(Tuple tuple) { Integer bucket = tuple.getInteger(1); Integer delta = tuple.getInteger(2); Integer curr = _accum.get(bucket); if (curr == null) curr = 0; _accum.put(bucket, curr + delta); }
Example 11
Source File: ReachTopology.java From jstorm with Apache License 2.0 | 4 votes |
@Override public void execute(Tuple tuple) { _count += tuple.getInteger(1); }
Example 12
Source File: TransactionalGlobalCount.java From jstorm with Apache License 2.0 | 4 votes |
@Override public void execute(Tuple tuple) { _sum += tuple.getInteger(1); LOG.info("---UpdateGlobalCount.execute(), _sum=" + _sum); }
Example 13
Source File: TridentBoltExecutor.java From jstorm with Apache License 2.0 | 4 votes |
@Override public void execute(Tuple tuple) { if (TupleUtils.isTick(tuple)) { long now = System.currentTimeMillis(); if (now - _lastRotate > _messageTimeoutMs) { _batches.rotate(); _lastRotate = now; } return; } String batchGroup = _batchGroupIds.get(tuple.getSourceGlobalStreamid()); if (batchGroup == null) { // this is so we can do things like have simple DRPC that doesn't need to use batch processing _coordCollector.setCurrBatch(null); _bolt.execute(null, tuple); _collector.ack(tuple); return; } IBatchID id = (IBatchID) tuple.getValue(0); //get transaction id //if it already exists and attempt id is greater than the attempt there TrackedBatch tracked = (TrackedBatch) _batches.get(id.getId()); // if(_batches.size() > 10 && _context.getThisTaskIndex() == 0) { // System.out.println("Received in " + _context.getThisComponentId() + " " + _context.getThisTaskIndex() // + " (" + _batches.size() + ")" + // "\ntuple: " + tuple + // "\nwith tracked " + tracked + // "\nwith id " + id + // "\nwith group " + batchGroup // + "\n"); // // } //System.out.println("Num tracked: " + _batches.size() + " " + _context.getThisComponentId() + " " + _context.getThisTaskIndex()); // this code here ensures that only one attempt is ever tracked for a batch, so when // failures happen you don't get an explosion in memory usage in the tasks if (tracked != null) { if (id.getAttemptId() > tracked.attemptId) { _batches.remove(id.getId()); tracked = null; } else if (id.getAttemptId() < tracked.attemptId) { // no reason to try to execute a previous attempt than we've already seen return; } } if (tracked == null) { tracked = new TrackedBatch(new BatchInfo(batchGroup, id, _bolt.initBatchState(batchGroup, id)), _coordConditions.get(batchGroup), id.getAttemptId()); _batches.put(id.getId(), tracked); } _coordCollector.setCurrBatch(tracked); //System.out.println("TRACKED: " + tracked + " " + tuple); TupleType t = getTupleType(tuple, tracked); if (t == TupleType.COMMIT) { tracked.receivedCommit = true; checkFinish(tracked, tuple, t); } else if (t == TupleType.COORD) { int count = tuple.getInteger(1); tracked.reportedTasks++; tracked.expectedTupleCount += count; checkFinish(tracked, tuple, t); } else { tracked.receivedTuples++; boolean success = true; try { _bolt.execute(tracked.info, tuple); if (tracked.condition.expectedTaskReports == 0) { success = finishBatch(tracked, tuple); } } catch (FailedException e) { failBatch(tracked, e); } if (success) { _collector.ack(tuple); } else { _collector.fail(tuple); } } _coordCollector.setCurrBatch(null); }