Hi Waler,

I invested some efforts to create a template class implementing waitForLock() functionality. It respects the JSR, so it can be used with any implementation that supports locking.

You can read about it here :
http://www.mail-archive.com/jackrabbit-dev%40incubator.apache.org/msg01870.html

Note: I haven't used it in production. I also welcome any comments...

Regards,

Nicolas


Le 10:29 2005-08-11, vous avez écrit:
Hi Stefan,

the first InvalidItemStateException is correct. i'll investigate the ItemNotFoundException. i guess there's a 'synchronized' missing somewhere...

I extended my testcase a little bit. Now I lock the rootnode for adding/deleting subnodes. But the program hangs sometimes while
locking or releasing the lock again.

Some waitForLock() method would be cool too ;) Perhaps with
some sort of waitQueue. But I know - its not in the spec.

cheers,
Walter
--

public void run() {
                // simulate a user...
                debug("started.");
                String state = "";
                Lock l = null;
                Node rn = null;
                try {
                        debug("1");
                        rn = session.getRootNode();
                        debug("2");
                        int count = 0;
                        while(rn.isLocked() && count < 30) {
                                sleep();
                                count++;
                        }
                        debug("3");
                        l = rn.lock(false, true);
                        debug("4");
                state = "searching testnode";
                        if (rn.hasNode("testnode-" + identity)) {
                                debug("4.1");
                        try {
                                state = "removing testnode";
                                rn.getNode("testnode-" + identity).remove();
                                debug("4.2");
                                session.save();
                                sleep();
                        } catch(ItemNotFoundException infe) {
debug("error while removing testnode " + identity);
                                infe.printStackTrace();
                        }
                    }
                        debug("5");
                state = "adding testnode";
Node n = rn.addNode("testnode-" + identity , "nt:unstructured");
                    debug("6");
                    session.save();
                    debug("7");
                    rn.unlock();
                    debug("8");
                    state = "setting property";
n.setProperty("testprop", new StringValue("Hello World!"));
                    session.save();
                    sleep();

                    for(int i=0; i<100; i++) {
                        state = "adding subnode " + i;
                        n.addNode("x" + i, "nt:unstructured");
                        state = "adding property to subnode " + i;
                        n.setProperty("testprop","xxx");
                        if(i%10==0)     {
                                state = "saving pending subnodes";
                                session.save();
                                System.out.print(".");
                        }
                        sleep();
                    }
                    session.save();

                } catch( Exception e) {
                        debug("Exception: " + state);
                        e.printStackTrace();
                } finally {
                        if(l != null && rn != null) {
                                try {
                                        rn.unlock();
} catch( RepositoryException e ) {
                                }
                        }
                        session.logout();
                }

                debug("ended.");
        }

Reply via email to