如何锁定节点以进行删除过程
在 alfresco 中,我想删除一个节点,但我不想被集群环境中的任何其他用户使用。
我知道我将使用 LockService 来锁定节点(在集群环境中),如下所示:
lockService.lock(deleteNode);
nodeService.deleteNode(deleteNode);
lockService.unlock(deleteNode);
最后一行可能会导致异常,因为该节点已被删除,并且确实会导致异常是
操作过程中发生系统错误:节点不存在:workspace://SpacesStore/cb6473ed-1f0c-4fa3-bfdf-8f0bc86f3a12
那么集群环境下删除节点时如何保证并发,防止两个用户访问同一个节点同时其中一个想要更新它,而第二个想要删除它?
Within alfresco, I want to delete a node but I don't want to be used by any other users in a cluster environment.
I know that I will use LockService for lock a node (in a cluster environment) as in the folloing lines:
lockService.lock(deleteNode);
nodeService.deleteNode(deleteNode);
lockService.unlock(deleteNode);
the last line may cause an exception because the node has already been deleted, and indeed it causes the exception is
A system error happened during the operation: Node does not exist: workspace://SpacesStore/cb6473ed-1f0c-4fa3-bfdf-8f0bc86f3a12
So how to ensure concurrency in a cluster environment when delete a node to prevent two users to access the same node at the same time one of them want to update it and the second once want o delete it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您的集群环境(例如所有 Alfresco 实例使用的同一数据库服务器),事务很可能足以确保不使用过时的内容:
JobLockService
允许在更复杂的操作(可能涉及多个操作)的情况下进行更多控制, 动态的节点(或根本没有节点,例如发送电子邮件或类似的):Depending on your cluster environment (e.g. same DB server used by all Alfresco instances), transactions might most likely just be enough to ensure no stale content is used:
The
JobLockService
allows more control in case of more complex operations, which might involve multiple, dynamic nodes (or no nodes at all, e.g. sending emails or similar):