예제 #1
0
 public void Associate(SubscriptionHandle first, SubscriptionHandle second)
 {
     if (SubscriptionCallBackHandle.Contains(first) && SubscriptionCallBackHandle.Contains(second))
     {
         Interlocked.Increment(ref NumAssociationsReceived);
     }
 }
예제 #2
0
 public void Callback(int id, SubscriptionHandle handle)
 {
     if (i % 2 == 0)
     {
         list.Add(handle);
     }
     i++;
 }
예제 #3
0
 private void Callback(string s, SubscriptionHandle handle)
 {
     NewDataHandle.Add(handle);
     rec = (string)s;
     if (rec == "hello")
     {
         numEventsReceived++;
     }
 }
예제 #4
0
        public void SelfEquals()
        {
            SubscriptionHandle h = new SubscriptionHandle {
                EventID = 1, SubscriberId = 2, PublisherId = 3
            };

            Assert.AreEqual(h, h);
// ReSharper disable EqualExpressionComparison
            Assert.IsTrue(h == h);
// ReSharper restore EqualExpressionComparison
        }
예제 #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);
        }
예제 #6
0
        public void EqualsSameValues()
        {
            SubscriptionHandle h = new SubscriptionHandle {
                EventID = 1, SubscriberId = 2, PublisherId = 3
            };
            SubscriptionHandle h2 = new SubscriptionHandle {
                EventID = 1, SubscriberId = 2, PublisherId = 3
            };

            Assert.AreEqual(h, h2);
            Assert.IsTrue(h == h2);
        }
예제 #7
0
        public void DifferentValues()
        {
            SubscriptionHandle h = new SubscriptionHandle {
                EventID = 1, SubscriberId = 2, PublisherId = 3
            };
            SubscriptionHandle h2 = new SubscriptionHandle {
                EventID = 3, SubscriberId = 2, PublisherId = 3
            };

            Assert.AreNotEqual(h, h2);
            Assert.IsFalse(h == h2);
        }
예제 #8
0
        /// <summary>
        /// Unsubscribes the <paramref name="subscriberInstance" /> by SubscriptionHandle <paramref name="handle" />
        /// </summary>
        /// <param name="subscriberInstance">The instance of a subscriber to be unsubscribed</param>
        /// <param name="handle"> The SubscriptionHandle by which subscriptions should be removed </param>
        /// <exception cref="System.ArgumentException">subscriberInstance must be a valid subscriber</exception>
        public static void From(object subscriberInstance, SubscriptionHandle handle)
        {
            _log.DebugFormat("Unsubscribing {0} from handle {1}", EllaModel.Instance.GetSubscriberId(subscriberInstance), handle);


            if (!Is.Subscriber(subscriberInstance.GetType()))
            {
                _log.ErrorFormat("Cannot unsubscribe. {0} is not a valid subscriber", subscriberInstance.GetType().ToString());
                throw new ArgumentException("subscriberInstance must be a valid subscriber");
            }

            SubscriptionController.PerformUnsubscribe(s => s.Handle == handle);
        }
예제 #9
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);
        }
예제 #10
0
파일: Send.cs 프로젝트: kouweizhong/Ella
        /// <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));
            }
        }
예제 #11
0
        /// <summary>
        /// This method associates two events published by one publisher to indicate that those events have a semantic connection.<br />
        /// This method does not regard the order of the events (i.e. exchanging <paramref name="firstEventId"/> and <paramref name="secondEventId"/> yields no different results
        /// </summary>
        /// <param name="firstEventId">The id of the first event</param>
        /// <param name="secondEventId">The id of the second event</param>
        /// <param name="publisher">The publisher.</param>
        public static void Events(int firstEventId, int secondEventId, object publisher)
        {
            if (Is.Publisher(publisher.GetType()))
            {
                EventHandle first = new EventHandle()
                {
                    EventId         = firstEventId,
                    PublisherId     = EllaModel.Instance.GetPublisherId(publisher),
                    PublisherNodeId = EllaConfiguration.Instance.NodeId
                };
                EventHandle second = new EventHandle()
                {
                    EventId         = secondEventId,
                    PublisherId     = first.PublisherId,
                    PublisherNodeId = EllaConfiguration.Instance.NodeId
                };
                EllaModel.Instance.AddEventCorrelation(first, second);

                foreach (var result in EllaModel.Instance.FilterSubscriptions(s => true).GroupBy(s => s.Subscriber).Where(g => g.Any(g1 => Equals(g1.Handle.EventHandle, first)) && g.Any(g2 => Equals(g2.Handle.EventHandle, second))).Select(g => new { Object = g.Key, Method = ReflectionUtils.GetAttributedMethod(g.Key.GetType(), typeof(AssociateAttribute)) }))
                {
                    if (result.Method != null)
                    {
                        if (result.Method.GetParameters().Count() != 2 || result.Method.GetParameters().Any(p => p.ParameterType != typeof(SubscriptionHandle)))
                        {
                            throw new IllegalAttributeUsageException(String.Format("Method {0} attributed as Associate has invalid parameters (count or type)", result.Method));
                        }
                        SubscriptionHandle handle1 = new SubscriptionHandle()
                        {
                            EventHandle = first
                        };
                        SubscriptionHandle handle2 = new SubscriptionHandle()
                        {
                            EventHandle = second
                        };

                        result.Method.Invoke(result.Object, new object[] { handle1, handle2 });
                        result.Method.Invoke(result.Object, new object[] { handle2, handle1 });
                    }
                }
            }
        }
예제 #12
0
 public void Callback(int id, SubscriptionHandle h)
 {
     callback++;
     _handle = h;
 }
예제 #13
0
 /// <summary>
 /// This method associates an event consumed by a publisher and an event published by it<br />
 /// This is used to indicate that the event published by the <paramref name="publisher"/> is based on (or otherwise related to) the data consumed in the <paramref name="incoming"/> event
 /// </summary>
 /// <param name="incoming">The incoming.</param>
 /// <param name="outgoingEventId">The outgoing ID.</param>
 /// <param name="publisher">The publisher.</param>
 public static void Events(SubscriptionHandle incoming, int outgoingEventId, object publisher)
 {
 }
예제 #14
0
 /// <summary>
 /// Equalses the specified other.
 /// </summary>
 /// <param name="other">The other.</param>
 /// <returns></returns>
 protected bool Equals(SubscriptionHandle other)
 {
     return(GetHashCode() == other.GetHashCode());
 }
예제 #15
0
 private void SubscriptionCallback(Type arg1, SubscriptionHandle arg2)
 {
     h = arg2;
     SubscriptionCallBackHandle.Add(arg2);
 }
예제 #16
0
        public void HandleEqualsNull()
        {
            SubscriptionHandle handle = null;

            Assert.IsTrue(handle == null);
        }
예제 #17
0
 private void BoolCallback(bool t, SubscriptionHandle h)
 {
     NewDataHandle.Add(h);
     numEventsReceived++;
 }