If you know which record is locked (i.e. ^My.Global(123) ) then you can identify the locking process (and therefore the user) in a simple method
Class DC.Lock Extends %RegisteredObject
{
/// For a given (global) reference
/// return the (exclusive) locking processID and username
///
/// ref: a global reference, for example: $name(^My.Global(1,2,3))
///
/// For other lock types (shared, remote)
/// use the infos obtained by info_types OWNER, MODE, FLAGS and COUNTS, see
/// https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls?KEY=RCOS_slock
///
ClassMethod Who(ref)
{
if ^$LOCK(ref,"MODE")="X" {
set pid=^$LOCK(ref,"OWNER")
if pid {
set job=##class(%SYS.ProcessQuery).%OpenId(pid)
quit {"pid":(pid), "usr":($s(job:job.UserName,1:""))}
}
} else { quit {} }
}
}
For example:
set ref=$name(^My.Global(123))
lock +@ref:1
if '$test {
// in case, the node is locked,
// check up, by who is the node locked
set who=##class(DC.Lock).Who(ref)
write who.%ToJSON() --> {"pid":"2396","usr":"kav"}
}- Log in to post comments