Recipe 16.14. Automatically Discovering DRb Services with RindaCredit: James Edward Gray II ProblemYou want to distribute Ruby code across your local network without hardcoding the clients with the addresses of the servers. SolutionUsing Ruby's standard
DiscussionThe RingServer provides automatic service detection for DRb servers. Any machine on your local network can find the local RingServer without knowing its address. Once it's found the server, a client can look up services and use them, not having to know the addresses of the DRb servers that host them. To find the Rinda server, a client broadcasts a UDP packet asking for the location of a RingServer. All computers on the local network will get this packet, and if a computer is running a RingServer, it will respond with its address. A server can use the RingServer to register services; a client can use the RingServer to look up services. A RingServer object keeps a service listing in a shared TupleSpace (see Recipe 16.12). Each service has a corresponding tuple with four members:
By retrieving this TupleSpace remotely, you can look up services as tuples and advertise your own services. Let's advertise an object (a simple TupleSpace) tHRough the RingServer under the name :TupleSpace:
The SimpleRenewer sent in with the namespace listing lets the RingServer periodically check whether the service has expired. Now we can write clients that find this service by querying the RingServer, without having to know which machine it lives on. All we need to know is the name of the service:
These two programs locate each other without needing hardcoded IP addresses. Addresses are still being used under the covers, but the address to the Rinda::RingFinger.primary stores the first RingServer to respond to your Ruby process's UDP packet. If your local network is running more than one RingServer, the first one to respond might not be the one with the service you want, so you should probably only run one RingServer on your network. If you do have more than one RingServer, you can iterate over them with Rinda::RingFinger#each. See Also
|
Saturday, October 31, 2009
Recipe 16.14. Automatically Discovering DRb Services with Rinda
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment