jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From SalmasCM <sal...@criticalmass.com>
Subject Re: modified externally: node / when deleting node
Date Thu, 07 May 2009 03:07:12 GMT

Stefan:

I do have a clustered environment. Not only this but my application is
running in BEA Weblogic which tends to spawn a variety of threads. What do
you mean when you say "one session/thread"? I am synchronizing and locking. 
Could you let me know if it is possible to use Jackrabbit in an application
server environment and perhaps a small example of how I should be
synchronizing and locking?
Right now my code looks like this:


            String topName =
DAOFactory.getInstance().getTopLevelNodeNameForType(type);
            removeTopLevelNode(topName);
            Session preview =
JCRConnectionUtil.getInstance().getNewSession(ConnectionManager.PREVIEW_WORKSPACE);
            previewRoot = preview.getRootNode();
            // JCRUtil.getInstance().lockNode(previewRoot, preview);
            dataLocation = EnvironmentUtil.getDataLoadDir();
            xmlDataLocation = dataLocation + "xml/";
            String fileName = xmlDataLocation + topName + ".xml";
            logger.info("loading " + fileName);
            InputStream stream = CommonUtil.getFile(fileName);
            preview.getWorkspace().importXML("/", stream,
ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
            preview.save();

            Node nodeToLock = previewRoot.getNode(topName);
            synchronized (nodeToLock) {
                JCRUtil.getInstance().lockNode(nodeToLock, preview);
                Session prod =
JCRConnectionUtil.getInstance().getNewSession(ConnectionManager.PRODUCTION_WORKSPACE);
                prod.save();
               
prod.getWorkspace().clone(ConnectionManager.PREVIEW_WORKSPACE, "/" +
topName, "/" + topName, true);
                prod.save();
                JCRUtil.getInstance().unlockNode(nodeToLock);
                preview.logout();
                prod.logout();
            }

   public void lockNode(Node node, Session session) {

        try {
            String nodeWSName = node.getSession().getWorkspace().getName();
            String sessionWSName = session.getWorkspace().getName();
            logLockPath(node);
            if (sessionWSName.equals(nodeWSName)) {
                if (node != null && session != null && !node.isLocked()) {
                    node.addMixin(LOCKABLE_MIXIN);
                    node.getSession().save();
                    for (int i = 0; i < MAX_LOCK_UNLOCK_TRIES; i++) {
                        node.lock(false, true);
                        if (node.isLocked()) {
                            break;
                        }
                        Thread.sleep(LOCK_UNLOCK_TRIES_SLEEP_INTERVAL);
                    }
                    node.getSession().save();
                    if (!node.isLocked()) {
                        throw new LockException("Cannot grab lock for node
");
                    }
                }
            } else {
                getInstance().logger.error("MISMATCHED WORKSPACE!!!: node="
+ 
                        nodeWSName + " sessionWSName " + sessionWSName);
            }
        } catch (NoSuchNodeTypeException e) {
            getInstance().logger.error("JCRUtil:lockNode
in:NoSuchNodeTypeException: " + e);
        } catch (VersionException e) {
            getInstance().logger.error("JCRUtil:lockNode
in:VersionException: " + e);
        } catch (ConstraintViolationException e) {
            getInstance().logger.error("JCRUtil:lockNode
in:ConstraintViolationException: " + e);
        } catch (LockException e) {
            getInstance().logger.error("JCRUtil:lockNode in:LockException: "
+ e);
        } catch (UnsupportedRepositoryOperationException e) {
            getInstance().logger.error("JCRUtil:lockNode
in:UnsupportedRepositoryOperationException: " + e);
        } catch (AccessDeniedException e) {
            getInstance().logger.error("JCRUtil:lockNode
in:AccessDeniedException: " + e);
        } catch (InvalidItemStateException e) {
            getInstance().logger.error("JCRUtil:lockNode
in:InvalidItemStateException: " + e);
        } catch (RepositoryException e) {
            getInstance().logger.error("JCRUtil:lockNode
in:RepositoryException: " + e);
        } catch (InterruptedException e) {
            getInstance().logger.error("JCRUtil:lockNode
in:InterruptedException: " + e);
        }
    }

    public void unlockNode(Node node) {
        try {
            if (node != null && node.isLocked()) {
                for (int i = 0; i < MAX_LOCK_UNLOCK_TRIES; i++) {
                    node.unlock();
                    if (!node.isLocked()) {
                        break;
                    }
                    Thread.sleep(LOCK_UNLOCK_TRIES_SLEEP_INTERVAL);
                }
                if (node.isLocked()) {
                    throw new LockException("Cannot unlock node ");
                }
            }
        } catch (UnsupportedRepositoryOperationException e) {
           
getInstance().logger.error("JCRUtil:UnsupportedRepositoryOperationException
in:unlockNode: " + e);
        } catch (LockException e) {
            getInstance().logger.error("JCRUtil:LockException in:unlockNode:
" + e);
        } catch (AccessDeniedException e) {
            getInstance().logger.error("JCRUtil:AccessDeniedException
in:unlockNode: " + e);
        } catch (InvalidItemStateException e) {
            getInstance().logger.error("JCRUtil:InvalidItemStateException
in:unlockNode: " + e);
        } catch (RepositoryException e) {
            getInstance().logger.error("JCRUtil:RepositoryException
in:unlockNode: " + e);
        } catch (InterruptedException e) {
            getInstance().logger.error("JCRUtil:lockNode
in:InterruptedException: " + e);
        }
    }

Stefan Guggisberg wrote:
> 
> On Tue, May 5, 2009 at 4:56 PM, SalmasCM <salmas@criticalmass.com> wrote:
>>
>> The following errors.
>>
>> failed to build path of dd740ff8-5108-40f2-9036-b6c769c86bd5:
>> cafebabe-cafe-babe-cafe-babecafebabe has no child entry for
>> dd740ff8-5108-40f2-9036-b6c769c86bd5
>> javax.jcr.ItemNotFoundException: failed to build path of
>> dd740ff8-5108-40f2-9036-b6c769c86bd5:
>> cafebabe-cafe-babe-cafe-babecafebabe
>> has no child entry for dd740ff8-5108-40f2-9036-b6c769c86bd5
> 
> assuming jcr sessions are used correctly (i.e. not shared among
> multiple threads)
> you should never see such an exception in a non-clustered jackrabbit
> setup.
> 
> it might be a CachingHierarchyManager bug. please create a jira issue
> and provide
> a simple test case for your problem. please also include detailed
> information about
> your setup/environment.
> 
> thanks
> stefan
> 
>>        at
>> org.apache.jackrabbit.core.HierarchyManagerImpl.buildPath(HierarchyManagerImpl.java:289)
>>        at
>> org.apache.jackrabbit.core.CachingHierarchyManager.buildPath(CachingHierarchyManager.java:195)
>>        at
>> org.apache.jackrabbit.core.HierarchyManagerImpl.buildPath(HierarchyManagerImpl.java:278)
>>        at
>> org.apache.jackrabbit.core.CachingHierarchyManager.buildPath(CachingHierarchyManager.java:195)
>>        at
>> org.apache.jackrabbit.core.HierarchyManagerImpl.getPath(HierarchyManagerImpl.java:393)
>>        at
>> org.apache.jackrabbit.core.CachingHierarchyManager.getPath(CachingHierarchyManager.java:229)
>>        at
>> org.apache.jackrabbit.core.ItemImpl.getPrimaryPath(ItemImpl.java:213)
>>        at
>> org.apache.jackrabbit.core.NodeImpl.getPrimaryPath(NodeImpl.java:3240)
>>        at org.apache.jackrabbit.core.ItemImpl.getPath(ItemImpl.java:1273)
>>        at
>> com.ashland.valvoline.ui.util.JCRUtil.getNodePath(JCRUtil.java:2353)
>>
>>
>>
>> Alexander Klimetschek wrote:
>>>
>>> On Tue, May 5, 2009 at 4:08 PM, SalmasCM <salmas@criticalmass.com>
>>> wrote:
>>>>
>>>> The reason I think its the index is because if I:
>>>>
>>>> 1. Load a file in from XML import under /nodeA in workspace 1.
>>>> 2. Clone nodeA to workspace2
>>>> 2. Exit my application.
>>>> 3. Delete nodeA from workspace 1 and 2
>>>> 4. Reload a file in from XML import.
>>>> 5. Do a XPATH query for a node in the imported data I get errors.
>>>
>>> What errors?
>>>
>>> Regards,
>>> Alex
>>>
>>> --
>>> Alexander Klimetschek
>>> alexander.klimetschek@day.com
>>>
>>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/modified-externally%3A-node---when-deleting-node-tp23352361p23389174.html
>> Sent from the Jackrabbit - Users mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/modified-externally%3A-node---when-deleting-node-tp23352361p23419439.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Mime
View raw message