0

I'm working on resource locking in SAP Fiori. To be more elaborate I am trying to lock a resource once a user logs in and opens my application and unlock the resource once he logs out or gets logged out.

I am aware of the onExit() event handler which is located in the main.controller.js and is called if the user performs an action which logs him out. This handles all scenarios except one: when the user's session is timed out.

Is anyone aware of a method(UI5 / Gateway layer) that is called once the session time's out?

As far as I think how this is handled is if a user's session is timed out then nothing happens until the user refreshes the screen. At this point an Odata call is made to fetch data. Once this hits the Gateway it checks and finds out that the session has timed out and triggers a relogin action.

Correct me if I'm wrong. If right does anyone know what is the event handler which does that?

Also I have read up quite a bit about this. This falls under optimistic and pessimistic concurrency. I would like to try a pessimistic apprach and not a optimistic

approach using etags.

Thanks in advance for your time.

Also I cant officially post any code as it would be against policy, but if you have any queries please feel free to ask and I will do my best :). Plus this is more a fact finding mission.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Reeth
  • 62
  • 1
  • 8
  • Why do you need to lock the resource for the entire period of the user's session - can you not just lock it at the point of update? I can think of a few scenarios where such a lock is needed, but perhaps you don't need it in your case. Remember, web applications are intended to be stateless... – mjturner Jul 11 '15 at 18:29
  • My scenerio if of a Employee and Manager self service. Only one entity should be able to access the resource at one single point. So if say the employee has recorded time(tuple created) and is currently editing it, then the manager shouldn't be able to approve his older record. The major pain point here being that web apps are stateless. Hence the older versions(cats and web dynpro) are working fine. I could always validate the record before saving but that would cause a performance drop(we can have multiple records). So I was looking for a pessimistic approach. – Reeth Jul 13 '15 at 09:05

1 Answers1

1

There is no way you can trust a request to be executed from a browser to signal time out. You will end up with locked resources that shouldn't be locked due to lost connectivity, app crashing, battery drain to name a few. A classic problem for web applications!

Instead, you can construct a lock refresh mechanism. Refresh the lock every 30 seconds or so in the background. Just make sure to fetch the latest version of the resource if the lock was ever released!

Mikael G
  • 712
  • 5
  • 13
  • Thanks for the answer Mikael! Could you please elaborate on that? How would I know when to release the lock? Would a background report, which would release open locks, which runs after a fixed time frame work? The drawback here would be if the time frame is insufficient then it can unlock a resource for a user who is still using the application. So from the application side I would need to make sure to lock the resource again. Would this work? Thanks again for your time! :) – Reeth Jul 13 '15 at 09:20
  • You have to find a reasonable compromise. If it's 30 seconds or 24 hours is based on your application scenario. But for a user that is active with the application, refreshing the lock every now and then is a good approach. – Mikael G Jul 13 '15 at 09:37
  • Another approach is to only lock during updating. By carefully checking changed data vs existing data you can determine if the resource have been changed by someone else in the meantime. The lock time is reduced to a second when the update occurs. – Mikael G Jul 13 '15 at 09:39
  • Thanks @Mikael, I'm taking a look at option 1. Validating records before saving is not something I'm looking at as that would hit performance considerably as the key attributes are quite a few and the user can try to make multiple records simultaneously. – Reeth Jul 13 '15 at 11:52