Class: Moneta::Server
Overview
Moneta server to be used together with Moneta::Adapters::Client
Defined Under Namespace
Classes: Connection
Instance Method Summary collapse
-
#initialize(store, options = {}) ⇒ Server
constructor
A new instance of Server.
-
#run ⇒ Object
Run the server.
-
#running? ⇒ Boolean
Is the server running.
-
#stop ⇒ Object
Stop the server.
Methods included from Config
Constructor Details
#initialize(store, options = {}) ⇒ Server
Returns a new instance of Server.
162 163 164 165 166 167 168 169 170 171 |
# File 'lib/moneta/server.rb', line 162 def initialize(store, = {}) = configure(**) @store = store @server = start(**) @ios = [@server] @reads = @ios.dup @writes = [] @connections = {} @running = false end |
Instance Method Details
#run ⇒ Object
Note:
This method blocks!
Run the server
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/moneta/server.rb', line 183 def run raise 'Already running' if running? @stop = false @running = true begin mainloop until @stop ensure @running = false @server.close unless @server.closed? @ios .reject { |io| io == @server } .each { |io| close_connection(io) } File.unlink(config.socket) if config.socket rescue nil end end |
#running? ⇒ Boolean
Is the server running
176 177 178 |
# File 'lib/moneta/server.rb', line 176 def running? @running end |
#stop ⇒ Object
Stop the server
200 201 202 203 204 205 |
# File 'lib/moneta/server.rb', line 200 def stop raise 'Not running' unless running? @stop = true @server.close nil end |