Class: ZooService::PublicationImpl

Inherits:
Object
  • Object
show all
Defined in:
lib/zoo_service/publication.rb

Overview

Performs service publication for a HTTP service provider.

Instance Method Summary collapse

Constructor Details

#initialize(phusion_passenger = nil) ⇒ PublicationImpl

Returns a new instance of PublicationImpl.



9
10
11
12
13
14
15
16
# File 'lib/zoo_service/publication.rb', line 9

def initialize(phusion_passenger = nil)
  return unless phusion_passenger
  phusion_passenger.on_event(:starting_worker_process) do |forked|
    if forked
      reconnect
    end
  end
end

Instance Method Details

#reconnectObject



39
40
41
42
# File 'lib/zoo_service/publication.rb', line 39

def reconnect
  @zk = nil
  zk
end

#register_service(name, url) ⇒ Object

:call-seq:

register_service(name, url) => Boolean

Registers a well-known service with name at url.

Returns true, if everything went OK, false otherwise.



24
25
26
27
28
# File 'lib/zoo_service/publication.rb', line 24

def register_service(name, url)
  registration_block = create_registration_block(name, url)
  service_registration_blocks[name.to_sym] = registration_block
  registration_block.(zk)
end

#unregister_service(name) ⇒ Object

:call-seq:

unregister_service(name) => Boolean

Unregisters all the instances of a well-known service with name.



34
35
36
37
# File 'lib/zoo_service/publication.rb', line 34

def unregister_service(name)
  service_registration_blocks.delete(name.to_sym)
  zk.rm_rf("/services/#{name}")
end