Class: TorqueBox::MSC

Inherits:
Object
  • Object
show all
Defined in:
lib/torquebox/msc.rb

Class Method Summary collapse

Class Method Details

.deployment_unitObject



28
29
30
# File 'lib/torquebox/msc.rb', line 28

def deployment_unit
  TorqueBox::Registry['deployment-unit']
end

.get_service(service_name) ⇒ Object



36
37
38
# File 'lib/torquebox/msc.rb', line 36

def get_service(service_name)
  service_registry.get_service(service_name)
end

.get_services(regexp, &block) ⇒ Object

Returns (or yields over the items) of list of services with (canonical) name matching provided regular expression.

Parameters:

  • Regular (Regexp)

    expression to match the name

  • Optional

    block. If block is provided it’ll iterate over the values. If there is no block given this method returns list of services



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/torquebox/msc.rb', line 49

def get_services(regexp, &block)
  services = []

  TorqueBox::MSC.service_names.each do |name|
    if name.canonical_name =~ regexp
      service = TorqueBox::MSC.get_service(name)
      services << service unless service.nil?
    end
  end

  if block
    services.each do |s|
      yield s
    end
  else
    services
  end
end

.java_web_contextObject



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/torquebox/msc.rb', line 68

def java_web_context
   = deployment_unit.get_attachment(org.jboss.as.web.deployment.WarMetaData::ATTACHMENT_KEY)
  return nil if .nil? # no web component in this application
   = .
  virtual_host = .virtual_hosts.first || 'default-host'
  context_path = .context_root
  context_path = "/#{context_path}" unless context_path.start_with?('/')
  deployment_service_name = org.jboss.msc.service.ServiceName.parse("jboss.web.deployment")
  service_name = deployment_service_name.append(virtual_host).append(context_path)
  get_service(service_name).value
end

.service_namesObject



32
33
34
# File 'lib/torquebox/msc.rb', line 32

def service_names
  service_registry.service_names
end

.service_registryObject



24
25
26
# File 'lib/torquebox/msc.rb', line 24

def service_registry
  TorqueBox::Registry['service-registry']
end

.wait_for_service_to_start(service, seconds_to_wait) ⇒ Object

Wait for the given MSC service to start.

STARTING, START_FAILED, UP, STOPPING, or REMOVED. This should be UP unless something went wrong.

Parameters:

  • MSC (org.jboss.msc.service.Service)

    service to wait on

Returns:

  • String the service state after waiting - one of DOWN,



87
88
89
90
91
92
93
94
95
# File 'lib/torquebox/msc.rb', line 87

def wait_for_service_to_start(service, seconds_to_wait)
  unless service.state.to_s == 'UP'
    listener = org.torquebox.core.gem.MSCServiceListener.new(service)
    service.add_listener(listener)
    service.set_mode(org.jboss.msc.service.ServiceController::Mode::ACTIVE)
    listener.wait_for_start_or_failure(seconds_to_wait)
  end
  service.state.to_s
end