forked from nathanmarz/storm
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unify committer and batch bolt abstractions with the ICommitter inter…
…face, this greatly simplifies the transactional topology abstraction and makes things more reusable
- Loading branch information
Nathan Marz
committed
Jan 27, 2012
1 parent
634706f
commit 297ee5a
Showing
12 changed files
with
37 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 2 additions & 38 deletions
40
src/jvm/backtype/storm/testing/KeyedCountingCommitterBolt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,7 @@ | ||
package backtype.storm.testing; | ||
|
||
import backtype.storm.task.TopologyContext; | ||
import backtype.storm.topology.OutputFieldsDeclarer; | ||
import backtype.storm.coordination.BatchOutputCollector; | ||
import backtype.storm.topology.base.BaseCommitterBolt; | ||
import backtype.storm.transactional.TransactionAttempt; | ||
import backtype.storm.tuple.Fields; | ||
import backtype.storm.tuple.Tuple; | ||
import backtype.storm.tuple.Values; | ||
import backtype.storm.utils.Utils; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import backtype.storm.transactional.ICommitter; | ||
|
||
public class KeyedCountingCommitterBolt extends BaseCommitterBolt { | ||
TransactionAttempt _id; | ||
Map<Object, Integer> _counts = new HashMap<Object, Integer>(); | ||
|
||
@Override | ||
public void prepare(Map conf, TopologyContext context, TransactionAttempt id) { | ||
_id = id; | ||
} | ||
public class KeyedCountingCommitterBolt extends KeyedCountingBatchBolt implements ICommitter { | ||
|
||
@Override | ||
public void execute(Tuple tuple) { | ||
Object key = tuple.getValue(1); | ||
int curr = Utils.get(_counts, key, 0); | ||
_counts.put(key, curr + 1); | ||
} | ||
|
||
@Override | ||
public void commit(BatchOutputCollector collector) { | ||
for(Object key: _counts.keySet()) { | ||
collector.emit(new Values(_id, key, _counts.get(key))); | ||
} | ||
} | ||
|
||
@Override | ||
public void declareOutputFields(OutputFieldsDeclarer declarer) { | ||
declarer.declare(new Fields("tx", "key", "count")); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
src/jvm/backtype/storm/topology/base/BaseCommitterBolt.java
This file was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
src/jvm/backtype/storm/topology/base/BaseTransactionalBolt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package backtype.storm.topology.base; | ||
|
||
import backtype.storm.transactional.TransactionAttempt; | ||
|
||
public abstract class BaseTransactionalBolt extends BaseBatchBolt<TransactionAttempt> { | ||
|
||
} |
45 changes: 0 additions & 45 deletions
45
src/jvm/backtype/storm/transactional/CommitterBoltExecutor.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package backtype.storm.transactional; | ||
|
||
/** | ||
* This marks an IBatchBolt within a transactional topology as a committer. This causes the | ||
* finishBatch method to be called in order of the transactions. | ||
*/ | ||
public interface ICommitter { | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters