Exemple #1
0
        public IList GetSubscribers(IMessage message, bool evalSelector)
        {
            lock (_objLock)
            {
                bool filter = true;
                if (message.headers == null || message.headers.Count == 0)
                {
                    filter = false;
                }

                if (!filter)
                {
                    return(GetSubscribers());
                }
                else
                {
                    Subtopic subtopic = null;
                    if (message.headers.ContainsKey(AsyncMessage.SubtopicHeader))
                    {
                        subtopic = new Subtopic(message.headers[AsyncMessage.SubtopicHeader] as string);
                        MessagingAdapter messagingAdapter = _messageDestination.ServiceAdapter as MessagingAdapter;
                        if (messagingAdapter != null)
                        {
                            if (!messagingAdapter.AllowSend(subtopic))
                            {
                                return(null);
                            }
                        }
                    }

                    ArrayList subscribers = new ArrayList();
                    foreach (MessageClient messageClient in _subscribers.Values)
                    {
                        bool include = true;
                        if (subtopic != null && messageClient.Subtopic != null)
                        {
                            include = include && subtopic.Matches(messageClient.Subtopic);
                        }
                        if (messageClient.Selector != null && evalSelector)
                        {
                            include = include && messageClient.Selector.Evaluate(null, message.headers);
                        }

                        if (include)
                        {
                            subscribers.Add(messageClient.ClientId);
                        }
                    }
                    return(subscribers);
                }
            }
        }
Exemple #2
0
 public MessageClient AddSubscriber(string clientId, string endpointId, Subtopic subtopic, Selector selector)
 {
     lock (_objLock)
     {
         if (subtopic != null)
         {
             MessagingAdapter messagingAdapter = _messageDestination.ServiceAdapter as MessagingAdapter;
             if (messagingAdapter != null)
             {
                 if (!messagingAdapter.AllowSubscribe(subtopic))
                 {
                     ASObject aso = new ASObject();
                     aso["subtopic"] = subtopic.Value;
                     throw new MessageException(aso);
                 }
             }
         }
         if (!_subscribers.Contains(clientId))
         {
             //Set in RtmpService
             MessageClient messageClient = new MessageClient(clientId, _messageDestination, endpointId);
             messageClient.Subtopic = subtopic;
             messageClient.Selector = selector;
             messageClient.AddSubscription(selector, subtopic);
             AddSubscriber(messageClient);
             messageClient.NotifyCreatedListeners();
             return(messageClient);
         }
         else
         {
             MessageClient messageClient = _subscribers[clientId] as MessageClient;
             IClient       client        = FluorineContext.Current.Client;
             if (client != null && !client.Id.Equals(messageClient.Client.Id))
             {
                 throw new MessageException("Duplicate subscriptions from multiple Flex Clients");
             }
             //Reset the endpoint push state for the subscription to make sure its current because a resubscribe could be arriving over a new endpoint or a new session.
             messageClient.ResetEndpoint(endpointId);
             return(messageClient);
         }
     }
 }