You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Sunil Dhage <su...@coreobjects.com> on 2009/11/20 08:47:57 UTC

Unable to lock Exception.

Hi,

I have a node "account" to be locked. Since there can be concurrent threads which try to access this node.

I have provided mix:lockable to the node definition in .cnd file.  [lc:account] >nt:folder,mix:lockable

And when I tried printing account.isNodeType("mix:lockable");  yielding false all the times.

And when I tried locking the node account.lock(true,true);  I am getting Item locked: Unable to lock the node..

Can you please let me know how should I provide.


Regards,
Sunil

RE: Unable to lock Exception.

Posted by Sunil Dhage <su...@coreobjects.com>.
Thanks Alex,

I got the issue resolved.

Actually, the problem is I am not at all passing the node type in my invokation.
All I have done is I invoked the verifyAndAddnode () like this
  Node account = verifyAndAddNode(session,candidatedocs,path,"lc:account","lc:account");
Since the last parameter will be treated as the node type and only then it will try to search through the node definitions
in the .cnd file.  Then it could learn that the node is of type lockable and I got true for
account.isNodeType("mix:lockable");

By the way thanks for your replies to my post.

Regards,
Sunil
________________________________________
From: Alexander Klimetschek [aklimets@day.com]
Sent: Monday, November 23, 2009 11:29 PM
To: users@jackrabbit.apache.org
Subject: Re: Unable to lock Exception.

On Mon, Nov 23, 2009 at 10:06, Sunil Dhage <su...@coreobjects.com> wrote:
>  public Node verifyAndAddNode(Session session,Node parent,String... parameters) throws RepositoryException
>    {   Node node2Add = null;
>        //code review comment - to ensure parameters size is either 2 or 3.
>        if(parameters.length < 2 || parameters.length > 3)
>        {   throw new IllegalArgumentException("Number of parameters to verify/add node invalid ");
>        }
>        NodeIterator iterator = queryForPath(session,parameters[0]);
>        if(iterator.hasNext())
>        {   log.info("Node exists in this path...");
>            node2Add = iterator.nextNode();
>        }else
>        {   if(parameters.length == 2)
>                node2Add = parent.addNode(parameters[1]);
>            else
>               node2Add = parent.addNode(parameters[1],parameters[2]);
>        }
>        return node2Add;
>    }

The "parameters" handling seems broken. You call the above method with

>           Node account = verifyAndAddNode(session,candidatedocs,path,"lc:account");

in which case parameters.length = 2 and the addNode() call will be
done without the node type. Also, the indexes look wrong to me:
parameters[1], which is used as the node name in the addNode() call,
will be "lc:account" in your case - the nodetype.

Regards,
Alex

--
Alexander Klimetschek
alexander.klimetschek@day.com

Re: Unable to lock Exception.

Posted by Alexander Klimetschek <ak...@day.com>.
On Mon, Nov 23, 2009 at 10:06, Sunil Dhage <su...@coreobjects.com> wrote:
>  public Node verifyAndAddNode(Session session,Node parent,String... parameters) throws RepositoryException
>    {   Node node2Add = null;
>        //code review comment - to ensure parameters size is either 2 or 3.
>        if(parameters.length < 2 || parameters.length > 3)
>        {   throw new IllegalArgumentException("Number of parameters to verify/add node invalid ");
>        }
>        NodeIterator iterator = queryForPath(session,parameters[0]);
>        if(iterator.hasNext())
>        {   log.info("Node exists in this path...");
>            node2Add = iterator.nextNode();
>        }else
>        {   if(parameters.length == 2)
>                node2Add = parent.addNode(parameters[1]);
>            else
>               node2Add = parent.addNode(parameters[1],parameters[2]);
>        }
>        return node2Add;
>    }

The "parameters" handling seems broken. You call the above method with

>           Node account = verifyAndAddNode(session,candidatedocs,path,"lc:account");

in which case parameters.length = 2 and the addNode() call will be
done without the node type. Also, the indexes look wrong to me:
parameters[1], which is used as the node name in the addNode() call,
will be "lc:account" in your case - the nodetype.

Regards,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com

RE: Unable to lock Exception.

Posted by Sunil Dhage <su...@coreobjects.com>.
Hi Alex,

