Ejemplo n.º 1
0
        public void MulticastRemoteSubscriptionHandleDeserializedAsRemoteSubscriptionHandle()
        {
            RemoteSubscriptionHandle h1 = new RemoteSubscriptionHandle
            {
                EventID               = 1,
                SubscriberId          = 2,
                PublisherId           = 3,
                PublisherNodeID       = 15,
                SubscriberNodeID      = 1,
                SubscriptionReference = 35
            };

            MulticastRemoteSubscriptionhandle h2 = new MulticastRemoteSubscriptionhandle
            {
                EventID               = 2,
                SubscriberId          = 3,
                PublisherId           = 1,
                PublisherNodeID       = 13,
                SubscriberNodeID      = 4,
                SubscriptionReference = 30,
                IpAddress             = "228.4.0.1",
                Port = 44550
            };

            List <RemoteSubscriptionHandle> list = new List <RemoteSubscriptionHandle>();

            list.Add(h1);
            list.Add(h2);

            byte [] serialized = Ella.Internal.Serializer.Serialize(list);

            List <RemoteSubscriptionHandle> list2 = Ella.Internal.Serializer.Deserialize <List <RemoteSubscriptionHandle> >(serialized);

            Assert.IsInstanceOfType(list2[1], typeof(MulticastRemoteSubscriptionhandle));
        }
Ejemplo n.º 2
0
        public void DifferentRemoteIdsAreNotEqual()
        {
            RemoteSubscriptionHandle h = new RemoteSubscriptionHandle {
                EventID = 1, SubscriberId = 2, PublisherId = 3, PublisherNodeID = 15
            };
            RemoteSubscriptionHandle h2 = new RemoteSubscriptionHandle {
                EventID = 1, SubscriberId = 2, PublisherId = 3, PublisherNodeID = 14
            };

            Assert.AreNotEqual(h, h2);
            Assert.IsTrue(h != h2);
        }
Ejemplo n.º 3
0
        public void SameRemoteAreEqual()
        {
            RemoteSubscriptionHandle h = new RemoteSubscriptionHandle {
                EventID = 1, SubscriberId = 2, PublisherId = 3, PublisherNodeID = 15
            };
            RemoteSubscriptionHandle h2 = new RemoteSubscriptionHandle {
                EventID = 1, SubscriberId = 2, PublisherId = 3, PublisherNodeID = 15
            };

            Assert.AreEqual(h, h2);
            Assert.IsTrue(h == h2);
        }
Ejemplo n.º 4
0
        public void SamePublisherAndSubscriberNodeDifferentSubscriberAreNotEqual()
        {
            RemoteSubscriptionHandle h = new RemoteSubscriptionHandle {
                EventID = 1, SubscriberId = 2, PublisherId = 3, PublisherNodeID = 15, SubscriberNodeID = 1, SubscriptionReference = 35
            };
            RemoteSubscriptionHandle h2 = new RemoteSubscriptionHandle {
                EventID = 1, SubscriberId = 3, PublisherId = 3, PublisherNodeID = 15, SubscriberNodeID = 1, SubscriptionReference = 34
            };

            Assert.AreNotEqual(h, h2);
            Assert.IsFalse(h == h2);
        }
Ejemplo n.º 5
0
        public void CastedRemoteAreNotEqual()
        {
            SubscriptionHandle h = new SubscriptionHandle {
                EventID = 1, SubscriberId = 2, PublisherId = 3
            };
            SubscriptionHandle h2 = new RemoteSubscriptionHandle {
                EventID = 1, SubscriberId = 2, PublisherId = 3, PublisherNodeID = 15
            };

            Assert.AreNotEqual(h, h2);
            Assert.IsFalse(h == h2);
        }
