Class: UState::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/ustate/server/backends/tcp.rb,
lib/ustate/server.rb

Overview

Stolen from Thin

Defined Under Namespace

Modules: Backends Classes: Connection, Error, Graphite, Index

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Server

Returns a new instance of Server.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ustate/server.rb', line 31

def initialize(opts = {})
  # Backends
  @backends = []
  b = Backends::TCP.new opts.merge(server: self)
  b.server = self
  @backends << b

  @index = Index.new :server => self

  @reaper = UState::Reaper.new(@index, server: self)

  @log = Logger.new('ustate.log', 4, 134217728)
  @log.level = Logger::INFO  

  setup_signals
end

Instance Attribute Details

#aggregator(opts = {}) ⇒ Object



48
49
50
51
# File 'lib/ustate/server.rb', line 48

def aggregator(opts = {})
  require 'ustate/aggregator'
  @aggregator ||= UState::Aggregator.new(@index, opts.merge(server: self))
end

#backendsObject

Returns the value of attribute backends.



22
23
24
# File 'lib/ustate/server.rb', line 22

def backends
  @backends
end

#emailer(opts = {}) ⇒ Object



53
54
55
56
# File 'lib/ustate/server.rb', line 53

def emailer(opts = {})
  require 'ustate/emailer'
  @emailer ||= UState::Emailer.new(@index, opts.merge(server: self))
end

#graphite(opts = {}) ⇒ Object



58
59
60
61
# File 'lib/ustate/server.rb', line 58

def graphite(opts = {})
  require 'ustate/graphite'
  @graphite ||= UState::Graphite.new(@index, opts.merge(server: self))
end

#indexObject

Returns the value of attribute index.



23
24
25
# File 'lib/ustate/server.rb', line 23

def index
  @index
end

#logObject

Returns the value of attribute log.



29
30
31
# File 'lib/ustate/server.rb', line 29

def log
  @log
end

#reaperObject

Returns the value of attribute reaper.



24
25
26
# File 'lib/ustate/server.rb', line 24

def reaper
  @reaper
end

Instance Method Details

#setup_signalsObject



92
93
94
95
# File 'lib/ustate/server.rb', line 92

def setup_signals
  trap('INT') { stop! }
  trap('TERM') { stop }
end

#startObject



63
64
65
66
67
68
69
70
# File 'lib/ustate/server.rb', line 63

def start
  @index.start
 
  # Right now b.start blocks... should look into EM 
  @backends.map do |b|
    b.start
  end
end

#stopObject



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/ustate/server.rb', line 72

def stop
  @backends.map do |b|
    if b.running?
      b.stop
    else
      stop!
    end
  end

  @index.stop
end

#stop!Object



84
85
86
87
88
89
90
# File 'lib/ustate/server.rb', line 84

def stop!
  @backends.map do |b|
    b.stop!
  end

  @index.stop!
end