Class: Moneta::Server
Overview
Moneta server
Constant Summary
Constants included from Net
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 Net
Constructor Details
#initialize(store, options = {}) ⇒ Server
Returns a new instance of Server.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/moneta/server.rb', line 10 def initialize(store, = {}) @store = store @server = if @file = [:file] UNIXServer.open(@file) else TCPServer.open([:port] || DEFAULT_PORT) end @clients = [@server] @running = false end |
Instance Method Details
#run ⇒ Object
Note:
This method blocks!
Run the server
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/moneta/server.rb', line 32 def run raise 'Already running' if @running @stop = false @running = true begin until @stop mainloop end ensure File.unlink(@file) if @file end end |
#running? ⇒ Boolean
Is the server running
25 26 27 |
# File 'lib/moneta/server.rb', line 25 def running? @running end |
#stop ⇒ Object
Stop the server
46 47 48 49 50 51 |
# File 'lib/moneta/server.rb', line 46 def stop raise 'Not running' unless @running @stop = true @server.close @server = nil end |