Class: Raft::Goliath

Inherits:
Object
  • Object
show all
Defined in:
lib/raft/goliath.rb

Defined Under Namespace

Classes: EventMachineAsyncProvider, HttpJsonRpcProvider, HttpJsonRpcResponder

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Goliath

Returns a new instance of Goliath.



118
119
120
# File 'lib/raft/goliath.rb', line 118

def initialize(node)

end

Instance Attribute Details

#runningObject (readonly)

Returns the value of attribute running.



123
124
125
# File 'lib/raft/goliath.rb', line 123

def running
  @running
end

#update_fiberObject (readonly)

Returns the value of attribute update_fiber.



122
123
124
# File 'lib/raft/goliath.rb', line 122

def update_fiber
  @update_fiber
end

Class Method Details

.async_providerObject



114
115
116
# File 'lib/raft/goliath.rb', line 114

def self.async_provider
  EventMachineAsyncProvider.new
end

.rpc_providerObject



110
111
112
# File 'lib/raft/goliath.rb', line 110

def self.rpc_provider
  HttpJsonRpcProvider.new
end

Instance Method Details

#startObject



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/raft/goliath.rb', line 125

def start
  @runner = Goliath::Runner.new(ARGV, nil)
  @runner.api = HttpJsonRpcResponder.new(node)
  @runner.app = Goliath::Rack::Builder.build(HttpJsonRpcResponder, runner.api)
  @runner.run

  @running = true

  runner = self
  @update_fiber = Fiber.new do
    while runner.running?
      EventMachine.add_timer node.config.update_interval, Proc.new do
        runner.update_fiber.resume if runner.running?
      end
      @node.update
      Fiber.yield
    end
  end
end

#stopObject



145
146
147
148
149
150
151
152
# File 'lib/raft/goliath.rb', line 145

def stop
  @running = false
  f = Fiber.current
  while @update_fiber.alive?
    EventMachine.add_timer 0.1, proc { f.resume }
    Fiber.yield
  end
end