rubysl-drb 1.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,87 +2,97 @@ require 'drb/drb'
2
2
  require 'monitor'
3
3
 
4
4
  module DRb
5
+
6
+ # Timer id conversion keeps objects alive for a certain amount of time after
7
+ # their last access. The default time period is 600 seconds and can be
8
+ # changed upon initialization.
9
+ #
10
+ # To use TimerIdConv:
11
+ #
12
+ # DRb.install_id_conv TimerIdConv.new 60 # one minute
13
+
5
14
  class TimerIdConv < DRbIdConv
6
- class TimerHolder2
15
+ class TimerHolder2 # :nodoc:
7
16
  include MonitorMixin
8
17
 
9
18
  class InvalidIndexError < RuntimeError; end
10
19
 
11
20
  def initialize(timeout=600)
12
- super()
13
- @sentinel = Object.new
14
- @gc = {}
15
- @curr = {}
16
- @renew = {}
17
- @timeout = timeout
18
- @keeper = keeper
21
+ super()
22
+ @sentinel = Object.new
23
+ @gc = {}
24
+ @curr = {}
25
+ @renew = {}
26
+ @timeout = timeout
27
+ @keeper = keeper
19
28
  end
20
29
 
21
30
  def add(obj)
22
- synchronize do
23
- key = obj.__id__
24
- @curr[key] = obj
25
- return key
26
- end
31
+ synchronize do
32
+ key = obj.__id__
33
+ @curr[key] = obj
34
+ return key
35
+ end
27
36
  end
28
37
 
29
38
  def fetch(key, dv=@sentinel)
30
- synchronize do
31
- obj = peek(key)
32
- if obj == @sentinel
33
- return dv unless dv == @sentinel
34
- raise InvalidIndexError
35
- end
36
- @renew[key] = obj # KeepIt
37
- return obj
38
- end
39
+ synchronize do
40
+ obj = peek(key)
41
+ if obj == @sentinel
42
+ return dv unless dv == @sentinel
43
+ raise InvalidIndexError
44
+ end
45
+ @renew[key] = obj # KeepIt
46
+ return obj
47
+ end
39
48
  end
40
49
 
41
50
  def include?(key)
42
- synchronize do
43
- obj = peek(key)
44
- return false if obj == @sentinel
45
- true
46
- end
51
+ synchronize do
52
+ obj = peek(key)
53
+ return false if obj == @sentinel
54
+ true
55
+ end
47
56
  end
48
57
 
49
58
  def peek(key)
50
- synchronize do
51
- return @curr.fetch(key, @renew.fetch(key, @gc.fetch(key, @sentinel)))
52
- end
59
+ synchronize do
60
+ return @curr.fetch(key, @renew.fetch(key, @gc.fetch(key, @sentinel)))
61
+ end
53
62
  end
54
63
 
55
64
  private
56
65
  def alternate
57
- synchronize do
58
- @gc = @curr # GCed
59
- @curr = @renew
60
- @renew = {}
61
- end
66
+ synchronize do
67
+ @gc = @curr # GCed
68
+ @curr = @renew
69
+ @renew = {}
70
+ end
62
71
  end
63
72
 
64
73
  def keeper
65
- Thread.new do
66
- loop do
67
- size = alternate
68
- sleep(@timeout)
69
- end
70
- end
74
+ Thread.new do
75
+ loop do
76
+ alternate
77
+ sleep(@timeout)
78
+ end
79
+ end
71
80
  end
72
81
  end
73
82
 
83
+ # Creates a new TimerIdConv which will hold objects for +timeout+ seconds.
74
84
  def initialize(timeout=600)
75
85
  @holder = TimerHolder2.new(timeout)
76
86
  end
77
87
 
78
- def to_obj(ref)
88
+ def to_obj(ref) # :nodoc:
79
89
  return super if ref.nil?
80
90
  @holder.fetch(ref)
81
91
  rescue TimerHolder2::InvalidIndexError
82
92
  raise "invalid reference"
83
93
  end
84
94
 
85
- def to_id(obj)
95
+ def to_id(obj) # :nodoc:
86
96
  return @holder.add(obj)
87
97
  end
88
98
  end
@@ -6,33 +6,39 @@ raise(LoadError, "UNIXServer is required") unless defined?(UNIXServer)
6
6
 
