Module: Pokan::Cluster

Defined in:
lib/pokan-cluster.rb,
lib/pokan-cluster/version.rb,
lib/pokan-cluster/autorunner.rb,
lib/pokan-cluster/log_messages.rb,
lib/pokan-cluster/configuration.rb,
lib/pokan-cluster/config_defaults.rb,
lib/pokan-cluster/prepared_string.rb

Overview

Cluster module, to be included on all classes that want to implement a custom Gossip server. Including this module enables the developer to customize the configuration file location (and format, as long as she provided a parser for that format). The user can also pass manually the values for the configuration options. However, this is not the recommended way, of course.

Example

class MyCustomGossiper
  include Pokan::Cluster

  config { JSON.parse(CONFIG_PATH) }

end

The ‘config` method expects a hash containing values for network connection, seed address, log information, and others. If you want to see an example of a valid configuration hash, you can parse the following YAML (recommened config format for pokan-cluster):

pokan:
  address: "10.10.10.8" # your IP address

  connect:
    tcp: 4444
    udp: 8787 # ports that will be binded
    epoll: true # Linux machine?

  gossip:
    every: 2 # seconds
    share: "cpu,memory,load" # these are the valid options (separated by comma).

  seed: "10.10.10.2" # will be contacted on startup

  log:
    enabled: true # always good!
    level: "info"
    file: "/path/to/my/log" # default is STDOUT

Optionally, you can directly pass a file, using the ‘config_file` method. However, only the YAML format is currently supported

class MyCustomGossiper
  include Pokan::Cluster

  config_file = '/path/to/my/config.yml'
end

Defined Under Namespace

Modules: ClassMethods Classes: Autorunner, Configuration, PreparedString

Constant Summary collapse

VERSION =
"0.1.10"
LOG_MESSAGES =
{
  :start => { :debug => m("
Address: %p
TCP port: %p
UDP port: %p\n
Using epoll: %p
Gossip interval: %p seconds\n
Seed address: %p
Log level is %p.
Logging to %p\n"),

              :info  => m('Server is starting at %p...')
  },

  :before_sync => { :debug => m("Starting Redis sync with seed on address %p, port %p"),
                    :info  => m("Syncing databases...")
  },

  :after_sync => { :debug => m("Databases synced in %p seconds"),
                   :info  => m("Done.")
  },

  :new_key => { :debug => m("Saving new key-value pair: %p:%p") },

  :new_peer => { :debug => m("New peer detected at address %p:%p"), 
                 :info  => m("New peer: %p") },

  :key_changed => { :debug => m("Key %p changing from %p to %p") },

  :key_removed => { :debug => m("Key %p was removed"),
                    :info  => m("Peer at addres %p just left")
  },

  :before_gossip => { :debug => m("Preparing digest message for gossiping with %p (length: %p bytes)"),
                      :info  => m("Sending gossip message to randomly selected peer (%p)")
  },

  :after_gossip => { :debug  => m("Gossip message sent") },

  :shutdown     => m('Server is finishing...')

}.freeze
DEFAULTS =

Default values for configuration, specifying:

  • TCP and UDP ports

  • epoll set to false

  • CPU, memory and load average sharing

  • logging enabled to ‘STDOUT`

  • gossip interval: 1 second

{
  :tcp_port         => 5555,
  :udp_port         => 5555,
  :epoll            => false,
  :gossip_interval  => 1,
  :shares           => ['cpu', 'memory', 'load'],
  :redis            => 6379,
  :logging          => true,
  :level            => :info
}.freeze

Class Method Summary collapse

Class Method Details

.included(klass) ⇒ Object

When a server includes the Pokan::Cluster module, it gains access to its class methods, allowing the user to set configuration and behavior of the server. It is also configured to automatically run when the server class is loaded.



70
71
72
73
# File 'lib/pokan-cluster.rb', line 70

def self.included(klass)
  klass.extend ClassMethods
  Autorunner.register_server(klass)
end

.m(string) ⇒ Object



4
5
6
# File 'lib/pokan-cluster/log_messages.rb', line 4

def self.m(string)
  PreparedString.new(string)
end