Object level isolation than locking
-
Hi there, This query is with respect to the isolation of object in a collection. And like to hear couple of approaches those are feasible in such scenario. First, let me explain the problem which I am facing at this time. Our application has few rules (objects in concize) associated with few entities, those are editable for all currently active users (U1, U2). Assume that, we have 2 rules (R1, R2). Our requirement is no two users can edit, delete or modify a specific rule at same point of time. Eg: If U1 update R1 then U2 has to wait till U1 release R1. If U1 update R2 then U2 have provision to update R1 since R1 is not locked by any user. I hope you are clear about the requirement. Now, to ensure the above discussed functionality we implemented a method which uses Interlocked Class in threading namespace (VS.NET & C#). This approach in fact helps us while avoiding concurrent user access over a specific instance on a specific time using some flag value. But the problem is, it locks the entire rule collection (R1, R2) even thou there is no concurrent user. I presume, this is because of the way we model the class and is a collection (rule collection). Eg: If I have N rules in rule collection, it doesn’t mean that I need to lock all N rule objects in the rule collection. But I only need to lock specific rule (subset of rule collection), those are currently used by some logged users. And ensure all other non affected rules are free from lock. I did have a thought on the object level locking using .Net object locking mechanisms. But this is practically impossible to implement locking mechanism for each and every functionality. FYI: It is small product which has 54 projects (30 services, test projects, script) in C#.NET. And the product has its 70% of functionalities in place. So a major rework in object level is not practical at this moment since it has to go through lot of review and regression process. I hope you are clear with respect to the problem statement. Can you explain me which method would be feasible in such scenario ? How will i make sure only the object lock is available for the object which is currently i use and not other objects in the collection? And how will I ensure object level isolation than locking an entire collection? Do we have any proved patterns for this kind of problems? Thanks in advance. :-D
-
Hi there, This query is with respect to the isolation of object in a collection. And like to hear couple of approaches those are feasible in such scenario. First, let me explain the problem which I am facing at this time. Our application has few rules (objects in concize) associated with few entities, those are editable for all currently active users (U1, U2). Assume that, we have 2 rules (R1, R2). Our requirement is no two users can edit, delete or modify a specific rule at same point of time. Eg: If U1 update R1 then U2 has to wait till U1 release R1. If U1 update R2 then U2 have provision to update R1 since R1 is not locked by any user. I hope you are clear about the requirement. Now, to ensure the above discussed functionality we implemented a method which uses Interlocked Class in threading namespace (VS.NET & C#). This approach in fact helps us while avoiding concurrent user access over a specific instance on a specific time using some flag value. But the problem is, it locks the entire rule collection (R1, R2) even thou there is no concurrent user. I presume, this is because of the way we model the class and is a collection (rule collection). Eg: If I have N rules in rule collection, it doesn’t mean that I need to lock all N rule objects in the rule collection. But I only need to lock specific rule (subset of rule collection), those are currently used by some logged users. And ensure all other non affected rules are free from lock. I did have a thought on the object level locking using .Net object locking mechanisms. But this is practically impossible to implement locking mechanism for each and every functionality. FYI: It is small product which has 54 projects (30 services, test projects, script) in C#.NET. And the product has its 70% of functionalities in place. So a major rework in object level is not practical at this moment since it has to go through lot of review and regression process. I hope you are clear with respect to the problem statement. Can you explain me which method would be feasible in such scenario ? How will i make sure only the object lock is available for the object which is currently i use and not other objects in the collection? And how will I ensure object level isolation than locking an entire collection? Do we have any proved patterns for this kind of problems? Thanks in advance. :-D
Hmmm. Not really sure about this one, but possibly the Observable pattern might help here. I'd really have to sit down with some paper to sketch it all out but basically you should be able to observe your rules (combine this with the Mediator pattern for best effect) and then notify the observer whenever a rule was being worked on or released from work.
Deja View - the feeling that you've seen this post before.
-
Hmmm. Not really sure about this one, but possibly the Observable pattern might help here. I'd really have to sit down with some paper to sketch it all out but basically you should be able to observe your rules (combine this with the Mediator pattern for best effect) and then notify the observer whenever a rule was being worked on or released from work.
Deja View - the feeling that you've seen this post before.
Hi Pete, Implementing pattern at this stage seems to be bit difficult since most of the functionalities are in place. This specific lock functionality wasn't there and introduced later stages. I presume, it would be nice to introduce some kind of wrapper or attribute in type level which ensure the object level isolation. However, my sincere thanks for your time. Please do update me in case if you sketch something. :-D
-
Hi Pete, Implementing pattern at this stage seems to be bit difficult since most of the functionalities are in place. This specific lock functionality wasn't there and introduced later stages. I presume, it would be nice to introduce some kind of wrapper or attribute in type level which ensure the object level isolation. However, my sincere thanks for your time. Please do update me in case if you sketch something. :-D
To be honest - it sounds like you are going to be looking at some amount of "rearchitecting" anyway. Sorry.
Deja View - the feeling that you've seen this post before.
-
Hi there, This query is with respect to the isolation of object in a collection. And like to hear couple of approaches those are feasible in such scenario. First, let me explain the problem which I am facing at this time. Our application has few rules (objects in concize) associated with few entities, those are editable for all currently active users (U1, U2). Assume that, we have 2 rules (R1, R2). Our requirement is no two users can edit, delete or modify a specific rule at same point of time. Eg: If U1 update R1 then U2 has to wait till U1 release R1. If U1 update R2 then U2 have provision to update R1 since R1 is not locked by any user. I hope you are clear about the requirement. Now, to ensure the above discussed functionality we implemented a method which uses Interlocked Class in threading namespace (VS.NET & C#). This approach in fact helps us while avoiding concurrent user access over a specific instance on a specific time using some flag value. But the problem is, it locks the entire rule collection (R1, R2) even thou there is no concurrent user. I presume, this is because of the way we model the class and is a collection (rule collection). Eg: If I have N rules in rule collection, it doesn’t mean that I need to lock all N rule objects in the rule collection. But I only need to lock specific rule (subset of rule collection), those are currently used by some logged users. And ensure all other non affected rules are free from lock. I did have a thought on the object level locking using .Net object locking mechanisms. But this is practically impossible to implement locking mechanism for each and every functionality. FYI: It is small product which has 54 projects (30 services, test projects, script) in C#.NET. And the product has its 70% of functionalities in place. So a major rework in object level is not practical at this moment since it has to go through lot of review and regression process. I hope you are clear with respect to the problem statement. Can you explain me which method would be feasible in such scenario ? How will i make sure only the object lock is available for the object which is currently i use and not other objects in the collection? And how will I ensure object level isolation than locking an entire collection? Do we have any proved patterns for this kind of problems? Thanks in advance. :-D
You might use Single Proxy between multiple Users and Rule collection. Let Proxy decide which user can access which rule object. Or let there be one Proxy object for each of your Rule object.Each user instead of accesing rule object directly can access Proxy of that rule object and in Proxy you can decide whether to allow user to access the rule object or not.
-
Hi there, This query is with respect to the isolation of object in a collection. And like to hear couple of approaches those are feasible in such scenario. First, let me explain the problem which I am facing at this time. Our application has few rules (objects in concize) associated with few entities, those are editable for all currently active users (U1, U2). Assume that, we have 2 rules (R1, R2). Our requirement is no two users can edit, delete or modify a specific rule at same point of time. Eg: If U1 update R1 then U2 has to wait till U1 release R1. If U1 update R2 then U2 have provision to update R1 since R1 is not locked by any user. I hope you are clear about the requirement. Now, to ensure the above discussed functionality we implemented a method which uses Interlocked Class in threading namespace (VS.NET & C#). This approach in fact helps us while avoiding concurrent user access over a specific instance on a specific time using some flag value. But the problem is, it locks the entire rule collection (R1, R2) even thou there is no concurrent user. I presume, this is because of the way we model the class and is a collection (rule collection). Eg: If I have N rules in rule collection, it doesn’t mean that I need to lock all N rule objects in the rule collection. But I only need to lock specific rule (subset of rule collection), those are currently used by some logged users. And ensure all other non affected rules are free from lock. I did have a thought on the object level locking using .Net object locking mechanisms. But this is practically impossible to implement locking mechanism for each and every functionality. FYI: It is small product which has 54 projects (30 services, test projects, script) in C#.NET. And the product has its 70% of functionalities in place. So a major rework in object level is not practical at this moment since it has to go through lot of review and regression process. I hope you are clear with respect to the problem statement. Can you explain me which method would be feasible in such scenario ? How will i make sure only the object lock is available for the object which is currently i use and not other objects in the collection? And how will I ensure object level isolation than locking an entire collection? Do we have any proved patterns for this kind of problems? Thanks in advance. :-D
It sounds like you are asking how to implement pessimistic locking. There are very simple ways of doing that, although most people agree that it is quite a user-unfriendly thing to do (but sometimes you have no choice). Basically, create a mutex on the server for the particular rule being edited, and deny edit access to that rule for other users until the mutex is released. The mutex can be anything - for example MS Office products create a file when you open a document for editing, and delete it when you are done.