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.

Parameters:

  • options (Hash) (defaults to: {})

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
# File 'lib/moneta/server.rb', line 28

def run
  raise 'Already running' if @running
  @stop = false
  @running = true
  begin
    mainloop until @stop
  ensure
    File.unlink(@socket) if @socket
    @ios.each { |io| io.close rescue nil }
  end
end

#running?Boolean

Is the server running

Returns:

  • (Boolean)

    true if the server is running



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

def running?
  @running
end

#stopObject

Stop the server



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

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