/// <summary>
        /// Process this IRequest and update the given <b>Response</b> with
        /// the result.
        /// </summary>
        /// <remarks>
        /// Implementations of this method are free to throw an exception
        /// while processing the IRequest. An exception will result in the
        /// <b>Response</b> being marked as a failure that the
        /// <b>Response</b> result will be the exception itself.
        /// </remarks>
        /// <param name="response">
        /// The <b>Response</b> that will be sent back to the requestor.
        /// </param>
        /// <exception cref="Exception">
        /// If exception occurs during execution.
        /// </exception>
        protected override void OnRun(Response response)
        {
            Connection connection = ConnectionOpen;

            Debug.Assert(!connection.IsOpen);

            Initiator module = (Initiator)Channel.Receiver;

            connection.OpenInternal();

            try
            {
                IChannel        channel0 = connection.GetChannel(0);
                IMessageFactory factory0 = channel0.MessageFactory;

                // sent a OpenConnectionRequest to the peer via "Channel0"
                OpenConnectionRequest request = (OpenConnectionRequest)factory0.CreateMessage(
                    Util.Daemon.QueueProcessor.Service.Peer.OpenConnectionRequest.TYPE_ID);

                request.ClientId           = Initiator.ProcessId;
                request.ConnectionOpen     = connection;
                request.Edition            = module.OperationalContext.Edition;
                request.IdentityToken      = IdentityToken;
                request.Member             = module.OperationalContext.LocalMember;
                request.Principal          = Principal;
                request.ProtocolVersionMap = module.ProtocolVersionMap;

                IService svcParent = module.ParentService;
                if (svcParent is RemoteService)
                {
                    RemoteService svcRemote = (RemoteService)svcParent;
                    request.ClusterName = svcRemote.RemoteClusterName;
                    request.ServiceName = svcRemote.RemoteServiceName;
                }

                response.Result = channel0.Send(request);
            }
            catch (Exception e)
            {
                connection.CloseInternal(false, e, -1);
                throw;
            }
        }
        /// <summary>
        /// Execute the action specific to the Message implementation.
        /// </summary>
        public override void Run()
        {
            Channel channel0 = (Channel)Channel;

            Debug.Assert(channel0.Id == 0);

            Connection connection = (Connection)channel0.Connection;

            if (IsFailure)
            {
                connection.CloseInternal(false, Result as Exception, -1);
                return;
            }

            Initiator module = (Initiator)channel0.Receiver;

            object[] ao = (object[])Result;

            Debug.Assert(ao != null && ao.Length == 2);

            // extract the "Channel0" configuration from the OpenConnectionRequest
            OpenConnectionRequest request = (OpenConnectionRequest)channel0.GetRequest(RequestId);

            Debug.Assert(request != null);

            connection.Id      = (UUID)ao[0];
            connection.Member  = request.Member;
            connection.PeerId  = (UUID)ao[1];
            channel0.Principal = request.Principal;

            // configure the MessageFactory map for the Connection
            IDictionary mapProtocol = module.ProtocolMap;
            IDictionary mapFactory  = new HashDictionary(mapProtocol.Count);
            IDictionary mapVersion  = ProtocolVersionMap;

            if (mapVersion != null)
            {
                foreach (DictionaryEntry entry in mapVersion)
                {
                    String    name     = (String)entry.Key;
                    Int32     version  = (Int32)entry.Value;
                    IProtocol protocol = (Protocol)mapProtocol[name];

                    mapFactory.Add(name, protocol.GetMessageFactory(version));
                }
            }
            foreach (DictionaryEntry entry in mapProtocol)
            {
                String name = (String)entry.Key;

                if (!mapFactory.Contains(name))
                {
                    IProtocol protocol = (Protocol)entry.Value;
                    mapFactory.Add(name, protocol.GetMessageFactory(protocol.CurrentVersion));
                }
            }
            connection.MessageFactoryMap = mapFactory;

            // the Connection is now ready for use
            module.OnConnectionOpened(connection);
        }