7
7
  module DRb
8
8
 
9
+ # Implements DRb over a UNIX socket
10
+ #
11
+ # DRb UNIX socket URIs look like <code>drbunix:<path>?<option></code>. The
12
+ # option is optional.
13
+
9
14
  class DRbUNIXSocket < DRbTCPSocket
15
+ # :stopdoc:
10
16
  def self.parse_uri(uri)
11
- if /^drbunix:(.*?)(\?(.*))?$/ =~ uri
12
- filename = $1
13
- option = $3
14
- [filename, option]
17
+ if /^drbunix:(.*?)(\?(.*))?$/ =~ uri
18
+ filename = $1
19
+ option = $3
20
+ [filename, option]
15
21
  else
16
- raise(DRbBadScheme, uri) unless uri =~ /^drbunix:/
17
- raise(DRbBadURI, 'can\'t parse uri:' + uri)
22
+ raise(DRbBadScheme, uri) unless uri =~ /^drbunix:/
23
+ raise(DRbBadURI, 'can\'t parse uri:' + uri)
18
24
  end
19
25
  end
20
26
 
21
27
  def self.open(uri, config)
22
- filename, option = parse_uri(uri)
28
+ filename, = parse_uri(uri)
23
29
  filename.untaint
24
30
  soc = UNIXSocket.open(filename)
25
31
  self.new(uri, soc, config)
26
32
  end
27
33
 
28
34
  def self.open_server(uri, config)
29
- filename, option = parse_uri(uri)
35
+ filename, = parse_uri(uri)
30
36
  if filename.size == 0
31
- soc = temp_server
37
+ soc = temp_server
32
38
  filename = soc.path
33
- uri = 'drbunix:' + soc.path
39
+ uri = 'drbunix:' + soc.path
34
40
  else
35
- soc = UNIXServer.open(filename)
41
+ soc = UNIXServer.open(filename)
36
42
  end
37
43
  owner = config[:UNIXFileOwner]
38
44
  group = config[:UNIXFileGroup]
@@ -59,7 +65,7 @@ module DRb
59
65
  @server_mode = server_mode
60
66
  @acl = nil
61
67
  end
62
-
68
+
63
69
  # import from tempfile.rb
64
70
  Max_try = 10
65
71
  private
@@ -67,18 +73,18 @@ module DRb
67
73
  tmpdir = Dir::tmpdir
68
74
  n = 0
69
75
  while true
70
- begin
71
- tmpname = sprintf('%s/druby%d.%d', tmpdir, $$, n)
72
- lock = tmpname + '.lock'
73
- unless File.exist?(tmpname) or File.exist?(lock)
74
- Dir.mkdir(lock)
75
- break
76
- end
77
- rescue
78
- raise "cannot generate tempfile `%s'" % tmpname if n >= Max_try
79
- #sleep(1)
80
- end
81
- n += 1
76
+ begin
77
+ tmpname = sprintf('%s/druby%d.%d', tmpdir, $$, n)
78
+ lock = tmpname + '.lock'
79
+ unless File.exist?(tmpname) or File.exist?(lock)
80
+ Dir.mkdir(lock)
81
+ break
82
+ end
83
+ rescue
84
+ raise "cannot generate tempfile `%s'" % tmpname if n >= Max_try
85
+ #sleep(1)
86
+ end
87
+ n += 1
82
88
  end
83
89
  soc = UNIXServer.new(tmpname)
84
90
  Dir.rmdir(lock)
@@ -100,9 +106,10 @@ module DRb
100
106
  end
101
107
 
102
108
  def set_sockopt(soc)
103
- soc.fcntl(Fcntl::F_SETFL, Fcntl::FD_CLOEXEC) if defined? Fcntl::FD_CLOEXEC
109
+ soc.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) if defined? Fcntl::FD_CLOEXEC
104
110
  end
105
111
  end
106
112
 
107
113
  DRbProtocol.add_protocol(DRbUNIXSocket)
114
+ # :startdoc:
108
115
  end
@@ -1,5 +1,5 @@
1
1
  module RubySL
2
2
  module DRb
3
- VERSION = "1.0.0"
3
+ VERSION = "2.0.1"
4
4
  end
