Skip to content

Commit 36ec55b

Browse files
committed
Import sample/drb/* from ruby/ruby
1 parent 45dccba commit 36ec55b

45 files changed

Lines changed: 1955 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

sample/README.ja.rdoc

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
= サンプルスクリプト
2+
3+
* Arrayをリモートから利用してイテレータを試す。
4+
* darray.rb --- server
5+
* darrayc.rb --- client
6+
7+
* 簡易チャット
8+
* dchats.rb --- server
9+
* dchatc.rb --- client
10+
11+
* 分散chasen
12+
* dhasen.rb --- server
13+
* dhasenc.rb --- client
14+
15+
* 簡易ログサーバ
16+
* dlogd.rb --- server
17+
* dlogc.rb --- client
18+
19+
* Queueサーバ。
20+
クライアントdqin.rbはQueueサーバの知らないオブジェクト(DQEntry)を
21+
pushするがDRbUnknownによりクライアントdqout.rbがpopできる。
22+
* dqueue.rb --- server
23+
* dqin.rb --- client。DQEntryオブジェクトをpushする
24+
* dqout.rb --- client。DQEntryオブジェクトをpopする
25+
* dqlib.rb --- DQEntryを定義したライブラリ
26+
27+
* 名前による参照
28+
IdConvをカスタマイズしてidでなく名前で参照する例
29+
* name.rb --- server
30+
* namec.rb --- client
31+
32+
* extservのサンプル
33+
* extserv_test.rb
34+
35+
* TimerIdConvの使用例
36+
* holders.rb --- server。ruby -d hodlers.rbとするとTimerIdConvを使用する。
37+
* holderc.rb --- client
38+
39+
* rinda.rbの使用例
40+
* rinda_ts.rb --- TupleSpaceサーバ。
41+
* rindac.rb --- TupleSpaceのclientでアプリケーションのclient
42+
* rindas.rb --- TupleSpaceのclientでアプリケーションのserver
43+
44+
* observerの使用例
45+
cdbiff - http://namazu.org/~satoru/cdbiff/
46+
* dbiff.rb --- dcdbiff server
47+
* dcdbiff.rb --- dcdbiff client
48+
49+
* drbsslの使用例
50+
* drbssl_s.rb
51+
* drbssl_c.rb
52+
53+
* DRbProtocolの追加例
54+
* http0.rb
55+
* http0serv.rb
56+
57+
* ringの使用例
58+
* ring_place.rb
59+
* ring_echo.rb

sample/README.rdoc

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
= Sample scripts
2+
3+
* array and iterator
4+
* darray.rb --- server
5+
* darrayc.rb --- client
6+
7+
* simple chat
8+
* dchats.rb --- server
9+
* dchatc.rb --- client
10+
11+
* distributed chasen (for Japanese)
12+
* dhasen.rb --- server
13+
* dhasenc.rb --- client
14+
15+
* simple log server
16+
* dlogd.rb --- server
17+
* dlogc.rb --- client
18+
19+
* Queue server, and DRbUnknown demo
20+
* dqueue.rb --- server
21+
* dqin.rb --- client. push DQEntry objects.
22+
* dqout.rb --- client. pop DQEntry objects.
23+
* dqlib.rb --- define DQEntry
24+
25+
* IdConv customize demo: reference by name
26+
* name.rb --- server
27+
* namec.rb --- client
28+
29+
* extserv
30+
* extserv_test.rb
31+
32+
* IdConv customize demo 2: using TimerIdConv
33+
* holders.rb --- server
34+
* holderc.rb --- client
35+
36+
* rinda, remote tuplespace
37+
* rinda_ts.rb --- TupleSpace server.
38+
* rindas.rb --- provide simple service via TupleSpace.
39+
* rindac.rb --- service user
40+
41+
* observer
42+
cdbiff - http://namazu.org/~satoru/cdbiff/
43+
* dbiff.rb --- dcdbiff server
44+
* dcdbiff.rb --- dcdbiff client
45+
46+
* drbssl
47+
* drbssl_s.rb
48+
* drbssl_c.rb
49+
50+
* add DRbProtocol
51+
* http0.rb
52+
* http0serv.rb
53+
54+
* Rinda::Ring
55+
* ring_place.rb
56+
* ring_echo.rb

sample/acl.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require 'drb/acl'
2+
3+
list = %w(deny all
4+
allow 192.168.1.1
5+
allow ::ffff:192.168.1.2
6+
allow 192.168.1.3
7+
)
8+
9+
addr = ["AF_INET", 10, "lc630", "192.168.1.3"]
10+
11+
acl = ACL.new
12+
p acl.allow_addr?(addr)
13+
14+
acl = ACL.new(list, ACL::DENY_ALLOW)
15+
p acl.allow_addr?(addr)

sample/darray.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=begin
2+
distributed Ruby --- Array
3+
Copyright (c) 1999-2001 Masatoshi SEKI
4+
=end
5+
6+
require 'drb/drb'
7+
8+
here = ARGV.shift
9+
DRb.start_service(here, [1, 2, "III", 4, "five", 6])
10+
puts DRb.uri
11+
DRb.thread.join
12+

sample/darrayc.rb

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
=begin
2+
distributed Ruby --- Array client
3+
Copyright (c) 1999-2001 Masatoshi SEKI
4+
=end
5+
6+
require 'drb/drb'
7+
8+
there = ARGV.shift || raise("usage: #{$0} <server_uri>")
9+
10+
DRb.start_service(nil, nil)
11+
ro = DRbObject.new(nil, there)
12+
p ro.size
13+
14+
puts "# collect"
15+
a = ro.collect { |x|
16+
x + x
17+
}
18+
p a
19+
20+
puts "# find"
21+
p ro.find { |x| x.kind_of? String }
22+
23+
puts "# each, break"
24+
ro.each do |x|
25+
next if x == "five"
26+
puts x
27+
end
28+
29+
puts "# each, break"
30+
ro.each do |x|
31+
break if x == "five"
32+
puts x
33+
end
34+
35+
puts "# each, next"
36+
ro.each do |x|
37+
next if x == "five"
38+
puts x
39+
end
40+
41+
puts "# each, redo"
42+
count = 0
43+
ro.each do |x|
44+
count += 1
45+
puts count
46+
redo if count == 3
47+
end

sample/dbiff.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#
2+
# dbiff.rb - distributed cdbiff (server)
3+
# * original: cdbiff by Satoru Takabayashi <http://namazu.org/~satoru/cdbiff>
4+
5+
require 'drb/drb'
6+
require 'drb/eq'
7+
require 'drb/observer'
8+
9+
class Biff
10+
include DRb::DRbObservable
11+
12+
def initialize(filename, interval)
13+
super()
14+
@filename = filename
15+
@interval = interval
16+
end
17+
18+
def run
19+
last = Time.now
20+
while true
21+
begin
22+
sleep(@interval)
23+
current = File::mtime(@filename)
24+
if current > last
25+
changed
26+
begin
27+
notify_observers(@filename, current)
28+
rescue Error
29+
end
30+
last = current
31+
end
32+
rescue
33+
next
34+
end
35+
end
36+
end
37+
end
38+
39+
def main
40+
filename = "/var/mail/#{ENV['USER']}"
41+
interval = 15
42+
uri = 'druby://:19903'
43+
44+
biff = Biff.new(filename, interval)
45+
46+
DRb.start_service(uri, biff)
47+
biff.run
48+
end
49+
50+
main
51+

sample/dcdbiff.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#
2+
# dcdbiff.rb - distributed cdbiff (client)
3+
# * original: cdbiff by Satoru Takabayashi <http://namazu.org/~satoru/cdbiff>
4+
5+
require 'drb/drb'
6+
require 'drb/eq'
7+
8+
class Notify
9+
include DRbUndumped
10+
11+
def initialize(biff, command)
12+
@biff = biff
13+
@command = command
14+
15+
@biff.add_observer(self)
16+
end
17+
18+
def update(filename, time)
19+
p [filename, time] if $DEBUG
20+
system(@command)
21+
end
22+
23+
def done
24+
begin
25+
@biff.delete_observer(self)
26+
rescue
27+
end
28+
end
29+
end
30+
31+
def main
32+
command = 'eject'
33+
uri = 'druby://localhost:19903'
34+
35+
DRb.start_service
36+
biff = DRbObject.new(nil, uri)
37+
notify = Notify.new(biff, command)
38+
39+
trap("INT"){ notify.done }
40+
DRb.thread.join
41+
end
42+
43+
main

sample/dchatc.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
=begin
2+
distributed Ruby --- chat client
3+
Copyright (c) 1999-2000 Masatoshi SEKI
4+
=end
5+
6+
require 'drb/drb'
7+
8+
class ChatClient
9+
include DRbUndumped
10+
11+
def initialize(name)
12+
@name = name
13+
@key = nil
14+
end
15+
attr_reader(:name)
16+
attr_accessor(:key)
17+
18+
def message(there, str)
19+
raise 'invalid key' unless @key == there
20+
puts str
21+
end
22+
end
23+
24+
if __FILE__ == $0
25+
begin
26+
there = ARGV.shift
27+
name = ARGV.shift
28+
raise "usage" unless (there and name)
29+
rescue
30+
$stderr.puts("usage: #{$0} <server_uri> <your_name>")
31+
exit 1
32+
end
33+
DRb.start_service
34+
ro = DRbObject.new(nil, there)
35+
36+
chat = ChatClient.new(name)
37+
entry = ro.add_member(chat)
38+
while gets
39+
entry.say($_)
40+
end
41+
end

0 commit comments

Comments
 (0)