Class: RedStorm::SimpleTopology::BoltDefinition

Inherits:
ComponentDefinition show all
Defined in:
lib/red_storm/simple_topology.rb

Direct Known Subclasses

InputBoltDefinition

Instance Attribute Summary collapse

Attributes inherited from ComponentDefinition

#clazz, #constructor_args, #id, #parallelism

Attributes inherited from Configurator

#config

Instance Method Summary collapse

Methods inherited from ComponentDefinition

#is_java?, #output_fields

Methods inherited from Configurator

#method_missing, #set

Constructor Details

#initialize(*args) ⇒ BoltDefinition

Returns a new instance of BoltDefinition.



56
57
58
59
# File 'lib/red_storm/simple_topology.rb', line 56

def initialize(*args)
  super
  @sources = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RedStorm::Configurator

Instance Attribute Details

#commandObject

Returns the value of attribute command.



54
55
56
# File 'lib/red_storm/simple_topology.rb', line 54

def command
  @command
end

#sourcesObject

Returns the value of attribute sources.



54
55
56
# File 'lib/red_storm/simple_topology.rb', line 54

def sources
  @sources
end

Instance Method Details

#define_grouping(declarer) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/red_storm/simple_topology.rb', line 65

def define_grouping(declarer)
  @sources.each do |source_id, grouping|
    grouper, params = grouping.first
      # declarer.fieldsGrouping(source_id, Fields.new())
    case grouper
    when :fields
      declarer.fieldsGrouping(source_id, Fields.new(*([params].flatten.map(&:to_s))))
    when :global
      declarer.globalGrouping(source_id)
    when :shuffle
      declarer.shuffleGrouping(source_id)
    when :local_or_shuffle
      declarer.localOrShuffleGrouping(source_id)
    when :none
      declarer.noneGrouping(source_id)
    when :all
      declarer.allGrouping(source_id)
    when :direct
      declarer.directGrouping(source_id)
    else
      raise("unknown grouper=#{grouper.inspect}")
    end
  end
end

#new_instance(base_class_path) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/red_storm/simple_topology.rb', line 90

def new_instance(base_class_path)
  # WARNING non-dry see BoltDefinition#new_instance
  if @clazz.name == "Java::RedstormStormJruby::JRubyShellBolt"
    @clazz.new(constructor_args, @output_fields)
  elsif is_java?
    @clazz.new(*constructor_args)
  else
    JRubyBolt.new(base_class_path, @clazz.name, @output_fields)
  end
  # is_java? ? @clazz.new : @clazz.is_a?(SimpleBolt) ? JRubyBolt.new(base_class_path, @clazz.name) : @clazz.new
end

#source(source_id, grouping) ⇒ Object



61
62
63
# File 'lib/red_storm/simple_topology.rb', line 61

def source(source_id, grouping)
  @sources << [source_id.is_a?(Class) ? SimpleTopology.underscore(source_id) : source_id.to_s, grouping.is_a?(Hash) ? grouping : {grouping => nil}]
end