Class: R2CORBA::INS::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/corba/svcs/ins/naming_service.rb

Constant Summary collapse

OPTIONS =

default options

{
  :iorfile => 'ins.ior',
  :debug => 0,
  :threads => 5,
  :orbprop => {},
  :port => 0
}

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Service

Returns a new instance of Service.

Raises:

  • (RuntimeError)


29
30
31
32
# File 'lib/corba/svcs/ins/naming_service.rb', line 29

def initialize(options = {})
  @options = OPTIONS.merge(options)
  raise RuntimeError, 'nr. of threads must >= 1' if @options[:threads] < 1
end

Instance Method Details

#runObject



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/corba/svcs/ins/naming_service.rb', line 95

def run
  STDERR.puts "INS - starting service run" if @options[:verbose]
  if (defined?(JRUBY_VERSION) or !R2CORBA::TAO::RUBY_THREAD_SUPPORT)
    STDERR.puts "INS - running ORB" if @options[:verbose]
    @orb.run
  else
    STDERR.puts "INS - starting #{@options[:threads]} ORB threads" if @options[:verbose]
    @threads = []
    @options[:threads].times do
      @threads << Thread.new(@orb) { |orb| orb.run }
    end
    STDERR.puts "INS - joining ORB threads" if @options[:verbose]
    @threads.each { |t| t.join }
  end
  STDERR.puts "INS - service run ended" if @options[:verbose]
end

#setupObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/corba/svcs/ins/naming_service.rb', line 34

def setup
  # process options
  #
  if defined?(JRUBY_VERSION)
    @options[:orbprop]['jacorb.poa.thread_pool_min'] = @options[:threads]
    @options[:orbprop]['jacorb.poa.thread_pool_max'] = @options[:threads]*4
    if @options[:debug] > 0
      @options[:orbprop]['jacorb.log.default.verbosity'] = case
      when @options[:debug] < 2
        1
      when (2...4) === @options[:debug]
        2
      when (5...7) === @options[:debug]
        3
      when @options[:debug] > 7
        4
      end
    end
    if @options[:port] > 0
      @options[:orbprop]['OAPort'] = @options[:port]
    end
  else
    if @options[:debug] > 0
      @options[:orbprop]['-ORBDebugLevel'] = @options[:debug]
    end
    if @options[:port] > 0
      @options[:orbprop]['-ORBListenEndpoints'] = "iiop://:#{@options[:port]}"
    end
  end

  # initialize ORB and POA.
  #
  @orb = CORBA.ORB_init('INS_ORB', @options[:orbprop])

  obj = @orb.resolve_initial_references('RootPOA')

  root_poa = PortableServer::POA._narrow(obj)

  poa_man = root_poa.the_POAManager

  poa_man.activate

  # create and activate root Naming context
  #
  @naming_srv = INS::NamingContext.new(@orb)

  naming_obj = @naming_srv._this()

  naming_ior = @orb.object_to_string(naming_obj)

  # simplify Corbaloc urls (corbaloc:iiop:[host][:port]/NamingService)
  #
  @orb.ior_map.map_ior('NamingService', naming_ior)

  # save INS IOR to file
  #
  open(@options[:iorfile], 'w') { |io|
    io.write naming_ior
  }
end

#shutdownObject



112
113
114
115
116
# File 'lib/corba/svcs/ins/naming_service.rb', line 112

def shutdown
  STDERR.puts "INS - shutting down ORB" if @options[:verbose]
  @orb.shutdown if @orb
  STDERR.puts "INS - shutdown finished" if @options[:verbose]
end