Module: TorqueBox::Naming

Defined in:
naming/lib/torquebox/naming.rb

Constant Summary

REMOTE_NAMING_FACTORY =
'org.jboss.naming.remote.client.InitialContextFactory'
LOCAL_NAMING_FACTORY =
'org.jboss.as.naming.InitialContextFactory'

Class Method Summary (collapse)

Class Method Details

+ (Object) log



77
78
79
# File 'naming/lib/torquebox/naming.rb', line 77

def self.log
  @logger ||= TorqueBox::Logger.new(self)
end

+ (Object) populate_properties(options = {})



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'naming/lib/torquebox/naming.rb', line 55

def self.populate_properties(options = {})
  options = { :host => 'localhost',
              :port => 4447,
              :remote => false }.merge(options)

  properties = {}

  if options[:remote]
    properties[javax.naming.Context.INITIAL_CONTEXT_FACTORY] = REMOTE_NAMING_FACTORY
    properties[javax.naming.Context.PROVIDER_URL] = "remote://#{options[:host]}:#{options[:port]}"

    properties[javax.naming.Context.SECURITY_PRINCIPAL] = options[:username] if options[:username]
    properties[javax.naming.Context.SECURITY_CREDENTIALS] = options[:password] if options[:password]
  else
    properties[javax.naming.Context.INITIAL_CONTEXT_FACTORY] = LOCAL_NAMING_FACTORY
  end

  log.debug("Naming properties used to connect: #{properties}")

  java.util.Hashtable.new(properties)
end

+ (Object) remote_context(options = {}, &block)



41
42
43
44
45
46
47
48
49
50
51
# File 'naming/lib/torquebox/naming.rb', line 41

def self.remote_context(options = {}, &block)
  ctx = javax.naming::InitialContext.new(populate_properties(options.merge(:remote => true)))

  return ctx unless block

  begin
    block.call(ctx)
  ensure
    ctx.close
  end
end