markbates-distribunaut 0.2.2.20090626214209 → 0.2.20090511204103

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,7 +17,6 @@ module Distribunaut # :nodoc:
17
17
  module Distributable
18
18
 
19
19
  def self.included(base) # :nodoc:
20
- raise Distribunaut::Distributed::Errors::ApplicationNameUndefined.new if configatron.distribunaut.app_name.nil?
21
20
  base.class_eval do
22
21
  include ::DRbUndumped
23
22
  end
@@ -34,23 +33,15 @@ module Distribunaut # :nodoc:
34
33
  undef :id if method_defined?(:id)
35
34
  undef :inspect if method_defined?(:inspect)
36
35
  undef :to_s if method_defined?(:to_s)
37
-
38
- def borrow(&block)
39
- Distribunaut::Utils::Rinda.borrow(:space => :#{base},
40
- :object => self,
41
- :description => "#{base} Service",
42
- :app_name => configatron.distribunaut.app_name.to_sym) do |tuple|
43
- yield tuple.object
44
- end
45
- end
46
36
 
47
37
  end
48
38
  }
49
- obj = "Distribunaut::Distributed::#{c_name}Proxy".constantize.instance
39
+ obj = "Distribunaut::Distributed::#{c_name}Proxy".constantize.instance
40
+ raise Distribunaut::Distributed::Errors::ApplicationNameUndefined.new if configatron.distribunaut.app_name.nil?
50
41
  Distribunaut::Utils::Rinda.register_or_renew(:space => "#{base}".to_sym,
51
- :object => obj,
52
- :description => "#{base} Service",
53
- :app_name => configatron.distribunaut.app_name.to_sym)
42
+ :object => obj,
43
+ :description => "#{base} Service",
44
+ :app_name => configatron.distribunaut.app_name)
54
45
  end
55
46
 
56
47
  end # Distributable
@@ -21,10 +21,6 @@ module Distribunaut # :nodoc:
21
21
  [self.app_name, self.space, nil, nil]
22
22
  end
23
23
 
24
- def to_s
25
- self.to_array.inspect
26
- end
27
-
28
24
  class << self
29
25
 
30
26
  def from_array(ar)
@@ -2,81 +2,53 @@ module Distribunaut
2
2
  module Utils # :nodoc:
3
3
  module Rinda
4
4
 
5
- class << self
6
-
7
- def register_or_renew(values = {})
8
- tuple = build_tuple(values)
9
- begin
10
- ring_server.take(tuple.to_search_array, tuple.timeout)
11
- rescue ::Rinda::RequestExpiredError => e
12
- # it's ok that it expired. It could be that it was never registered.
13
- end
14
- register(values)
15
- end
16
-
17
- def register(values = {})
18
- tuple = build_tuple(values)
19
- ring_server.write(tuple.to_array, ::Rinda::SimpleRenewer.new)
20
- end
21
-
22
- def ring_server
23
- if configatron.distribunaut.retrieve(:acl, nil)
24
- acl = ACL.new(configatron.distribunaut.acl)
25
- DRb.install_acl(acl)
26
- end
27
- ::DRb.start_service
28
- rs = ::Rinda::RingFinger.primary
29
- rs
30
- end
31
-
32
- def read(values = {})
33
- tuple = build_tuple(values)
34
- results = ring_server.read(tuple.to_array, tuple.timeout)
35
- tuple = Distribunaut::Tuple.from_array(results)
36
- tuple.object
37
- end
38
-
39
- def borrow(values = {}, &block)
40
- tuple = build_tuple(values)
41
- results = ring_server.take(tuple.to_array, tuple.timeout)
42
- tuple = Distribunaut::Tuple.from_array(results)
43
- tuple.space = "#{tuple.space}-onloan-#{Time.now}".to_sym
44
- register(tuple)
45
- begin
46
- yield tuple if block_given?
47
- rescue Exception => e
48
- raise e
49
- ensure
50
- # (.+)-onloan-.+$
51
- tuple.space.to_s.match(/(.+)-onloan-.+$/)
52
- tuple.space = $1.to_sym
53
- register(tuple)
54
- end
55
- end
56
-
57
- def available_services
58
- ring_server = self.ring_server
59
- all = ring_server.read_all([nil, nil, nil, nil])
60
- services = []
61
- all.each do |service|
62
- services << Distribunaut::Tuple.from_array(service)
63
- end
64
- services
65
- end
66
-
67
- def remove_all_services!
68
- available_services.each do |service|
69
- ring_server.take(service.to_array)
70
- end
71
- end
72
-
73
- private
74
- def build_tuple(values = {})
75
- return values if values.is_a?(Distribunaut::Tuple)
76
- Distribunaut::Tuple.new({:timeout => configatron.distribunaut.timeout}.merge(values))
77
- end
78
-
79
- end # class << self
5
+ def self.register_or_renew(values = {})
6
+ tuple = build_tuple(values)
7
+ begin
8
+ ring_server.take(tuple.to_search_array, tuple.timeout)
9
+ rescue ::Rinda::RequestExpiredError => e
10
+ # it's ok that it expired. It could be that it was never registered.
11
+ end
12
+ register(values)
13
+ end
14
+
15
+ def self.register(values = {})
16
+ tuple = build_tuple(values)
17
+ ring_server.write(tuple.to_array, ::Rinda::SimpleRenewer.new)
18
+ end
19
+
20
+ def self.ring_server
21
+ if configatron.distribunaut.retrieve(:acl, nil)
22
+ acl = ACL.new(configatron.distribunaut.acl)
23
+ DRb.install_acl(acl)
24
+ end
25
+ ::DRb.start_service
26
+ rs = ::Rinda::RingFinger.primary
27
+ rs
28
+ end
29
+
30
+ def self.read(values = {})
31
+ tuple = build_tuple(values)
32
+ results = ring_server.read(tuple.to_array, tuple.timeout)
33
+ tuple = Distribunaut::Tuple.from_array(results)
34
+ tuple.object
35
+ end
36
+
37
+ def self.available_services
38
+ ring_server = self.ring_server
39
+ all = ring_server.read_all([nil, nil, nil, nil])
40
+ services = []
41
+ all.each do |service|
42
+ services << Distribunaut::Tuple.from_array(service)
43
+ end
44
+ services
45
+ end
46
+
47
+ private
48
+ def self.build_tuple(values = {})
49
+ return values if values.is_a?(Distribunaut::Tuple)
50
+ Distribunaut::Tuple.new({:timeout => configatron.distribunaut.timeout}.merge(values))
51
+ end
80
52
 
81
53
  end
82
54
  end
data/lib/distribunaut.rb CHANGED
@@ -8,6 +8,7 @@ require 'activesupport'
8
8
 
9
9
  base = File.join(File.dirname(__FILE__), 'distribunaut')
10
10
 
11
+ configatron.distribunaut.set_default(:share_objects, false)
11
12
  configatron.distribunaut.set_default(:app_name, nil)
12
13
  configatron.distribunaut.set_default(:timeout, 0)
13
14
 
@@ -16,6 +17,3 @@ Dir.glob(File.join(base, "**", "*.rb")).each do |f|
16
17
  require(f)
17
18
  end
18
19
 
19
- # Make sure no one can call eval() and related
20
- # methods remotely!
21
- $SAFE = 1 unless $SAFE > 0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markbates-distribunaut
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2.20090626214209
4
+ version: 0.2.20090511204103
5
5
  platform: ruby
6
6
  authors:
7
7
  - markbates
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-26 00:00:00 -07:00
12
+ date: 2009-05-11 00:00:00 -07:00
13
13
  default_executable: distribunaut_ring_server
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency