Class: ModernTimes::ManagerMBean

Inherits:
RubyDynamicMBean
  • Object
show all
Defined in:
lib/modern_times/manager_mbean.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain, manager) ⇒ ManagerMBean

Returns a new instance of ManagerMBean.



8
9
10
11
# File 'lib/modern_times/manager_mbean.rb', line 8

def initialize(domain, manager)
  super(ModernTimes.manager_mbean_name(domain), 'Manager')
  @manager = manager
end

Instance Attribute Details

#managerObject (readonly)

Returns the value of attribute manager.



5
6
7
# File 'lib/modern_times/manager_mbean.rb', line 5

def manager
  @manager
end

Instance Method Details

#allowed_workersObject



13
14
15
16
17
# File 'lib/modern_times/manager_mbean.rb', line 13

def allowed_workers
  all = manager.allowed_workers || ['No Restrictions']
  all = all.map {|worker_klass| worker_klass.name }
  java.util.ArrayList.new(all)
end

#start_worker(worker, count, options) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/modern_times/manager_mbean.rb', line 24

def start_worker(worker, count, options)
  ModernTimes.logger.debug "Attempting to start #{worker} with count=#{count} and options=#{options}"
  opts = {}
  unless options.empty?
    require 'json'
    opts_string_keys = ::JSON::Parser.new(options).parse
    opts_string_keys.each { |k,v| opts[k.to_sym] = v }
  end
  manager.add(worker, count, opts)
  return 'Successfuly started'
rescue Exception => e
  ModernTimes.logger.error "Exception starting worker #{worker}: {e.message}\n\t#{e.backtrace.join("\n\t")}"
  return "Exception starting worker #{worker}: {e.message}"
rescue java.lang.Exception => e
  ModernTimes.logger.error "Java exception starting worker #{worker}: {e.message}\n\t#{e.backtrace.join("\n\t")}"
  return "Java exception starting worker #{worker}: {e.message}"
end