Example #1
0
        /// <summary>
        /// Opens the topology instance in client mode.
        /// </summary>
        /// <param name="router">The message router to be used by the cluster.</param>
        /// <param name="clusterEP">The cluster's logical endpoint.</param>
        /// <param name="args">Topology implementation specific parameters (ignored for this implementation).</param>
        /// <remarks>
        /// </remarks>
        public virtual void OpenClient(MsgRouter router, MsgEP clusterEP, ArgCollection args)
        {
            if (!clusterEP.IsLogical)
            {
                throw new ArgumentException(TopologyHelper.ClusterEPNotLogicalMsg);
            }

            if (!router.EnableP2P)
            {
                SysLog.LogWarning(NoP2PMsg);
            }

            this.router      = router;
            this.instanceID  = Helper.NewGuid();
            this.clusterEP   = clusterEP;
            this.broadcastEP = new MsgEP(clusterEP, "*");
            this.instanceEP  = null;
            this.isClient    = true;

            ArgCollection argsCopy;

            argsCopy = args.Clone();
            argsCopy["topology-type"] = TopologyHelper.SerializeType(this.GetType());
            serialized = argsCopy.ToString();

            OnLogicalChange();      // Forces the initial load of the instance EPs
        }
Example #2
0
        /// <summary>
        /// Opens the topology instance in server mode.
        /// </summary>
        /// <param name="router">The message router to be used by the cluster.</param>
        /// <param name="dynamicScope">The dynamic scope name.</param>
        /// <param name="target">The target object whose dynamic message handlers are to be registered (or <c>null</c>).</param>
        /// <param name="clusterEP">The cluster's logical endpoint.</param>
        /// <param name="args">Topology implementation specific parameters (ignored for this implementation).</param>
        /// <remarks>
        /// <para>
        /// This method also registers the dynamic message handlers that case-insensitvely
        /// match the dynamicScope parameter passed that are found within the
        /// target object passed with the router's message dispatcher, after performing
        /// any necessary munging of their message endpoints.  This is done by
        /// matching the dynamicScope parameter passed against the <see cref="MsgHandler.DynamicScope" />
        /// property in the <see cref="MsgHandler" /> attribute tagging the message handler.
        /// </para>
        /// <para>
        /// The matching message handler endpoints will be set to clusterEP.
        /// </para>
        /// </remarks>
        public virtual void OpenServer(MsgRouter router, string dynamicScope, MsgEP clusterEP, object target, ArgCollection args)
        {
            if (!clusterEP.IsLogical)
            {
                throw new ArgumentException(TopologyHelper.ClusterEPNotLogicalMsg);
            }

            if (!router.EnableP2P)
            {
                SysLog.LogWarning(NoP2PMsg);
            }

            this.router      = router;
            this.instanceID  = Helper.NewGuid();
            this.clusterEP   = clusterEP;
            this.broadcastEP = new MsgEP(clusterEP, "*");
            this.instanceEP  = new MsgEP(clusterEP, Helper.NewGuid().ToString());
            this.isClient    = false;

            if (target != null)
            {
                router.Dispatcher.AddTarget(target, dynamicScope, this, null);
            }

            OnLogicalChange();      // Forces the initial load of the instance EPs
        }
Example #3
0
        private int cbRecv;                         // Bytes to receive

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="router">The associated message router.</param>
        public TcpChannel(MsgRouter router)
        {
            this.router        = router;
            this.sock          = null;
            this.routerEP      = null;
            this.remoteEP      = null;
            this.localEP       = null;
            this.connected     = false;
            this.initProcessed = false;
            this.lastAccess    = SysTime.Now;
            this.isUplink      = false;
            this.isDownlink    = false;
            this.isP2P         = false;

            this.sending   = false;
            this.sendMsg   = null;
            this.sendQueue = new PriorityQueue <Msg>();
            this.onSend    = new AsyncCallback(OnSend);
            this.sendBuf   = null;
            this.sendPos   = 0;
            this.cbSend    = 0;

            this.onReceive  = new AsyncCallback(OnReceive);
            this.recvHeader = false;
            this.recvBuf    = null;
            this.recvPos    = 0;
        }
Example #4
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="router">The associated router.</param>
 /// <param name="routeTTL">The lifetime of an unrenewed route.</param>
 public PhysicalRouteTable(MsgRouter router, TimeSpan routeTTL)
 {
     this.router   = router;
     this.routerEP = router.RouterEP;
     this.routeTTL = routeTTL;
     this.routes   = new Dictionary <string, PhysicalRoute>();
 }
