Inserting single semaphore into the JavaSpace
Oliver Plohmann <[email protected]> Wed, 15 Oct 2008 13:35:54 +0200
| Newsgroups | gmane.comp.java.sun.javaspaces |
|---|---|
| Message-ID | <[email protected]> |
Hello, I need to have for certain operations exclusive access to the JavaSpace or at least part of it. I found the approach of a distributed semaphore in the book from Freeman. So far so good. Now I have the problem that this semaphore must only be inserted once into the space. Two or more clients might be in a race to be the first one that inserts the semaphore. GigaSpaces has a write method that you can call with a parameter so that an exception is thrown if the entry already exists in the space. Unhappily, this is not possible with the JavaSpace05 interface. I could create my own Jini service for this, but I would prefer a simpler solution as I have other things to do. I found the threads "Re: Seeding a space with a semaphore" and "Adding a "singleton" method to JavaSpace API?" in the mailing archive, but a "cookbook" solution wasn't provided there. What I do at the moment is adding a token with a specific label to an RMI registry. Not really a nice solution when you have Jini at your disposal anyway, but simple and quick. Any possible race condition is then handled by the RMI registry. The guy that comes second in a race to register this token with the same label will receive an exception, so the token cannot be inserted twice. Any other ideas I was pursuing (harcoded seed, and others) always turn out as not working. Maybe someone knows a simple solution that works without installing a new Jini service. Thanks, Oliver Plohmann -- www.objectscape.org =========================================================================== To unsubscribe, send email to [email protected] and include in the body of the message "signoff JAVASPACES-USERS". For general help, send email to [email protected] and include in the body of the message "help". To view past JAVASPACES-USERS postings, please see: http://archives.java.sun.com/archives/javaspaces-users.html