Ejemplo n.º 1
0
        /// <summary>
        /// Opens a client side instance of a reliable messenger implementation.
        /// </summary>
        /// <param name="router">The message router to be used by the messenger.</param>
        /// <param name="confirmEP">
        /// The logical endpoint the instance created should use to receive delivery confirmations
        /// or <c>null</c> if confirmations are to be disabled.
        /// </param>
        /// <param name="args">Messenger implementation specific parameters (ignored for this implementation).</param>
        /// <param name="confirmCallback">
        /// The delegate to call when delivery confirmations are received from the
        /// server side of the messenger or <c>null</c> if no special processing is necessary.
        /// </param>
        /// <remarks>
        /// <note>
        /// <see cref="Close" /> should be called promptly when a messenger instance
        /// is not longer required to release any unneeded resource.
        /// </note>
        /// </remarks>
        public void OpenClient(MsgRouter router, MsgEP confirmEP, ArgCollection args, DeliveryConfirmCallback confirmCallback)
        {
            if (confirmEP != null && !confirmEP.IsLogical)
            {
                throw new ArgumentException(ReliableMessenger.ConfirmEPNotLogicalMsg);
            }

            this.router             = router;
            this.isClient           = true;
            this.onEndpointDelivery = new AsyncCallback(OnEndpointDelivery);
            this.onClusterDelivery  = new AsyncCallback(OnClusterDelivery);

            if (confirmEP == null || confirmCallback == null)
            {
                this.confirmEP       = null;
                this.confirmCallback = null;
            }
            else
            {
                this.confirmEP       = confirmEP;
                this.confirmCallback = confirmCallback;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Instantiates and initializes an <see cref="IReliableMessenger" /> plug-in defined by a configuration setting
        /// and then opens it as a client side messenger.
        /// </summary>
        /// <param name="router">The message router to associate with the messenger.</param>
        /// <param name="argsKey">The fully qualified configuration key specifying the messenger arguments formatted for <see cref="ArgCollection" />.</param>
        /// <param name="confirmCallback">The callback for delivery confirmations or <c>null</c> to disable confirmations.</param>
        /// <returns>The messenger instance.</returns>
        /// <remarks>
        /// <para>
        /// The messenger arguments must include an argument named <b>messenger-type</b> which must be
        /// a reference to a <see cref="IReliableMessenger" /> implementation formatted as described
        /// in <see cref="Config.Parse(string,System.Type)" />.
        /// </para>
        /// <para>
        /// This utility method maps the messenger type reference to a .NET assembly and type and then
        /// instantiates an instance and then opens it as a client side messenger.  The arguments loaded
        /// are then passed to the messenger's <see cref="IReliableMessenger.OpenClient" /> method.
        /// </para>
        /// <para>
        /// The optional <b>confirm-ep</b> argument may also be present in the arguments loaded from
        /// the configuration.  If present, this specifies the logical endpoint where delivery confirmations
        /// are to be addressed.  This is used internally by <see cref="IReliableMessenger" /> implementations
        /// for the server side of a messenger to send notifications back to a client side instance.
        /// </para>
        /// </remarks>
        public static IReliableMessenger OpenClient(MsgRouter router, string argsKey, DeliveryConfirmCallback confirmCallback)
        {
            IReliableMessenger messenger;
            ArgCollection      args;
            string             messengerType;
            string             s;
            MsgEP confirmEP;

            System.Type type;

            if (!router.IsOpen)
            {
                throw new InvalidOperationException(RouterClosedMsg);
            }

            args = ArgCollection.Parse(Config.Global.Get(argsKey));

            messengerType = args["messenger-type"];
            if (messengerType == null)
            {
                throw new ArgumentException("Messenger arguments must specify [messenger-type].");
            }

            type = Config.Parse(messengerType, (System.Type)null);

            if (type == null || !typeof(IReliableMessenger).IsAssignableFrom(type))
            {
                throw new ArgumentException(string.Format("Unable to map setting [{0}] into an IReliableMessenger.", messengerType));
            }

            s = args["confirm-ep"];
            if (s != null)
            {
                try
                {
                    confirmEP = MsgEP.Parse(s);
                }
                catch
                {
                    throw new ArgumentException("[{0}] is not a valid endpoint for [confirm-ep].", s);
                }
            }
            else
            {
                confirmEP = null;
            }

            messenger = Helper.CreateInstance <IReliableMessenger>(type);
            messenger.OpenClient(router, confirmEP, args, confirmCallback);

            return(messenger);
        }