internal WoopsaSubscriptionChannel(WoopsaSubscriptionServiceImplementation serviceImplementation, int notificationQueueSize) { _subscriptions = new Dictionary <int, BaseWoopsaSubscriptionServiceSubscription>(); _waitNotificationEvent = new AutoResetEvent(false); _waitStopEvent = new ManualResetEvent(false); ServiceImplementation = serviceImplementation; _idLock = new Object(); Id = GetNextChannelId(); NotificationQueueSize = notificationQueueSize; _pendingNotifications = new NotificationConcurrentQueue(notificationQueueSize); _watchClientActivity = new Stopwatch(); _watchClientActivity.Start(); }
internal WoopsaSubscriptionChannel(WoopsaSubscriptionServiceImplementation serviceImplementation, int notificationQueueSize) { _subscriptions = new Dictionary<int, BaseWoopsaSubscriptionServiceSubscription>(); _waitNotificationEvent = new AutoResetEvent(false); _waitStopEvent = new ManualResetEvent(false); ServiceImplementation = serviceImplementation; _idLock = new Object(); Id = GetNextChannelId(); NotificationQueueSize = notificationQueueSize; _pendingNotifications = new NotificationConcurrentQueue(notificationQueueSize); _watchClientActivity = new Stopwatch(); _watchClientActivity.Start(); }
public WoopsaSubscriptionServiceImplementation(WoopsaContainer root, bool isServerSide) { _root = root; _isServerSide = isServerSide; _channels = new Dictionary<int, WoopsaSubscriptionChannel>(); TimerScheduler = new LightWeightTimerScheduler(); TimerScheduler.Started += (sender, e) => { _currentService = this; }; TimerScheduler.Start(); _timerCheckChannelTimedOut = TimerScheduler.AllocateTimer( WoopsaSubscriptionServiceConst.SubscriptionChannelLifeTimeCheckInterval); _timerCheckChannelTimedOut.Elapsed += _timerCheckChannelTimedOut_Elapsed; _timerCheckChannelTimedOut.IsEnabled = true; }
public WoopsaSubscriptionService(WoopsaServer server, WoopsaContainer container) : base(container, WoopsaSubscriptionServiceConst.WoopsaServiceSubscriptionName) { _server = server; _subscriptionServiceImplementation = new WoopsaSubscriptionServiceImplementation(container, true); _subscriptionServiceImplementation.BeforeWoopsaModelAccess += (sender, e) => { server.ExecuteBeforeWoopsaModelAccess(); }; _subscriptionServiceImplementation.AfterWoopsaModelAccess += (sender, e) => { server.ExecuteAfterWoopsaModelAccess(); }; MethodCreateSubscriptionChannel = new WoopsaMethod( this, WoopsaSubscriptionServiceConst.WoopsaCreateSubscriptionChannel, WoopsaValueType.Integer, new WoopsaMethodArgumentInfo[] { new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaNotificationQueueSize, WoopsaValueType.Integer) }, arguments => _subscriptionServiceImplementation.CreateSubscriptionChannel(arguments[0].ToInt32()) ); MethodRegisterSubscription = new WoopsaMethod( this, WoopsaSubscriptionServiceConst.WoopsaRegisterSubscription, WoopsaValueType.Integer, new WoopsaMethodArgumentInfo[] { new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaSubscriptionChannel, WoopsaValueType.Integer), new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaPropertyLink, WoopsaValueType.WoopsaLink), new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaMonitorInterval, WoopsaValueType.TimeSpan), new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaPublishInterval, WoopsaValueType.TimeSpan) }, arguments => { return _subscriptionServiceImplementation.RegisterSubscription( arguments[0].ToInt32(), arguments[1].DecodeWoopsaLocalLink(), arguments[2].ToTimeSpan(), arguments[3].ToTimeSpan()); }); MethodUnregisterSubscription = new WoopsaMethod( this, WoopsaSubscriptionServiceConst.WoopsaUnregisterSubscription, WoopsaValueType.Logical, new WoopsaMethodArgumentInfo[] { new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaSubscriptionChannel, WoopsaValueType.Integer), new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaSubscriptionId, WoopsaValueType.Integer) }, arguments => { return _subscriptionServiceImplementation.UnregisterSubscription( arguments[0].ToInt32(), arguments[1].ToInt32()); }); MethodWaitNotification = new WoopsaMethod( this, WoopsaSubscriptionServiceConst.WoopsaWaitNotification, WoopsaValueType.JsonData, new WoopsaMethodArgumentInfo[] { new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaSubscriptionChannel, WoopsaValueType.Integer), new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaLastNotificationId, WoopsaValueType.Integer) }, arguments => { using (var accessFreeSection = _server.EnterModelAccessFreeSection()) return new WoopsaValue(_subscriptionServiceImplementation.WaitNotification( arguments[0].ToInt32(), arguments[1].ToInt32())); }); }
protected override void Dispose(bool disposing) { base.Dispose(disposing); if (disposing) { if (_subscriptionServiceImplementation != null) { _subscriptionServiceImplementation.Dispose(); _subscriptionServiceImplementation = null; } } }
public WoopsaSubscriptionService(WoopsaServer server, WoopsaContainer container) : base(container, WoopsaSubscriptionServiceConst.WoopsaServiceSubscriptionName) { _server = server; _subscriptionServiceImplementation = new WoopsaSubscriptionServiceImplementation(container, true); _subscriptionServiceImplementation.BeforeWoopsaModelAccess += (sender, e) => { server.ExecuteBeforeWoopsaModelAccess(); }; _subscriptionServiceImplementation.AfterWoopsaModelAccess += (sender, e) => { server.ExecuteAfterWoopsaModelAccess(); }; _subscriptionServiceImplementation.CanWatch += OnCanReconnectSubscriptionToNewObject; MethodCreateSubscriptionChannel = new WoopsaMethod( this, WoopsaSubscriptionServiceConst.WoopsaCreateSubscriptionChannel, WoopsaValueType.Integer, new WoopsaMethodArgumentInfo[] { new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaNotificationQueueSize, WoopsaValueType.Integer) }, arguments => _subscriptionServiceImplementation.CreateSubscriptionChannel(arguments[0].ToInt32()) ); MethodRegisterSubscription = new WoopsaMethod( this, WoopsaSubscriptionServiceConst.WoopsaRegisterSubscription, WoopsaValueType.Integer, new WoopsaMethodArgumentInfo[] { new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaSubscriptionChannel, WoopsaValueType.Integer), new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaPropertyLink, WoopsaValueType.WoopsaLink), new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaMonitorInterval, WoopsaValueType.TimeSpan), new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaPublishInterval, WoopsaValueType.TimeSpan) }, arguments => { return(_subscriptionServiceImplementation.RegisterSubscription( arguments[0].ToInt32(), arguments[1].DecodeWoopsaLocalLink(), arguments[2].ToTimeSpan(), arguments[3].ToTimeSpan())); }); MethodUnregisterSubscription = new WoopsaMethod( this, WoopsaSubscriptionServiceConst.WoopsaUnregisterSubscription, WoopsaValueType.Logical, new WoopsaMethodArgumentInfo[] { new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaSubscriptionChannel, WoopsaValueType.Integer), new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaSubscriptionId, WoopsaValueType.Integer) }, arguments => { return(_subscriptionServiceImplementation.UnregisterSubscription( arguments[0].ToInt32(), arguments[1].ToInt32())); }); MethodWaitNotification = new WoopsaMethod( this, WoopsaSubscriptionServiceConst.WoopsaWaitNotification, WoopsaValueType.JsonData, new WoopsaMethodArgumentInfo[] { new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaSubscriptionChannel, WoopsaValueType.Integer), new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaLastNotificationId, WoopsaValueType.Integer) }, arguments => { using (var accessFreeSection = _server.EnterModelAccessFreeSection()) return(new WoopsaValue(_subscriptionServiceImplementation.WaitNotification( arguments[0].ToInt32(), arguments[1].ToInt32()))); }); }
private void OpenChannel() { lock (_channelLock) { try { _subscriptionOpenChannel = CreateSubscriptionChannel(_notificationQueueSize); } catch (WoopsaNotFoundException) { // No subscription service available, create a local one _localSubscriptionService = new WoopsaSubscriptionServiceImplementation(_woopsaRoot, false); try { _subscriptionOpenChannel = CreateSubscriptionChannel(_notificationQueueSize); //TODO : détecter la perte de connection du service de souscription et fermer le canal } catch { _localSubscriptionService.Dispose(); throw; } } } }
private void CloseChannel() { lock (_channelLock) { if (_localSubscriptionService != null) { _localSubscriptionService.Dispose(); _localSubscriptionService = null; } _subscriptionOpenChannel = null; _lastNotificationId = 0; foreach (var item in _subscriptions) item.SubscriptionId = null; SubscriptionsChanged = true; } }