Please find the code for verifyAndAdd();

 public Node verifyAndAddNode(Session session,Node parent,String... parameters) throws RepositoryException
    {   Node node2Add = null;
        //code review comment - to ensure parameters size is either 2 or 3.
        if(parameters.length < 2 || parameters.length > 3)
        {   throw new IllegalArgumentException("Number of parameters to verify/add node invalid ");
        }
        NodeIterator iterator = queryForPath(session,parameters[0]);
        if(iterator.hasNext())
        {   log.info("Node exists in this path...");
            node2Add = iterator.nextNode();
        }else
        {   if(parameters.length == 2)
                node2Add = parent.addNode(parameters[1]);
            else
               node2Add = parent.addNode(parameters[1],parameters[2]);
        }
        return node2Add;
    }

    protected NodeIterator queryForPath(Session session, String path) throws RepositoryException
    {   log.info("Querying for path : "+path);
        Workspace workspace = session.getWorkspace();
        QueryManager queryManager = workspace.getQueryManager();
        Query query = queryManager.createQuery(path, Query.XPATH);
        QueryResult result = query.execute();
        return result.getNodes();
    }


Regards,
Sunil
________________________________________
From: Alexander Klimetschek [aklimets@day.com]
Sent: Monday, November 23, 2009 4:50 PM
To: users@jackrabbit.apache.org
Subject: Re: Unable to lock Exception.

On Mon, Nov 23, 2009 at 07:30, Sunil Dhage <su...@coreobjects.com> wrote:
> xyz.cnd contains these node type definitions.
>
> [lc:account] > nt:folder, mix:lockable
> -lc:accountid (string) mandatory primary
>
>  /**
>     * Registers custom node types for the application
>     */
>    protected void registerCustomNodeTypes(Workspace workspace) throws RepositoryException
>    {   try
>        {   ClassLoader loader = Thread.currentThread().getContextClassLoader();
>            InputStream in = loader.getResourceAsStream("xyz.cnd");
>            NodeTypeManagerImpl nodeTypeManager = (NodeTypeManagerImpl) workspace.getNodeTypeManager();
>            // Registors the custom node types and namespaces
>            nodeTypeManager.registerNodeTypes(in, JackrabbitNodeTypeManager.TEXT_X_JCR_CND, true);
>        }catch (NamespaceException nse)
>        {   log.error("[contentCallback] Namespace registration issue : " + nse.getMessage());
>        }catch (RepositoryException repse)
>        {   log.error("[contentCallback] Repository registeration issue : " + repse.getMessage());
>        } catch (IOException ex)
>        {  log.error("[contentCallback] Error reading custom node definitions. Check dms-lc.cnd is in classpath: " + ex.getMessage());
>        }
>    }

Looks good to me, if you didn't get any errors here. Maybe you changed
the nodetype (adding mix:lockable) and restarted your repository and
the above code failed with an cannot update nodetypes exception (or
similar)?

>           Node account = verifyAndAddNode(session,candidatedocs,path,"lc:account");

What about this method? We can only help when seeing what exact JCR
API calls you are doing. (I can imagine what that method does, but
maybe there is a slight error there).

Regards,
Alex

--
Alexander Klimetschek
alexander.klimetschek@day.com

Re: Unable to lock Exception.

Posted by Alexander Klimetschek <ak...@day.com>.
On Mon, Nov 23, 2009 at 07:30, Sunil Dhage <su...@coreobjects.com> wrote:
> xyz.cnd contains these node type definitions.
>
> [lc:account] > nt:folder, mix:lockable
> -lc:accountid (string) mandatory primary
>
>  /**
>     * Registers custom node types for the application
>     */
>    protected void registerCustomNodeTypes(Workspace workspace) throws RepositoryException
>    {   try
>        {   ClassLoader loader = Thread.currentThread().getContextClassLoader();
>            InputStream in = loader.getResourceAsStream("xyz.cnd");
>            NodeTypeManagerImpl nodeTypeManager = (NodeTypeManagerImpl) workspace.getNodeTypeManager();
>            // Registors the custom node types and namespaces
>            nodeTypeManager.registerNodeTypes(in, JackrabbitNodeTypeManager.TEXT_X_JCR_CND, true);
>        }catch (NamespaceException nse)
>        {   log.error("[contentCallback] Namespace registration issue : " + nse.getMessage());
>        }catch (RepositoryException repse)
>        {   log.error("[contentCallback] Repository registeration issue : " + repse.getMessage());
>        } catch (IOException ex)
>        {  log.error("[contentCallback] Error reading custom node definitions. Check dms-lc.cnd is in classpath: " + ex.getMessage());
>        }
>    }

Looks good to me, if you didn't get any errors here. Maybe you changed
the nodetype (adding mix:lockable) and restarted your repository and
the above code failed with an cannot update nodetypes exception (or
similar)?

>           Node account = verifyAndAddNode(session,candidatedocs,path,"lc:account");

What about this method? We can only help when seeing what exact JCR
API calls you are doing. (I can imagine what that method does, but
maybe there is a slight error there).

