Discover resource endpoint locations via a DRb registry. For HTTP-based endpoints.

Namespace
Methods
A
C
D
F
Constants
FRONT_OBJECT =
Hoodoo::Services::Discovery::ByDRb::DRbServer.new
 

Singleton “Front object” for the DRB service used in local development.

LOCAL_ACL =
ACL.new( %w[
deny all
allow ::1
allow fe80::1%lo0
allow 127.0.0.1
] )
 

Only allow connections from 127.0.0.1.

Instance Public methods
flush_services_for_test()

Intended for testing only - flushes the records held in the DRb service.

# File lib/hoodoo/services/discovery/discoverers/by_drb/by_drb.rb, line 27
def flush_services_for_test
  drb_service().flush()
end
Instance Protected methods
announce_remote( resource, version, options = {} )

Announce the location of an instance through the DRb service (which may be started up if necessary).

Returns a Hoodoo::Services::Discovery::ForHTTP instance.

Call via Hoodoo::Services::Discovery::Base#announce.

resource

Passed to discover_remote.

version

Passed to discover_remote.

options

Options hash as described below.

Options keys are:

host

Host name as a string for location of service endpoint, over HTTP (usually, local development is assumed).

port

Port number of service endpoint.

path

Path on the above host and port of service endpoint.

If any are missing or nil, remote announcement is aborted and the return value is correspondingly nil.

# File lib/hoodoo/services/discovery/discoverers/by_drb/by_drb.rb, line 78
def announce_remote( resource, version, options = {} )

  host = options[ :host ]
  port = options[ :port ]
  path = options[ :path ]

  endpoint_uri_string = unless host.nil? || port.nil? || path.nil?
    "http://#{ host }:#{ port }#{ path }"
  end

  # Announce our local services only if we have an endpoint URI. In a
  # 'guard' based environment, first-run determines host and port but
  # subsequent runs do not - yet it stays the same, so it works out
  # OK there.
  #
  unless endpoint_uri_string.nil? || discover_remote( resource, version )
    drb_service().add( resource, version, endpoint_uri_string )
  end

  return result_for( resource, version, endpoint_uri_string )
end
configure_with( options )

Configure an instance. Call via Hoodoo::Services::Discovery::Base#new. Parameters:

options

Options hash as described below.

Options are:

drb_port

Optional port on which to launch the DRb service. If omitted, environment variable HOODOO_DISCOVERY_BY_DRB_PORT_OVERRIDE will be consulted. If unset, port 8787 is used.

drb_uri

Optional URI String at which to find an existing DRB service. It must alreayd be running. If omitted, the drb_port option's behaviour applies. If present, the drb_port option is ignored.

# File lib/hoodoo/services/discovery/discoverers/by_drb/by_drb.rb, line 50
def configure_with( options )
  @drb_port = options[ :drb_port ]
  @drb_uri  = options[ :drb_uri  ]
end
discover_remote( resource, version )

Discover an endpoint someone previously registered via announce_remote.

Returns a Hoodoo::Services::Discovery::ForHTTP instance if the endpoint is found, else nil.

resource

Resource name as a String.

version

Endpoint version as an Integer.

# File lib/hoodoo/services/discovery/discoverers/by_drb/by_drb.rb, line 109
def discover_remote( resource, version )
  endpoint_uri_string = drb_service().find( resource, version )
  return result_for( resource, version, endpoint_uri_string )
end