SendCallback.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Threading;
  5. namespace Taobao.Top.Link.Endpoints
  6. {
  7. public class SendCallback
  8. {
  9. private EventWaitHandle _handle;
  10. private Exception _error;
  11. private IDictionary<string, object> _return;
  12. /// <summary>get which endpoint to send
  13. /// </summary>
  14. public EndpointProxy Target { get; private set; }
  15. /// <summary>get error in sending
  16. /// </summary>
  17. public Exception Error
  18. {
  19. get { return this._error; }
  20. internal set
  21. {
  22. this._error = value;
  23. this._handle.Set();
  24. }
  25. }
  26. /// <summary>get reply
  27. /// </summary>
  28. public IDictionary<string, object> Return
  29. {
  30. get { return this._return; }
  31. internal set
  32. {
  33. this._return = value;
  34. this._handle.Set();
  35. }
  36. }
  37. public SendCallback(EndpointProxy endpointProxy)
  38. {
  39. this.Target = endpointProxy;
  40. this._handle = new EventWaitHandle(false, EventResetMode.AutoReset);
  41. }
  42. /// <summary>wait until got return message
  43. /// </summary>
  44. /// <param name="timeout">timeout in milliseconds</param>
  45. public void WaitReturn(int timeout)
  46. {
  47. if (timeout > 0)
  48. {
  49. if (!this._handle.WaitOne(timeout, false))
  50. throw new LinkException(Text.E_EXECUTE_TIMEOUT);
  51. }
  52. else
  53. this._handle.WaitOne();
  54. }
  55. }
  56. }