mirror of https://github.com/apache/activemq.git
Thanks to the suggestion from Lars Eirik Sivesind of this article describing how to convert Java concurrency programming constructs to .Net http://www.ondotnet.com/pub/a/dotnet/2001/08/06/csharp.html?page=3
I've ported the FutureResponse class to use the proper .Net mechanism, Monitor git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@374076 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e62711760b
commit
a4b970bebc
|
@ -12,6 +12,8 @@ namespace OpenWire.Client.Core {
|
|||
|
||||
private Response response;
|
||||
private Mutex asyncWaitHandle = new Mutex();
|
||||
private Object semaphore = new Object();
|
||||
private int maxWait = 3000;
|
||||
private bool isCompleted;
|
||||
|
||||
public WaitHandle AsyncWaitHandle {
|
||||
|
@ -20,7 +22,7 @@ namespace OpenWire.Client.Core {
|
|||
|
||||
public object AsyncState {
|
||||
get { return response; }
|
||||
set { response = (Response) value; }
|
||||
set { Response = (Response) value; }
|
||||
}
|
||||
|
||||
public bool IsCompleted {
|
||||
|
@ -32,18 +34,21 @@ namespace OpenWire.Client.Core {
|
|||
}
|
||||
|
||||
public Response Response {
|
||||
// Blocks the caller until a value has been set
|
||||
get {
|
||||
// TODO use the proper .Net version of notify/wait()
|
||||
lock (semaphore) {
|
||||
while (response == null) {
|
||||
Thread.Sleep(100);
|
||||
Monitor.Wait(semaphore, maxWait);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
}
|
||||
set {
|
||||
asyncWaitHandle.WaitOne();
|
||||
lock (semaphore) {
|
||||
response = value;
|
||||
isCompleted = true;
|
||||
asyncWaitHandle.ReleaseMutex();
|
||||
Monitor.PulseAll(semaphore);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue