alfresco共享JavaScript API-检查文档节点上的竞赛条件

发布于 2025-01-26 19:55:42 字数 906 浏览 2 评论 0原文

这应该是一个简单的答案,尽管我自己没有找到任何东西,但我会认为一个普遍的问题,因此问题!

使用Alfresco共享端JavaScript(在文件夹规则执行的脚本中),我想通过检查共享文档,进行签出,更新然后再次检查来更新共享文档。整个过程只需毫秒毫秒,但是从理论上讲,该脚本可能同时由多个用户执行。多么小,我仍然想消除这种可能性。因此,我想检查一下文档是否已锁定,以及是否等待直到再次免费。基本的交易行为。

使用Alfresco JavaScript控制台,我创建了此代码,该代码演示了我要做的事情:(

var n1 = search.findNode(document.nodeRef);

var l1 = n1.isLocked;
while(l1 == true){
    print("locked");
    java.lang.Thread.sleep(1000);
    var n2 = search.findNode(n1.nodeRef);
    var l1 = n2.isLocked;
}

print("unlocked");

不用担心,我不会无限期地循环这只是一个示例!)。

我的问题是,如果Islocked属性是真实的,一旦脚本开始执行,它似乎永远不会变成错误。我已经尝试了编写JS代码的各种方法(包括仅检查文档。锁定了所有迭代),但是看来该脚本的过程似乎从未记录过锁定已消失。如果我通过执行中的一半解锁文档,那么该脚本就会继续等待。如果我再次运行脚本,则发现该文件现在已解锁。

我的问题是,我该如何解决这个问题,甚至有可能吗?我知道Alfresco JS是Rhino JavaScript,所以问题可能与基础Java过程有关吗?

当然,我可以简单地使脚本失败,并通过锁定文档(或者至少希望我可以 - 我还没有尝试过)来停止操作,但这并不能完全赋予出色的用户经验。

任何帮助或愉快地指出男生的错误都值得赞赏!

This should be a simple answer, and I would have thought quite a common issue although I've not found anything myself, hence the question!

Using Alfresco Share-side Javascript (in a script executed by a folder rule) I want to update a shared document by checking it out, updating and then checking in again. The whole process only takes milliseconds but it is in theory possible that this script might be executed by more than one user at the same time. However vanishingly small that possibility I still want to eliminate it. So I want to check to see if the document is locked, and if it is wait until it is free again. Basic transactional behaviour.

Using the Alfresco Javascript Console I've created this code that demonstrates what I am trying to do:

var n1 = search.findNode(document.nodeRef);

var l1 = n1.isLocked;
while(l1 == true){
    print("locked");
    java.lang.Thread.sleep(1000);
    var n2 = search.findNode(n1.nodeRef);
    var l1 = n2.isLocked;
}

print("unlocked");

(Don't worry I don't loop indefinitely this is just an example!).

My problem is that if the isLocked property is true once the script starts executing then it never seems to become false. I've tried various ways of writing the JS code (including just checking document.isLocked every iteration) but it seems that the script's process never seems to register that the lock has disappeared. If I unlock the document half way through execution then the script just carries on waiting. If I run the script again it sees that the file is now unlocked.

My question is, how do I resolve this, and is it even possible? I know that Alfresco JS is Rhino Javascript, so might the problem be something to do with the underlying Java process?

I can of course simply fail the script and stop the action by throwing an exception if the document is locked (or at least I hope I can - I've not tried that yet!), but that doesn't exactly give a great user experience.

Any help or gleeful pointing out a schoolboy error appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文