added fields constructor arg for future dsl integration

This commit is contained in:
Colin Surprenant 2013-05-13 00:03:36 -04:00
parent c55e69b983
commit 72fbac4e92
6 changed files with 41 additions and 20 deletions

View File

@ -7,6 +7,7 @@ import backtype.storm.coordination.BatchOutputCollector;
import backtype.storm.coordination.IBatchBolt; import backtype.storm.coordination.IBatchBolt;
import backtype.storm.topology.OutputFieldsDeclarer; import backtype.storm.topology.OutputFieldsDeclarer;
import backtype.storm.tuple.Tuple; import backtype.storm.tuple.Tuple;
import backtype.storm.tuple.Fields;
import java.util.Map; import java.util.Map;
/** /**
@ -23,15 +24,18 @@ public class JRubyBatchBolt extends BaseBatchBolt {
IBatchBolt _proxyBolt; IBatchBolt _proxyBolt;
String _realBoltClassName; String _realBoltClassName;
String _baseClassPath; String _baseClassPath;
String[] _fields;
/** /**
* create a new JRubyBolt * create a new JRubyBolt
* *
* @param baseClassPath the topology/project base JRuby class file path * @param baseClassPath the topology/project base JRuby class file path
* @param realBoltClassName the fully qualified JRuby bolt implementation class name * @param realBoltClassName the fully qualified JRuby bolt implementation class name
*/ */
public JRubyBatchBolt(String baseClassPath, String realBoltClassName) { public JRubyBatchBolt(String baseClassPath, String realBoltClassName, String[] fields) {
_baseClassPath = baseClassPath; _baseClassPath = baseClassPath;
_realBoltClassName = realBoltClassName; _realBoltClassName = realBoltClassName;
_fields = fields;
} }
@Override @Override
@ -56,8 +60,12 @@ public class JRubyBatchBolt extends BaseBatchBolt {
// declareOutputFields is executed in the topology creation time, before serialisation. // declareOutputFields is executed in the topology creation time, before serialisation.
// do not set the _proxyBolt instance variable here to avoid JRuby serialization // do not set the _proxyBolt instance variable here to avoid JRuby serialization
// issues. Just create tmp bolt instance to call declareOutputFields. // issues. Just create tmp bolt instance to call declareOutputFields.
IBatchBolt bolt = newProxyBolt(_baseClassPath, _realBoltClassName); if (_fields.length > 0) {
bolt.declareOutputFields(declarer); declarer.declare(new Fields(_fields));
} else {
IBatchBolt bolt = newProxyBolt(_baseClassPath, _realBoltClassName);
bolt.declareOutputFields(declarer);
}
} }
@Override @Override

View File

@ -3,7 +3,7 @@ package redstorm.storm.jruby;
import backtype.storm.transactional.ICommitter; import backtype.storm.transactional.ICommitter;
public class JRubyBatchCommitterBolt extends JRubyBatchBolt implements ICommitter { public class JRubyBatchCommitterBolt extends JRubyBatchBolt implements ICommitter {
public JRubyBatchCommitterBolt(String baseClassPath, String realBoltClassName) { public JRubyBatchCommitterBolt(String baseClassPath, String realBoltClassName, String[] fields) {
super(baseClassPath, realBoltClassName); super(baseClassPath, realBoltClassName, fields);
} }
} }

View File

@ -8,6 +8,7 @@ import backtype.storm.coordination.BatchOutputCollector;
import backtype.storm.coordination.IBatchBolt; import backtype.storm.coordination.IBatchBolt;
import backtype.storm.topology.OutputFieldsDeclarer; import backtype.storm.topology.OutputFieldsDeclarer;
import backtype.storm.tuple.Tuple; import backtype.storm.tuple.Tuple;
import backtype.storm.tuple.Fields;
import java.util.Map; import java.util.Map;
/** /**
@ -24,15 +25,18 @@ public class JRubyTransactionalBolt extends BaseTransactionalBolt {
IBatchBolt _proxyBolt; IBatchBolt _proxyBolt;
String _realBoltClassName; String _realBoltClassName;
String _baseClassPath; String _baseClassPath;
/** String[] _fields;
/**
* create a new JRubyBolt * create a new JRubyBolt
* *
* @param baseClassPath the topology/project base JRuby class file path * @param baseClassPath the topology/project base JRuby class file path
* @param realBoltClassName the fully qualified JRuby bolt implementation class name * @param realBoltClassName the fully qualified JRuby bolt implementation class name
*/ */
public JRubyTransactionalBolt(String baseClassPath, String realBoltClassName) { public JRubyTransactionalBolt(String baseClassPath, String realBoltClassName, String[] fields) {
_baseClassPath = baseClassPath; _baseClassPath = baseClassPath;
_realBoltClassName = realBoltClassName; _realBoltClassName = realBoltClassName;
_fields = fields;
} }
@Override @Override
@ -57,8 +61,12 @@ public class JRubyTransactionalBolt extends BaseTransactionalBolt {
// declareOutputFields is executed in the topology creation time, before serialisation. // declareOutputFields is executed in the topology creation time, before serialisation.
// do not set the _proxyBolt instance variable here to avoid JRuby serialization // do not set the _proxyBolt instance variable here to avoid JRuby serialization
// issues. Just create tmp bolt instance to call declareOutputFields. // issues. Just create tmp bolt instance to call declareOutputFields.
IBatchBolt bolt = newProxyBolt(_baseClassPath, _realBoltClassName); if (_fields.length > 0) {
bolt.declareOutputFields(declarer); declarer.declare(new Fields(_fields));
} else {
IBatchBolt bolt = newProxyBolt(_baseClassPath, _realBoltClassName);
bolt.declareOutputFields(declarer);
}
} }
@Override @Override

