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); }
public static DelegateCallback Create <T>(IStreamingCallback <T> callback) { var c = new DelegateCallback(); c.SetCallback(callback); return(c); }
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); }
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); } }
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); }
private CallbackContext <TKey> GetCallbackContext(IStreamingCallback <TData> callback) { return(_callbackContexts.GetOrAdd(callback, streamingCallback => new CallbackContext <TKey>())); }
public void RemoveSubscription(IStreamingCallback <TData> subscription) { _subscriptions.Remove(subscription); }
public void AddSubscription(IStreamingCallback <TData> subsciption) { _subscriptions.Add(subsciption); }
public void SetCallback(IStreamingCallback <MyCStreamingData> callback) { _callback = callback; _timer = new Timer(OnTimer, null, TimeSpan.FromMilliseconds(1), TimeSpan.FromMilliseconds(1)); }
public bool Unsubscribe(IStreamingCallback <MyCStreamingData> callback) { return(_streamingManager.UnsubscribeCallback(callback)); }
public bool Subscribe(int key, IStreamingCallback <MyCStreamingData> callback) { return(_streamingManager.SubscribeCallback(key, callback)); }
private void SetCallback <T>(IStreamingCallback <T> callback) { Type = typeof(T); _delegate = (data) => callback.Send((T)data); }