Rinda and DRB technology explain (in preparation ...)

DRB (Distributed Ruby) is a ruby library of remote calls, use it, you can call a local object like the same access an object remotely.

The following code shows how to use drb.

# Server
the require 'DRB'
class the TestServer
  DEF the Add (* args)
    args.inject {| n-, V | V} + n-
  End
End
Server = TestServer.new
DRb.start_service ( 'druby: // localhost: 9000', Server )
! # DRb.thread.join the Just yet the Do not Exit

# client
The require 'DRB'
DRb.start_service ()
obj = DRbObject.new (nil, 'druby: // localhost: 9000')
# obj Now use
the puts " Sum is: # {obj.add (1 , 2, 3)} "

to achieve only a few hundred lines of code DRB.
The technology is based on java JNI JavaSpaces technology, and technology-based JavaSpaces Linda, author of DRB implements
called Rinda's Ruby version of Linda.

Linda realized that the process of collaboration among a distributed scenario.
Basic operation target is Linda tuple.
Read tuple may be a standard size may be a tuple in a tuple element content matches or not.

Allow drb services / clients to find each other is RingServer.

An example of the code for Rinda:
######### Rinda Server
the require 'DRB / DRB'
the require 'Rinda / tuplespace'
the require 'Rinda / Ring'

DRb.start_service
tuple_space Rinda TupleSpace.new :: =
ring_server Rinda :: = RingServer.new tuple_space
the while to true
   MSG = the gets
   tuple_space.write [: Message, MSG]
End

######### Rinda Client
the require 'DRB / DRB'
the require ' Rinda / tuplespace '
the require' Rinda / Ring '

DRb.start_service
tuple_space Rinda :: = RingFinger.
to true the while
   the puts "Message:" + tuple_space.take ([: Message, nil]) [1]
End

Issue:
1, but the client does not have to take the plurality of tuple
2, the client can not find another machine ringserver.
. 3 If the statement is removed take to get the message, but the tuple newly written can not overwrite the old tuple.

a RingServer android.permission bE a Rinda :: tuplespace located block to Via UDP Broadcasts.

can solve this problem, use RingServer, RingFinger indeed can find other by broadcast udp packet
rinda service. but to explicitly bind to drb service uri.

 
Published 46 original articles · won praise 7 · views 80000 +

Guess you like

Origin blog.csdn.net/yangbo_hr/article/details/1965662