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.
164 165 166 167 168 169 170 171 172 173 |
# File 'lib/moneta/server.rb', line 164 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
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/moneta/server.rb', line 185 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
178 179 180 |
# File 'lib/moneta/server.rb', line 178 def running? @running end |
#stop ⇒ Object
Stop the server
202 203 204 205 206 207 |
# File 'lib/moneta/server.rb', line 202 def stop raise 'Not running' unless running? @stop = true @server.close nil end |