Class: Roma::Romad
- Inherits:
-
Object
- Object
- Roma::Romad
- Includes:
- AsyncProcess, WriteBehindProcess
- Defined in:
- lib/roma/romad.rb
Instance Attribute Summary collapse
-
#eventloop ⇒ Object
Returns the value of attribute eventloop.
-
#rttable ⇒ Object
readonly
Returns the value of attribute rttable.
-
#startup ⇒ Object
Returns the value of attribute startup.
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
-
#storages ⇒ Object
readonly
Returns the value of attribute storages.
-
#wb_writer ⇒ Object
readonly
Returns the value of attribute wb_writer.
Instance Method Summary collapse
- #daemon? ⇒ Boolean
-
#initialize(argv = nil) ⇒ Romad
constructor
A new instance of Romad.
- #start ⇒ Object
- #stop_clean_up ⇒ Object
Methods included from WriteBehindProcess
push, #start_wb_process, #stop_wb_process, #wb_get_current_file_path, #wb_get_path, #wb_get_stat, #wb_rotate
Methods included from AsyncProcess
queue, queue_latency, #start_async_process
Constructor Details
#initialize(argv = nil) ⇒ Romad
Returns a new instance of Romad.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/roma/romad.rb', line 29 def initialize(argv = nil) @stats = Roma::Stats.instance @startup = true (argv) initialize_stats initialize_connection initialize_logger initialize_rttable initialize_storages initialize_handler initialize_plugin initialize_wb_writer end |
Instance Attribute Details
#eventloop ⇒ Object
Returns the value of attribute eventloop.
26 27 28 |
# File 'lib/roma/romad.rb', line 26 def eventloop @eventloop end |
#rttable ⇒ Object (readonly)
Returns the value of attribute rttable.
22 23 24 |
# File 'lib/roma/romad.rb', line 22 def rttable @rttable end |
#startup ⇒ Object
Returns the value of attribute startup.
27 28 29 |
# File 'lib/roma/romad.rb', line 27 def startup @startup end |
#stats ⇒ Object (readonly)
Returns the value of attribute stats.
23 24 25 |
# File 'lib/roma/romad.rb', line 23 def stats @stats end |
#storages ⇒ Object (readonly)
Returns the value of attribute storages.
21 22 23 |
# File 'lib/roma/romad.rb', line 21 def storages @storages end |
#wb_writer ⇒ Object (readonly)
Returns the value of attribute wb_writer.
24 25 26 |
# File 'lib/roma/romad.rb', line 24 def wb_writer @wb_writer end |
Instance Method Details
#daemon? ⇒ Boolean
159 |
# File 'lib/roma/romad.rb', line 159 def daemon?; @stats.daemon; end |
#start ⇒ Object
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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/roma/romad.rb', line 43 def start # config version check if !Config.const_defined?(:VERSION) @log.error("ROMA FAIL TO BOOT! : config.rb's version is too old.") exit elsif Config::VERSION != Roma::VERSION if /(\d+)\.(\d+)\.(\d+)/ =~ Config::VERSION version_config = ($1.to_i << 16) + ($2.to_i << 8) + $3.to_i end if /(\d+)\.(\d+)\.(\d+)/ =~ Roma::VERSION version_roma = ($1.to_i << 16) + ($2.to_i << 8) + $3.to_i end if version_config == version_roma @log.info("This version is development version.") else @log.error("ROMA FAIL TO BOOT! : config.rb's version is differ from current ROMA version.") exit end end if node_check(@stats.ap_str) @log.error("#{@stats.ap_str} is already running.") return end @storages.each{|hashname,st| st.opendb } start_async_process start_wb_process timer if @stats.join_ap AsyncProcess::queue.push(AsyncMessage.new('start_join_process')) end # select a kind of system call if Config.const_defined?(:CONNECTION_USE_EPOLL) && Config::CONNECTION_USE_EPOLL @log.info("use an epoll") EM.epoll if Config.const_defined?(:CONNECTION_DESCRIPTOR_TABLE_SIZE) EM.set_descriptor_table_size(Config::CONNECTION_DESCRIPTOR_TABLE_SIZE) end else @log.info("use a select") end @eventloop = true while(@eventloop) @eventloop = false begin # initialize an instance of connections as restarting of an evantmachine Event::Handler::connections.each_key{|k| begin k.close_connection rescue Exception => e @log.error("#{e}\n#{$@}") end } Event::Handler::connections.clear EventMachine::run do EventMachine.start_server('0.0.0.0', @stats.port, Roma::Command::Receiver, @storages, @rttable) # a management of connections lives EventMachine::add_periodic_timer( 10 ) { if Event::Handler::connection_expire_time > 0 dellist = [] Event::Handler::connections.each{|k,v| if k.connected == false || k.last_access == nil dellist << k elsif k.last_access < Time.now - Event::Handler::connection_expire_time begin k.close_connection if k.addr @log.info("connection expired from #{k.addr}:#{k.port},lastcmd = #{k.lastcmd}") else @log.info("connection expired in irregular connection") dellist << k end rescue Exception => e @log.error("#{e}\n#{$@}") dellist << k end end } dellist.each{|k| @log.info("delete connection lastcmd = #{k.lastcmd}") Event::Handler::connections.delete(k) } end } @log.info("Now accepting connections on address #{@stats.address}, port #{@stats.port}") end rescue Interrupt => e if daemon? @log.error("#{e.inspect}\n#{$@}") retry else $stderr.puts "#{e.inspect}" end rescue Exception => e @log.error("#{e}\n#{$@}") @log.error("restart an eventmachine") retry end end stop_async_process stop_wb_process stop end |
#stop_clean_up ⇒ Object
161 162 163 164 165 166 167 168 |
# File 'lib/roma/romad.rb', line 161 def stop_clean_up @stats.last_clean_up = Time.now while(@stats.run_storage_clean_up) @log.info("Storage clean up process will be stop.") @storages.each_value{|st| st.stop_clean_up} sleep 0.005 end end |