예제 #1
0
        public bool UnsubscribeCallback(IStreamingCallback <TData> callback)
        {
            var callbackContext = GetCallbackContext(callback);
            var unsubscribe     = false;

            lock (callbackContext)
            {
                foreach (var contextKey in callbackContext.Keys)
                {
                    var subscription = GetSubscription(contextKey);
                    lock (subscription)
                    {
                        subscription.RemoveSubscription(callback);
                        if (subscription.IsEmpty)
                        {
                            _subscriptions.TryRemove(contextKey, out _);
                            unsubscribe = true;
                        }
                        if (unsubscribe)
                        {
                            return(_streamingAdapter.Unsubscribe(contextKey));
                        }
                    }
                }
            }

            return(true);
        }
예제 #2
0
        public static DelegateCallback Create <T>(IStreamingCallback <T> callback)
        {
            var c = new DelegateCallback();

            c.SetCallback(callback);
            return(c);
        }
예제 #3
0
        public bool UnsubscribeCallback(TKey key, IStreamingCallback <TData> callback)
        {
            var callbackContext = GetCallbackContext(callback);
            var subscription    = GetSubscription(key);
            var unsubscribe     = false;

            lock (callbackContext)
                lock (subscription)
                {
                    callbackContext.RemoveKey(key);
                    subscription.RemoveSubscription(callback);
                    if (subscription.IsEmpty)
                    {
                        _subscriptions.TryRemove(key, out _);
                        unsubscribe = true;
                    }

                    if (callbackContext.IsEmpty)
                    {
                        _callbackContexts.TryRemove(callback, out _);
                    }

                    if (unsubscribe)
                    {
                        return(_streamingAdapter.Unsubscribe(key));
                    }
                }

            return(true);
        }
예제 #4
0
 private static void Send(TData data, IStreamingCallback <TData> callback)
 {
     try
     {
         callback.Send(data);
     }
     catch (NetworkChannelDisconnected e)
     {
         _log.Warn("Unable to send data, client channel is disconnected", e);
     }
 }
예제 #5
0
        public bool SubscribeCallback(TKey key, IStreamingCallback <TData> callback)
        {
            var callbackContext = GetCallbackContext(callback);
            var subscription    = GetSubscription(key);

            lock (callbackContext)
                lock (subscription)
                {
                    var subscribe = subscription.IsEmpty;
                    callbackContext.AddKey(key);
                    subscription.AddSubscription(callback);
                    if (subscribe)
                    {
                        return(_streamingAdapter.Subscribe(key));
                    }
                }

            return(true);
        }
예제 #6
0
 private CallbackContext <TKey> GetCallbackContext(IStreamingCallback <TData> callback)
 {
     return(_callbackContexts.GetOrAdd(callback, streamingCallback => new CallbackContext <TKey>()));
 }
예제 #7
0
 public void RemoveSubscription(IStreamingCallback <TData> subscription)
 {
     _subscriptions.Remove(subscription);
 }
예제 #8
0
 public void AddSubscription(IStreamingCallback <TData> subsciption)
 {
     _subscriptions.Add(subsciption);
 }
예제 #9
0
 public void SetCallback(IStreamingCallback <MyCStreamingData> callback)
 {
     _callback = callback;
     _timer    = new Timer(OnTimer, null, TimeSpan.FromMilliseconds(1), TimeSpan.FromMilliseconds(1));
 }
예제 #10
0
 public bool Unsubscribe(IStreamingCallback <MyCStreamingData> callback)
 {
     return(_streamingManager.UnsubscribeCallback(callback));
 }
예제 #11
0
 public bool Subscribe(int key, IStreamingCallback <MyCStreamingData> callback)
 {
     return(_streamingManager.SubscribeCallback(key, callback));
 }
예제 #12
0
 private void SetCallback <T>(IStreamingCallback <T> callback)
 {
     Type      = typeof(T);
     _delegate = (data) => callback.Send((T)data);
 }