Class: ProxyMgr::Watcher::Base

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/proxymgr/watcher/base.rb

Direct Known Subclasses

Dns, Zookeeper

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

disable!, #logger, logger

Constructor Details

#initialize(name, config, manager) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
13
14
15
16
17
# File 'lib/proxymgr/watcher/base.rb', line 8

def initialize(name, config, manager)
  @name           = name
  @manager        = manager
  @config         = config

  @servers        = []
  @listen_options = @config['listen_options']
  @server_options = @config['server_options']
  @port           = @config['port']
end

Instance Attribute Details

#listen_optionsObject (readonly)

Returns the value of attribute listen_options.



4
5
6
# File 'lib/proxymgr/watcher/base.rb', line 4

def listen_options
  @listen_options
end

#portObject (readonly)

Returns the value of attribute port.



4
5
6
# File 'lib/proxymgr/watcher/base.rb', line 4

def port
  @port
end

#server_optionsObject (readonly)

Returns the value of attribute server_options.



4
5
6
# File 'lib/proxymgr/watcher/base.rb', line 4

def server_options
  @server_options
end

#serversObject (readonly)

Returns the value of attribute servers.



4
5
6
# File 'lib/proxymgr/watcher/base.rb', line 4

def servers
  @servers
end

Instance Method Details

#==(obj) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/proxymgr/watcher/base.rb', line 25

def ==(obj)
  if obj.is_a? Watcher::Base
    obj.listen_options == @listen_options and
      obj.server_options == @server_options and
      obj.port == @port
  else
    super
  end
end

#shutdownObject



23
# File 'lib/proxymgr/watcher/base.rb', line 23

def shutdown; end

#valid?Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/proxymgr/watcher/base.rb', line 35

def valid?
  unless @port
    warn 'port is not defined'
    return false
  end

  unless @port.is_a? Integer and (@port > 0 and @port <= 65535)
    warn 'port is not an integer or not valid'
    return false
  end

  unless !@listen_options || @listen_options.is_a?(Array)
    warn 'listen_options is not an array'
    return false
  end

  unless !@server_options || @server_options.is_a?(Array)
    warn 'server_options is not an array'
    return false
  end

  if has_validation? and !validate_config
    warn 'config failed to validate'
    return false
  end

  true
end

#watchObject



19
20
21
# File 'lib/proxymgr/watcher/base.rb', line 19

def watch
  fail Exception 'This method should be overridden'
end