private void RemoveSubscriptionInternal <TMessage>(TinyMessageSubscriptionToken subscriptionToken) where TMessage : class, ITinyMessage { if (subscriptionToken == null) { throw new ArgumentNullException("subscriptionToken"); } lock (_SubscriptionsPadlock) { var currentlySubscribed = (from sub in _Subscriptions where object.ReferenceEquals(sub.Subscription.SubscriptionToken, subscriptionToken) select sub).ToList(); currentlySubscribed.ForEach(sub => _Subscriptions.Remove(sub)); } }
/// <summary> /// Initializes a new instance of the TinyMessageSubscription class. /// </summary> /// <param name="destination">Destination object</param> /// <param name="deliveryAction">Delivery action</param> /// <param name="messageFilter">Filter function</param> public StrongTinyMessageSubscription(TinyMessageSubscriptionToken subscriptionToken, Action <TMessage> deliveryAction, Func <TMessage, bool> messageFilter) { if (subscriptionToken == null) { throw new ArgumentNullException("subscriptionToken"); } if (deliveryAction == null) { throw new ArgumentNullException("deliveryAction"); } if (messageFilter == null) { throw new ArgumentNullException("messageFilter"); } _SubscriptionToken = subscriptionToken; _DeliveryAction = deliveryAction; _MessageFilter = messageFilter; }
/// <summary> /// Initializes a new instance of the WeakTinyMessageSubscription class. /// </summary> /// <param name="destination">Destination object</param> /// <param name="deliveryAction">Delivery action</param> /// <param name="messageFilter">Filter function</param> public WeakTinyMessageSubscription(TinyMessageSubscriptionToken subscriptionToken, Action <TMessage> deliveryAction, Func <TMessage, bool> messageFilter) { if (subscriptionToken == null) { throw new ArgumentNullException("subscriptionToken"); } if (deliveryAction == null) { throw new ArgumentNullException("deliveryAction"); } if (messageFilter == null) { throw new ArgumentNullException("messageFilter"); } _SubscriptionToken = subscriptionToken; _DeliveryAction = new WeakReference(deliveryAction); _MessageFilter = new WeakReference(messageFilter); }
private TinyMessageSubscriptionToken AddSubscriptionInternal <TMessage>(Action <TMessage> deliveryAction, Func <TMessage, bool> messageFilter, bool strongReference, ITinyMessageProxy proxy) where TMessage : class, ITinyMessage { if (deliveryAction == null) { throw new ArgumentNullException("deliveryAction"); } if (messageFilter == null) { throw new ArgumentNullException("messageFilter"); } if (proxy == null) { throw new ArgumentNullException("proxy"); } lock (_SubscriptionsPadlock) { var subscriptionToken = new TinyMessageSubscriptionToken(this, typeof(TMessage)); ITinyMessageSubscription subscription; if (strongReference) { subscription = new StrongTinyMessageSubscription <TMessage>(subscriptionToken, deliveryAction, messageFilter); } else { subscription = new WeakTinyMessageSubscription <TMessage>(subscriptionToken, deliveryAction, messageFilter); } _Subscriptions.Add(new SubscriptionItem(proxy, subscription)); return(subscriptionToken); } }
public static void Unsubscribe(TinyMessageSubscriptionToken subscriptionToken) { Hub.Unsubscribe(subscriptionToken); }
public static void Unsubscribe <TMessage>(TinyMessageSubscriptionToken subscriptionToken) where TMessage : class, ITinyMessage { Hub.Unsubscribe(subscriptionToken); }
/// <summary> /// Unsubscribe from a particular message type. /// /// Does not throw an exception if the subscription is not found. /// </summary> /// <param name="subscriptionToken">Subscription token received from Subscribe</param> public void Unsubscribe(TinyMessageSubscriptionToken subscriptionToken) { RemoveSubscriptionInternal <ITinyMessage>(subscriptionToken); }
/// <summary> /// Unsubscribe from a particular message type. /// /// Does not throw an exception if the subscription is not found. /// </summary> /// <typeparam name="TMessage">Type of message</typeparam> /// <param name="subscriptionToken">Subscription token received from Subscribe</param> public void Unsubscribe <TMessage>(TinyMessageSubscriptionToken subscriptionToken) where TMessage : class, ITinyMessage { RemoveSubscriptionInternal <TMessage>(subscriptionToken); }