// BaseRichSpout @Override public void open(Map map, TopologyContext tc, SpoutOutputCollector collector) { super.open(map, tc, collector); if (_harmonizerSyncedSpoutName != null && _zookeeperhost != null) { _scHarmonizer = new SignalClient(_zookeeperhost, _harmonizerSyncedSpoutName); _scHarmonizer.start(); } }
// from IRichSpout interface @Override public void nextTuple() { final String line = generateLine(); // Send frequency statistics & housekeeping if (_isHarmonized && _currentHarmonizerUpdateFreq > _harmonizerUpdateThreshold) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutput out = null; out = new ObjectOutputStream(bos); out.writeObject(_keyFrequencies); byte[] objectBytes = bos.toByteArray(); _scHarmonizer.send(objectBytes); out.close(); bos.close(); } catch (Exception e) { e.printStackTrace(); } _keyFrequencies.clear(); _currentHarmonizerUpdateFreq = 0; } if (_numSentTuples >= _numOfTuplesThreshold) { if (!_hasReachedEOF) { _hasReachedEOF = true; eofFinalization(); } sendEOF(); Utils.sleep(SystemParameters.EOF_TIMEOUT_MILLIS); return; } final List<String> tuple = MyUtilities.fileLineToTuple(line, getConf()); applyOperatorsAndSend(tuple); // Update frequency statistics if (_isHarmonized) { updateHistogram(Integer.parseInt(tuple.get(_keyIndex))); _currentHarmonizerUpdateFreq++; } }
@Override public void close() { super.close(); _scHarmonizer.close(); }