Regards,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com

RE: Unable to lock Exception.

Posted by Sunil Dhage <su...@coreobjects.com>.
Hi,
Thanks for your reply.

xyz.cnd contains these node type definitions.

[lc:account] > nt:folder, mix:lockable
-lc:accountid (string) mandatory primary

 /**
     * Registers custom node types for the application
     */
    protected void registerCustomNodeTypes(Workspace workspace) throws RepositoryException
    {   try
        {   ClassLoader loader = Thread.currentThread().getContextClassLoader();
            InputStream in = loader.getResourceAsStream("xyz.cnd");
            NodeTypeManagerImpl nodeTypeManager = (NodeTypeManagerImpl) workspace.getNodeTypeManager();
            // Registors the custom node types and namespaces
            nodeTypeManager.registerNodeTypes(in, JackrabbitNodeTypeManager.TEXT_X_JCR_CND, true);
        }catch (NamespaceException nse)
        {   log.error("[contentCallback] Namespace registration issue : " + nse.getMessage());
        }catch (RepositoryException repse)
        {   log.error("[contentCallback] Repository registeration issue : " + repse.getMessage());
        } catch (IOException ex)
        {  log.error("[contentCallback] Error reading custom node definitions. Check dms-lc.cnd is in classpath: " + ex.getMessage());
        }
    }

 /*
     * Adds a new candidate photo node from the root. adding,appending all the nodes
     * in the path.
     */
    private Node addPhotoContent(Session session,Node root) throws IOException,RepositoryException
    { ....

       try
       {  ......
           //looking for node at LC-root/candidatedocs/account
           path = getNodePath(contentpath.getProperty(ContentConstants.LC_ACCOUNT_PATH),new Object[]{accountID});
           log.debug("Adding "+ContentConstants.LC_NODE_ACCOUNT+" at path ["+path+"]");
           Node account = verifyAndAddNode(session,candidatedocs,path,"lc:account");
           log.info("lockable status of account: '+account.isNodeType("mix:lockable"));  //ALWAYS YIELDING FALSE
           account.save();
           account.lock(true,true);  //YIELDING EXCEPTION:  Unable to lock ....

**********Can I have a link, containing any example of how to create lockable nodes and how to invoke lock on such nodes.

Regards,
Sunil

________________________________________
From: Alexander Klimetschek [aklimets@day.com]
Sent: Friday, November 20, 2009 8:01 PM
To: users@jackrabbit.apache.org
Subject: Re: Unable to lock Exception.

On Fri, Nov 20, 2009 at 08:47, Sunil Dhage <su...@coreobjects.com> wrote:
> I have a node "account" to be locked. Since there can be concurrent threads which try to access this node.
>
> I have provided mix:lockable to the node definition in .cnd file.  [lc:account] >nt:folder,mix:lockable
>
> And when I tried printing account.isNodeType("mix:lockable");  yielding false all the times.

Maybe something with node type registration fails or the account node
is not created with the primary node type lc:account. Could you check?
And/or provide code example?

Regards,
Alex

--
Alexander Klimetschek
alexander.klimetschek@day.com

Re: Unable to lock Exception.

Posted by Alexander Klimetschek <ak...@day.com>.
On Fri, Nov 20, 2009 at 08:47, Sunil Dhage <su...@coreobjects.com> wrote:
> I have a node "account" to be locked. Since there can be concurrent threads which try to access this node.
>
> I have provided mix:lockable to the node definition in .cnd file.  [lc:account] >nt:folder,mix:lockable
>
> And when I tried printing account.isNodeType("mix:lockable");  yielding false all the times.

Maybe something with node type registration fails or the account node
is not created with the primary node type lc:account. Could you check?
And/or provide code example?

Regards,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com

RE: Unable to lock Exception.

Posted by Sunil Dhage <su...@coreobjects.com>.
Hi all,

any pointers please.

regards,
Sunil
________________________________________
From: Sunil Dhage [sunil.dhage@coreobjects.com]
Sent: Friday, November 20, 2009 1:17 PM
To: users@jackrabbit.apache.org
Subject: Unable to lock Exception.

Hi,

I have a node "account" to be locked. Since there can be concurrent threads which try to access this node.

I have provided mix:lockable to the node definition in .cnd file.  [lc:account] >nt:folder,mix:lockable  and registered the node types

And when I tried printing account.isNodeType("mix:lockable");  yielding false all the times.

And when I tried locking the node account.lock(true,true);  I am getting """""Item locked: Unable to lock the node..""""""

Can you please let me know how should I provide.


Regards,
Sunil