Class: Mongo::Srv::Monitor Private

Inherits:
Object
  • Object
show all
Includes:
BackgroundThread, Loggable
Defined in:
lib/mongo/srv/monitor.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Periodically retrieves SRV records for the cluster’s SRV URI, and sets the cluster’s server list to the SRV lookup result.

If an error is encountered during SRV lookup or an SRV record is invalid or disallowed for security reasons, a warning is logged and monitoring continues.

Constant Summary collapse

MIN_SCAN_INTERVAL =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

60
DEFAULT_TIMEOUT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

10

Constants included from Loggable

Loggable::PREFIX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BackgroundThread

#run!, #running?, #stop!

Methods included from Loggable

#log_debug, #log_error, #log_fatal, #log_info, #log_warn, #logger

Constructor Details

#initialize(cluster, **opts) ⇒ Monitor

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates the SRV monitor.

Parameters:

  • cluster (Cluster)

    The cluster.

  • opts (Hash)

    a customizable set of options

Options Hash (**opts):

  • :timeout (Float)

    The timeout to use for DNS lookups.

  • :srv_uri (URI::SRVProtocol)

    The SRV URI to monitor.

  • :resolv_options (Hash)

    For internal driver use only. Options to pass through to Resolv::DNS constructor for SRV lookups.



45
46
47
48
49
50
51
52
53
54
# File 'lib/mongo/srv/monitor.rb', line 45

def initialize(cluster, **opts)
  @cluster = cluster
  unless @srv_uri = opts.delete(:srv_uri)
    raise ArgumentError, 'SRV URI is required'
  end
  @options = opts.freeze
  @resolver = Srv::Resolver.new(**opts)
  @last_result = @srv_uri.srv_result
  @stop_semaphore = Semaphore.new
end

Instance Attribute Details

#clusterObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



58
59
60
# File 'lib/mongo/srv/monitor.rb', line 58

def cluster
  @cluster
end

#last_resultSrv::Result (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns Last known SRV lookup result. Used for determining intervals between SRV lookups, which depend on SRV DNS records’ TTL values.

Returns:

  • (Srv::Result)

    Last known SRV lookup result. Used for determining intervals between SRV lookups, which depend on SRV DNS records’ TTL values.



63
64
65
# File 'lib/mongo/srv/monitor.rb', line 63

def last_result
  @last_result
end

#optionsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



56
57
58
# File 'lib/mongo/srv/monitor.rb', line 56

def options
  @options
end