Re: FW: Inserting single semaphore into the JavaSpace

Gregg Wonderly <[email protected]> Sat, 18 Oct 2008 08:49:41 -0500
Newsgroups gmane.comp.java.sun.javaspaces
Message-ID <[email protected]>
Oliver Plohmann wrote:
> Oh no ... Just realized that I don't get my exception when I do this:
....
> Don't count your chickens before they are hatched...

Yes Oliver, you can export something multiple times, if you use separate 
exporters for each export.  Jini service registry is the same way.  If you 
register with different service ids, the same object can appear in the lookup 
server multiple times.  If you register with the same service ID, that 
registration replaces the previous registration.  The Java/Jini/Jeri security 
mechanisms allow you to control who gets to register services.

In the end, this is not a "simple" problem given the existing APIs.  Using 
javaspaces to store singletons just might not be the right choice.  If you are 
feeling adventurous, you could actually just create a proxy service that 
implements the javaspaces api, and delegates to a "private" javaspace instance. 
  You could put another interface on that service that does the singleton work 
for you.  You'd mark the javaspace that you want used with an additional Entry 
that you'd use for lookup by all your clients in the system.

public interface MySpace implements JavaSpace,JavaSpace05,Remote {
	public void writeSingleton( Entry ent,
		Transaction tr, long timeout ) throws RemoteException;
}

Then just create a service that performs a lookup of the core space (use another 
Entry to separate it from your service proxy).

Now you can just use writeSingleton() to do what you want.

Gregg Wonderly

===========================================================================
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