Module: RubySkynet

Includes:
SyncAttr
Defined in:
lib/ruby_skynet/base.rb,
lib/ruby_skynet.rb,
lib/ruby_skynet/client.rb,
lib/ruby_skynet/common.rb,
lib/ruby_skynet/server.rb,
lib/ruby_skynet/railtie.rb,
lib/ruby_skynet/service.rb,
lib/ruby_skynet/version.rb,
lib/ruby_skynet/registry.rb,
lib/ruby_skynet/zookeeper.rb,
lib/ruby_skynet/connection.rb,
lib/ruby_skynet/exceptions.rb,
lib/ruby_skynet/ruby_skynet.rb,
lib/ruby_skynet/service_registry.rb,
lib/ruby_skynet/zookeeper/registry.rb,
lib/ruby_skynet/zookeeper/cached_registry.rb,
lib/ruby_skynet/zookeeper/json/serializer.rb,
lib/ruby_skynet/zookeeper/json/deserializer.rb,
lib/rails/generators/ruby_skynet/config/config_generator.rb

Overview

CachedRegistry

Store information in ZooKeeper and subscribe to future changes and keep a local copy of the information in ZooKeeper

Notifies registered subscribers when information has changed

All paths specified are relative to the root_path. As such the root key is never returned, nor is it required when a key is supplied as input. For example, with a root_path of /foo/bar, any paths passed in will leave out the root_path: host/name

Keeps a local copy in memory of all descendant values of the supplied root_path Supports high-frequency calls to retrieve registry data The in-memory cache will be kept in synch with any changes on the server

Defined Under Namespace

Modules: Base, Common, Generators, Service, Zookeeper Classes: Client, Connection, Exception, InvalidConfigurationException, InvalidServiceException, ProtocolError, Railtie, Server, ServiceException, ServiceRegistry, ServiceUnavailable, SkynetException

Constant Summary collapse

VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.configure!(filename = nil, environment = nil) ⇒ Object

Load the Configuration information from a YAML file filename:

Name of file to read.
   Mandatory for non-Rails apps
   Default: Rails.root/config/ruby_skynet.yml

environment:

Which environment config to load. Usually: production, development, etc.
Default: Rails.env


77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/ruby_skynet/ruby_skynet.rb', line 77

def self.configure!(filename=nil, environment=nil)
  config_file = filename.nil? ? Rails.root.join('config', 'ruby_skynet.yml') : Pathname.new(filename)
  raise "ruby_skynet config not found. Create a config file at: config/ruby_skynet.yml" unless config_file.file?

  config = YAML.load(ERB.new(File.new(config_file).read).result)[environment || Rails.env]
  raise("Environment #{Rails.env} not defined in config/ruby_skynet.yml") unless config

  @@config = config.dup

  RubySkynet.region           = config.delete(:region)           || 'Development'
  RubySkynet.services_path    = config.delete(:services_path)    || 'app/services'
  RubySkynet.server_port      = config.delete(:server_port)      || 2000
  RubySkynet.local_ip_address = config.delete(:local_ip_address) || Common::local_ip_address

  # Extract just the zookeeper or doozer configuration element
  key = config[:zookeeper] ? :zookeeper : :doozer
  RubySkynet.service_registry = ServiceRegistry.new(
    :root => '/services',
    key   => config.delete(key)
  )

  config.each_pair {|k,v| RubySkynet::Server.logger.warn "Ignoring unknown RubySkynet config option #{k} => #{v}"}
end

.local_ip_address ⇒ Object

The ip address at which this server instance can be reached by remote Skynet clients Note: Must be an IP address, not the hostname



40
41
42
# File 'lib/ruby_skynet/ruby_skynet.rb', line 40

def self.local_ip_address
  @@local_ip_address ||= Common::local_ip_address
end

.local_ip_address=(local_ip_address) ⇒ Object



44
45
46
# File 'lib/ruby_skynet/ruby_skynet.rb', line 44

def self.local_ip_address=(local_ip_address)
  @@local_ip_address = local_ip_address
end

.new_cache_registry(root) ⇒ Object

Returns an instance of RubySkynet::Zookeeper::CachedRegistry or RubyDoozer::CachedRegistry based on which was loaded in RubySkynet.configure!



103
104
105
106
107
108
109
110
111
112
113
# File 'lib/ruby_skynet/ruby_skynet.rb', line 103

def self.new_cache_registry(root)
  # Load config
  service_registry

  if zookeeper = @@config[:zookeeper]
    RubySkynet::Zookeeper::CachedRegistry.new(:root => root, :zookeeper => zookeeper)
  else
    raise "How did we get here", @@config
    Doozer::CachedRegistry.new(:root => root, :doozer => @@config[:doozer])
  end
end

.region ⇒ Object

Returns the default region for all Ruby Skynet Clients and Services



7
8
9
# File 'lib/ruby_skynet/ruby_skynet.rb', line 7

def self.region
  @@region ||= 'Development'
end

.region=(region) ⇒ Object

Sets the default region to use for Skynet Clients and Services



12
13
14
# File 'lib/ruby_skynet/ruby_skynet.rb', line 12

def self.region=(region)
  @@region = region
end

.server_port ⇒ Object

Returns the starting port for the server to listen on If this port is in use the next available port will be used upto 999 above the server_port value



29
30
31
# File 'lib/ruby_skynet/ruby_skynet.rb', line 29

def self.server_port
  @@server_port ||= 2000
end

.server_port=(server_port) ⇒ Object



33
34
35
# File 'lib/ruby_skynet/ruby_skynet.rb', line 33

def self.server_port=(server_port)
  @@server_port = server_port
end

.service_registry=(service_registry) ⇒ Object

Set the services registry It is recommended to call RubySkynet.configure! rather than calling this method directly



60
61
62
# File 'lib/ruby_skynet/ruby_skynet.rb', line 60

def self.service_registry=(service_registry)
  @@service_registry = service_registry
end

.services ⇒ Object

DEPRECATED - Use RubySkynet.service_registry



65
66
67
# File 'lib/ruby_skynet/ruby_skynet.rb', line 65

def self.services
  @@service_registry
end

.services_path ⇒ Object

Returns the service_path where services are located



17
18
19
# File 'lib/ruby_skynet/ruby_skynet.rb', line 17

def self.services_path
  @@services_path ||= 'app/services'
end

.services_path=(services_path) ⇒ Object

Sets the service_path where services are located



22
23
24
# File 'lib/ruby_skynet/ruby_skynet.rb', line 22

def self.services_path=(services_path)
  @@services_path = services_path
end