Class: Moneta::Server
- Inherits:
-
Object
- Object
- Moneta::Server
- Defined in:
- lib/moneta/server.rb
Overview
Moneta server to be used together with Moneta::Adapters::Client
Defined Under Namespace
Classes: Connection
Constant Summary collapse
- TIMEOUT =
1
- MAXSIZE =
0x100000
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.
Constructor Details
#initialize(store, options = {}) ⇒ Server
Returns a new instance of Server.
158 159 160 161 162 163 164 165 166 |
# File 'lib/moneta/server.rb', line 158 def initialize(store, = {}) @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
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/moneta/server.rb', line 178 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(@socket) if @socket rescue nil end end |
#running? ⇒ Boolean
Is the server running
171 172 173 |
# File 'lib/moneta/server.rb', line 171 def running? @running end |
#stop ⇒ Object
Stop the server
195 196 197 198 199 200 |
# File 'lib/moneta/server.rb', line 195 def stop raise 'Not running' unless running? @stop = true @server.close nil end |