I'm not quite sure that I understand your question, but based on it seems to be a concurrency problem that allows multiple clients to change the state of a service at the same time.
As I understand it, you have a client that allows the user to view the state of the system (your simulation) and change it. On the client side, you have an event-based MVC where the listener expects changes from the user interface and then passes the changes along with the client, which notifies the server. In a very rudimentary sense, for example:
Today: -------- ------------------ ---------- | UI | - change event -> | Event Listener | - set value -> | Server | -------- ------------------ ----------
If I understand your proposed solution correctly, you want to intercept these events and first ask the server if someone has recently changed state before trying to make changes.
Proposed: -------- ------------------ ------------------ ---------- | UI | - change event -> | Proxy Listener | - event -> | Event Listener | - set value -> | Server | -------- ------------------ ------------------ ---------- | timestamp | v ---------- | Server | ----------
In my opinion, this is not an ideal solution for various reasons. First, you talk to the server twice. Secondly, you will need to figure out how to create proxies for the various types of event handlers that exist, which you mentioned in the section “How to find out which method to call”. This will require either a lot of different proxy listeners, or some very dirty reflective logic. (Perhaps you could do this with dynamic proxies.) Finally, you need to rely on the proxy listener added every time, so concurrent security is not the default.
I think a more general solution that can be applied to your current use cases and any future extensions will look at making the setpoint call a secure server. This means that the server must detect when the Event Listener is trying to make changes to the current value (aka: the value is "out of date") and in this case, discard this change. In this case, there are two smaller problems: how to detect the change in an outdated state, and secondly, how to inform the client that the change has not been made.
For the first problem, you can implement some form of optimistic blocking. Like the proposed solution, you can use timestamps for this. For example, when the user interface displays, it will receive a value from the server. The server can pass the value as well as the timestamp when this value was last changed. When a user makes a change, the client passes the new value to the server and the initial last modified timestamp. (ie, “Server, set foo to 10 and the last time someone changed foo yesterday.”) Then the server knows if your change has the last value, and if not, it can refuse the change.
If you don’t have the ability to save the last modified timestamp with each value that can be changed, you can do the same with the hash. When the server returns the value to the client, calculate and return the hash with the value. When the server receives an update request, the client will send the hash, and the server can recalculate the hash from the value that it has. If they match, then the customer change is at the most recent value.
(Terminology warning: whether you use a timestamp or a hash, this value serves as a mutex.)
You do not provide much details about the interaction between the client and server, so I can only guess about the interface, but if the server has the ability to track clients in sessions on the server side, you can do the storage work and provide the corresponding mutex value completely on the server side. In this case, the server keeps track of what values it provided to a particular client for a given session and what were the mutex values. When a client returns with an update request in the same session, the server can find the mutexes for this value and take the appropriate action, even if the client does not even know that the server is doing this. In this case, you can provide compatible code without changing your client from what it looks like today.
Regarding the second issue, how to notify the client that the change was rejected because it was deprecated, this should be relatively easy depending on the interaction of your client and server. If you are using some kind of SOAP or RPC that allows remote exceptions, I would recommend that you throw something similar to the Java ConcurrentModificationException. In this case, all you have to do is review, review the exception, and handle it accordingly. This probably means that the server should again get the latest value and probably notify the user that their requested update was not accepted, because the simulation state has changed from it.