/// <summary> /// Send a p2p message from the specified inbox using the throttle. /// The lifecycle of the message sent is controlled by the user of the API. The /// callback indicates when the API is no longer using the message and can be /// destroyed/reused by the application. /// </summary> /// <param name="inbox">The MamaInbox which will process any response to the sent message.</param> /// <param name="message">The MamaMsg to send.</param> /// <param name="callback">The callback which will be invoked when the message /// is sent from the throttle queue.</param> /// <param name="closure">User supplied data returned when the callback is invoked.</param> public void sendFromInboxWithThrottle( MamaInbox inbox, MamaMsg message, MamaSendCompleteCallback callback, object closure) { #if MAMA_WRAPPERS_CHECK_ARGUMENTS if (inbox == null) { throw new ArgumentNullException("inbox"); } if (message == null) { throw new ArgumentNullException("message"); } if (callback == null) { throw new ArgumentNullException("callback"); } EnsurePeerCreated(); #endif // MAMA_WRAPPERS_CHECK_ARGUMENTS // Create a new callback wrapper MamaCallbackWrapper <MamaSendCompleteCallback, MamaThrottledSendCompleteDelegate> wrapper = new MamaCallbackWrapper <MamaSendCompleteCallback, MamaThrottledSendCompleteDelegate>( callback, closure, new MamaThrottledSendCompleteDelegate(onSendComplete)); // Add this to the store IntPtr nativeClosure = mCallbackStore.StoreWrapper(wrapper); // Call the native function int code = NativeMethods.mamaPublisher_sendFromInboxWithThrottle( nativeHandle, inbox.NativeHandle, message.NativeHandle, (Wombat.MamaPublisher.MamaThrottledSendCompleteDelegate)wrapper.NativeDelegate, nativeClosure); try { CheckResultCode(code); } // If something goes wrong then remove the wrapper from the store catch { // Remove the wrapper mCallbackStore.RemoveWrapper(nativeClosure); // Dispose it ((IDisposable)wrapper).Dispose(); // Rethrow the exception throw; } // Ensure that the message passed will not delete its native peer message.SelfManageLifeTime(false); }
/* ************************************************************** */ #region Construction and Finalization /// <summary> /// Constructor initialises all member variables. /// </summary> /// <param name="callback"> /// The user callback implementation. /// </param> /// <param name="closure"> /// The closure supplied to the MamaInbox.create function. /// </param> /// <param name="inbox"> /// The actual C# inbox object. /// </param> internal MamaInboxImpl(MamaInboxCallback callback, object closure, MamaInbox inbox) { // Save arguments in member variables mCallback = callback; mClosure = closure; mInbox = inbox; }
private void CreateInbox() { try { inbox = new MamaInbox(); inboxCallback = new InboxCallback(); inbox.create(transport, defaultQueue, inboxCallback); } catch (MamaException e) { Console.WriteLine("Error creating inbox: {0}", e.ToString()); Exit(1); } }
/// <summary> /// Send a p2p message from the specified inbox using the throttle. /// </summary> /// <param name="inbox">The mamaInbox which will process any response to the sent /// message.</param> /// <param name="message">The mamaMsg to send.</param> public void sendFromInbox( MamaInbox inbox, MamaMsg message) { #if MAMA_WRAPPERS_CHECK_ARGUMENTS if (inbox == null) { throw new ArgumentNullException("inbox"); } if (message == null) { throw new ArgumentNullException("message"); } EnsurePeerCreated(); #endif // MAMA_WRAPPERS_CHECK_ARGUMENTS int code = NativeMethods.mamaPublisher_sendFromInbox(nativeHandle, inbox.NativeHandle, message.NativeHandle); CheckResultCode(code); GC.KeepAlive(inbox); GC.KeepAlive(message); }
/// <summary> /// Send a p2p message from the specified inbox using the throttle. /// The lifecycle of the message sent is controlled by the user of the API. The /// callback indicates when the API is no longer using the message and can be /// destroyed/reused by the application. /// </summary> /// <param name="inbox">The MamaInbox which will process any response to the sent message.</param> /// <param name="message">The MamaMsg to send.</param> /// <param name="callback">The callback which will be invoked when the message /// is sent from the throttle queue.</param> /// <param name="closure">User supplied data returned when the callback is invoked.</param> public void sendFromInboxWithThrottle( MamaInbox inbox, MamaMsg message, MamaSendCompleteCallback callback, object closure) { #if MAMA_WRAPPERS_CHECK_ARGUMENTS if (inbox == null) { throw new ArgumentNullException("inbox"); } if (message == null) { throw new ArgumentNullException("message"); } if (callback == null) { throw new ArgumentNullException("callback"); } EnsurePeerCreated(); #endif // MAMA_WRAPPERS_CHECK_ARGUMENTS // Create a new callback wrapper MamaCallbackWrapper<MamaSendCompleteCallback, MamaThrottledSendCompleteDelegate> wrapper = new MamaCallbackWrapper<MamaSendCompleteCallback, MamaThrottledSendCompleteDelegate>( callback, closure, new MamaThrottledSendCompleteDelegate(onSendComplete)); // Add this to the store IntPtr nativeClosure = mCallbackStore.StoreWrapper(wrapper); // Call the native function int code = NativeMethods.mamaPublisher_sendFromInboxWithThrottle( nativeHandle, inbox.NativeHandle, message.NativeHandle, (Wombat.MamaPublisher.MamaThrottledSendCompleteDelegate)wrapper.NativeDelegate, nativeClosure); try { CheckResultCode(code); } // If something goes wrong then remove the wrapper from the store catch { // Remove the wrapper mCallbackStore.RemoveWrapper(nativeClosure); // Dispose it ((IDisposable)wrapper).Dispose(); // Rethrow the exception throw; } // Ensure that the message passed will not delete its native peer message.SelfManageLifeTime(false); }
/* ************************************************************** */ #region Internal Operations /// <summary> /// This function creates a new impl and returns an IntPtr that can then be passed to /// the native layer. /// </summary> /// <param name="callback"> /// The user callback implementation. /// </param> /// <param name="closure"> /// The closure supplied to the MamaInbox.create function. /// </param> /// <param name="inbox"> /// The actual C# inbox object. /// </param> /// <returns> /// The IntPtr that can then be used for the closure. /// </returns> internal static IntPtr Create(MamaInboxCallback callback, object closure, MamaInbox inbox) { // Allocate a new impl MamaInboxImpl impl = new MamaInboxImpl(callback, closure, inbox); // Create a GC handle GCHandle handle = GCHandle.Alloc(impl); // Return the native pointer return((IntPtr)handle); }
public void onDestroy(MamaInbox inbox, object closure) { }
public void onError(MamaInbox inbox, MamaStatus.mamaStatus status) { Console.WriteLine("Error creating inbox: {0}", MamaStatus.stringForStatus(status)); Exit(1); }
public void onMsg(MamaInbox inbox, MamaMsg msg) { Console.WriteLine("Received reply:"); }
/* ************************************************************** */ #region Internal Operations /// <summary> /// This function creates a new impl and returns an IntPtr that can then be passed to /// the native layer. /// </summary> /// <param name="callback"> /// The user callback implementation. /// </param> /// <param name="closure"> /// The closure supplied to the MamaInbox.create function. /// </param> /// <param name="inbox"> /// The actual C# inbox object. /// </param> /// <returns> /// The IntPtr that can then be used for the closure. /// </returns> internal static IntPtr Create(MamaInboxCallback callback, object closure, MamaInbox inbox) { // Allocate a new impl MamaInboxImpl impl = new MamaInboxImpl(callback, closure, inbox); // Create a GC handle GCHandle handle = GCHandle.Alloc(impl); // Return the native pointer return (IntPtr)handle; }