Sha256: 2f45037b9d5f24e22731b43d766b1c35d2bf79e56c9a61d9d8344717a90efd63

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

require 'jmx'

module ModernTimes
  class ManagerMBean < RubyDynamicMBean
    attr_reader :manager
    rw_attribute :foobar, :int, "Number of workers"

    def initialize(name, description, manager)
      super(name, description)
      @manager = manager
    end

    operation 'Allowed workers'
    returns :list
    def allowed_workers
      all = manager.allowed_workers || ['No Restrictions']
      all.map {|worker_klass| worker_klass.name }
    end

    operation 'Start worker'
    parameter :string, "worker", "The worker class to start"
    parameter :int, "count", "Number of workers"
    returns :string
    def start_worker(worker, count)
      ModernTimes.logger.debug "Attempting to start #{worker} with count=#{count}"
      manager.add(worker, count)
      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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
modern_times-0.1.1 lib/modern_times/manager_mbean.rb
modern_times-0.1.0 lib/modern_times/manager_mbean.rb