Example #5
0
        /// <summary>
        /// Initializes a server side session.
        /// </summary>
        /// <param name="router">The associated message router.</param>
        /// <param name="sessionMgr">The associated session manager.</param>
        /// <param name="ttl">Session time-to-live.</param>
        /// <param name="msg">The message that triggered this session.</param>
        /// <param name="target">The dispatch target instance.</param>
        /// <param name="method">The dispatch method.</param>
        /// <param name="sessionInfo">
        /// The session information associated with the handler or <c>null</c>
        /// to use session defaults.
        /// </param>
        public virtual void InitServer(MsgRouter router, ISessionManager sessionMgr, TimeSpan ttl, Msg msg, object target,
                                       MethodInfo method, SessionHandlerInfo sessionInfo)
        {
            if (sessionInfo == null)
            {
                sessionInfo = SessionHandlerInfo.Default;
            }

            this.isClient      = false;
            this.router        = router;
            this.sessionMgr    = sessionMgr;
            this.sessionID     = msg._SessionID;
            this.isAsync       = sessionInfo.IsAsync;
            this.isRunning     = true;
            this.startTime     = SysTime.Now;
            this.finishTime    = DateTime.MaxValue;
            this.ttd           = startTime + ttl;
            this.ttl           = ttl;
            this.serverInitMsg = msg;
            this.clientEP      = msg._FromEP;
            this.target        = target;
            this.method        = method;
            this.sessionInfo   = sessionInfo != null ? sessionInfo : defSessionInfo;
            this.cachedReply   = null;

            msg._Session = (ISession)this;
        }
Example #6
0
        /// <summary>
        /// Constuctor.
        /// </summary>
        /// <param name="operation">Specifies how the message should be interpreted.</param>
        /// <param name="timestamp">The time (UTC) when the delivery was completed successfully or was aborted.</param>
        /// <param name="targetEP">The original target or cluster endpoint.</param>
        /// <param name="confirmEP">The confirmation endpoint (or <c>null</c>).</param>
        /// <param name="query">The query message.</param>
        /// <param name="topologyID">The globally unique cluster topology provider instance ID or <see cref="Guid.Empty" />.</param>
        /// <param name="topologyInfo">The serialized cluster itopology nformation (or <c>null</c>).</param>
        /// <param name="topologyParam">The serialized topology parameter (or <c>null</c>).</param>
        /// <param name="exception">The exception for failed deliveries or queries.</param>
        /// <param name="response">The response message (or <c>null</c>).</param>
        public DeliveryMsg(DeliveryOperation operation, DateTime timestamp, MsgEP targetEP, MsgEP confirmEP, Msg query,
                           Guid topologyID, string topologyInfo, string topologyParam, Exception exception, Msg response)
        {
            this.Operation     = operation;
            this.Timestamp     = timestamp;
            this.TargetEP      = targetEP;
            this.ConfirmEP     = confirmEP;
            this.TopologyID    = topologyID;
            this.TopologyInfo  = topologyInfo;
            this.TopologyParam = topologyParam;
            this.Exception     = exception;
            this.query         = query;
            this.response      = response;

            // Serialize the query and responses to the message blob

            EnhancedBlockStream es = new EnhancedBlockStream();

            try
            {
                Msg.Save(es, query);

                if (response != null)
                {
                    Msg.Save(es, response);
                }

                base._Data = es.ToArray();
            }
            finally
            {
                es.Close();
            }
        }
Example #7
0
        /// <summary>
        /// Private constructor for initializing <b>client side</b> sessions.
        /// </summary>
        /// <param name="router">The message router.</param>
        /// <param name="serverEP">The server endpoint.</param>
        /// <param name="direction">The transfer direction.</param>
        /// <param name="stream">The input or output stream.</param>
        private StreamTransferSession(MsgRouter router, MsgEP serverEP, TransferDirection direction, EnhancedStream stream)
        {
            ReliableTransferHandler handler;

            reliableSession = router.CreateReliableTransferSession();
            reliableSession.SessionHandler =
                handler = new ReliableTransferHandler(reliableSession);
            handler.BeginTransferEvent += new ReliableTransferDelegate(OnBeginTransfer);
            handler.EndTransferEvent   += new ReliableTransferDelegate(OnEndTransfer);

            if (direction == TransferDirection.Upload)
            {
                handler.SendEvent += new ReliableTransferDelegate(OnSend);
            }
            else
            {
                handler.ReceiveEvent += new ReliableTransferDelegate(OnReceive);
            }

            this.router       = router;
            this.serverEP     = serverEP;
            this.direction    = direction;
            this.args         = null;
            this.stream       = stream;
            this.started      = false;
            this.closed       = false;
            this.streamClosed = false;
            this.arTransfer   = null;
            this.simError     = false;
            this.simCancel    = false;
            this.delay        = 0;
        }
