Class: Raft::Goliath

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

Defined Under Namespace

Modules: HashMarshalling 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.



213
214
215
# File 'lib/raft/goliath.rb', line 213

def initialize(node)
  @node = node
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



217
218
219
# File 'lib/raft/goliath.rb', line 217

def node
  @node
end

#runningObject (readonly)

Returns the value of attribute running.



219
220
221
# File 'lib/raft/goliath.rb', line 219

def running
  @running
end

#update_fiberObject (readonly)

Returns the value of attribute update_fiber.



218
219
220
# File 'lib/raft/goliath.rb', line 218

def update_fiber
  @update_fiber
end

Class Method Details

.async_providerObject



209
210
211
# File 'lib/raft/goliath.rb', line 209

def self.async_provider
  EventMachineAsyncProvider.new
end

.log(message) ⇒ Object



8
9
10
11
12
# File 'lib/raft/goliath.rb', line 8

def self.log(message)
  STDOUT.write("\n\n")
  STDOUT.write(message)
  STDOUT.write("\n\n")
end

.rpc_provider(uri_generator) ⇒ Object



205
206
207
# File 'lib/raft/goliath.rb', line 205

def self.rpc_provider(uri_generator)
  HttpJsonRpcProvider.new(uri_generator)
end

Instance Method Details

#start(options = {}) ⇒ Object



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/raft/goliath.rb', line 221

def start(options = {})
  @runner = ::Goliath::Runner.new(ARGV, nil)
  @runner.api = HttpJsonRpcResponder.new(node)
  @runner.app = ::Goliath::Rack::Builder.build(HttpJsonRpcResponder, @runner.api)
  @runner.address = options[:address] if options[:address]
  @runner.port = options[:port] if options[:port]
  @runner.run
  @running = true

  update_proc = Proc.new do
    EM.synchrony do
      @node.update
    end
  end
  @update_timer = EventMachine.add_periodic_timer(node.config.update_interval, update_proc)
#      @node.update
end

#stopObject



239
240
241
# File 'lib/raft/goliath.rb', line 239

def stop
  @update_timer.cancel
end