mirror of
https://github.com/apache/activemq.git
synced 2025-02-17 07:24:51 +00:00
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 Response response;
|
||||||
private Mutex asyncWaitHandle = new Mutex();
|
private Mutex asyncWaitHandle = new Mutex();
|
||||||
|
private Object semaphore = new Object();
|
||||||
|
private int maxWait = 3000;
|
||||||
private bool isCompleted;
|
private bool isCompleted;
|
||||||
|
|
||||||
public WaitHandle AsyncWaitHandle {
|
public WaitHandle AsyncWaitHandle {
|
||||||
@ -20,7 +22,7 @@ namespace OpenWire.Client.Core {
|
|||||||
|
|
||||||
public object AsyncState {
|
public object AsyncState {
|
||||||
get { return response; }
|
get { return response; }
|
||||||
set { response = (Response) value; }
|
set { Response = (Response) value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsCompleted {
|
public bool IsCompleted {
|
||||||
@ -32,18 +34,21 @@ namespace OpenWire.Client.Core {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Response Response {
|
public Response Response {
|
||||||
|
// Blocks the caller until a value has been set
|
||||||
get {
|
get {
|
||||||
// TODO use the proper .Net version of notify/wait()
|
lock (semaphore) {
|
||||||
while (response == null) {
|
while (response == null) {
|
||||||
Thread.Sleep(100);
|
Monitor.Wait(semaphore, maxWait);
|
||||||
}
|
}
|
||||||
return response;
|
return response;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
asyncWaitHandle.WaitOne();
|
lock (semaphore) {
|
||||||
response = value;
|
response = value;
|
||||||
isCompleted = true;
|
isCompleted = true;
|
||||||
asyncWaitHandle.ReleaseMutex();
|
Monitor.PulseAll(semaphore);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user