Example #8
0
        /// <summary>
        /// Initializes an instance by loading settings from the application
        /// configuration using the specified configuration key prefix.
        /// </summary>
        /// <param name="keyPrefix">The fully qualified configuration key prefix.</param>
        /// <param name="defClusterBaseEP">The default cluster <b>ClusterBaseEP</b> setting.</param>
        /// <exception cref="ArgumentException">Thrown if the required <b>ClusterBaseEP</b> setting was not found.</exception>
        public ClusterMemberSettings(string keyPrefix, MsgEP defClusterBaseEP)
        {
            var config = new Config(keyPrefix);

            this.ClusterBaseEP = config.Get("ClusterBaseEP", (string)defClusterBaseEP);
            if (this.ClusterBaseEP == null)
            {
                throw new ArgumentException(string.Format("[{0}ClusterBaseEP] configuration setting is required.", config.KeyPrefix));
            }

            this.Mode = config.Get <ClusterMemberMode>("Mode", ClusterMemberMode.Normal);
            if (this.Mode == ClusterMemberMode.Unknown)
            {
                throw new ArgumentException(string.Format("[{0}Mode] cannot be [Unknown].", config.KeyPrefix));
            }

            this.MasterBroadcastInterval = config.Get("MasterBroadcastInterval", this.MasterBroadcastInterval);
            this.SlaveUpdateInterval     = config.Get("SlaveUpdateInterval", this.SlaveUpdateInterval);
            this.ElectionInterval        = config.Get("ElectionInterval", this.ElectionInterval);
            this.MissingMasterCount      = config.Get("MissingMasterCount", this.MissingMasterCount);
            this.MissingSlaveCount       = config.Get("MissingSlaveCount", this.MissingSlaveCount);
            this.MasterBkInterval        = config.Get("MasterBkInterval", this.MasterBkInterval);
            this.SlaveBkInterval         = config.Get("SlaveBkInterval", this.SlaveBkInterval);
            this.BkInterval = config.Get("BkInterval", this.BkInterval);
        }
Example #9
0
        /// <summary>
        /// Opens the topology instance in server mode.
        /// </summary>
        /// <param name="router">The message router to be used by the cluster.</param>
        /// <param name="dynamicScope">The dynamic scope name.</param>
        /// <param name="target">The target object whose dynamic message handlers are to be registered (or <c>null</c>).</param>
        /// <param name="clusterEP">The cluster's logical endpoint.</param>
        /// <param name="args">Topology implementation specific parameters.</param>
        /// <remarks>
        /// <para>
        /// This method also registers the dynamic message handlers that case-insensitvely
        /// match the dynamicScope parameter passed that are found within the
        /// target object passed with the router's message dispatcher, after performing
        /// any necessary munging of their message endpoints.  This is done by
        /// matching the dynamicScope parameter passed against the <see cref="MsgHandler.DynamicScope" />
        /// property in the <see cref="MsgHandler" /> attribute tagging the message handler.
        /// </para>
        /// <para>
        /// The matching message handler endpoints will be set to clusterEP.
        /// </para>
        /// </remarks>
        public virtual void OpenServer(MsgRouter router, string dynamicScope, MsgEP clusterEP, object target, ArgCollection args)
        {
            string arg;
            int    index;

            if (!clusterEP.IsLogical)
            {
                throw new ArgumentException(TopologyHelper.ClusterEPNotLogicalMsg);
            }

            this.router      = router;
            this.instanceID  = Helper.NewGuid();
            this.clusterEP   = clusterEP;
            this.broadcastEP = new MsgEP(clusterEP, "*");
            this.isClient    = false;

            GetServiceInstances(clusterEP, args);

            arg = args["this-instance"];
            if (arg == null || !int.TryParse(arg, out index) || index < 0 || index >= instances.Length)
            {
                throw new ArgumentException("[this-instance] topology argument is not a valid index into the instances array.");
            }

            instanceEP = instances[index];

            if (target != null)
            {
                router.Dispatcher.AddTarget(target, dynamicScope, this, null);
            }
        }