View File

@ -15,8 +15,8 @@ import backtype.storm.transactional.ICommitter;
* serialization at topology creation. * serialization at topology creation.
*/ */
public class JRubyTransactionalCommitterBolt extends JRubyTransactionalBolt implements ICommitter { public class JRubyTransactionalCommitterBolt extends JRubyTransactionalBolt implements ICommitter {
public JRubyTransactionalCommitterBolt(String baseClassPath, String realBoltClassName) { public JRubyTransactionalCommitterBolt(String baseClassPath, String realBoltClassName, String[] fields) {
super(baseClassPath, realBoltClassName); super(baseClassPath, realBoltClassName, fields);
} }
private static IBatchBolt newProxyBolt(String baseClassPath, String realBoltClassName) { private static IBatchBolt newProxyBolt(String baseClassPath, String realBoltClassName) {

View File

@ -19,8 +19,8 @@ public class JRubyTransactionalCommitterSpout extends JRubyTransactionalSpout im
ICommitterTransactionalSpout _proxySpout; ICommitterTransactionalSpout _proxySpout;
public JRubyTransactionalCommitterSpout(String baseClassPath, String realSpoutClassName) { public JRubyTransactionalCommitterSpout(String baseClassPath, String realSpoutClassName, String[] fields) {
super(baseClassPath, realSpoutClassName); super(baseClassPath, realSpoutClassName, fields);
} }
@Override @Override

View File

@ -2,12 +2,11 @@ package redstorm.storm.jruby;
import backtype.storm.spout.SpoutOutputCollector; import backtype.storm.spout.SpoutOutputCollector;
import backtype.storm.task.TopologyContext; import backtype.storm.task.TopologyContext;
import backtype.storm.topology.base.BaseTransactionalSpout; import backtype.storm.topology.base.BaseTransactionalSpout;
import backtype.storm.transactional.ITransactionalSpout;
import backtype.storm.topology.OutputFieldsDeclarer; import backtype.storm.topology.OutputFieldsDeclarer;
import backtype.storm.transactional.ITransactionalSpout;
import backtype.storm.tuple.Tuple; import backtype.storm.tuple.Tuple;
import backtype.storm.tuple.Fields;
import java.util.Map; import java.util.Map;
/** /**
@ -24,6 +23,7 @@ public class JRubyTransactionalSpout extends BaseTransactionalSpout {
ITransactionalSpout _proxySpout; ITransactionalSpout _proxySpout;
String _realSpoutClassName; String _realSpoutClassName;
String _baseClassPath; String _baseClassPath;
String[] _fields;
/** /**
* create a new JRubySpout * create a new JRubySpout
@ -31,9 +31,10 @@ public class JRubyTransactionalSpout extends BaseTransactionalSpout {
* @param baseClassPath the topology/project base JRuby class file path * @param baseClassPath the topology/project base JRuby class file path
* @param realSpoutClassName the fully qualified JRuby spout implementation class name * @param realSpoutClassName the fully qualified JRuby spout implementation class name
*/ */
public JRubyTransactionalSpout(String baseClassPath, String realSpoutClassName) { public JRubyTransactionalSpout(String baseClassPath, String realSpoutClassName, String[] fields) {
_baseClassPath = baseClassPath; _baseClassPath = baseClassPath;
_realSpoutClassName = realSpoutClassName; _realSpoutClassName = realSpoutClassName;
_fields = fields;
} }
@Override @Override
@ -46,7 +47,7 @@ public class JRubyTransactionalSpout extends BaseTransactionalSpout {
} }
@Override @Override
public Emitter getEmitter(Map conf, TopologyContext context) { public ITransactionalSpout.Emitter getEmitter(Map conf, TopologyContext context) {
// create instance of the jruby class here, after deserialization in the workers. // create instance of the jruby class here, after deserialization in the workers.
if (_proxySpout == null) { if (_proxySpout == null) {
_proxySpout = newProxySpout(_baseClassPath, _realSpoutClassName); _proxySpout = newProxySpout(_baseClassPath, _realSpoutClassName);
@ -59,8 +60,12 @@ public class JRubyTransactionalSpout extends BaseTransactionalSpout {
// declareOutputFields is executed in the topology creation time before serialisation. // declareOutputFields is executed in the topology creation time before serialisation.
// do not set the _proxySpout instance variable here to avoid JRuby serialization // do not set the _proxySpout instance variable here to avoid JRuby serialization
// issues. Just create tmp spout instance to call declareOutputFields. // issues. Just create tmp spout instance to call declareOutputFields.
ITransactionalSpout spout = newProxySpout(_baseClassPath, _realSpoutClassName); if (_fields.length > 0) {
spout.declareOutputFields(declarer); declarer.declare(new Fields(_fields));
} else {
ITransactionalSpout spout = newProxySpout(_baseClassPath, _realSpoutClassName);
spout.declareOutputFields(declarer);
}
} }
@Override @Override