redstorm 0.6.6 → 0.7.0.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +6 -1
- data/README.md +8 -7
- data/examples/dsl/exclamation_topology.rb +2 -4
- data/examples/dsl/exclamation_topology2.rb +4 -5
- data/examples/dsl/hello_world_topology.rb +7 -0
- data/examples/dsl/kafka_topology.rb +5 -1
- data/examples/dsl/redis_word_count_topology.rb +5 -9
- data/examples/dsl/ruby_version_topology.rb +2 -0
- data/examples/dsl/word_count_topology.rb +4 -5
- data/examples/trident/word_count_query.rb +33 -0
- data/examples/trident/word_count_topology.rb +153 -0
- data/ivy/storm_dependencies.xml +1 -1
- data/ivy/topology_dependencies.xml +3 -2
- data/lib/red_storm.rb +5 -2
- data/lib/red_storm/configurator.rb +12 -0
- data/lib/red_storm/dsl/batch_bolt.rb +34 -0
- data/lib/red_storm/dsl/batch_committer_bolt.rb +9 -0
- data/lib/red_storm/dsl/batch_spout.rb +53 -0
- data/lib/red_storm/dsl/bolt.rb +7 -2
- data/lib/red_storm/dsl/output_collector.rb +8 -0
- data/lib/red_storm/dsl/spout.rb +3 -1
- data/lib/red_storm/dsl/topology.rb +2 -2
- data/lib/red_storm/dsl/tuple.rb +2 -0
- data/lib/red_storm/topology_launcher.rb +14 -10
- data/lib/red_storm/version.rb +1 -1
- data/redstorm.gemspec +1 -0
- data/src/main/redstorm/storm/jruby/JRubyBatchBolt.java +53 -35
- data/src/main/redstorm/storm/jruby/JRubyBatchSpout.java +77 -42
- data/src/main/redstorm/storm/jruby/JRubyBolt.java +54 -34
- data/src/main/redstorm/storm/jruby/JRubySpout.java +62 -40
- data/src/main/redstorm/storm/jruby/JRubyTransactionalBolt.java +57 -35
- data/src/main/redstorm/storm/jruby/JRubyTransactionalCommitterBolt.java +6 -17
- data/src/main/redstorm/storm/jruby/JRubyTransactionalCommitterSpout.java +14 -26
- data/src/main/redstorm/storm/jruby/JRubyTransactionalSpout.java +60 -37
- data/src/main/redstorm/storm/jruby/JRubyTridentFunction.java +66 -0
- metadata +16 -23
- data/lib/red_storm/proxy/batch_bolt.rb +0 -63
- data/lib/red_storm/proxy/batch_committer_bolt.rb +0 -52
- data/lib/red_storm/proxy/batch_spout.rb +0 -59
- data/lib/red_storm/proxy/bolt.rb +0 -63
- data/lib/red_storm/proxy/proxy_function.rb +0 -40
- data/lib/red_storm/proxy/spout.rb +0 -87
- data/lib/red_storm/proxy/transactional_committer_spout.rb +0 -47
- data/lib/red_storm/proxy/transactional_spout.rb +0 -46
- data/src/main/redstorm/storm/jruby/JRubyProxyFunction.java +0 -51
@@ -5,40 +5,28 @@ import backtype.storm.transactional.ITransactionalSpout;
|
|
5
5
|
import backtype.storm.task.TopologyContext;
|
6
6
|
import java.util.Map;
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
* serialization at topology creation.
|
17
|
-
*/
|
8
|
+
import org.jruby.Ruby;
|
9
|
+
import org.jruby.RubyObject;
|
10
|
+
import org.jruby.runtime.Helpers;
|
11
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
12
|
+
import org.jruby.javasupport.JavaUtil;
|
13
|
+
import org.jruby.RubyModule;
|
14
|
+
import org.jruby.exceptions.RaiseException;
|
15
|
+
|
18
16
|
public class JRubyTransactionalCommitterSpout extends JRubyTransactionalSpout implements ICommitterTransactionalSpout {
|
19
17
|
|
20
|
-
ICommitterTransactionalSpout _proxySpout;
|
21
|
-
|
22
18
|
public JRubyTransactionalCommitterSpout(String baseClassPath, String realSpoutClassName, String[] fields) {
|
23
19
|
super(baseClassPath, realSpoutClassName, fields);
|
24
20
|
}
|
25
21
|
|
26
22
|
@Override
|
27
23
|
public ICommitterTransactionalSpout.Emitter getEmitter(Map conf, TopologyContext context) {
|
28
|
-
|
29
|
-
|
30
|
-
_proxySpout = newProxySpout(_baseClassPath, _realSpoutClassName);
|
31
|
-
}
|
32
|
-
return _proxySpout.getEmitter(conf, context);
|
33
|
-
}
|
34
|
-
|
35
|
-
private static ICommitterTransactionalSpout newProxySpout(String baseClassPath, String realSpoutClassName) {
|
36
|
-
try {
|
37
|
-
redstorm.proxy.TransactionalCommitterSpout proxy = new redstorm.proxy.TransactionalCommitterSpout(baseClassPath, realSpoutClassName);
|
38
|
-
return proxy;
|
39
|
-
}
|
40
|
-
catch (Exception e) {
|
41
|
-
throw new RuntimeException(e);
|
24
|
+
if (_ruby_spout == null) {
|
25
|
+
IRubyObject _ruby_spout = initialize_ruby_spout();
|
42
26
|
}
|
27
|
+
IRubyObject ruby_conf = JavaUtil.convertJavaToRuby(__ruby__, conf);
|
28
|
+
IRubyObject ruby_context = JavaUtil.convertJavaToRuby(__ruby__, context);
|
29
|
+
IRubyObject ruby_result = Helpers.invoke(__ruby__.getCurrentContext(), _ruby_spout, "get_emitter", ruby_conf, ruby_context);
|
30
|
+
return (ICommitterTransactionalSpout.Emitter)ruby_result.toJava(ICommitterTransactionalSpout.Emitter.class);
|
43
31
|
}
|
44
32
|
}
|
@@ -9,81 +9,104 @@ import backtype.storm.tuple.Tuple;
|
|
9
9
|
import backtype.storm.tuple.Fields;
|
10
10
|
import java.util.Map;
|
11
11
|
|
12
|
+
import org.jruby.Ruby;
|
13
|
+
import org.jruby.RubyObject;
|
14
|
+
import org.jruby.runtime.Helpers;
|
15
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
16
|
+
import org.jruby.javasupport.JavaUtil;
|
17
|
+
import org.jruby.RubyModule;
|
18
|
+
import org.jruby.exceptions.RaiseException;
|
19
|
+
|
12
20
|
/**
|
13
21
|
* the JRubySpout class is a simple proxy class to the actual spout implementation in JRuby.
|
14
22
|
* this proxy is required to bypass the serialization/deserialization process when dispatching
|
15
23
|
* the spout to the workers. JRuby does not yet support serialization from Java
|
16
|
-
* (Java serialization call on a JRuby class).
|
24
|
+
* (Java serialization call on a JRuby class).
|
17
25
|
*
|
18
|
-
* Note that the JRuby spout proxy class is instanciated in the open method which is called after
|
19
|
-
* deserialization at the worker and in both the declareOutputFields and isDistributed methods which
|
20
|
-
* are called once before serialization at topology creation.
|
26
|
+
* Note that the JRuby spout proxy class is instanciated in the open method which is called after
|
27
|
+
* deserialization at the worker and in both the declareOutputFields and isDistributed methods which
|
28
|
+
* are called once before serialization at topology creation.
|
21
29
|
*/
|
22
30
|
public class JRubyTransactionalSpout extends BaseTransactionalSpout {
|
23
|
-
|
24
|
-
String
|
25
|
-
String
|
26
|
-
|
27
|
-
|
31
|
+
private final String _realSpoutClassName;
|
32
|
+
private final String[] _fields;
|
33
|
+
private final String _bootstrap;
|
34
|
+
|
35
|
+
// transient to avoid serialization
|
36
|
+
protected transient IRubyObject _ruby_spout;
|
37
|
+
protected transient Ruby __ruby__;
|
38
|
+
|
28
39
|
/**
|
29
40
|
* create a new JRubySpout
|
30
|
-
*
|
31
|
-
* @param baseClassPath the topology/project base JRuby class file path
|
41
|
+
*
|
42
|
+
* @param baseClassPath the topology/project base JRuby class file path
|
32
43
|
* @param realSpoutClassName the fully qualified JRuby spout implementation class name
|
44
|
+
* @param fields the output fields names
|
33
45
|
*/
|
34
46
|
public JRubyTransactionalSpout(String baseClassPath, String realSpoutClassName, String[] fields) {
|
35
|
-
_baseClassPath = baseClassPath;
|
36
47
|
_realSpoutClassName = realSpoutClassName;
|
37
48
|
_fields = fields;
|
49
|
+
_bootstrap = "require '" + baseClassPath + "'";
|
38
50
|
}
|
39
51
|
|
40
52
|
@Override
|
41
53
|
public ITransactionalSpout.Coordinator getCoordinator(Map conf, TopologyContext context) {
|
42
|
-
|
43
|
-
|
44
|
-
_proxySpout = newProxySpout(_baseClassPath, _realSpoutClassName);
|
54
|
+
if (_ruby_spout == null) {
|
55
|
+
IRubyObject _ruby_spout = initialize_ruby_spout();
|
45
56
|
}
|
46
|
-
|
57
|
+
IRubyObject ruby_conf = JavaUtil.convertJavaToRuby(__ruby__, conf);
|
58
|
+
IRubyObject ruby_context = JavaUtil.convertJavaToRuby(__ruby__, context);
|
59
|
+
IRubyObject ruby_result = Helpers.invoke(__ruby__.getCurrentContext(), _ruby_spout, "get_coordinator", ruby_conf, ruby_context);
|
60
|
+
return (ITransactionalSpout.Coordinator)ruby_result.toJava(ITransactionalSpout.Coordinator.class);
|
47
61
|
}
|
48
62
|
|
49
63
|
@Override
|
50
64
|
public ITransactionalSpout.Emitter getEmitter(Map conf, TopologyContext context) {
|
51
|
-
|
52
|
-
|
53
|
-
_proxySpout = newProxySpout(_baseClassPath, _realSpoutClassName);
|
65
|
+
if (_ruby_spout == null) {
|
66
|
+
IRubyObject _ruby_spout = initialize_ruby_spout();
|
54
67
|
}
|
55
|
-
|
68
|
+
IRubyObject ruby_conf = JavaUtil.convertJavaToRuby(__ruby__, conf);
|
69
|
+
IRubyObject ruby_context = JavaUtil.convertJavaToRuby(__ruby__, context);
|
70
|
+
IRubyObject ruby_result = Helpers.invoke(__ruby__.getCurrentContext(), _ruby_spout, "get_emitter", ruby_conf, ruby_context);
|
71
|
+
return (ITransactionalSpout.Emitter)ruby_result.toJava(ITransactionalSpout.Emitter.class);
|
56
72
|
}
|
57
73
|
|
58
74
|
@Override
|
59
75
|
public void declareOutputFields(OutputFieldsDeclarer declarer) {
|
60
|
-
// declareOutputFields is executed in the topology creation time before serialisation.
|
61
|
-
//
|
62
|
-
|
76
|
+
// declareOutputFields is executed in the topology creation time, before serialisation.
|
77
|
+
// just create tmp spout instance to call declareOutputFields.
|
78
|
+
|
63
79
|
if (_fields.length > 0) {
|
64
80
|
declarer.declare(new Fields(_fields));
|
65
81
|
} else {
|
66
|
-
|
67
|
-
|
82
|
+
IRubyObject ruby_spout = initialize_ruby_spout();
|
83
|
+
IRubyObject ruby_declarer = JavaUtil.convertJavaToRuby(__ruby__, declarer);
|
84
|
+
Helpers.invoke(__ruby__.getCurrentContext(), ruby_spout, "declare_output_fields", ruby_declarer);
|
68
85
|
}
|
69
|
-
}
|
86
|
+
}
|
70
87
|
|
71
88
|
@Override
|
72
89
|
public Map<String, Object> getComponentConfiguration() {
|
73
|
-
// getComponentConfiguration is executed in the topology creation time before serialisation.
|
74
|
-
//
|
75
|
-
|
76
|
-
|
77
|
-
|
90
|
+
// getComponentConfiguration is executed in the topology creation time, before serialisation.
|
91
|
+
// just create tmp spout instance to call getComponentConfiguration.
|
92
|
+
|
93
|
+
IRubyObject ruby_spout = initialize_ruby_spout();
|
94
|
+
IRubyObject ruby_result = Helpers.invoke(__ruby__.getCurrentContext(), ruby_spout, "get_component_configuration");
|
95
|
+
return (Map)ruby_result.toJava(Map.class);
|
78
96
|
}
|
79
|
-
|
80
|
-
|
97
|
+
|
98
|
+
protected IRubyObject initialize_ruby_spout() {
|
99
|
+
__ruby__ = Ruby.getGlobalRuntime();
|
100
|
+
|
101
|
+
RubyModule ruby_class;
|
81
102
|
try {
|
82
|
-
|
83
|
-
return proxy;
|
103
|
+
ruby_class = __ruby__.getClassFromPath(_realSpoutClassName);
|
84
104
|
}
|
85
|
-
catch (
|
86
|
-
|
105
|
+
catch (RaiseException e) {
|
106
|
+
// after deserialization we need to recreate ruby environment
|
107
|
+
__ruby__.evalScriptlet(_bootstrap);
|
108
|
+
ruby_class = __ruby__.getClassFromPath(_realSpoutClassName);
|
87
109
|
}
|
110
|
+
return Helpers.invoke(__ruby__.getCurrentContext(), ruby_class, "new");
|
88
111
|
}
|
89
112
|
}
|
@@ -0,0 +1,66 @@
|
|
1
|
+
package redstorm.storm.jruby;
|
2
|
+
|
3
|
+
import storm.trident.tuple.TridentTuple;
|
4
|
+
import storm.trident.operation.TridentCollector;
|
5
|
+
import java.util.Map;
|
6
|
+
import storm.trident.operation.TridentOperationContext;
|
7
|
+
import storm.trident.operation.Function;
|
8
|
+
|
9
|
+
import org.jruby.Ruby;
|
10
|
+
import org.jruby.RubyObject;
|
11
|
+
import org.jruby.runtime.Helpers;
|
12
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
13
|
+
import org.jruby.javasupport.JavaUtil;
|
14
|
+
import org.jruby.RubyModule;
|
15
|
+
import org.jruby.exceptions.RaiseException;
|
16
|
+
|
17
|
+
public class JRubyTridentFunction implements Function {
|
18
|
+
private final String _realClassName;
|
19
|
+
private final String _bootstrap;
|
20
|
+
|
21
|
+
// transient to avoid serialization
|
22
|
+
private transient IRubyObject _ruby_function;
|
23
|
+
private transient Ruby __ruby__;
|
24
|
+
|
25
|
+
public JRubyTridentFunction(final String baseClassPath, final String realClassName) {
|
26
|
+
_realClassName = realClassName;
|
27
|
+
_bootstrap = "require '" + baseClassPath + "'";
|
28
|
+
}
|
29
|
+
|
30
|
+
@Override
|
31
|
+
public void execute(final TridentTuple tuple, final TridentCollector collector) {
|
32
|
+
IRubyObject ruby_tuple = JavaUtil.convertJavaToRuby(__ruby__, tuple);
|
33
|
+
IRubyObject ruby_collector = JavaUtil.convertJavaToRuby(__ruby__, collector);
|
34
|
+
Helpers.invoke(__ruby__.getCurrentContext(), _ruby_function, "execute", ruby_tuple, ruby_collector);
|
35
|
+
}
|
36
|
+
|
37
|
+
@Override
|
38
|
+
public void cleanup() {
|
39
|
+
Helpers.invoke(__ruby__.getCurrentContext(), _ruby_function, "cleanup");
|
40
|
+
}
|
41
|
+
|
42
|
+
@Override
|
43
|
+
public void prepare(final Map conf, final TridentOperationContext context) {
|
44
|
+
if(_ruby_function == null) {
|
45
|
+
_ruby_function = initialize_ruby_function();
|
46
|
+
}
|
47
|
+
IRubyObject ruby_conf = JavaUtil.convertJavaToRuby(__ruby__, conf);
|
48
|
+
IRubyObject ruby_context = JavaUtil.convertJavaToRuby(__ruby__, context);
|
49
|
+
Helpers.invoke(__ruby__.getCurrentContext(), _ruby_function, "prepare", ruby_conf, ruby_context);
|
50
|
+
}
|
51
|
+
|
52
|
+
private IRubyObject initialize_ruby_function() {
|
53
|
+
__ruby__ = Ruby.getGlobalRuntime();
|
54
|
+
|
55
|
+
RubyModule ruby_class;
|
56
|
+
try {
|
57
|
+
ruby_class = __ruby__.getClassFromPath(_realClassName);
|
58
|
+
}
|
59
|
+
catch (RaiseException e) {
|
60
|
+
// after deserialization we need to recreate ruby environment
|
61
|
+
__ruby__.evalScriptlet(_bootstrap);
|
62
|
+
ruby_class = __ruby__.getClassFromPath(_realClassName);
|
63
|
+
}
|
64
|
+
return Helpers.invoke(__ruby__.getCurrentContext(), ruby_class, "new");
|
65
|
+
}
|
66
|
+
}
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redstorm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.7.0.beta1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Colin Surprenant
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-03-03 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec
|
@@ -18,13 +17,11 @@ dependencies:
|
|
18
17
|
- - ~>
|
19
18
|
- !ruby/object:Gem::Version
|
20
19
|
version: '2.13'
|
21
|
-
none: false
|
22
20
|
requirement: !ruby/object:Gem::Requirement
|
23
21
|
requirements:
|
24
22
|
- - ~>
|
25
23
|
- !ruby/object:Gem::Version
|
26
24
|
version: '2.13'
|
27
|
-
none: false
|
28
25
|
prerelease: false
|
29
26
|
type: :development
|
30
27
|
- !ruby/object:Gem::Dependency
|
@@ -34,13 +31,11 @@ dependencies:
|
|
34
31
|
- - '>='
|
35
32
|
- !ruby/object:Gem::Version
|
36
33
|
version: '0'
|
37
|
-
none: false
|
38
34
|
requirement: !ruby/object:Gem::Requirement
|
39
35
|
requirements:
|
40
36
|
- - '>='
|
41
37
|
- !ruby/object:Gem::Version
|
42
38
|
version: '0'
|
43
|
-
none: false
|
44
39
|
prerelease: false
|
45
40
|
type: :runtime
|
46
41
|
description: JRuby integration & DSL for the Storm distributed realtime computation system
|
@@ -59,19 +54,15 @@ files:
|
|
59
54
|
- lib/red_storm/loggable.rb
|
60
55
|
- lib/red_storm/topology_launcher.rb
|
61
56
|
- lib/red_storm/version.rb
|
57
|
+
- lib/red_storm/dsl/batch_bolt.rb
|
58
|
+
- lib/red_storm/dsl/batch_committer_bolt.rb
|
59
|
+
- lib/red_storm/dsl/batch_spout.rb
|
62
60
|
- lib/red_storm/dsl/bolt.rb
|
63
61
|
- lib/red_storm/dsl/drpc_topology.rb
|
62
|
+
- lib/red_storm/dsl/output_collector.rb
|
64
63
|
- lib/red_storm/dsl/spout.rb
|
65
64
|
- lib/red_storm/dsl/topology.rb
|
66
65
|
- lib/red_storm/dsl/tuple.rb
|
67
|
-
- lib/red_storm/proxy/batch_bolt.rb
|
68
|
-
- lib/red_storm/proxy/batch_committer_bolt.rb
|
69
|
-
- lib/red_storm/proxy/batch_spout.rb
|
70
|
-
- lib/red_storm/proxy/bolt.rb
|
71
|
-
- lib/red_storm/proxy/proxy_function.rb
|
72
|
-
- lib/red_storm/proxy/spout.rb
|
73
|
-
- lib/red_storm/proxy/transactional_committer_spout.rb
|
74
|
-
- lib/red_storm/proxy/transactional_spout.rb
|
75
66
|
- lib/tasks/red_storm.rake
|
76
67
|
- ivy/settings.xml
|
77
68
|
- ivy/storm_dependencies.xml
|
@@ -99,11 +90,12 @@ files:
|
|
99
90
|
- examples/shell/shell_topology.rb
|
100
91
|
- examples/shell/resources/splitsentence.py
|
101
92
|
- examples/shell/resources/storm.py
|
93
|
+
- examples/trident/word_count_query.rb
|
94
|
+
- examples/trident/word_count_topology.rb
|
102
95
|
- src/main/redstorm/storm/jruby/JRubyBatchBolt.java
|
103
96
|
- src/main/redstorm/storm/jruby/JRubyBatchCommitterBolt.java
|
104
97
|
- src/main/redstorm/storm/jruby/JRubyBatchSpout.java
|
105
98
|
- src/main/redstorm/storm/jruby/JRubyBolt.java
|
106
|
-
- src/main/redstorm/storm/jruby/JRubyProxyFunction.java
|
107
99
|
- src/main/redstorm/storm/jruby/JRubyShellBolt.java
|
108
100
|
- src/main/redstorm/storm/jruby/JRubyShellSpout.java
|
109
101
|
- src/main/redstorm/storm/jruby/JRubySpout.java
|
@@ -111,6 +103,7 @@ files:
|
|
111
103
|
- src/main/redstorm/storm/jruby/JRubyTransactionalCommitterBolt.java
|
112
104
|
- src/main/redstorm/storm/jruby/JRubyTransactionalCommitterSpout.java
|
113
105
|
- src/main/redstorm/storm/jruby/JRubyTransactionalSpout.java
|
106
|
+
- src/main/redstorm/storm/jruby/JRubyTridentFunction.java
|
114
107
|
- bin/redstorm
|
115
108
|
- redstorm.gemspec
|
116
109
|
- Rakefile
|
@@ -118,7 +111,9 @@ files:
|
|
118
111
|
- CHANGELOG.md
|
119
112
|
- LICENSE.md
|
120
113
|
homepage: https://github.com/colinsurprenant/redstorm
|
121
|
-
licenses:
|
114
|
+
licenses:
|
115
|
+
- Apache 2.0
|
116
|
+
metadata: {}
|
122
117
|
post_install_message:
|
123
118
|
rdoc_options: []
|
124
119
|
require_paths:
|
@@ -128,17 +123,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
128
123
|
- - '>='
|
129
124
|
- !ruby/object:Gem::Version
|
130
125
|
version: '0'
|
131
|
-
none: false
|
132
126
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
127
|
requirements:
|
134
|
-
- - '
|
128
|
+
- - '>'
|
135
129
|
- !ruby/object:Gem::Version
|
136
|
-
version:
|
137
|
-
none: false
|
130
|
+
version: 1.3.1
|
138
131
|
requirements: []
|
139
132
|
rubyforge_project: redstorm
|
140
|
-
rubygems_version: 1.
|
133
|
+
rubygems_version: 2.1.9
|
141
134
|
signing_key:
|
142
|
-
specification_version:
|
135
|
+
specification_version: 4
|
143
136
|
summary: JRuby on Storm
|
144
137
|
test_files: []
|
@@ -1,63 +0,0 @@
|
|
1
|
-
require 'java'
|
2
|
-
|
3
|
-
java_import 'backtype.storm.coordination.BatchOutputCollector'
|
4
|
-
java_import 'backtype.storm.task.TopologyContext'
|
5
|
-
java_import 'backtype.storm.topology.IRichBolt'
|
6
|
-
java_import 'backtype.storm.coordination.IBatchBolt'
|
7
|
-
java_import 'backtype.storm.topology.OutputFieldsDeclarer'
|
8
|
-
java_import 'backtype.storm.tuple.Tuple'
|
9
|
-
java_import 'java.util.Map'
|
10
|
-
|
11
|
-
module Backtype
|
12
|
-
java_import 'backtype.storm.Config'
|
13
|
-
end
|
14
|
-
|
15
|
-
java_package 'redstorm.proxy'
|
16
|
-
|
17
|
-
# the Bolt class is a proxy to the real bolt to avoid having to deal with all the
|
18
|
-
# Java artifacts when creating a bolt.
|
19
|
-
#
|
20
|
-
# The real bolt class implementation must define these methods:
|
21
|
-
# - prepare(conf, context, collector)
|
22
|
-
# - execute(tuple)
|
23
|
-
# - declare_output_fields
|
24
|
-
#
|
25
|
-
# and optionnaly:
|
26
|
-
# - cleanup
|
27
|
-
#
|
28
|
-
class BatchBolt
|
29
|
-
java_implements IBatchBolt
|
30
|
-
|
31
|
-
java_signature 'IBatchBolt (String base_class_path, String real_bolt_class_name)'
|
32
|
-
def initialize(base_class_path, real_bolt_class_name)
|
33
|
-
@real_bolt = Object.module_eval(real_bolt_class_name).new
|
34
|
-
rescue NameError
|
35
|
-
require base_class_path
|
36
|
-
@real_bolt = Object.module_eval(real_bolt_class_name).new
|
37
|
-
end
|
38
|
-
|
39
|
-
java_signature 'void prepare(Map, TopologyContext, BatchOutputCollector, Object)'
|
40
|
-
def prepare(conf, context, collector, id)
|
41
|
-
@real_bolt.prepare(conf, context, collector, id)
|
42
|
-
end
|
43
|
-
|
44
|
-
java_signature 'void execute(Tuple)'
|
45
|
-
def execute(tuple)
|
46
|
-
@real_bolt.execute(tuple)
|
47
|
-
end
|
48
|
-
|
49
|
-
java_signature 'void finishBatch()'
|
50
|
-
def finishBatch
|
51
|
-
@real_bolt.finish_batch if @real_bolt.respond_to?(:finish_batch)
|
52
|
-
end
|
53
|
-
|
54
|
-
java_signature 'void declareOutputFields(OutputFieldsDeclarer)'
|
55
|
-
def declareOutputFields(declarer)
|
56
|
-
@real_bolt.declare_output_fields(declarer)
|
57
|
-
end
|
58
|
-
|
59
|
-
java_signature 'Map<String, Object> getComponentConfiguration()'
|
60
|
-
def getComponentConfiguration
|
61
|
-
@real_bolt.get_component_configuration
|
62
|
-
end
|
63
|
-
end
|