Example #10
0
 public void MsgEP_Physical_GetParent()
 {
     Assert.AreEqual("physical://foo.com:70", MsgEP.Parse("physical://foo.com:70/bar").GetPhysicalParent().ToString());
     Assert.AreEqual("physical://foo.com:70", MsgEP.Parse("physical://foo.com:70/bar").GetPhysicalParent().ToString());
     Assert.AreEqual("physical://foo.com:70/bar", MsgEP.Parse("physical://foo.com:70/bar/foobar").GetPhysicalParent().ToString());
     Assert.IsNull(MsgEP.Parse("physical://foo.com:70").GetPhysicalParent());
 }
Example #11
0
        private bool closed = false;                        // True if the transaction has completed

        /// <summary>
        /// Constructs a <see cref="MsgRequestContext" /> for transactions that are not within a session.
        /// </summary>
        /// <param name="router">The <see cref="MsgRouter" />.</param>
        /// <param name="requestMsg">The request <see cref="Msg" />.</param>
        /// <exception cref="ArgumentException">Thrown if the message passed does not have all of the headers necessary to be a request.</exception>
        internal MsgRequestContext(MsgRouter router, Msg requestMsg)
        {
            if (router == null)
            {
                throw new ArgumentNullException("router");
            }

            if (requestMsg._FromEP == null)
            {
                throw new ArgumentException("Message cannot be a request: Null [_FromEP] header.", "requestMsg");
            }

            if (requestMsg._SessionID == Guid.Empty)
            {
                throw new ArgumentException("Message cannot be a request: Empty [_SessionID] header.", "requestMsg");
            }

            this.router    = router;
            this.session   = null;
            this.FromEP    = requestMsg._FromEP.Clone();
            this.SessionID = requestMsg._SessionID;
#if TRACE
            this.TraceName = requestMsg.GetType().Name;
#else
            this.TraceName = "(trace disabled)";
#endif
        }
Example #12
0
        public void Msg_Clone_RouteAdvertiseMsg()
        {
            RouterAdvertiseMsg msgIn, msgOut;

            Msg.ClearTypes();
            Msg.LoadTypes(Assembly.GetExecutingAssembly());

            msgOut         = new RouterAdvertiseMsg(MsgEP.Parse("physical://root.com:80/hub/leaf"), "appname", "appdescription", new MsgRouterInfo(new Version(1000, 0)), 10, 20, Helper.NewGuid(), false, true);
            msgOut._FromEP = MsgEP.Parse("physical://root.com:80/hub/leaf?c=mcast://1.2.3.4:57");
            msgIn          = (RouterAdvertiseMsg)msgOut.Clone();

            Assert.AreEqual("physical://root.com:80/hub/leaf", msgIn.RouterEP.ToString());
            Assert.AreEqual("appname", msgIn.AppName);
            Assert.AreEqual("appdescription", msgIn.AppDescription);
            Assert.AreEqual(new Version(1000, 0), msgIn.RouterInfo.ProtocolVersion);
            Assert.AreEqual(IPAddress.Parse("1.2.3.4"), msgIn.IPAddress);
            Assert.AreEqual(10, msgIn.UdpPort);
            Assert.AreEqual(20, msgIn.TcpPort);
            Assert.AreEqual(msgOut.LogicalEndpointSetID, msgIn.LogicalEndpointSetID);
            Assert.IsFalse(msgIn.ReplyAdvertise);
            Assert.IsTrue(msgIn.DiscoverLogical);
            Assert.IsTrue(msgIn.RouterInfo.IsP2P);

            TestBaseCloning(msgOut);
        }
Example #13
0
        /// <summary>
        /// Shallow copies the base fields from the source message to this instance.
        /// </summary>
        /// <param name="source">The source message.</param>
        /// <param name="regenMsgID">
        /// Pass as <c>true</c> to renegerate the <see cref="_MsgID" /> property if the
        /// source message ID property is not empty.
        /// </param>
        /// <remarks>
        /// Use this in overriden <see cref="Clone" /> method implementations
        /// to ensure that the base message fields are copied properly.
        /// </remarks>
        protected virtual void CopyBaseFields(Msg source, bool regenMsgID)
        {
            this.version   = source.version;
            this.flags     = source.flags;
            this.ttl       = source.ttl;
            this.toEP      = source.toEP;
            this.fromEP    = source.fromEP;
            this.receiptEP = source.receiptEP;
            this.sessionID = source.sessionID;
            this.token     = source.token;

            if (source.msgID == Guid.Empty)
            {
                this.msgID = Guid.Empty;
            }
            else if (regenMsgID)
            {
                this.msgID = Helper.NewGuid();
            }
            else
            {
                this.msgID = source.msgID;
            }

            if (source.extHeaders != null)
            {
                this.extHeaders = source.extHeaders.Clone();
            }
        }
