redstorm 0.6.5 → 0.6.6.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.
- data/CHANGELOG.md +12 -1
- data/README.md +66 -47
- data/Rakefile +1 -1
- data/examples/dsl/exclamation_bolt.rb +10 -0
- data/examples/{simple → dsl}/exclamation_topology.rb +5 -5
- data/examples/{simple → dsl}/exclamation_topology2.rb +5 -5
- data/examples/{simple → dsl}/hello_world_topology.rb +4 -4
- data/examples/{simple → dsl}/kafka_topology.rb +17 -18
- data/examples/{simple → dsl}/random_sentence_spout.rb +1 -1
- data/examples/{simple → dsl}/redis_word_count_topology.rb +6 -7
- data/examples/{simple → dsl}/ruby_version_topology.rb +9 -9
- data/examples/{simple → dsl}/split_sentence_bolt.rb +6 -6
- data/examples/{simple → dsl}/word_count_bolt.rb +2 -2
- data/examples/{simple → dsl}/word_count_topology.rb +6 -6
- data/examples/shell/shell_topology.rb +2 -2
- data/ivy/storm_dependencies.xml +2 -2
- data/ivy/topology_dependencies.xml +10 -2
- data/lib/red_storm.rb +6 -5
- data/lib/red_storm/application.rb +5 -5
- data/lib/red_storm/dsl/bolt.rb +155 -0
- data/lib/red_storm/dsl/drpc_topology.rb +92 -0
- data/lib/red_storm/dsl/spout.rb +194 -0
- data/lib/red_storm/dsl/topology.rb +227 -0
- data/lib/red_storm/dsl/tuple.rb +34 -0
- data/lib/red_storm/environment.rb +8 -8
- data/lib/red_storm/topology_launcher.rb +2 -2
- data/lib/red_storm/version.rb +1 -1
- data/lib/tasks/red_storm.rake +45 -27
- data/redstorm.gemspec +4 -4
- metadata +31 -34
- data/examples/simple/exclamation_bolt.rb +0 -10
- data/lib/red_storm/simple_bolt.rb +0 -135
- data/lib/red_storm/simple_drpc_topology.rb +0 -87
- data/lib/red_storm/simple_spout.rb +0 -184
- data/lib/red_storm/simple_topology.rb +0 -219
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'java'
|
2
|
+
java_import 'java.lang.System'
|
3
|
+
|
1
4
|
module RedStorm
|
2
5
|
|
3
6
|
LAUNCH_PATH = File.expand_path(File.dirname(__FILE__))
|
@@ -12,7 +15,7 @@ module RedStorm
|
|
12
15
|
REDSTORM_HOME = File.expand_path(LAUNCH_PATH + '/../..')
|
13
16
|
TARGET_PATH = "#{BASE_PATH}/target"
|
14
17
|
end
|
15
|
-
|
18
|
+
|
16
19
|
unless defined?(SPECS_CONTEXT)
|
17
20
|
GEM_PATH = "#{TARGET_PATH}/gems/"
|
18
21
|
ENV["GEM_PATH"] = GEM_PATH
|
@@ -30,12 +33,9 @@ module RedStorm
|
|
30
33
|
version_map[ruby_version.to_s] || version_map[RedStorm.current_ruby_mode]
|
31
34
|
end
|
32
35
|
|
33
|
-
|
36
|
+
def java_runtime_version
|
37
|
+
System.properties["java.runtime.version"].to_s =~ /^(\d+\.\d+).[^\s]+$/ ? $1 : "1.7"
|
38
|
+
end
|
34
39
|
|
35
|
-
|
36
|
-
# puts("*** JAR_CONTEXT=#{JAR_CONTEXT}")
|
37
|
-
# puts("*** BASE_PATH=#{BASE_PATH}")
|
38
|
-
# puts("*** REDSTORM_HOME=#{REDSTORM_HOME}")
|
39
|
-
# puts("*** TARGET_PATH=#{TARGET_PATH}")
|
40
|
-
# puts("*** GEM_PATH=#{GEM_PATH}") if defined?(GEM_PATH)
|
40
|
+
module_function :current_ruby_mode, :jruby_mode_token, :java_runtime_version
|
41
41
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'java'
|
2
2
|
|
3
3
|
# This hack get rif of the "Use RbConfig instead of obsolete and deprecated Config"
|
4
|
-
# deprecation warning that is triggered by "java_import 'backtype.storm.Config'".
|
4
|
+
# deprecation warning that is triggered by "java_import 'backtype.storm.Config'".
|
5
5
|
Object.send :remove_const, :Config
|
6
6
|
Config = RbConfig
|
7
7
|
|
@@ -59,7 +59,7 @@ class TopologyLauncher
|
|
59
59
|
|
60
60
|
topology_name = RedStorm::Configuration.topology_class.respond_to?(:topology_name) ? "/#{RedStorm::Configuration.topology_class.topology_name}" : ''
|
61
61
|
puts("RedStorm v#{RedStorm::VERSION} starting topology #{RedStorm::Configuration.topology_class.name}#{topology_name} in #{env.to_s} environment")
|
62
|
-
RedStorm::Configuration.topology_class.new.start(
|
62
|
+
RedStorm::Configuration.topology_class.new.start(env)
|
63
63
|
end
|
64
64
|
|
65
65
|
private
|
data/lib/red_storm/version.rb
CHANGED
data/lib/tasks/red_storm.rake
CHANGED
@@ -7,7 +7,7 @@ rescue
|
|
7
7
|
end
|
8
8
|
|
9
9
|
require 'jruby/jrubyc'
|
10
|
-
require 'red_storm'
|
10
|
+
require 'red_storm/environment'
|
11
11
|
require 'red_storm/application'
|
12
12
|
|
13
13
|
INSTALL_IVY_VERSION = "2.3.0"
|
@@ -15,7 +15,7 @@ INSTALL_IVY_VERSION = "2.3.0"
|
|
15
15
|
task :launch, :env, :ruby_mode, :class_file do |t, args|
|
16
16
|
# use ruby mode parameter or default to current interpreter version
|
17
17
|
version_token = RedStorm.jruby_mode_token(args[:ruby_mode])
|
18
|
-
|
18
|
+
|
19
19
|
command = case args[:env]
|
20
20
|
when "local"
|
21
21
|
RedStorm::Application.local_storm_command(args[:class_file], args[:ruby_mode])
|
@@ -43,22 +43,24 @@ end
|
|
43
43
|
|
44
44
|
task :setup do
|
45
45
|
puts("\n--> Setting up target directories")
|
46
|
-
ant.mkdir 'dir' => TARGET_DIR
|
47
|
-
ant.mkdir 'dir' => TARGET_CLASSES_DIR
|
46
|
+
ant.mkdir 'dir' => TARGET_DIR
|
47
|
+
ant.mkdir 'dir' => TARGET_CLASSES_DIR
|
48
48
|
ant.mkdir 'dir' => TARGET_DEPENDENCY_DIR
|
49
49
|
ant.mkdir 'dir' => TARGET_SRC_DIR
|
50
50
|
ant.mkdir 'dir' => TARGET_GEM_DIR
|
51
51
|
ant.mkdir 'dir' => TARGET_SPECS_DIR
|
52
|
-
ant.path 'id' => 'classpath' do
|
53
|
-
fileset 'dir' => TARGET_DEPENDENCY_DIR
|
54
|
-
fileset 'dir' => TARGET_CLASSES_DIR
|
55
|
-
end
|
52
|
+
ant.path 'id' => 'classpath' do
|
53
|
+
fileset 'dir' => TARGET_DEPENDENCY_DIR
|
54
|
+
fileset 'dir' => TARGET_CLASSES_DIR
|
55
|
+
end
|
56
56
|
end
|
57
57
|
|
58
|
-
|
58
|
+
desc "install dependencies and compile proxy classes"
|
59
|
+
task :install, [:jvm_version] => [:deps, :build] do |t, args|
|
59
60
|
puts("\nRedStorm install completed. All dependencies installed in #{TARGET_DIR}")
|
60
61
|
end
|
61
62
|
|
63
|
+
desc "locally install examples"
|
62
64
|
task :examples do
|
63
65
|
if File.identical?(SRC_EXAMPLES, DST_EXAMPLES)
|
64
66
|
STDERR.puts("error: cannot copy examples into itself")
|
@@ -78,23 +80,27 @@ task :copy_red_storm do
|
|
78
80
|
FileUtils.cp_r(REDSTORM_LIB_DIR, TARGET_DIR)
|
79
81
|
end
|
80
82
|
|
81
|
-
|
83
|
+
desc "compile JRuby and Java proxy classes"
|
84
|
+
task :build, [:jvm_version] => [:setup, :copy_red_storm] do |t, args|
|
85
|
+
jvm_version = args[:jvm_version].to_s =~ /--(1.\d)/ ? $1 : RedStorm.java_runtime_version
|
86
|
+
|
82
87
|
# compile the JRuby proxy classes to Java
|
83
88
|
build_jruby("#{REDSTORM_LIB_DIR}/red_storm/proxy")
|
84
89
|
|
85
90
|
# compile the generated Java proxy classes
|
86
|
-
build_java_dir("#{TARGET_SRC_DIR}")
|
91
|
+
build_java_dir("#{TARGET_SRC_DIR}", jvm_version)
|
87
92
|
|
88
93
|
# generate the JRuby topology launcher
|
89
94
|
build_jruby("#{REDSTORM_LIB_DIR}/red_storm/topology_launcher.rb")
|
90
95
|
|
91
96
|
# compile the JRuby proxy classes
|
92
|
-
build_java_dir("#{REDSTORM_JAVA_SRC_DIR}")
|
97
|
+
build_java_dir("#{REDSTORM_JAVA_SRC_DIR}", jvm_version)
|
93
98
|
|
94
99
|
# compile the JRuby proxy classes
|
95
|
-
build_java_dir("#{TARGET_SRC_DIR}")
|
100
|
+
build_java_dir("#{TARGET_SRC_DIR}", jvm_version)
|
96
101
|
end
|
97
102
|
|
103
|
+
desc "package topology gems into #{TARGET_GEM_DIR}"
|
98
104
|
task :bundle, [:groups] => :setup do |t, args|
|
99
105
|
require 'bundler'
|
100
106
|
defaulted_args = {:groups => 'default'}.merge(args.to_hash.delete_if{|k, v| v.to_s.empty?})
|
@@ -143,18 +149,29 @@ namespace :ivy do
|
|
143
149
|
end
|
144
150
|
end
|
145
151
|
|
146
|
-
task :
|
147
|
-
puts("\n--> Installing dependencies")
|
148
|
-
|
152
|
+
task :ivy_config do
|
149
153
|
ant.configure 'file' => File.exists?(CUSTOM_IVY_SETTINGS) ? CUSTOM_IVY_SETTINGS : DEFAULT_IVY_SETTINGS
|
154
|
+
end
|
150
155
|
|
151
|
-
|
152
|
-
|
156
|
+
task :storm_deps => ["ivy:install", :ivy_config] do
|
157
|
+
puts("\n--> Installing Storm dependencies")
|
153
158
|
|
154
|
-
ant.resolve 'file' => File.exists?(
|
155
|
-
ant.retrieve 'pattern' => "#{TARGET_DEPENDENCY_DIR}/
|
159
|
+
ant.resolve 'file' => File.exists?(CUSTOM_IVY_STORM_DEPENDENCIES) ? CUSTOM_IVY_STORM_DEPENDENCIES : DEFAULT_IVY_STORM_DEPENDENCIES
|
160
|
+
ant.retrieve 'pattern' => "#{TARGET_DEPENDENCY_DIR}/storm/[conf]/[artifact](-[classifier])-[revision].[ext]", 'sync' => "true"
|
156
161
|
end
|
157
162
|
|
163
|
+
task :topology_deps => ["ivy:install", :ivy_config] do
|
164
|
+
puts("\n--> Installing topology dependencies")
|
165
|
+
|
166
|
+
ant.resolve 'file' => File.exists?(CUSTOM_IVY_TOPOLOGY_DEPENDENCIES) ? CUSTOM_IVY_TOPOLOGY_DEPENDENCIES : DEFAULT_IVY_TOPOLOGY_DEPENDENCIES
|
167
|
+
ant.retrieve 'pattern' => "#{TARGET_DEPENDENCY_DIR}/topology/[conf]/[artifact](-[classifier])-[revision].[ext]", 'sync' => "true"
|
168
|
+
end
|
169
|
+
|
170
|
+
desc "install storm and topology dependencies in #{TARGET_DEPENDENCY_DIR}"
|
171
|
+
task :deps => ["ivy:install", :ivy_config, :storm_deps, :topology_deps] do
|
172
|
+
end
|
173
|
+
|
174
|
+
desc "generate #{TARGET_CLUSTER_JAR}"
|
158
175
|
task :jar, [:include_dir] => [:clean_jar] do |t, args|
|
159
176
|
puts("\n--> Generating JAR file #{TARGET_CLUSTER_JAR}")
|
160
177
|
|
@@ -199,22 +216,23 @@ task :jar, [:include_dir] => [:clean_jar] do |t, args|
|
|
199
216
|
puts("\nRedStorm generated JAR file #{TARGET_CLUSTER_JAR}")
|
200
217
|
end
|
201
218
|
|
202
|
-
def build_java_dir(source_folder)
|
203
|
-
puts("\n--> Compiling Java")
|
219
|
+
def build_java_dir(source_folder, jvm_version)
|
220
|
+
puts("\n--> Compiling Java for JVM #{jvm_version}")
|
204
221
|
ant.javac(
|
205
222
|
'srcdir' => source_folder,
|
206
223
|
'destdir' => TARGET_CLASSES_DIR,
|
207
|
-
'classpathref' => 'classpath',
|
208
|
-
'source' =>
|
209
|
-
'target' =>
|
224
|
+
'classpathref' => 'classpath',
|
225
|
+
'source' => jvm_version,
|
226
|
+
'target' => jvm_version,
|
210
227
|
'debug' => "yes",
|
211
228
|
'includeantruntime' => "no",
|
212
229
|
'verbose' => false,
|
213
230
|
'listfiles' => true
|
214
231
|
) do
|
232
|
+
# compilerarg :value => "-Xlint:deprecation"
|
215
233
|
# compilerarg :value => "-Xlint:unchecked"
|
216
|
-
end
|
217
|
-
end
|
234
|
+
end
|
235
|
+
end
|
218
236
|
|
219
237
|
def build_jruby(source_path)
|
220
238
|
puts("\n--> Compiling JRuby")
|
data/redstorm.gemspec
CHANGED
@@ -3,7 +3,7 @@ $:.unshift libdir unless $:.include?(libdir)
|
|
3
3
|
|
4
4
|
require 'red_storm/version'
|
5
5
|
|
6
|
-
Gem::Specification.new do |s|
|
6
|
+
Gem::Specification.new do |s|
|
7
7
|
s.name = 'redstorm'
|
8
8
|
s.version = RedStorm::VERSION
|
9
9
|
s.authors = ['Colin Surprenant']
|
@@ -11,14 +11,14 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.homepage = 'https://github.com/colinsurprenant/redstorm'
|
12
12
|
s.summary = 'JRuby on Storm'
|
13
13
|
s.description = 'JRuby integration & DSL for the Storm distributed realtime computation system'
|
14
|
-
|
14
|
+
|
15
15
|
s.rubyforge_project = 'redstorm'
|
16
|
-
|
16
|
+
|
17
17
|
s.files = Dir.glob("{lib/**/*}") + Dir.glob("{ivy/*.xml}") + Dir.glob("{examples/**/*}") + Dir.glob("{src/**/*.java}") + Dir.glob("{bin/**/*}") + %w(redstorm.gemspec Rakefile README.md CHANGELOG.md LICENSE.md)
|
18
18
|
s.require_paths = ['lib']
|
19
19
|
s.bindir = 'bin'
|
20
20
|
s.executables = ['redstorm']
|
21
21
|
|
22
|
-
s.add_development_dependency 'rspec', '~> 2.
|
22
|
+
s.add_development_dependency 'rspec', '~> 2.13'
|
23
23
|
s.add_runtime_dependency 'rake'
|
24
24
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redstorm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
5
|
-
prerelease:
|
4
|
+
version: 0.6.6.beta1
|
5
|
+
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Colin Surprenant
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-07-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
16
|
version_requirements: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- -
|
18
|
+
- - ~>
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 2.
|
20
|
+
version: '2.13'
|
21
21
|
none: false
|
22
22
|
requirement: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.
|
26
|
+
version: '2.13'
|
27
27
|
none: false
|
28
28
|
prerelease: false
|
29
29
|
type: :development
|
@@ -31,17 +31,15 @@ dependencies:
|
|
31
31
|
name: rake
|
32
32
|
version_requirements: !ruby/object:Gem::Requirement
|
33
33
|
requirements:
|
34
|
-
- -
|
34
|
+
- - '>='
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version:
|
37
|
-
MA==
|
36
|
+
version: '0'
|
38
37
|
none: false
|
39
38
|
requirement: !ruby/object:Gem::Requirement
|
40
39
|
requirements:
|
41
|
-
- -
|
40
|
+
- - '>='
|
42
41
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
44
|
-
MA==
|
42
|
+
version: '0'
|
45
43
|
none: false
|
46
44
|
prerelease: false
|
47
45
|
type: :runtime
|
@@ -59,12 +57,13 @@ files:
|
|
59
57
|
- lib/red_storm/configurator.rb
|
60
58
|
- lib/red_storm/environment.rb
|
61
59
|
- lib/red_storm/loggable.rb
|
62
|
-
- lib/red_storm/simple_bolt.rb
|
63
|
-
- lib/red_storm/simple_drpc_topology.rb
|
64
|
-
- lib/red_storm/simple_spout.rb
|
65
|
-
- lib/red_storm/simple_topology.rb
|
66
60
|
- lib/red_storm/topology_launcher.rb
|
67
61
|
- lib/red_storm/version.rb
|
62
|
+
- lib/red_storm/dsl/bolt.rb
|
63
|
+
- lib/red_storm/dsl/drpc_topology.rb
|
64
|
+
- lib/red_storm/dsl/spout.rb
|
65
|
+
- lib/red_storm/dsl/topology.rb
|
66
|
+
- lib/red_storm/dsl/tuple.rb
|
68
67
|
- lib/red_storm/proxy/batch_bolt.rb
|
69
68
|
- lib/red_storm/proxy/batch_committer_bolt.rb
|
70
69
|
- lib/red_storm/proxy/batch_spout.rb
|
@@ -77,6 +76,17 @@ files:
|
|
77
76
|
- ivy/settings.xml
|
78
77
|
- ivy/storm_dependencies.xml
|
79
78
|
- ivy/topology_dependencies.xml
|
79
|
+
- examples/dsl/exclamation_bolt.rb
|
80
|
+
- examples/dsl/exclamation_topology.rb
|
81
|
+
- examples/dsl/exclamation_topology2.rb
|
82
|
+
- examples/dsl/hello_world_topology.rb
|
83
|
+
- examples/dsl/kafka_topology.rb
|
84
|
+
- examples/dsl/random_sentence_spout.rb
|
85
|
+
- examples/dsl/redis_word_count_topology.rb
|
86
|
+
- examples/dsl/ruby_version_topology.rb
|
87
|
+
- examples/dsl/split_sentence_bolt.rb
|
88
|
+
- examples/dsl/word_count_bolt.rb
|
89
|
+
- examples/dsl/word_count_topology.rb
|
80
90
|
- examples/native/cluster_word_count_topology.rb
|
81
91
|
- examples/native/exclamation_bolt.rb
|
82
92
|
- examples/native/local_exclamation_topology.rb
|
@@ -89,17 +99,6 @@ files:
|
|
89
99
|
- examples/shell/shell_topology.rb
|
90
100
|
- examples/shell/resources/splitsentence.py
|
91
101
|
- examples/shell/resources/storm.py
|
92
|
-
- examples/simple/exclamation_bolt.rb
|
93
|
-
- examples/simple/exclamation_topology.rb
|
94
|
-
- examples/simple/exclamation_topology2.rb
|
95
|
-
- examples/simple/hello_world_topology.rb
|
96
|
-
- examples/simple/kafka_topology.rb
|
97
|
-
- examples/simple/random_sentence_spout.rb
|
98
|
-
- examples/simple/redis_word_count_topology.rb
|
99
|
-
- examples/simple/ruby_version_topology.rb
|
100
|
-
- examples/simple/split_sentence_bolt.rb
|
101
|
-
- examples/simple/word_count_bolt.rb
|
102
|
-
- examples/simple/word_count_topology.rb
|
103
102
|
- src/main/redstorm/storm/jruby/JRubyBatchBolt.java
|
104
103
|
- src/main/redstorm/storm/jruby/JRubyBatchCommitterBolt.java
|
105
104
|
- src/main/redstorm/storm/jruby/JRubyBatchSpout.java
|
@@ -126,17 +125,15 @@ require_paths:
|
|
126
125
|
- lib
|
127
126
|
required_ruby_version: !ruby/object:Gem::Requirement
|
128
127
|
requirements:
|
129
|
-
- -
|
128
|
+
- - '>='
|
130
129
|
- !ruby/object:Gem::Version
|
131
|
-
version:
|
132
|
-
MA==
|
130
|
+
version: '0'
|
133
131
|
none: false
|
134
132
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
133
|
requirements:
|
136
|
-
- -
|
134
|
+
- - '>'
|
137
135
|
- !ruby/object:Gem::Version
|
138
|
-
version:
|
139
|
-
MA==
|
136
|
+
version: 1.3.1
|
140
137
|
none: false
|
141
138
|
requirements: []
|
142
139
|
rubyforge_project: redstorm
|
@@ -1,135 +0,0 @@
|
|
1
|
-
require 'java'
|
2
|
-
require 'red_storm/configurator'
|
3
|
-
|
4
|
-
module RedStorm
|
5
|
-
|
6
|
-
class SimpleBolt
|
7
|
-
attr_reader :collector, :context, :config
|
8
|
-
|
9
|
-
# DSL class methods
|
10
|
-
|
11
|
-
def self.log
|
12
|
-
@log ||= Java::OrgApacheLog4j::Logger.getLogger(self.name)
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.output_fields(*fields)
|
16
|
-
@fields = fields.map(&:to_s)
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.configure(&configure_block)
|
20
|
-
@configure_block = block_given? ? configure_block : lambda {}
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.on_receive(*args, &on_receive_block)
|
24
|
-
options = args.last.is_a?(Hash) ? args.pop : {}
|
25
|
-
method_name = args.first
|
26
|
-
|
27
|
-
self.receive_options.merge!(options)
|
28
|
-
@on_receive_block = block_given? ? on_receive_block : lambda {|tuple| self.send(method_name || :on_receive, tuple)}
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.on_init(method_name = nil, &on_init_block)
|
32
|
-
@on_init_block = block_given? ? on_init_block : lambda {self.send(method_name || :on_init)}
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.on_close(method_name = nil, &close_block)
|
36
|
-
@close_block = block_given? ? close_block : lambda {self.send(method_name || :on_close)}
|
37
|
-
end
|
38
|
-
|
39
|
-
# DSL instance methods
|
40
|
-
|
41
|
-
def log
|
42
|
-
self.class.log
|
43
|
-
end
|
44
|
-
|
45
|
-
def unanchored_emit(*values)
|
46
|
-
@collector.emit(Values.new(*values))
|
47
|
-
end
|
48
|
-
|
49
|
-
def anchored_emit(tuple, *values)
|
50
|
-
@collector.emit(tuple, Values.new(*values))
|
51
|
-
end
|
52
|
-
|
53
|
-
def ack(tuple)
|
54
|
-
@collector.ack(tuple)
|
55
|
-
end
|
56
|
-
|
57
|
-
def fail(tuple)
|
58
|
-
@collector.fail(tuple)
|
59
|
-
end
|
60
|
-
|
61
|
-
# Bolt proxy interface
|
62
|
-
|
63
|
-
def execute(tuple)
|
64
|
-
output = instance_exec(tuple, &self.class.on_receive_block)
|
65
|
-
if output && self.class.emit?
|
66
|
-
values_list = !output.is_a?(Array) ? [[output]] : !output.first.is_a?(Array) ? [output] : output
|
67
|
-
values_list.each{|values| self.class.anchor? ? anchored_emit(tuple, *values) : unanchored_emit(*values)}
|
68
|
-
@collector.ack(tuple) if self.class.ack?
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def prepare(config, context, collector)
|
73
|
-
@collector = collector
|
74
|
-
@context = context
|
75
|
-
@config = config
|
76
|
-
instance_exec(&self.class.on_init_block)
|
77
|
-
end
|
78
|
-
|
79
|
-
def cleanup
|
80
|
-
instance_exec(&self.class.close_block)
|
81
|
-
end
|
82
|
-
|
83
|
-
def declare_output_fields(declarer)
|
84
|
-
declarer.declare(Fields.new(self.class.fields))
|
85
|
-
end
|
86
|
-
|
87
|
-
def get_component_configuration
|
88
|
-
configurator = Configurator.new
|
89
|
-
configurator.instance_exec(&self.class.configure_block)
|
90
|
-
configurator.config
|
91
|
-
end
|
92
|
-
|
93
|
-
private
|
94
|
-
|
95
|
-
# default noop optional dsl callbacks
|
96
|
-
def on_init; end
|
97
|
-
def on_close; end
|
98
|
-
|
99
|
-
def self.fields
|
100
|
-
@fields ||= []
|
101
|
-
end
|
102
|
-
|
103
|
-
def self.configure_block
|
104
|
-
@configure_block ||= lambda {}
|
105
|
-
end
|
106
|
-
|
107
|
-
def self.on_receive_block
|
108
|
-
@on_receive_block ||= lambda {|tuple| self.send(:on_receive, tuple)}
|
109
|
-
end
|
110
|
-
|
111
|
-
def self.on_init_block
|
112
|
-
@on_init_block ||= lambda {self.send(:on_init)}
|
113
|
-
end
|
114
|
-
|
115
|
-
def self.close_block
|
116
|
-
@close_block ||= lambda {self.send(:on_close)}
|
117
|
-
end
|
118
|
-
|
119
|
-
def self.receive_options
|
120
|
-
@receive_options ||= {:emit => true, :ack => false, :anchor => false}
|
121
|
-
end
|
122
|
-
|
123
|
-
def self.emit?
|
124
|
-
!!self.receive_options[:emit]
|
125
|
-
end
|
126
|
-
|
127
|
-
def self.ack?
|
128
|
-
!!self.receive_options[:ack]
|
129
|
-
end
|
130
|
-
|
131
|
-
def self.anchor?
|
132
|
-
!!self.receive_options[:anchor]
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|