FW: Inserting single semaphore into the JavaSpace
Tom Hobbs <[email protected]> Fri, 17 Oct 2008 17:59:33 +0100
| Newsgroups | gmane.comp.java.sun.javaspaces |
|---|---|
| Message-ID | <[email protected]> |
--MCBoundary=_108101717593702001 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Sorry, just realised that I failed to send this to the list. Gregg get's two apologies because he's going to get this email twice now... Tom -----Original Message----- From: Tom Hobbs=20 Sent: 17 October 2008 17:07 To: '[email protected]' Subject: RE: Inserting single semaphore into the JavaSpace A simple solution which I've come across (and we use successfully within my= company) is a two-fold solution. The first is a flag on the JavaSpace that indicates that it is "Available",= that is, it is ready to be discovered/used. The second is the concept of = a post-start operation. For example, the code to start your JavaSpace might look something like thi= s; NonActivatableServiceDescriptor.Created c =3D (NonActivatableServiceDescrip= tor.Created) sd.create(javaSpaceConfig); JavaSpace js =3D (JavaSpace) c.proxy; js.write(...); //put the token in makeAvailable(js); Where "makeAvailable(js)" is a method which adds an initialLookupAttribute = to the supplied service (in this case a space). The attribute might be som= ething as simple as "new Comment("Available")". Other code changes that are required is when your other services are lookin= g for this space the service validator they use must only return a JavaSpac= e which has the "Available" comment in its initialLookupAttributes. What this gives you is that your JavaSpace is only every eligible for disco= very when it is in a known good state - in this case it has the token insid= e it. Your services now never have to worry about putting the first token = in themselves. We find this solution very simple and it meets our needs. The only real ov= erhead is the extra check in the Service Validator when discovering service= s - and that itself is pretty small. Hope this makes sense. Tom -----Original Message----- From: Gregg Wonderly [mailto:[email protected]]=20 Sent: 17 October 2008 15:39 To: [email protected] Subject: Re: Inserting single semaphore into the JavaSpace You said without another service... Dan Creswell has a distributed lock ma= nager=20 on his web site that works. I have one as well that is a little different = in=20 design, using Jeri for communications instead jgroups. But, in the end, it= s=20 something that is generally useful. I had some thoughts about how to do t= his=20 using Javaspaces, but have never had a chance to explore the ideas to see i= f=20 they'd work. Gregg Wonderly Oliver Plohmann wrote: > Hello, >=20 > thanks for the link. The article explains the idea of a token used as a= =20 > semaphore. This is what I saw in Freeman's book and that's how I intend= =20 > to do synchronization. Problem is that someone must be the first one to= =20 > insert the >single< semaphore entry into the space since it is empty to= =20 > begin with. Now there might be several clients using the space and there= =20 > must be one of them who will insert the initial semaphore. How do they=20 > agree on who will do this when an initial semaphore not yet exists in=20 > the space to prevent race conditions from happening when working out the= =20 > agreement who will be the one? >=20 > As explained I use the RMI registry as a workaround to determine who is= =20 > the first one (everyone that comes second faces a AlreadyExistsException= =20 > when binding a remote object to the registry that already exists there=20 > with the same name) and thus is allowed to write the initial semaphore=20 > to the space. >=20 > I feel a method like >=20 > writeOnce(Entry entry, Transaction trx, long timeout) throws=20 > EntryAlreadyExistsException >=20 > would be a nice thing to have in the JavaSpace interface. Many=20 > concurrency issues could be solved easily this way and efficiently.=20 > Maybe there is still someone who has had this problem as well and found= =20 > a simple quick solution. >=20 > Thanks, Oliver Plohmann >=20 > Holger Hoffst=E4tte wrote: >> Oliver Plohmann wrote: >> =20 >>> I need to have for certain operations exclusive access to the JavaSpace >>> or at least part of it. [..] >>> =20 >> >> There is a "discussion" with a pointer to an article on TSS: >> http://www.theserverside.com/common/printthread.tss?thread_id=3D45418 >> >> This should do what you want. >> >> -h >> >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=20 >> >> To unsubscribe, send email to [email protected] and include in the= =20 >> body >> of the message "signoff JAVASPACES-USERS". For general help, send=20 >> 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 >> >> =20 >=20 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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 www.sucden.co.uk Sucden (UK) Limited, 5 London Bridge Street, London SE1 9SG Telephone +44 20 7940 9400 =20 Registered in England no. 1095841 VAT registration no. GB 446 9061 33 Authorised and Regulated by the Financial Services Authority (FSA) and ente= red in the FSA register under no. 114239 This email, including any files transmitted with it, is confidential and ma= y be privileged. It may be read, copied and used only by the intended recip= ient. If you are not the intended recipient of this message, please notify = [email protected] immediately and delete it from your computer system= . We believe, but do not warrant, that this email and its attachments are vir= us-free, but you should check.=20 Sucden (UK) Ltd may monitor traffic data of both business and personal emai= ls. By replying to this email, you consent to Sucden=92s monitoring the con= tent of any emails you send to or receive from Sucden. Sucden is not liable= for any opinions expressed by the sender where this is a non-business emai= l. The contents of this e-mail do not constitute advice and should not be rega= rded as a recommendation to buy, sell or otherwise deal with any particular= investment. This message has been scanned for viruses by Mimecast. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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 --MCBoundary=_108101717593702001 Content-Type: text/html; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable <HTML><BODY> Sorry, just realised that I failed to send this to the list.<BR> <BR> Gregg get's two apologies because he's going to get this email twice now...= <BR> <BR> Tom<BR> <BR> <BR> -----Original Message-----<BR> From: Tom Hobbs <BR> Sent: 17 October 2008 17:07<BR> To: <a href=3D"mailto:'[email protected]'">'[email protected]= '</a> <BR> Subject: RE: Inserting single semaphore into the JavaSpace<BR> <BR> A simple solution which I've come across (and we use successfully within my= company) is a two-fold solution.<BR> <BR> The first is a flag on the JavaSpace that indicates that it is "Availa= ble", that is, it is ready to be discovered/used. The second is the c= oncept of a post-start operation.<BR> <BR> For example, the code to start your JavaSpace might look something like thi= s;<BR> <BR> NonActivatableServiceDescriptor.Created c =3D (NonActivatableServiceDescrip= tor.Created) sd.create(javaSpaceConfig);<BR> JavaSpace js =3D (JavaSpace) c.proxy;<BR> js.write(...); //put the token in<BR> makeAvailable(js);<BR> <BR> Where "makeAvailable(js)" is a method which adds an initialLookup= Attribute to the supplied service (in this case a space). The attribute mi= ght be something as simple as "new Comment("Available")"= ;.<BR> <BR> Other code changes that are required is when your other services are lookin= g for this space the service validator they use must only return a JavaSpac= e which has the "Available" comment in its initialLookupAttribute= s.<BR> <BR> What this gives you is that your JavaSpace is only every eligible for disco= very when it is in a known good state - in this case it has the token insid= e it. Your services now never have to worry about putting the first token = in themselves.<BR> <BR> We find this solution very simple and it meets our needs. The only real ov= erhead is the extra check in the Service Validator when discovering service= s - and that itself is pretty small.<BR> <BR> Hope this makes sense.<BR> <BR> Tom<BR> <BR> <BR> -----Original Message-----<BR> From: Gregg Wonderly [mailto:[email protected]] <BR> Sent: 17 October 2008 15:39<BR> To: <a href=3D"mailto:[email protected]">JAVASPACES-USERS@JAVA.= SUN.COM</a> <BR> Subject: Re: Inserting single semaphore into the JavaSpace<BR> <BR> You said without another service... Dan Creswell has a distributed lock ma= nager <BR> on his web site that works. I have one as well that is a little different = in <BR> design, using Jeri for communications instead jgroups. But, in the end, it= s <BR> something that is generally useful. I had some thoughts about how to do t= his <BR> using Javaspaces, but have never had a chance to explore the ideas to see i= f <BR> they'd work.<BR> <BR> Gregg Wonderly<BR> <BR> Oliver Plohmann wrote:<BR> > Hello,<BR> > <BR> > thanks for the link. The article explains the idea of a token used as = a <BR> > semaphore. This is what I saw in Freeman's book and that's how I inten= d <BR> > to do synchronization. Problem is that someone must be the first one t= o <BR> > insert the >single< semaphore entry into the space since it is e= mpty to <BR> > begin with. Now there might be several clients using the space and the= re <BR> > must be one of them who will insert the initial semaphore. How do they= <BR> > agree on who will do this when an initial semaphore not yet exists in = <BR> > the space to prevent race conditions from happening when working out t= he <BR> > agreement who will be the one?<BR> > <BR> > As explained I use the RMI registry as a workaround to determine who i= s <BR> > the first one (everyone that comes second faces a AlreadyExistsExcepti= on <BR> > when binding a remote object to the registry that already exists there= <BR> > with the same name) and thus is allowed to write the initial semaphore= <BR> > to the space.<BR> > <BR> > I feel a method like<BR> > <BR> > writeOnce(Entry entry, Transaction trx, long timeout) throws <BR> > EntryAlreadyExistsException<BR> > <BR> > would be a nice thing to have in the JavaSpace interface. Many <BR> > concurrency issues could be solved easily this way and efficiently. <B= R> > Maybe there is still someone who has had this problem as well and foun= d <BR> > a simple quick solution.<BR> > <BR> > Thanks, Oliver Plohmann<BR> > <BR> > Holger Hoffst=E4tte wrote:<BR> >> Oliver Plohmann wrote:<BR> >> <BR> >>> I need to have for certain operations exclusive access to the = JavaSpace<BR> >>> or at least part of it. [..]<BR> >>> <BR> >><BR> >> There is a "discussion" with a pointer to an article on = TSS:<BR> >> <a href=3D"http://www.theserverside.com/common/printthread.tss?thr= ead_id=3D45418" target=3D"_blank">http://www.theserverside.com/common/print= thread.tss?thread_id=3D45418</a> <BR> >><BR> >> This should do what you want.<BR> >><BR> >> -h<BR> >><BR> >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D <BR> >><BR> >> To unsubscribe, send email to <a href=3D"mailto:[email protected].= com">[email protected]</a> and include in the <BR> >> body<BR> >> of the message "signoff JAVASPACES-USERS". For general = help, send <BR> >> email to<BR> >> <a href=3D"mailto:[email protected]">[email protected]</a>= and include in the body of the message "help". <BR> >><BR> >> To view past JAVASPACES-USERS postings, please see:<BR> >> <a href=3D"http://archives.java.sun.com/archives/javaspaces-users.= html" target=3D"_blank">http://archives.java.sun.com/archives/javaspaces-us= ers.html</a> <BR> >><BR> >> <BR> > <BR> <BR> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= <BR> To unsubscribe, send email to <a href=3D"mailto:[email protected]">list= [email protected]</a> and include in the body <BR> of the message "signoff JAVASPACES-USERS". For general help, sen= d email to<BR> <a href=3D"mailto:[email protected]">[email protected]</a> and incl= ude in the body of the message "help". <BR> <BR> To view past JAVASPACES-USERS postings, please see:<BR> <a href=3D"http://archives.java.sun.com/archives/javaspaces-users.html" tar= get=3D"_blank">http://archives.java.sun.com/archives/javaspaces-users.html<= /a> <BR> <FONT style=3D"BACKGROUND-COLOR: #ffffff"> <P style=3D"TEXT-ALIGN: center" align=3Dcenter><SPAN lang=3DEN-US style=3D"= FONT-SIZE: 10pt; BACKGROUND: white"><A title=3Dhttp://www.sucden.co.uk/ hre= f=3D"http://www.sucden.co.uk/"><FONT face=3D"Times New Roman" color=3D#0000= ff>www.sucden.co.uk</FONT></A></SPAN><SPAN lang=3DEN-US style=3D"FONT-SIZE:= 10pt"><?xml:namespace prefix =3D o ns =3D "urn:schemas-microsoft-com:offic= e:office" /><o:p></o:p></SPAN></P> <P style=3D"TEXT-ALIGN: center" align=3Dcenter><FONT face=3D"Times New Roma= n"><SPAN lang=3DEN-US style=3D"FONT-SIZE: 10pt; BACKGROUND: white">Sucden (= UK) Limited, <?xml:namespace prefix =3D st1 ns =3D "urn:schemas-microsoft-c= om:office:smarttags" /><st1:address w:st=3D"on"><st1:Street w:st=3D"on">5 L= ondon Bridge Street</st1:Street>, <st1:City w:st=3D"on">London</st1:City> <= st1:PostalCode w:st=3D"on">SE1 9SG</st1:PostalCode></st1:address><BR>Teleph= one +44 20 7940 9400<BR> <BR>Registered in <st1:country-region w:st=3D"on">= <st1:place w:st=3D"on">England</st1:place></st1:country-region> no. 1095841= <BR>VAT registration no. GB 446 9061 33</SPAN><SPAN lang=3DEN-US style=3D"F= ONT-SIZE: 10pt"><o:p></o:p></SPAN></FONT></P> <P style=3D"TEXT-ALIGN: center" align=3Dcenter><FONT face=3D"Times New Roma= n"><SPAN lang=3DEN-US style=3D"FONT-SIZE: 10pt; BACKGROUND: white">Authoris= ed and Regulated by the Financial Services Authority (FSA) and entered in t= he FSA register under no. 114239</SPAN><SPAN lang=3DEN-US style=3D"FONT-SIZ= E: 10pt"><o:p></o:p></SPAN></FONT></P> <P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt" align=3Dcenter><SPAN sty= le=3D"FONT-SIZE: 10pt; mso-ansi-language: EN-GB"><o:p><FONT face=3D"Times N= ew Roman"> </FONT></o:p></SPAN></P> <P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt" align=3Dcenter><SPAN sty= le=3D"FONT-SIZE: 10pt; mso-ansi-language: EN-GB"><FONT face=3D"Times New Ro= man">This email, including any files transmitted with it, is confidential a= nd may be privileged. It may be read, copied and used only by the intended = recipient. If you are not the intended recipient of this message, please no= tify <U>[email protected] </U>immediately and delete it from your com= puter system.<o:p></o:p></FONT></SPAN></P> <P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt" align=3Dcenter><SPAN sty= le=3D"FONT-SIZE: 10pt; mso-ansi-language: EN-GB"><o:p><FONT face=3D"Times N= ew Roman"> </FONT></o:p></SPAN></P> <P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt" align=3Dcenter><SPAN sty= le=3D"FONT-SIZE: 10pt; mso-ansi-language: EN-GB"><FONT face=3D"Times New Ro= man">We believe, but do not warrant, that this email and its attachments ar= e virus-free, but you should check. <o:p></o:p></FONT></SPAN></P> <P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt"><SPAN style=3D"FONT-SIZE= : 10pt; mso-ansi-language: EN-GB"><o:p><FONT face=3D"Times New Roman"> </FO= NT></o:p></SPAN></P> <P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt"><SPAN style=3D"FONT-SIZE= : 10pt; mso-ansi-language: EN-GB"><FONT face=3D"Times New Roman">Sucden (UK= ) Ltd may monitor traffic data of both business and personal emails. By rep= lying to this email, you consent to Sucden's monitoring the content of any = emails you send to or receive from Sucden. Sucden is not liable for any opi= nions expressed by the sender where this is a non-business email.<SPAN styl= e=3D"COLOR: black"><o:p></o:p></SPAN></FONT></SPAN></P> <P style=3D"TEXT-ALIGN: center" align=3Dcenter><FONT face=3D"Times New Roma= n"><SPAN lang=3DEN-US style=3D"FONT-SIZE: 10pt; BACKGROUND: white">The cont= ents of this e-mail do not constitute advice and should not be regarded as = a recommendation to buy, sell or otherwise deal with any particular investm= ent.</SPAN><SPAN lang=3DEN-US style=3D"FONT-SIZE: 10pt"><o:p></o:p></SPAN><= /FONT></P> <P style=3D"TEXT-ALIGN: center" align=3Dcenter><FONT face=3D"Times New Roma= n"><SPAN lang=3DEN-US style=3D"FONT-SIZE: 10pt; BACKGROUND: white">This mes= sage has been scanned for viruses by </SPAN><SPAN lang=3DEN-US style=3D"FON= T-SIZE: 10pt"><A title=3Dhttp://www.mimecast.com/ href=3D"http://www.mimeca= st.com/"><SPAN style=3D"BACKGROUND: white; COLOR: black">Mimecast</SPAN></A= ><o:p></o:p></SPAN></FONT></P> <P align=3Dcenter></FONT></P> </BODY></HTML> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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". <p> To view past JAVASPACES-USERS postings, please see: http://archives.java.sun.com/archives/javaspaces-users.html --MCBoundary=_108101717593702001--