Example #14
0
        public void Msg_Clone_HubAdvertiseMsg()
        {
            HubAdvertiseMsg msgIn, msgOut;

            Msg.ClearTypes();
            Msg.LoadTypes(Assembly.GetExecutingAssembly());

            msgOut         = new HubAdvertiseMsg(MsgEP.Parse("physical://root.com:80/hub/leaf"), "appname", "appdescription", new MsgRouterInfo(new Version(1000, 0)), Helper.NewGuid());
            msgOut._FromEP = MsgEP.Parse("physical://root.com:80/hub/leaf?c=tcp://1.2.3.4:57");
            Assert.AreEqual(Guid.Empty, msgOut._MsgID);

            msgIn = (HubAdvertiseMsg)msgOut.Clone();

            Assert.AreEqual("physical://root.com:80/hub/leaf", msgIn.HubEP.ToString());
            Assert.AreEqual("appname", msgIn.AppName);
            Assert.AreEqual("appdescription", msgIn.AppDescription);
            Assert.AreEqual(new Version(1000, 0), msgIn.RouterInfo.ProtocolVersion);
            Assert.AreEqual(IPAddress.Parse("1.2.3.4"), msgIn.IPAddress);
            Assert.AreEqual(57, msgIn.TcpPort);
            Assert.AreEqual(msgOut.LogicalEndpointSetID, msgIn.LogicalEndpointSetID);
            Assert.AreEqual(Guid.Empty, msgIn._MsgID);

            msgOut._MsgID = Helper.NewGuid();
            msgIn         = (HubAdvertiseMsg)msgOut.Clone();

            Assert.AreNotEqual(Guid.Empty, msgIn._MsgID);

            TestBaseCloning(msgOut);
        }
Example #15
0
        public void OnMsg(LeafSettingsMsg msg)
        {
            using (TimedLock.Lock(this.SyncRoot))
            {
                if (advertiseTime != msg.AdvertiseTime)
                {
                    advertiseTime = msg.AdvertiseTime;
                    lastAdvertise = SysTime.Now;
                }

                if (msg.HubIPAddress != null && msg.HubTcpPort != 0)
                {
                    if (hubIPAddress != msg.HubIPAddress || hubTcpPort != msg.HubTcpPort)
                    {
                        hubChannelEP = new ChannelEP(Transport.Tcp, new IPEndPoint(msg.HubIPAddress, msg.HubTcpPort));
                    }
                }
                else
                {
                    hubChannelEP = null;
                }

                hubEP        = msg.HubEP;
                hubIPAddress = msg.HubIPAddress;
                hubUdpPort   = msg.HubUdpPort;
                hubTcpPort   = msg.HubTcpPort;

                if (msg.DiscoverLogical)
                {
                    SendLogicalAdvertiseMsgs(msg.HubEP);
                }
            }
        }
Example #16
0
 public void MsgEP_Compare()
 {
     Assert.AreEqual(0, MsgEP.Compare("logical://test/*", "logical://test/*"));
     Assert.AreEqual(0, MsgEP.Compare("logical://aa", "logical://AA"));
     Assert.AreEqual(-1, MsgEP.Compare("logical://aa", "logical://bb"));
     Assert.AreEqual(+1, MsgEP.Compare("logical://BB", "logical://aa"));
 }
Example #17
0
        /// <summary>
        /// Updates a message's target endpoint and status.  This is typically used
        /// for moving an expired message to a dead letter queue.
        /// </summary>
        /// <param name="persistID">The provider specific ID of the message.</param>
        /// <param name="targetEP">The new message target endpoint.</param>
        /// <param name="deliveryTime">The new message delivery time.</param>
        /// <param name="expireTime">The new message expiration time.</param>
        /// <param name="status">The new <see cref="DeliveryStatus" />.</param>
        public void Modify(object persistID, MsgEP targetEP, DateTime deliveryTime, DateTime expireTime, DeliveryStatus status)
        {
            using (TimedLock.Lock(this))
            {
                if (messages == null)
                {
                    throw new ObjectDisposedException(this.GetType().Name);
                }

                Guid          msgID = (Guid)persistID;
                QueuedMsgInfo msgInfo;
                QueuedMsg     msg;

                if (messages.TryGetValue(msgID, out msgInfo))
                {
                    msgInfo.TargetEP     = targetEP;
                    msgInfo.DeliveryTime = deliveryTime;
                    msgInfo.ExpireTime   = expireTime;
                    msgInfo.Status       = status;

                    msg            = (QueuedMsg)msgInfo.ProviderData;
                    msg.TargetEP   = targetEP;
                    msg.ExpireTime = expireTime;
                }
            }
        }
