2011-10-28 20:24:22 +00:00
require 'java'
2011-11-04 21:47:48 +00:00
2013-05-14 21:22:31 +00:00
# This hack get rif of the "Use RbConfig instead of obsolete and deprecated Config"
2013-06-20 04:50:03 +00:00
# deprecation warning that is triggered by "java_import 'backtype.storm.Config'".
2014-03-02 09:33:30 +00:00
begin
Object . send :remove_const , :Config
Config = RbConfig
rescue NameError
end
2013-05-14 21:22:31 +00:00
2012-05-19 21:08:32 +00:00
# see https://github.com/colinsurprenant/redstorm/issues/7
module Backtype
java_import 'backtype.storm.Config'
end
2011-10-28 20:24:22 +00:00
java_import 'backtype.storm.LocalCluster'
2012-12-10 23:45:32 +00:00
java_import 'backtype.storm.LocalDRPC'
2011-11-03 17:52:41 +00:00
java_import 'backtype.storm.StormSubmitter'
2011-10-28 20:24:22 +00:00
java_import 'backtype.storm.topology.TopologyBuilder'
2012-09-18 15:41:32 +00:00
java_import 'backtype.storm.coordination.BatchBoltExecutor'
2012-12-10 23:45:32 +00:00
java_import 'backtype.storm.drpc.LinearDRPCTopologyBuilder'
2011-10-28 20:24:22 +00:00
java_import 'backtype.storm.tuple.Fields'
java_import 'backtype.storm.tuple.Tuple'
java_import 'backtype.storm.tuple.Values'
2014-03-02 08:04:01 +00:00
# java_import 'redstorm.storm.jruby.JRubyBolt'
# java_import 'redstorm.storm.jruby.JRubySpout'
# java_import 'redstorm.storm.jruby.JRubyBatchBolt'
# java_import 'redstorm.storm.jruby.JRubyBatchCommitterBolt'
# java_import 'redstorm.storm.jruby.JRubyBatchSpout'
# java_import 'redstorm.storm.jruby.JRubyTransactionalSpout'
# java_import 'redstorm.storm.jruby.JRubyTransactionalBolt'
# java_import 'redstorm.storm.jruby.JRubyTransactionalCommitterBolt'
2014-03-03 00:43:10 +00:00
# java_import 'redstorm.storm.jruby.JRubyProxyFunction'
2011-11-03 22:33:33 +00:00
java_package 'redstorm'
2011-10-28 20:24:22 +00:00
2012-12-10 23:45:32 +00:00
# TopologyLauncher is the application entry point when launching a topology. Basically it will
2011-12-09 20:28:23 +00:00
# call require on the specified Ruby topology class file path and call its start method
2011-10-28 20:24:22 +00:00
class TopologyLauncher
java_signature 'void main(String[])'
def self . main ( args )
2012-06-05 19:08:01 +00:00
unless args . size > 1
2011-11-11 23:32:02 +00:00
puts ( " Usage: redstorm local|cluster topology_class_file_name " )
2011-10-28 20:24:22 +00:00
exit ( 1 )
end
2012-06-02 00:00:10 +00:00
2012-06-05 19:08:01 +00:00
env = args [ 0 ] . to_sym
class_path = args [ 1 ]
2012-06-28 18:35:07 +00:00
launch_path = Dir . pwd
$: . unshift File . expand_path ( launch_path )
$: . unshift File . expand_path ( launch_path + '/lib' )
2012-06-28 21:34:16 +00:00
$: . unshift File . expand_path ( launch_path + '/target/lib' )
2012-06-02 00:00:10 +00:00
2012-12-10 23:45:32 +00:00
require " #{ class_path } "
2011-12-09 20:28:23 +00:00
2013-05-14 21:22:31 +00:00
if RedStorm :: Configuration . topology_class . nil? || ! RedStorm :: Configuration . topology_class . method_defined? ( :start )
puts ( " \n ERROR: invalid topology class. make sure your topology class is a subclass of one of the DSL topology classes or that your class sets RedStorm::Configuration.topology_class and defines the start method \n \n " )
exit ( 1 )
end
2011-12-09 20:28:23 +00:00
topology_name = RedStorm :: Configuration . topology_class . respond_to? ( :topology_name ) ? " / #{ RedStorm :: Configuration . topology_class . topology_name } " : ''
puts ( " RedStorm v #{ RedStorm :: VERSION } starting topology #{ RedStorm :: Configuration . topology_class . name } #{ topology_name } in #{ env . to_s } environment " )
2013-06-20 04:50:03 +00:00
RedStorm :: Configuration . topology_class . new . start ( env )
2011-10-28 20:24:22 +00:00
end
2012-12-10 23:45:32 +00:00
private
2011-10-28 20:24:22 +00:00
def self . camel_case ( s )
s . to_s . gsub ( / \/ (.?) / ) { " :: #{ $1 . upcase } " } . gsub ( / (?:^|_)(.) / ) { $1 . upcase }
end
2011-11-03 17:52:41 +00:00
end