• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
drb09
 

drb09

on

  • 971 views

Slide of lecture on Shimane University on December 4

Slide of lecture on Shimane University on December 4

Statistics

Views

Total Views
971
Views on SlideShare
909
Embed Views
62

Actions

Likes
1
Downloads
3
Comments
0

1 Embed 62

http://d.hatena.ne.jp 62

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    drb09 drb09 Presentation Transcript

    • dRuby Web
    • hello() hello_server.rb hello_client.rb "Hello, World."
    • hello_server.rb require 'drb/drb' class Hello def hello puts('Hello, World.') end end DRb.start_service('druby://localhost:54000', Hello.new) while true sleep 1 end
    • require require 'drb/drb' class Hello def hello puts('Hello, World.') end end DRb.start_service('druby://localhost:54000', Hello.new) while true sleep 1 end
    • DRb.start_service require 'drb/drb' class Hello def hello puts('Hello, World.') end end DRb.start_service('druby://localhost:54000', Hello.new) while true sleep 1 end
    • URI require 'drb/drb' class Hello def hello puts('Hello, World.') end end DRb.start_service('druby://localhost:54000', Hello.new) while true sleep 1 end
    • require 'drb/drb' class Hello def hello puts('Hello, World.') end end DRb.start_service('druby://localhost:54000', Hello.new) while true sleep 1 end
    • hello_client.rb require 'drb/drb' DRb.start_service ro = DRbObject.new_with_uri('druby://localhost:54000') ro.hello
    • hello_client.rb require 'drb/drb' DRb.start_service ro = DRbObject.new_with_uri('druby://localhost:54000') ro.hello
    • hello_client.rb require 'drb/drb' DRb.start_service ro = DRbObject.new_with_uri('druby://localhost:54000') ro.hello
    • hello_client.rb require 'drb/drb' DRb.start_service ro = DRbObject.new_with_uri('druby://localhost:54000') ro.hello
    • require 'drb/drb' class Hello def hello puts('Hello, World.') end end DRb.start_service('druby://localhost:54000', Hello.new) while true sleep 1 end require 'drb/drb' DRb.start_service ro = DRbObject.new_with_uri('druby://localhost:54000') ro.hello
    • class Hello def hello puts('Hello, World.') end end ro = Hello.new ro.hello
    • KVS... require 'drb/drb' DRb.start_service('druby://localhost:54300', Hash.new) while true sleep 1 end
    • hash_server.rb irb irb
    • def hoge(a1, a2, a3, &block) ... raise FooError unless some_cond ... return value end
    • Marshal dumpable pass by value Number, String, Boolean... can’t dump pass by reference Proc, Thread, File ...
    • Queue
    • Queue
    • irb Queue deque.rb
    • require 'drb/drb' require 'thread' DRb.start_service('druby://localhost:54320', Queue.new) while true sleep 1 end require 'drb/drb' DRb.start_service queue = DRbObject.new_with_uri('druby://localhost:54320') while true p queue.pop sleep(rand) end
    • deque.rb irb Queue deque.rb deque.rb
    • 1 "Hello, World." 2 "Hello, Again." 3 :Three 4 4 5 [5]
    • 1 "Hello, World." 2 "Hello, Again." 3 :Three 4 4 5 [5]
    • 1 "Hello, World." 2 "Hello, Again." 3 :Three 4 4
    • 1 "Hello, World." 2 "Hello, Again." 3 :Three 4 4 5 [5]
    • 1 "Hello, World." 2 "Hello, Again." 3 :Three 4 4 5 [5]
    • require 'rinda/tuplespace' require 'drb/drb' class Notifier def initialize @ts = Rinda::TupleSpace.new @ts.write([:tail, 0]) end def notify(it) tuple = @ts.take([:tail, nil]) tail = tuple[1] + 1 @ts.write([tail, it]) @ts.write([:tail, tail]) tail end def receive(key) @ts.read([key, nil]) end end DRb.start_service('druby://localhost:54321', Notifier.new) while true sleep 1 end
    • class Notifier class Notifier def initialize @ts = Rinda::TupleSpace.new @ts.write([:tail, 0]) end def notify(it) tuple = @ts.take([:tail, nil]) tail = tuple[1] + 1 @ts.write([tail, it]) @ts.write([:tail, tail]) tail end def receive(key) @ts.read([key, nil]) end end
    • Tuple Space Engine Client Engine TupleSpace Client Engine
    • Tuple [:chopstick, 2] [:room_ticket] [‘abc’, 2, 5] [:matrix, 1.6, 3.14] [‘family’, ‘is-sister’, ’Carolyn’, ’Elinor’]
    • Pattern • Tuple === • case equals • Regexp, Range, Class • nil
    • Pattern [/^A/, nil, nil] [:matrix, Numeric, Numeric] [’family’, ’is-sister’, ’Carolyn’, nil] [nil, ’age’, (0..18)]
    • [’seki’, ’age’, 20] >> require ‘rinda/tuplespace’ >> ts = Rinda::TupleSpace.new >> ts.write([’seki’, ’age’, 20]) >> ts.write([’sougo’, ’age’, 18]) >> ts.write([’leonard’, ’age’, 18]) >> ts.read_all([nil, ’age’, 0..19]) => [["sougo", "age", 18], ["leonard", "age", 18]] >> ts.read_all([/^s/, ’age’, Numeric]) => [["seki", "age", 20], ["sougo", "age", 18]]
    • >> ts.write([:seki, :age, 20]) => #<Rinda::TupleEntry:...> >> TupleSpace :seki :age 20
    • >> ts.write([:seki, :age, 20]) => #<Rinda::TupleEntry:...> >> TupleSpace >> ts.take([:seki, :age, nil]) => [:seki, :age, 20] >> :seki :age 20
    • class Notifier def initialize @ts = Rinda::TupleSpace.new @ts.write([:tail, 0]) end def notify(it) tuple = @ts.take([:tail, nil]) tail = tuple[1] + 1 @ts.write([tail, it]) @ts.write([:tail, tail]) tail end def receive(key) @ts.read([key, nil]) end end
    • initialize :tail 0
    • notify("Hello, World.") :tail 0
    • take([:tail, nil]) :tail 0
    • write([tail, it]) 1 "Hello, World."
    • write([:tail, tail]) :tail 1 1 "Hello, World."
    • receive(1) :tail 1 1 "Hello, World."
    • read([1, nil]) :tail 1 1 "Hello, World."
    • receive(2) :tail 1 1 "Hello, World."
    • read([2, nil]) :tail 1 1 "Hello, World."
    • notify("Hello, Again.") :tail 1 1 "Hello, World."
    • take([:tail, nil]) :tail 1 1 "Hello, World."
    • write([tail, it]) 1 "Hello, World." 2 "Hello, Again."
    • write([:tail, tail]) :tail 2 1 "Hello, World." 2 "Hello, Again."
    • read([2, nil]) :tail 1 1 "Hello, World." 2 "Hello, Again."
    • receive.rb require 'drb/drb' DRb.start_service ro = DRbObject.new_with_uri('druby://localhost:54321') key = 0 while true key, obj = ro.receive(key + 1) p [key, obj] sleep(3) end
    • dRuby Web