Example #18
0
        public void MsgQueueEngineSettings_Load()
        {
            try
            {
                MsgQueueEngineSettings settings;

                Config.SetConfig(@"
&section Engine

    QueueMap[0]         = logical://test1
    QueueMap[1]         = logical://test2
    FlushInterval       = 1s
    DeadLetterTTL       = 2s
    MaxDeliveryAttempts = 3
    KeepAliveInterval   = 4s
    SessionTimeout      = 5s
    BkTaskInterval      = 6s

&endsection
".Replace('&', '#'));

                settings = MsgQueueEngineSettings.LoadConfig("Engine");
                CollectionAssert.AreEqual(new MsgEP[] { MsgEP.Parse("logical://test1"), MsgEP.Parse("logical://test2") }, settings.QueueMap);
                Assert.AreEqual(TimeSpan.FromSeconds(1), settings.FlushInterval);
                Assert.AreEqual(TimeSpan.FromSeconds(2), settings.DeadLetterTTL);
                Assert.AreEqual(3, settings.MaxDeliveryAttempts);
                Assert.AreEqual(TimeSpan.FromSeconds(4), settings.KeepAliveInterval);
                Assert.AreEqual(TimeSpan.FromSeconds(5), settings.SessionTimeout);
                Assert.AreEqual(TimeSpan.FromSeconds(6), settings.BkTaskInterval);
            }
            finally
            {
                Config.SetConfig(null);
            }
        }
Example #19
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="senderEP">The sender instance endpoint.</param>
 /// <param name="command">The command string.</param>
 public ClusterMemberMsg(MsgEP senderEP, string command)
 {
     base._Set("sender", (string)senderEP);
     base._Set("cmd", command);
     base._Set("caps", (int)ClusterMemberProtocolCaps.Current);
     base._Set("flags", (int)ClusterMemberMsgFlag.None);
 }
Example #20
0
        /// <summary>
        /// Constructs a <see cref="MsgRequestContext" /> for transactions that are within a session.
        /// </summary>
        /// <param name="session">The <see cref="DuplexSession" />.</param>
        /// <param name="query">The request <see cref="Msg" />.</param>
        /// <exception cref="ArgumentException">Thrown if the message passed does not have all of the headers necessary to be a request.</exception>
        internal MsgRequestContext(DuplexSession session, Msg query)
        {
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }

            if (query._FromEP == null)
            {
                throw new ArgumentException("Message cannot be a request: Null [_FromEP] header.", "requestMsg");
            }

            if (query._SessionID == Guid.Empty)
            {
                throw new ArgumentException("Message cannot be a request: Empty [_SessionID] header.", "requestMsg");
            }

            this.Header = query._ExtensionHeaders[MsgHeaderID.DuplexSession];
            if (this.Header == null)
            {
                throw new ArgumentException("Message is not a DuplexSession query.", "requestMsg");
            }

            this.router    = session.Router;
            this.session   = session;
            this.FromEP    = query._FromEP.Clone();
            this.SessionID = query._SessionID;
#if TRACE
            this.TraceName = query.GetType().Name;
#else
            this.TraceName = "(trace disabled)";
#endif
        }
Example #21
0
        public void MsgDispatcherLogical_DynamicEP()
        {
            MsgDispatcher dispatcher;
            MsgRouter     router;
            ChannelEP     target;

            dispatcher = new MsgDispatcher();
            router     = new MsgRouter(dispatcher);

            router.Dispatcher.AddTarget(this, "foo", new Munger(), null);
            router.RouterEP = MsgEP.Parse("physical://foo.com/" + Helper.NewGuid().ToString());
            router.Start(IPAddress.Any, null, new IPEndPoint(IPAddress.Any, 0), new IPEndPoint(IPAddress.Any, 0), 5, TimeSpan.FromSeconds(60));
            target = new ChannelEP(Transport.Udp, router.UdpEP);

            try
            {
                Clear();
                router.Transmit(target, new _DispatchMsg1("logical://MungedDynamic"));
                Thread.Sleep(DispatchWait);
                Assert.IsTrue(dispatchDynamic);
            }
            finally
            {
                router.Stop();
            }
        }