Ejemplo n.º 6
0
        public void RemoteAndLocalAreNotEqual()
        {
            SubscriptionHandle h = new SubscriptionHandle {
                EventID = 1, SubscriberId = 2, PublisherId = 3
            };
            RemoteSubscriptionHandle h2 = new RemoteSubscriptionHandle {
                EventID = 1, SubscriberId = 2, PublisherId = 3, PublisherNodeID = 15, SubscriptionReference = 1, SubscriberNodeID = 1
            };

            Assert.AreNotEqual(h, h2);
            Assert.IsFalse(h.Equals(h2));
            Assert.IsFalse(h == h2);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Sends the specified <paramref name="message" /> to the publisher identified by handle <paramref name="to" />.<br />
        /// This is used by subscribers to send messages directly to a certain publisher of an event.<br />
        /// However, it is not guaranteed, that the publisher is a) subscribed to application messages and b) can interpret this specific message type
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="to">The receiver identified by a subscription handle</param>
        /// <param name="sender">The sender instance.</param>
        public static bool Message(ApplicationMessage message, SubscriptionHandle to, object sender)
        {
            //TODO check if sender is subscriber
            _log.DebugFormat("New application message from {0} to {1}", message.Sender, to);
            message.Handle = to;

            /*Check if subscription is remote or local
             * if local: pass it to local module
             * if remote: serialize, wrap in Message, send
             */
            if (to is RemoteSubscriptionHandle)
            {
                _log.Debug("Sending message to remote receiver");
                int nodeId = EllaConfiguration.Instance.NodeId;

                RemoteSubscriptionHandle h = (RemoteSubscriptionHandle)to;
                if (h.PublisherNodeID == nodeId)
                {
                    message.Sender = EllaModel.Instance.GetPublisherId(sender);
                }
                else if (h.SubscriberNodeID == nodeId)
                {
                    message.Sender = EllaModel.Instance.GetSubscriberId(sender);
                }

                return(Networking.SendApplicationMessage(message, to as RemoteSubscriptionHandle));
            }
            else
            {
                int  publisherId       = EllaModel.Instance.GetPublisherId(sender);
                int  subscriberId      = EllaModel.Instance.GetSubscriberId(sender);
                bool senderIsPublisher = false;

                _log.Debug("Delivering message locally");

                //publisher sends msg to subscriber
                if (to.PublisherId == publisherId)
                {
                    message.Sender    = publisherId;
                    senderIsPublisher = true;
                }
                //subscriber sends msg to publisher
                else if (to.SubscriberId == subscriberId)
                {
                    message.Sender = subscriberId;
                }

                return(DeliverApplicationMessage(message, senderIsPublisher));
            }
        }
Ejemplo n.º 8
0
        public void SendMessageReply()
        {
            ApplicationMessage       msg    = new ApplicationMessage();
            RemoteSubscriptionHandle handle = new RemoteSubscriptionHandle()
            {
                EventID          = 1,
                PublisherId      = 234,
                PublisherNodeID  = EllaConfiguration.Instance.NodeId,
                SubscriberNodeID = EllaConfiguration.Instance.NodeId + 1
            };
            ApplicationMessage inReplyTo = new ApplicationMessage()
            {
                Handle = handle
            };

            Send.Reply(msg, inReplyTo, this);
        }
Ejemplo n.º 9
0
        public void NetworkControllerSendMessage()
        {
            byte[] data = new byte[1024];

            NetworkController nc     = new NetworkController();
            FakeServer        server = new FakeServer();
            FakeSender        sender = new FakeSender();

            nc.Servers.Add(server);
            Networking.NetworkController = nc;
            Networking.Start();

            SenderBase.FactoryMethod = e => sender;

            Message msg = new Message();

            msg.Data   = data;
            msg.Sender = EllaConfiguration.Instance.NodeId + 1;
            msg.Type   = MessageType.Discover;

            IPEndPoint ep = new IPEndPoint(IPAddress.Parse("234.234.234.4"), 3456);

            server.DiscoveryMessageEvent(msg, ep);

            TestSubscriber s = new TestSubscriber();

            s.Subscribe();

            byte[] b = { 1, 2 };

            ApplicationMessage app = new ApplicationMessage();

            app.Data = b;

            RemoteSubscriptionHandle rh = new RemoteSubscriptionHandle();

            rh.PublisherNodeID = EllaConfiguration.Instance.NodeId + 1;

            Send.Message(app, rh, s);

            Thread.Sleep(1000);

            Assert.AreEqual(1, sender._messages[MessageType.ApplicationMessage]);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Sends the application message.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="remoteSubscriptionHandle">The remote subscription handle.</param>
 /// <param name="isReply">if set to <c>true</c>, this is a reply to another message.</param>
 /// <returns></returns>
 internal static bool SendApplicationMessage(ApplicationMessage message, RemoteSubscriptionHandle remoteSubscriptionHandle, bool isReply = false)
 {
     return(NetworkController.SendMessage(message, remoteSubscriptionHandle, isReply));
 }