[1.1.4] Should the Stack switch to Application Context when reporting a HN operation complete?
There seems to be some asymmetery in the way requests are dispatched to a HN server and the response sent back to the client. That is, if an application attempts to set a value on a server we can get either a Null Pointer Exception, or if we code around that an Access Control Exception as the context trying to manipulate a service context is not that which previously created it.
It's hard to reproduce the problem, but here's a textual walk through.
The app calls,. for example,
RecordingContentItem[Impl].requestSetMediaTime(new Time(0), this);
This in turn creates an ActionRequest which is then processed by
This purposely jumps to the System Context before calling doTask() on a newly created ActionRequest.
Once the post() is complete the registered Stack listener is called [still in the System Context] and it then reports the response to Application listener, but still in the System Context.
At this point, if the Application decides to do anything, it's in the wrong context and so chaos can ensue. [What this application does is select the existing service based on the returned mediaTime, but it no longer owns the context...]
In recording.ActionRequest.notifyEvent(...) there is a deliberate avoidance of a context switch:
/* Notify the completion of the action */
super.handler.notify((NetActionEvent) new NetActionEventImpl(this, null, super.error, super.actionStatus));
If we were to call super.notify() here, then the context would be switched.
This is only in 1.1.4, the way Action/Response is performed in 1.2 seems to have fixed this issue.