Example #22
0
        /// <summary>
        /// Reads the member status from a stream.
        /// </summary>
        /// <param name="input">The input stream.</param>
        public ClusterMemberStatus(EnhancedStream input)
        {
            properties = input.ReadProperties(StringComparer.OrdinalIgnoreCase);

            try
            {
                string v;

                if (!properties.TryGetValue("_state", out v))
                {
                    this.State = ClusterMemberState.Unknown;
                }
                else
                {
                    this.State = (ClusterMemberState)Enum.Parse(typeof(ClusterMemberState), v);
                }
            }
            catch
            {
                this.State = ClusterMemberState.Unknown;
            }

            this.Mode         = this.Settings.Mode;
            this.InstanceEP   = properties["_instance-ep"];
            this.MachineName  = properties["_machine-name"];
            this.ProtocolCaps = (ClusterMemberProtocolCaps)int.Parse(properties["_caps"]);
        }
Example #23
0
        private bool hostStarted;                                               // Indicates whether call to ChannelHost.Start() is current

        //---------------------------------------------------------------------
        // Implementation

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="context">The <see cref="BindingContext" /> holding the information necessary to construct the channel stack.</param>
        /// <exception cref="InvalidOperationException">Thrown if problems were found with the binding parameters.</exception>
        internal LillTekChannelListener(BindingContext context)
        {
            this.maxAcceptedChannels = ServiceModelHelper.MaxAcceptedChannels;      // $todo(jeff.lill): Hardcoded
            bkTaskInterval           = ServiceModelHelper.DefaultBkTaskInterval;    //                   This too

            this.context     = context;
            this.uri         = GetListenUri(context);
            this.ep          = ServiceModelHelper.ToMsgEP(uri);
            this.onBkTask    = new AsyncCallback(OnBkTask);
            this.sessionMode = false;
            this.hostStarted = false;

            // Initialize the message encoder factory from the binding context if
            // one was specified.  Use the binary message encoding factory otherwise.

            if (context.BindingParameters.FindAll <MessageEncodingBindingElement>().Count > 1)
            {
                throw new InvalidOperationException("Multiple MessageEncodingBindingElements were found in the BindingParameters of the BindingContext.");
            }

            MessageEncodingBindingElement element = context.BindingParameters.Find <MessageEncodingBindingElement>();

            if (element != null)
            {
                messageEncoderFactory = element.CreateMessageEncoderFactory();
            }
            else
            {
                messageEncoderFactory = new BinaryMessageEncodingBindingElement().CreateMessageEncoderFactory();
            }
        }
Example #24
0
 /// <summary>
 /// Constructs a MsgTrack instance from the parameters passed.
 /// </summary>
 /// <param name="routerEP">The target router's physical endpoint.</param>
 /// <param name="logicalEndpointSetID">
 /// The logical endpoint set ID if the message is being sent at a logical
 /// endpoint on the targeted router, null otherwise.
 /// </param>
 /// <param name="msgID">The forwarded message's GUID.</param>
 /// <param name="ttd">
 /// The time (SYS) beyond which we'll consider that we've detected a dead
 /// router if we haven't seen a valid <see cref="ReceiptMsg" />.
 /// </param>
 public MsgTrack(MsgEP routerEP, Guid logicalEndpointSetID, Guid msgID, DateTime ttd)
 {
     this.RouterEP             = routerEP;
     this.LogicalEndpointSetID = logicalEndpointSetID;
     this.MsgID = msgID;
     this.TTD   = ttd;
 }
