Module: TorqueBox

Defined in:
lib/torquebox/core.rb,
lib/torquebox/msc.rb,
lib/torquebox/codecs.rb,
lib/torquebox/kernel.rb,
lib/torquebox/logger.rb,
lib/torquebox/service.rb,
lib/torquebox/registry.rb,
lib/torquebox/injectors.rb,
lib/torquebox/codecs/edn.rb,
lib/torquebox/codecs/json.rb,
lib/torquebox/scheduled_job.rb,
lib/torquebox/codecs/marshal.rb,
lib/torquebox/service_registry.rb,
lib/torquebox/component_manager.rb,
lib/torquebox/codecs/marshal_smart.rb,
lib/torquebox/codecs/marshal_base64.rb

Overview

Copyright 2008-2013 Red Hat, Inc, and individual contributors.

This is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this software; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF site: www.fsf.org.

Defined Under Namespace

Modules: Codecs, Injectors Classes: ComponentManager, FallbackLogger, InjectionError, Kernel, Logger, MSC, Registry, ScheduledJob, Service, ServiceRegistry

Class Method Summary collapse

Class Method Details

.fetch(something, options = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/torquebox/injectors.rb', line 27

def self.fetch(something,options={})
  timeout = options[:timeout] || 45
  unless TorqueBox::Registry.has_key?(something.to_s)
    handler_registry = TorqueBox::ServiceRegistry['torquebox.core.injection.injectable-handler-registry']
    # handler_registry should only be nil when running outside of
    # TorqueBox so we just return the nil value and skip everything
    # else to facilitate testing outside the container
    return nil if handler_registry.nil?
    handler = handler_registry.get_handler(something)
    raise InjectionError.new("Invalid injection - #{something}") if handler.nil?
    injectable = handler.handle(something, true)
    service_name = injectable.get_service_name(TorqueBox::Registry['service-target'],
                                               TorqueBox::Registry['deployment-unit'])
    service = TorqueBox::ServiceRegistry.registry.getService(service_name)
    raise InjectionError.new("Service not found for injection - #{something}") if service.nil?
    state = TorqueBox::MSC.wait_for_service_to_start(service, timeout)
    raise InjectionError.new("Injected service failed to start - #{service_name}") if state != 'UP'
    value = service.value
    raise InjectionError.new("Injected service had no value - #{service_name}") if value.nil?
    value = value.convert(JRuby.runtime) if value.respond_to?(:convert)
    if something.to_s.start_with?("service:")
      # don't cache services to support zero-downtime deploys (TORQUE-1217)
      return value
    else
      TorqueBox::Registry.merge!(something.to_s => value)
    end
  end
  TorqueBox::Registry[something.to_s]
end