Class: Moneta::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/moneta/server.rb

Overview

Moneta server to be used together with Moneta::Adapters::Client

Instance Method Summary collapse

Constructor Details

#initialize(store, options = {}) ⇒ Server

Returns a new instance of Server

Options Hash (options):

  • :port (Integer) — default: 9000

    TCP port

  • :socket (String)

    Alternative Unix socket file name


10
11
12
13
14
15
16
# File 'lib/moneta/server.rb', line 10

def initialize(store, options = {})
  @store = store
  @server = start(options)
  @ios = [@server]
  @clients = {}
  @running = false
end

Instance Method Details

#runObject

Note:

This method blocks!

Run the server


28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/moneta/server.rb', line 28

def run
  raise 'Already running' if @running
  @stop = false
  @running = true
  begin
    until @stop
      mainloop
    end
  ensure
    File.unlink(@socket) if @socket
  end
end

#running?Boolean

Is the server running


21
22
23
# File 'lib/moneta/server.rb', line 21

def running?
  @running
end

#stopObject

Stop the server


42
43
44
45
46
47
# File 'lib/moneta/server.rb', line 42

def stop
  raise 'Not running' unless @running
  @stop = true
  @server.close
  @server = nil
end