Locking / unlocking
Hi.
What is the best/right way to unlock the object in ObjectScript after the lock was acquired by %OpenId class method? Setting the opened object to null (Set object="") doesn't release the lock.
Regards,
Matjaž
Product version: IRIS 2021.1
Hi @Matjaz Murko,
It's strange.
For example, If the object is open with concurrency 4.
The lock should be released on set object=""
Documentation : Object Concurrency Options
Have you got a simple example to reproduce?
Hi.
Tnx for your quick reply.
Here is the class method:
{
Set person=##class(MasterData.Person).CardNoOpen(CardNo,4)
Quit:person="" "null"
Set checking=##class(Production.Checking).%New()
Set checking.Person=person
Set checking.Condition.Type=person.Condition.Type
Set checking.Condition.ValidBy=person.Condition.ValidBy
Set checking.ConditionIsValid=(person.Condition.ValidBy>=+$Horolog)
Do checking.%Save()
Set model=##class(API.Models.Operative.PersonGetData).%New()
Set model.Ident=person.Ident
Set model.FirstName=person.FirstName
Set model.LastName=person.LastName
Set model.Department=person.Department.Name
Set model.IsValid=checking.ConditionIsValid
If ('checking.ConditionIsValid)
{
Set person.Condition.Type="T"
Set person.Condition.ValidBy=+$Horolog+6
Do person.%Save()
}
Do model.%JSONExportToString(.json)
Do ##class(MasterData.Person).%UnlockId(person.%Id())
Quit json
}
I'm using now %UnlockId method instead of setting the object to null.
Regards,
Matjaž
Ok,
Could you test with
I guess the lock should be released after leaving the classmethod, but if the class is procedure block or not the behavior could be different.
These are my findings:
- class has ProcedureBlock enabled by default,
- if I run the class method from terminal window, it behaves as a procedure block,
- if I run it from IRIS Native API (C# app) then it behaves as non procedure block and I have to set person & checking instances to null to release the lock.
Interesting.
I don't have environment to test wit Native API, but perhaps you could test explicitly "ProcedureBlock" instead of default behavior. Just by using the class key word "ProcedureBlock"
ex:
edit : also you can try with
[ ProcedureBlock = 1 ]
on the classmethod. doc linkI do not know if it is important, but I'm using abstract class. And although I explicitly add ProcedureBlock to the class definition it doesn't help when I'm calling the method with Native API...
Code snipet to expose the problem.
And if so?
Hi.
Tnx for reply.
Regardless that I'm using ProcedureBlock, Native API calls to class methods do not put instances out of scope (and consequently do not release locks).
Regards, Matjaž.
Example:
Sure, with the `New` lock will be released.
I'm not using IRISObjects, just ClassMethodString:
PersonData = JsonSerializer.Deserialize<PersonDataClass>(App.Iris.ClassMethodString("API.Calls.Operative", "Checking", CardNo.Text));
if (PersonData != null)
{
if (!PersonData.IsValid)
{
SystemSounds.Exclamation.Play();
}
I did a test and that's what found out.
It is assumed that the data has already been generated.
COS
If executed from the terminal, the lock is removed automatically immediately after the method is completed:
C#
I'm setting all referenced instances to null in COS to release locks as workaround. But I'm not sure it is a bug or expected behaviour...
There is one thing you should check, than this could trigger effects observed by you.
Objects are tracked by reference counts, as long as an objects reference count is greater then one, locks won't be released and the object isn't deleted.
There are methods to detect such a situation:
- $system.OBJ.ShowObjects(), lists all objects with reference counts
- $system.OBJ.ShowReferences(obj), list all variables which contains a reference to <obj>
A quick and dirty approach:
Give it a try, maybe your object has multiple references which cause the problem
Hi.
As I've mentioned in previous post I'm using workaround, but I think it's a bug in API, because the same method works fine in terminal window without explicite set the objects to null (all used objects are released and consequently all locks are released also - expected behaviour in class with procedure block enabled).
Regards,
Matjaž
Yes, most likely this is a feature of the API.
Here's what I found about it in the "old" documentation:
PS: by the way, for ActiveX, Factory.ForceSync() method serves the same purpose.
That's the way the proxy classes are functioning (caching). But in new Native API for IRIS there are no proxies, just class methods/functions are called from app and I think, it should be pretty the same as calling this methods/functions from terminal window.
Social networks
InterSystems resources
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue