Hello Everybody,
I need your help and Suggestion on how to Use pub.storage.lock
Scenario :
Two Flow Services are accessing a single File for writing. I need to lock an “Object”(Using Store as an Object) in order to make any one Service to use the file at any given point of time.
What I have tried to Implement :
(I)i have defined a Store.
call 1)registerStore by giving a Suitable Store Name(Name: Store1).
call 2)add by giving a key and a value( Key : key1, value: false).
(II)i have written first flow Service which writes to the file.
call 1)lock(pub.storage:lock) by giving the following values
storeName : Store1
key : key1
waitLength : 20000
lockMode : EXCLUSIVE
call 2)writeToFile(My Custom Service)
i have not unlocked here(purposfully to test locking mechanism)
Then i have written second flow service with the same code as above calling lock again.
(So both the services are locking now on the same Store to access same file)
RunTime :
I first run the service which creates Store.
I run my first flow service which writes to file (now the store is locked and not been unlocked)
I then run my second flow service which also writes to file.
I am expecting that the second flow service should not be able to lock unless the first service releases the lock.
But surprisingly, the second service also writes to file without even waiting for anytime( second service runs normally as if there was no lock on the store)
I tried this using put and get also , but got the same results.
I initially was trying to run these services in Trace-Mode, but later i understood from documentation that locks cannot be tested in Trace-Mode. From then on, i am running the Services normally. But still not able to get the desired results.
I kindly request you all to help me in identifying where i am going wrong. or pls advice me if i am on the right track to accomplish my requirement.
Best Regards,
Nagaraj.