markbates-distribunaut 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +43 -0
- data/bin/distribunaut_ring_server +33 -0
- data/lib/distribunaut/distributable.rb +65 -0
- data/lib/distribunaut/distributed.rb +24 -0
- data/lib/distribunaut/errors/errors.rb +33 -0
- data/lib/distribunaut/tasks/ring_server_tasks.rake +33 -0
- data/lib/distribunaut/utils/rinda.rb +48 -0
- data/lib/distribunaut.rb +24 -0
- data/lib/distribunaut_tasks.rb +6 -0
- metadata +100 -0
data/README
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
=== Example #1
|
2
|
+
|
3
|
+
# 'Server' application
|
4
|
+
require 'distribunaut'
|
5
|
+
|
6
|
+
configatron.distribunaut.app_name = :user_app
|
7
|
+
configatron.distribunaut.share_objects = true
|
8
|
+
|
9
|
+
class User
|
10
|
+
include Distribunaut::Distributable
|
11
|
+
|
12
|
+
attr_accessor :username
|
13
|
+
|
14
|
+
def self.hi
|
15
|
+
'hello!!!'
|
16
|
+
end
|
17
|
+
|
18
|
+
def save
|
19
|
+
puts "Saving: #{self.inspect}"
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
DRb.thread.join
|
25
|
+
|
26
|
+
# 'Client' application
|
27
|
+
require 'distribunaut'
|
28
|
+
|
29
|
+
puts Distribunaut::Distributed::User.hi
|
30
|
+
|
31
|
+
User = Distribunaut::Distributed::User
|
32
|
+
|
33
|
+
puts User.hi
|
34
|
+
|
35
|
+
user = User.new
|
36
|
+
|
37
|
+
puts user.inspect
|
38
|
+
|
39
|
+
user.username = 'markbates'
|
40
|
+
|
41
|
+
puts user.inspect
|
42
|
+
|
43
|
+
user.save
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
# require 'rubygems'
|
3
|
+
require 'daemons'
|
4
|
+
require 'rinda/ring'
|
5
|
+
require 'rinda/tuplespace'
|
6
|
+
require 'fileutils'
|
7
|
+
require 'optparse'
|
8
|
+
require 'optparse/time'
|
9
|
+
require 'ostruct'
|
10
|
+
|
11
|
+
options = OpenStruct.new
|
12
|
+
opts = OptionParser.new do |opts|
|
13
|
+
opts.banner = <<-BANNER
|
14
|
+
Usage: distribunaut_ring_server <command>
|
15
|
+
Available commands are:
|
16
|
+
|
17
|
+
- start
|
18
|
+
- stop
|
19
|
+
- restart
|
20
|
+
|
21
|
+
BANNER
|
22
|
+
end
|
23
|
+
|
24
|
+
opts.parse!(ARGV)
|
25
|
+
|
26
|
+
FileUtils.mkdir_p(File.join("tmp", "pids"))
|
27
|
+
|
28
|
+
Daemons.run_proc('distribunaut_ring_server', {:dir_mode => :normal, :dir => File.join("tmp", "pids"), :monitor => true, :multiple => false}) do
|
29
|
+
puts 'Starting distribunaut_ring_server...'
|
30
|
+
DRb.start_service
|
31
|
+
Rinda::RingServer.new(Rinda::TupleSpace.new)
|
32
|
+
DRb.thread.join
|
33
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Distribunaut # :nodoc:
|
2
|
+
# Include this module into any class it will instantly register that class with
|
3
|
+
# the distribunaut_ring_server. The class will be registered with the name of the class
|
4
|
+
# and the distribunaut.distributed_app_name configured in your config/configatron/*.rb file.
|
5
|
+
# If the distribunaut.distributed_app_name configuration parameter is nil it will raise
|
6
|
+
# an Distribunaut::Distributed::Errors::ApplicationNameUndefined exception.
|
7
|
+
#
|
8
|
+
# Example:
|
9
|
+
# class User
|
10
|
+
# include Distribunaut::Distributable
|
11
|
+
# def name
|
12
|
+
# "mark"
|
13
|
+
# end
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# Distribunaut::Distributed::User.new.name # => "mark"
|
17
|
+
module Distributable
|
18
|
+
|
19
|
+
def self.included(base) # :nodoc:
|
20
|
+
if configatron.distribunaut.share_objects
|
21
|
+
base.class_eval do
|
22
|
+
include ::DRbUndumped
|
23
|
+
end
|
24
|
+
eval %{
|
25
|
+
class ::Distribunaut::Distributed::#{base}Proxy
|
26
|
+
include Singleton
|
27
|
+
include DRbUndumped
|
28
|
+
|
29
|
+
def method_missing(sym, *args)
|
30
|
+
#{base}.send(sym, *args)
|
31
|
+
end
|
32
|
+
|
33
|
+
def inspect
|
34
|
+
#{base}.inspect
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_s
|
38
|
+
#{base}.to_s
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
}
|
43
|
+
raise Distribunaut::Distributed::Errors::ApplicationNameUndefined.new if configatron.distribunaut.app_name.nil?
|
44
|
+
Distribunaut::Distributed::Utils::Rinda.register_or_renew(:space => configatron.distribunaut.app_name.to_sym,
|
45
|
+
:klass_def => "#{base}".to_sym,
|
46
|
+
:object => "Distribunaut::Distributed::#{base}Proxy".constantize.instance)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end # Distributable
|
51
|
+
end # Distribunaut
|
52
|
+
|
53
|
+
module DRb # :nodoc:
|
54
|
+
class DRbObject # :nodoc:
|
55
|
+
|
56
|
+
alias_method :_original_inspect, :inspect unless method_defined?(:_original_inspect)
|
57
|
+
|
58
|
+
def inspect
|
59
|
+
"#{_original_inspect}|#{method_missing(:inspect)}"
|
60
|
+
end
|
61
|
+
|
62
|
+
undef :id if method_defined?(:id)
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Distribunaut # :nodoc:
|
2
|
+
module Distributed # :nodoc:
|
3
|
+
|
4
|
+
# Looks up and tries to find the missing constant using the ring server.
|
5
|
+
def self.const_missing(const)
|
6
|
+
Distribunaut::Distributed::Utils::Rinda.read(:klass_def => "#{const}".to_sym)
|
7
|
+
end
|
8
|
+
|
9
|
+
# Allows for the specific lookup of services on the ring server
|
10
|
+
#
|
11
|
+
# Examples:
|
12
|
+
# Distribunaut::Distributed::Utils::Rinda.register_or_renew(:space => :app_1, :klass_def => :Test, :object => "Hello World!")
|
13
|
+
# Distribunaut::Distributed::Utils::Rinda.register_or_renew(:space => :app_2, :klass_def => :Test, :object => "Hello WORLD!")
|
14
|
+
# Distribunaut::Distributed.lookup("distributed://app_1/Test") # => "Hello World!"
|
15
|
+
# Distribunaut::Distributed.lookup("distributed://app_2/Test") # => "Hello WORLD!"
|
16
|
+
def self.lookup(address)
|
17
|
+
uri = Addressable::URI.parse(address)
|
18
|
+
path = uri.path[1..uri.path.size] # remove the first slash
|
19
|
+
host = uri.host
|
20
|
+
Distribunaut::Distributed::Utils::Rinda.read(:klass_def => path.to_sym, :space => host.to_sym)
|
21
|
+
end
|
22
|
+
|
23
|
+
end # Distributed
|
24
|
+
end # Distribunaut
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Distribunaut
|
2
|
+
module Distributed # :nodoc:
|
3
|
+
module Errors # :nodoc:
|
4
|
+
|
5
|
+
# Raised when an unknown distributed application is referenced.
|
6
|
+
class UnknownApplication < StandardError
|
7
|
+
# Takes the application name.
|
8
|
+
def initialize(app_name)
|
9
|
+
super("APPLICATION: #{app_name} is not a known/registered distributed application.")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Raised when an unknown distributed route name for a distributed application is referenced.
|
14
|
+
class UnknownRouteName < StandardError
|
15
|
+
# Takes the application name and the route name.
|
16
|
+
def initialize(app_name, route_name)
|
17
|
+
super("ROUTE_NAME: #{route_name}, is not a known/registered distributed route name for application: #{app_name}.")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Raised when an application doesn't declare it's application name for use in a distributed system.
|
22
|
+
class ApplicationNameUndefined < StandardError
|
23
|
+
end
|
24
|
+
|
25
|
+
# Raised when the distributed path is not a well formed addressable format
|
26
|
+
class InvalidAddressableURIFormat < StandardError
|
27
|
+
def inititalize(msg)
|
28
|
+
super("Invalid addressable format: #{msg}")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end # Errors
|
32
|
+
end # Distributed
|
33
|
+
end # Distribunaut
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rinda/ring'
|
2
|
+
namespace :distribunaut do
|
3
|
+
namespace :ring_server do
|
4
|
+
|
5
|
+
desc "Start the Rinda ring server"
|
6
|
+
task :start do
|
7
|
+
`distribunaut_ring_server start`
|
8
|
+
end
|
9
|
+
|
10
|
+
desc "Stop the Rinda ring server"
|
11
|
+
task :stop do
|
12
|
+
`distribunaut_ring_server stop`
|
13
|
+
end
|
14
|
+
|
15
|
+
namespace :services do
|
16
|
+
|
17
|
+
desc "Lists all services on the ring server"
|
18
|
+
task :list do
|
19
|
+
DRb.start_service
|
20
|
+
ring_server = Rinda::RingFinger.primary
|
21
|
+
services = ring_server.read_all([nil, nil, nil, nil])
|
22
|
+
puts "Services on #{ring_server.__drburi}"
|
23
|
+
services.each do |service|
|
24
|
+
puts "#{service[0]}: #{service[1]} on #{service[2].__drburi} - #{service[3]}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end # services
|
29
|
+
|
30
|
+
end # ring_server
|
31
|
+
end # distribunaut
|
32
|
+
|
33
|
+
alias_task "distribunaut:ring_server:restart", "distribunaut:ring_server:stop", "distribunaut:ring_server:start"
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Distribunaut
|
2
|
+
module Distributed
|
3
|
+
module Utils # :nodoc:
|
4
|
+
module Rinda
|
5
|
+
|
6
|
+
def self.register_or_renew(options = {})
|
7
|
+
options = handle_options(options)
|
8
|
+
begin
|
9
|
+
ring_server.take([options[:space], options[:klass_def], nil, nil], options[:timeout])
|
10
|
+
rescue Exception => e
|
11
|
+
# Distribunaut.logger.error(e)
|
12
|
+
end
|
13
|
+
register(options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.register(options = {})
|
17
|
+
options = handle_options(options)
|
18
|
+
ring_server.write([options[:space],
|
19
|
+
options[:klass_def],
|
20
|
+
options[:object],
|
21
|
+
options[:description]],
|
22
|
+
::Rinda::SimpleRenewer.new)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.ring_server
|
26
|
+
if configatron.distribunaut.retrieve(:acl, nil)
|
27
|
+
acl = ACL.new(configatron.distribunaut.acl)
|
28
|
+
DRb.install_acl(acl)
|
29
|
+
end
|
30
|
+
::DRb.start_service
|
31
|
+
rs = ::Rinda::RingFinger.primary
|
32
|
+
rs
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.read(options = {})
|
36
|
+
options = handle_options(options)
|
37
|
+
ring_server.read([options[:space], options[:klass_def], nil, options[:description]], options[:timeout])[2]
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
def self.handle_options(options = {})
|
42
|
+
{:space => nil, :klass_def => nil, :object => nil, :description => nil, :timeout => configatron.distribunaut.timeout}.merge(options)
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/distribunaut.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'configatron'
|
2
|
+
require 'cachetastic'
|
3
|
+
require 'drb/drb'
|
4
|
+
require 'drb/acl'
|
5
|
+
require 'rinda/ring'
|
6
|
+
require 'rinda/tuplespace'
|
7
|
+
require 'addressable/uri'
|
8
|
+
require 'activesupport'
|
9
|
+
|
10
|
+
base = File.join(File.dirname(__FILE__), 'distribunaut')
|
11
|
+
|
12
|
+
configatron.distribunaut.set_default(:share_routes, false)
|
13
|
+
configatron.distribunaut.set_default(:share_objects, false)
|
14
|
+
configatron.distribunaut.set_default(:share_views, false)
|
15
|
+
configatron.distribunaut.set_default(:app_name, nil)
|
16
|
+
configatron.distribunaut.set_default(:site_domain, nil)
|
17
|
+
configatron.distribunaut.set_default(:timeout, 0)
|
18
|
+
configatron.distribunaut.set_default(:enable_view_cache, false)
|
19
|
+
|
20
|
+
# load *.rb files
|
21
|
+
Dir.glob(File.join(base, "**", "*.rb")).each do |f|
|
22
|
+
require(f)
|
23
|
+
end
|
24
|
+
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: markbates-distribunaut
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- markbates
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-04-05 00:00:00 -07:00
|
13
|
+
default_executable: distribunaut_ring_server
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: configatron
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: cachetastic
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: addressable
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: daemons
|
47
|
+
type: :runtime
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
description: "distribunaut was developed by: markbates"
|
56
|
+
email: ""
|
57
|
+
executables:
|
58
|
+
- distribunaut_ring_server
|
59
|
+
extensions: []
|
60
|
+
|
61
|
+
extra_rdoc_files:
|
62
|
+
- README
|
63
|
+
files:
|
64
|
+
- lib/distribunaut/distributable.rb
|
65
|
+
- lib/distribunaut/distributed.rb
|
66
|
+
- lib/distribunaut/errors/errors.rb
|
67
|
+
- lib/distribunaut/tasks/ring_server_tasks.rake
|
68
|
+
- lib/distribunaut/utils/rinda.rb
|
69
|
+
- lib/distribunaut.rb
|
70
|
+
- lib/distribunaut_tasks.rb
|
71
|
+
- README
|
72
|
+
- bin/distribunaut_ring_server
|
73
|
+
has_rdoc: true
|
74
|
+
homepage: ""
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: "0"
|
85
|
+
version:
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: "0"
|
91
|
+
version:
|
92
|
+
requirements: []
|
93
|
+
|
94
|
+
rubyforge_project: distribunaut
|
95
|
+
rubygems_version: 1.2.0
|
96
|
+
signing_key:
|
97
|
+
specification_version: 2
|
98
|
+
summary: distribunaut
|
99
|
+
test_files: []
|
100
|
+
|