Return-Path: Delivered-To: apmail-incubator-jackrabbit-dev-archive@www.apache.org Received: (qmail 40808 invoked from network); 21 Jul 2005 18:46:20 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 21 Jul 2005 18:46:20 -0000 Received: (qmail 99687 invoked by uid 500); 21 Jul 2005 18:46:19 -0000 Mailing-List: contact jackrabbit-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jackrabbit-dev@incubator.apache.org Delivered-To: mailing list jackrabbit-dev@incubator.apache.org Received: (qmail 99674 invoked by uid 99); 21 Jul 2005 18:46:19 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Jul 2005 11:46:19 -0700 X-ASF-Spam-Status: No, hits=0.1 required=10.0 tests=FORGED_RCVD_HELO X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [132.203.250.27] (HELO clouso.ulaval.ca) (132.203.250.27) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 21 Jul 2005 11:46:13 -0700 Received: from hermes.ulaval.ca(132.203.250.27) by clouso.ulaval.ca via csmap id b994aed4_fa17_11d9_88bf_00304811f440_30676; Thu, 21 Jul 2005 14:46:19 -0400 (EDT) Received: from clouso.ulaval.ca (poste015-130.bibl.ulaval.ca [132.203.130.15]) by hermes.ulaval.ca (8.12.9/8.12.9) with ESMTP id j6LIkDbq004346 for ; Thu, 21 Jul 2005 14:46:13 -0400 Received: from poste015-130.bibl.ulaval.ca(132.203.130.15) by clouso.ulaval.ca via csmap id b7e32bd8_fa17_11d9_9568_00304811f440_30580; Thu, 21 Jul 2005 14:46:16 -0400 (EDT) Message-Id: <6.1.1.1.2.20050721143221.01a62a18@hermes.ulaval.ca> X-Sender: biblnbe@hermes.ulaval.ca X-Mailer: QUALCOMM Windows Eudora Version 6.1.1.1 Date: Thu, 21 Jul 2005 14:46:13 -0400 To: jackrabbit-dev@incubator.apache.org From: Nicolas Belisle Subject: Re: Problems with concurrent sessions In-Reply-To: <42DCCDE5.1030703@gmx.net> References: <6.1.1.1.2.20050706142809.01afdcd8@hermes.ulaval.ca> <90a8d1c00507070233521f9893@mail.gmail.com> <6.1.1.1.2.20050707112258.01a594b8@hermes.ulaval.ca> <42CE3410.2030407@gmx.net> <6.1.1.1.2.20050708111147.019f7fd8@hermes.ulaval.ca> <42CEAB1A.5040709@gmx.net> <6.1.1.1.2.20050714134841.01a036c8@hermes.ulaval.ca> <42D77CC3.4020303@gmx.net> <6.1.1.1.2.20050715112238.01a926e8@hermes.ulaval.ca> <42DCCDE5.1030703@gmx.net> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1"; format=flowed Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Hi Marcel, If all three tryLock() fail, the event is certainly active. The event is=20 then waiting for an ACTIVE lock to be released (the last tryLock() confirms= =20 that fact). The event is not cancelled/removed until the lock is obtained.= =20 Then doInTransaction() is called. The only way I see to stop the transaction from executing is to stop the=20 server... Am I missing something ? Regards, Nicolas Le 05:54 2005-07-19, vous avez =E9crit: >Hi Nicolas, > >Looks better now, but there are still cases where the doTransaction()=20 >method will not be called, though very unlikely: when all three tryLock()= =20 >attempts fail. not very likely but theoretically possible... > >regards > marcel > >Nicolas Belisle wrote: >>Hi, >>Thanks again for your comments. >>Here's the second version of my template class. It should resolves the=20 >>concurrency issues you mentionned : >>package app; >>import javax.jcr.Credentials; >>import javax.jcr.LoginException; >>import javax.jcr.Node; >>import javax.jcr.Repository; >>import javax.jcr.RepositoryException; >>import javax.jcr.Session; >>import javax.jcr.lock.LockException; >>import javax.jcr.observation.Event; >>import javax.jcr.observation.EventIterator; >>import javax.jcr.observation.EventListener; >>public abstract class SerializableTemplate { >> private Session session; >> private Node scope; >> private boolean done =3D false; >> private EventListener el; >> public SerializableTemplate(Repository repository, Credentials cr,=20 >> String scopePath) throws LoginException, RepositoryException { >> session =3D repository.login(cr); >> scope =3D session.getRootNode().getNode(scopePath); >> //scope =3D session.getNodeByUUID(scope.getUUID()); >> } >> public abstract void doInTransaction(Session session) throws=20 >> RepositoryException; >> public void execute() throws RepositoryException { >> if (tryLock()) { >> return; >> } >> this.el =3D new EventListener() { >> public void onEvent(EventIterator events) { >> try { >> tryLock(); >> } catch (RepositoryException e) { >> throw new RuntimeException(e); >> } >> } >> }; >> >>session.getWorkspace().getObservationManager().addEventListener(el,=20 >>Event.PROPERTY_REMOVED, scope.getPath(), true, null, null, false); >> //Try again, in case the lock is removed before observer could=20 >> be put in place >> tryLock(); >> } >> private synchronized boolean tryLock() throws RepositoryException { >> try { >> if (done) { >> return false; >> } >> if (!scope.isLocked()) { >> scope.lock(true, true); >> try { >> if (el !=3D null) { >> >>session.getWorkspace().getObservationManager().removeEventListener(el); >> } >> doInTransaction(session); >> } finally { >> done =3D true; >> if (session.isLive()) { >> session.logout(); >> } >> } >> return true; >> } >> } catch (LockException e) { >> e.printStackTrace(); >> } >> return false; >> } >>} >>Here's how to use it : >>SerializableTemplate sTemplate =3D new SerializableTemplate(repository,= new=20 >>SimpleCredentials("user", "password".toCharArray()), "node/path") { >> //@Override >> public void doInTransaction(Session session) throws=20 >> RepositoryException { >> //Do your favorite transaction... >> }; >>sTemplate.execute(); >> >>For the constructor you suggested, I actually came up with a similiar=20 >>design at first, but found a problem with it : since the template class=20 >>might use an EventListener the class should be responsible for closing=20 >>the session (the EventListener can wait a while...). Else, the event=20 >>could be removed by the user before being invoked. That's the reason for= =20 >>my ugly constructor. >>I welcome your comments again... >>Regards, >>Nicolas