J Doe
J Doe

Reputation: 33

How do I eliminate the possibility of simultaneous aceess of a Notes Document

In our project we have the following:

A list of Notes documents with fields:

  1. Our System's user ID (our name)
  2. System B's Auth Object (their name)
  3. System B's token

I decided to write a Java method for updating the token (every 30 minutes). Basically, it'll iterate through the list, execute a REST method to their system and finally we'll get a new token and write it to the document. There are not so many documents (in fact, always fewer than 10, but the request can take a lot of time)

However, I stumbled upon a problem. What if a user's request will be executed simultaneously with token refreshing? How should we treat such a case? Should I have something like a lock for eliminating such a possibility? And in the code of each user's request we should send a request only if the document is unlocked? How can we "wait" for that unlock?

Thanks in advance.

Upvotes: 0

Views: 126

Answers (1)

Tode
Tode

Reputation: 12080

Just use the default Locking mechanism in Notes: document locking needs to be enabled in Database Properties. Then you can do the following:

If doc.lock( timestamp ) then 
    'Document has not been locked previously
    'Your code comes here
    'Don‘t forget to unlock at the end
End if

Parameter usually is a username, so why use a timestamp as a „pseudouser“? The „locking“ user is always the signer of the code, you need to differentiate between the different calls, so use a timestamp to identify the session uniquely.

Upvotes: 1

Related Questions