Example #25
0
        public void ReliableMessengerMsgs_DeliveryMsg_Serialize()
        {
            DeliveryMsg    msgIn, msgOut;
            EnhancedStream es  = new EnhancedMemoryStream();
            DateTime       now = Helper.UtcNowRounded;
            Guid           id  = Helper.NewGuid();
            PropertyMsg    query;
            PropertyMsg    response;

            Msg.ClearTypes();
            Msg.LoadTypes(Assembly.GetExecutingAssembly());

            query           = new PropertyMsg();
            query["hello"]  = "world";
            response        = new PropertyMsg();
            response["foo"] = "bar";

            msgOut = new DeliveryMsg(DeliveryOperation.Attempt, now, "logical://foo", "logical://bar", query, id,
                                     "clusterInfo", "clusterParam", new TimeoutException("Timeout"), response);
            Msg.Save(es, msgOut);
            es.Seek(0, SeekOrigin.Begin);
            msgIn = (DeliveryMsg)Msg.Load(es);

            Assert.IsNotNull(msgIn);
            Assert.AreEqual(DeliveryOperation.Attempt, msgIn.Operation);
            Assert.AreEqual(now, msgIn.Timestamp);
            Assert.AreEqual(MsgEP.Parse("logical://foo"), msgIn.TargetEP);
            Assert.AreEqual(MsgEP.Parse("logical://bar"), msgIn.ConfirmEP);
            Assert.IsInstanceOfType(msgIn.Query, typeof(PropertyMsg));
            Assert.AreEqual("world", ((PropertyMsg)msgIn.Query)["hello"]);
            Assert.AreEqual(id, msgIn.TopologyID);
            Assert.AreEqual("clusterInfo", msgIn.TopologyInfo);
            Assert.AreEqual("clusterParam", msgIn.TopologyParam);
            Assert.IsInstanceOfType(msgIn.Exception, typeof(TimeoutException));
            Assert.AreEqual("Timeout", msgIn.Exception.Message);
            Assert.IsInstanceOfType(msgIn.Response, typeof(PropertyMsg));
            Assert.AreEqual("bar", ((PropertyMsg)msgIn.Response)["foo"]);

            msgOut = new DeliveryMsg(DeliveryOperation.Confirmation, now, "logical://foo", null, query, id,
                                     null, null, new ArgumentException("Test"), null);
            es.SetLength(0);
            Msg.Save(es, msgOut);
            es.Seek(0, SeekOrigin.Begin);
            msgIn = (DeliveryMsg)Msg.Load(es);

            Assert.IsNotNull(msgIn);
            Assert.AreEqual(DeliveryOperation.Confirmation, msgIn.Operation);
            Assert.AreEqual(now, msgIn.Timestamp);
            Assert.AreEqual(MsgEP.Parse("logical://foo"), msgIn.TargetEP);
            Assert.IsNull(msgIn.ConfirmEP);
            Assert.IsInstanceOfType(msgIn.Query, typeof(PropertyMsg));
            Assert.AreEqual("world", ((PropertyMsg)msgIn.Query)["hello"]);
            Assert.AreEqual(id, msgIn.TopologyID);
            Assert.IsNull(msgIn.TopologyInfo);
            Assert.IsNull(msgIn.TopologyParam);
            Assert.IsInstanceOfType(msgIn.Exception, typeof(SessionException));
            Assert.AreEqual("Test", msgIn.Exception.Message);
            Assert.IsNull(msgIn.Response);
        }
Example #26
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="routerEP">Physical endpoint of the sending router.</param>
 /// <param name="routerInfo">The sending router's capability information.</param>
 /// <param name="isUplink"><c>true</c> if the sender side is an uplink.</param>
 /// <param name="listenPort">The listening port.</param>
 public TcpInitMsg(MsgEP routerEP, MsgRouterInfo routerInfo, bool isUplink, int listenPort)
 {
     this._Flags     = MsgFlag.Priority;
     this.RouterEP   = routerEP;
     this.RouterInfo = routerInfo;
     this.IsUplink   = isUplink;
     this.ListenPort = listenPort;
 }
Example #27
0
        private MsgEP instanceEP;           // Endpoint of the connected sentinel instance.

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="router">The application message router to be used for communications.</param>
        /// <param name="serviceEP">The sentinel service endpoint.</param>
        public Sentinel(MsgRouter router, MsgEP serviceEP)
        {
            Global.RegisterMsgTypes();

            this.router     = router;
            this.serviceEP  = serviceEP;
            this.instanceEP = null;
        }
Example #28
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="senderEP">The sender instance endpoint.</param>
 /// <param name="protocolCaps">Indicates the sender's protocol implementation capabilities.</param>
 /// <param name="command">The command string.</param>
 /// <param name="data">The message BLOB data.</param>
 public ClusterMemberMsg(MsgEP senderEP, ClusterMemberProtocolCaps protocolCaps, string command, byte[] data)
 {
     base._Set("sender", (string)senderEP);
     base._Set("cmd", command);
     base._Set("caps", (int)protocolCaps);
     base._Set("flags", (int)ClusterMemberMsgFlag.None);
     base._Data = data;
 }
Example #29
0
        public void MsgEP_Logical_EscapeInput()
        {
            MsgEP ep;

            ep = MsgEP.Parse("logical://root%20node/hub%20node/leaf%20node");
            Assert.IsTrue(ep.IsLogical);
            CollectionAssert.AreEqual(new string[] { "root node", "hub node", "leaf node" }, ep.Segments);
        }
Example #30
0
        /// <summary>
        /// Initializes the channel endpoints of the message's FROM
        /// endpoint, creating the endpoint object if necessary.
        /// </summary>
        /// <param name="fromChannelEP">The channel endpoint.</param>
        public void _SetFromChannel(ChannelEP fromChannelEP)
        {
            if (this.fromEP == null)
            {
                this.fromEP = new MsgEP(fromChannelEP);
            }

            this.fromEP.ChannelEP = fromChannelEP;
        }