5
5
  end
@@ -16,8 +16,10 @@ Gem::Specification.new do |spec|
16
16
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
17
  spec.require_paths = ["lib"]
18
18
 
19
+ spec.required_ruby_version = "~> 2.0"
20
+
19
21
  spec.add_development_dependency "bundler", "~> 1.3"
20
22
  spec.add_development_dependency "rake", "~> 10.0"
21
23
  spec.add_development_dependency "mspec", "~> 1.5"
22
- spec.add_development_dependency "rubysl-prettyprint", "~> 1.0"
24
+ spec.add_development_dependency "rubysl-prettyprint", "~> 2.0"
23
25
  end
@@ -0,0 +1,6 @@
1
+
2
+ require 'drb'
3
+
4
+ describe "DRb::DRbServer#here?" do
5
+ it "needs to be reviewed for spec completeness"
6
+ end
@@ -1,18 +1,18 @@
1
1
 
2
2
  require 'drb'
3
3
 
4
- describe "DRb::DRbServer#verbose" do
4
+ describe "DRb::DRbServer.verbose" do
5
5
  it "needs to be reviewed for spec completeness"
6
6
  end
7
7
 
8
- describe "DRb::DRbServer#verbose=" do
8
+ describe "DRb::DRbServer.verbose=" do
9
9
  it "needs to be reviewed for spec completeness"
10
10
  end
11
11
 
12
- describe "DRb::DRbServer.verbose" do
12
+ describe "DRb::DRbServer#verbose" do
13
13
  it "needs to be reviewed for spec completeness"
14
14
  end
15
15
 
16
- describe "DRb::DRbServer.verbose=" do
16
+ describe "DRb::DRbServer#verbose=" do
17
17
  it "needs to be reviewed for spec completeness"
18
18
  end
metadata CHANGED
@@ -1,71 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubysl-drb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Shirai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-26 00:00:00.000000000 Z
11
+ date: 2013-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: mspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.5'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.5'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rubysl-prettyprint
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.0'
61
+ version: '2.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1.0'
68
+ version: '2.0'
69
69
  description: Ruby standard library drb.
70
70
  email:
71
71
  - brixen@gmail.com
@@ -73,8 +73,8 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
- - .gitignore
77
- - .travis.yml
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
78
  - Gemfile
79
79
  - LICENSE
80
80
  - README.md
@@ -142,6 +142,7 @@ files:
142
142
  - spec/drbserver/default_load_limit_spec.rb
143
143
  - spec/drbserver/default_safe_level_spec.rb
144
144
  - spec/drbserver/front_spec.rb
145
+ - spec/drbserver/here_spec.rb
145
146
  - spec/drbserver/invokemethod/perform_spec.rb
146
147
  - spec/drbserver/invokemethod18mixin/block_yield_spec.rb
147
148
  - spec/drbserver/invokemethod18mixin/perform_with_block_spec.rb
@@ -212,12 +213,12 @@ require_paths:
212
213
  - lib
213
214
  required_ruby_version: !ruby/object:Gem::Requirement
214
215
  requirements:
215
- - - '>='
216
+ - - "~>"
216
217
  - !ruby/object:Gem::Version
217
- version: '0'
218
+ version: '2.0'
218
219
  required_rubygems_version: !ruby/object:Gem::Requirement
219
220
  requirements:
220
- - - '>='
221
+ - - ">="
221
222
  - !ruby/object:Gem::Version
222
223
  version: '0'
223
224
  requirements: []
@@ -274,6 +275,7 @@ test_files:
274
275
  - spec/drbserver/default_load_limit_spec.rb
275
276
  - spec/drbserver/default_safe_level_spec.rb
276
277
  - spec/drbserver/front_spec.rb
278
+ - spec/drbserver/here_spec.rb
277
279
  - spec/drbserver/invokemethod/perform_spec.rb
278
280
  - spec/drbserver/invokemethod18mixin/block_yield_spec.rb
279
281
  - spec/drbserver/invokemethod18mixin/perform_with_block_spec.rb
@@ -334,3 +336,4 @@ test_files:
334
336
  - spec/to_id_spec.rb
335
337
  - spec/to_obj_spec.rb
336
338
  - spec/uri_spec.rb
339
+ has_rdoc: