Skip to content

Import sample/drb/* from ruby/ruby #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions sample/README.ja.rdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
= サンプルスクリプト

* Arrayをリモートから利用してイテレータを試す。
* darray.rb --- server
* darrayc.rb --- client

* 簡易チャット
* dchats.rb --- server
* dchatc.rb --- client

* 分散chasen
* dhasen.rb --- server
* dhasenc.rb --- client

* 簡易ログサーバ
* dlogd.rb --- server
* dlogc.rb --- client

* Queueサーバ。
クライアントdqin.rbはQueueサーバの知らないオブジェクト(DQEntry)を
pushするがDRbUnknownによりクライアントdqout.rbがpopできる。
* dqueue.rb --- server
* dqin.rb --- client。DQEntryオブジェクトをpushする
* dqout.rb --- client。DQEntryオブジェクトをpopする
* dqlib.rb --- DQEntryを定義したライブラリ

* 名前による参照
IdConvをカスタマイズしてidでなく名前で参照する例
* name.rb --- server
* namec.rb --- client

* extservのサンプル
* extserv_test.rb

* TimerIdConvの使用例
* holders.rb --- server。ruby -d hodlers.rbとするとTimerIdConvを使用する。
* holderc.rb --- client

* rinda.rbの使用例
* rinda_ts.rb --- TupleSpaceサーバ。
* rindac.rb --- TupleSpaceのclientでアプリケーションのclient
* rindas.rb --- TupleSpaceのclientでアプリケーションのserver

* observerの使用例
cdbiff - http://namazu.org/~satoru/cdbiff/
* dbiff.rb --- dcdbiff server
* dcdbiff.rb --- dcdbiff client

* drbsslの使用例
* drbssl_s.rb
* drbssl_c.rb

* DRbProtocolの追加例
* http0.rb
* http0serv.rb

* ringの使用例
* ring_place.rb
* ring_echo.rb
56 changes: 56 additions & 0 deletions sample/README.rdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
= Sample scripts

* array and iterator
* darray.rb --- server
* darrayc.rb --- client

* simple chat
* dchats.rb --- server
* dchatc.rb --- client

* distributed chasen (for Japanese)
* dhasen.rb --- server
* dhasenc.rb --- client

* simple log server
* dlogd.rb --- server
* dlogc.rb --- client

* Queue server, and DRbUnknown demo
* dqueue.rb --- server
* dqin.rb --- client. push DQEntry objects.
* dqout.rb --- client. pop DQEntry objects.
* dqlib.rb --- define DQEntry

* IdConv customize demo: reference by name
* name.rb --- server
* namec.rb --- client

* extserv
* extserv_test.rb

* IdConv customize demo 2: using TimerIdConv
* holders.rb --- server
* holderc.rb --- client

* rinda, remote tuplespace
* rinda_ts.rb --- TupleSpace server.
* rindas.rb --- provide simple service via TupleSpace.
* rindac.rb --- service user

* observer
cdbiff - http://namazu.org/~satoru/cdbiff/
* dbiff.rb --- dcdbiff server
* dcdbiff.rb --- dcdbiff client

* drbssl
* drbssl_s.rb
* drbssl_c.rb

* add DRbProtocol
* http0.rb
* http0serv.rb

* Rinda::Ring
* ring_place.rb
* ring_echo.rb
15 changes: 15 additions & 0 deletions sample/acl.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'drb/acl'

list = %w(deny all
allow 192.168.1.1
allow ::ffff:192.168.1.2
allow 192.168.1.3
)

addr = ["AF_INET", 10, "lc630", "192.168.1.3"]

acl = ACL.new
p acl.allow_addr?(addr)

acl = ACL.new(list, ACL::DENY_ALLOW)
p acl.allow_addr?(addr)
12 changes: 12 additions & 0 deletions sample/darray.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
=begin
distributed Ruby --- Array
Copyright (c) 1999-2001 Masatoshi SEKI
=end

require 'drb/drb'

here = ARGV.shift
DRb.start_service(here, [1, 2, "III", 4, "five", 6])
puts DRb.uri
DRb.thread.join

47 changes: 47 additions & 0 deletions sample/darrayc.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
=begin
distributed Ruby --- Array client
Copyright (c) 1999-2001 Masatoshi SEKI
=end

require 'drb/drb'

there = ARGV.shift || raise("usage: #{$0} <server_uri>")

DRb.start_service(nil, nil)
ro = DRbObject.new(nil, there)
p ro.size

puts "# collect"
a = ro.collect { |x|
x + x
}
p a

puts "# find"
p ro.find { |x| x.kind_of? String }

puts "# each, break"
ro.each do |x|
next if x == "five"
puts x
end

puts "# each, break"
ro.each do |x|
break if x == "five"
puts x
end

puts "# each, next"
ro.each do |x|
next if x == "five"
puts x
end

puts "# each, redo"
count = 0
ro.each do |x|
count += 1
puts count
redo if count == 3
end
51 changes: 51 additions & 0 deletions sample/dbiff.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#
# dbiff.rb - distributed cdbiff (server)
# * original: cdbiff by Satoru Takabayashi <http://namazu.org/~satoru/cdbiff>

require 'drb/drb'
require 'drb/eq'
require 'drb/observer'

class Biff
include DRb::DRbObservable

def initialize(filename, interval)
super()
@filename = filename
@interval = interval
end

def run
last = Time.now
while true
begin
sleep(@interval)
current = File::mtime(@filename)
if current > last
changed
begin
notify_observers(@filename, current)
rescue Error
end
last = current
end
rescue
next
end
end
end
end

def main
filename = "/var/mail/#{ENV['USER']}"
interval = 15
uri = 'druby://:19903'

biff = Biff.new(filename, interval)

DRb.start_service(uri, biff)
biff.run
end

main

43 changes: 43 additions & 0 deletions sample/dcdbiff.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# dcdbiff.rb - distributed cdbiff (client)
# * original: cdbiff by Satoru Takabayashi <http://namazu.org/~satoru/cdbiff>

require 'drb/drb'
require 'drb/eq'

class Notify
include DRbUndumped

def initialize(biff, command)
@biff = biff
@command = command

@biff.add_observer(self)
end

def update(filename, time)
p [filename, time] if $DEBUG
system(@command)
end

def done
begin
@biff.delete_observer(self)
rescue
end
end
end

def main
command = 'eject'
uri = 'druby://localhost:19903'

DRb.start_service
biff = DRbObject.new(nil, uri)
notify = Notify.new(biff, command)

trap("INT"){ notify.done }
DRb.thread.join
end

main
41 changes: 41 additions & 0 deletions sample/dchatc.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
=begin
distributed Ruby --- chat client
Copyright (c) 1999-2000 Masatoshi SEKI
=end

require 'drb/drb'

class ChatClient
include DRbUndumped

def initialize(name)
@name = name
@key = nil
end
attr_reader(:name)
attr_accessor(:key)

def message(there, str)
raise 'invalid key' unless @key == there
puts str
end
end

if __FILE__ == $0
begin
there = ARGV.shift
name = ARGV.shift
raise "usage" unless (there and name)
rescue
$stderr.puts("usage: #{$0} <server_uri> <your_name>")
exit 1
end
DRb.start_service
ro = DRbObject.new(nil, there)

chat = ChatClient.new(name)
entry = ro.add_member(chat)
while gets
entry.say($_)
end
end
Loading