コード例 #1
0
 protected BaseWoopsaSubscriptionServiceSubscription(
     WoopsaSubscriptionChannel channel,
     WoopsaContainer root,
     int subscriptionId, string propertyPath,
     TimeSpan monitorInterval, TimeSpan publishInterval)
 {
     Channel = channel;
     Root = root;
     SubscriptionId = subscriptionId;
     MonitorInterval = monitorInterval;
     PublishInterval = publishInterval;
     PropertyPath = propertyPath;
     _lock = new object();
     _notifications = new List<IWoopsaNotification>();
     if (monitorInterval == WoopsaSubscriptionServiceConst.MonitorIntervalLastPublishedValueOnly &&
         publishInterval == WoopsaSubscriptionServiceConst.PublishIntervalOnce)
         DoPublish();
     else if (publishInterval > TimeSpan.FromMilliseconds(0))
     {
         _publishTimer = channel.ServiceImplementation.TimerScheduler.AllocateTimer(publishInterval);
         _publishTimer.Elapsed += _publishTimer_Elapsed;
         _publishTimer.IsEnabled = true;
     }
     else
         throw new WoopsaException("A publish interval of 0 with a non-zero monitor interval is not allowed");
 }
コード例 #2
0
        public LightWeightTimer AllocateTimer()
        {
            LightWeightTimer newTimer = new LightWeightTimer(this, _scheduler);

            lock (_timers)
                _timers.Add(newTimer);
            return(newTimer);
        }
コード例 #3
0
 internal void DeallocateTimer(LightWeightTimer timer, LightWeightTimerTimeClass timeClass)
 {
     lock (_timeClasses)
     {
         timeClass.DeallocateTimer(timer);
         if (timeClass.Count == 0)
         {
             _timeClasses.Remove(timeClass);
             _timeClassesByTimeSpan.Remove(timeClass.Interval);
         }
     }
 }
 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;
 }
コード例 #5
0
        internal void Execute()
        {
            if (_watch.Elapsed >= Interval)
            {
                _watch.Restart();
                int i = 0;

                LightWeightTimer timer = null;
                do
                {
                    lock (_timers)
                    {
                        if (i < _timers.Count)
                        {
                            timer = _timers[i];
                        }
                        else
                        {
                            timer = null;
                        }
                        i++;
                    }
                    if (timer != null)
                    {
                        try
                        {
                            timer.Execute();
                        }
                        catch (Exception)
                        {
                            // TODO : Define how to manage properly user code exceptions
                        }
                    }
                }while (timer != null);
            }
        }
コード例 #6
0
 public void DeallocateTimer(LightWeightTimer timer)
 {
     lock (_timers)
         _timers.Remove(timer);
 }
コード例 #7
0
 protected override void Dispose(bool disposing)
 {
     base.Dispose(disposing);
     if (disposing)
     {
         if (_monitorTimer != null)
         {
             _monitorTimer.Dispose();
             _monitorTimer = null;
         }
     }
 }
コード例 #8
0
 public WoopsaSubscriptionServiceSubscriptionMonitor(
     WoopsaSubscriptionChannel channel,
     WoopsaContainer root,
     int subscriptionId, string propertyPath,
     TimeSpan monitorInterval, TimeSpan publishInterval)
     : base(channel, root, subscriptionId, propertyPath, monitorInterval, publishInterval)
 {
     if (monitorInterval != WoopsaSubscriptionServiceConst.MonitorIntervalLastPublishedValueOnly)
     {
         // create monitor timer
         _monitorTimer = channel.ServiceImplementation.TimerScheduler.AllocateTimer(monitorInterval);
         _monitorTimer.Elapsed += _monitorTimer_Elapsed;
         _monitorTimer.IsEnabled = true;
     }
     // Force immediate publishing of the current value
     DoMonitor();
     DoPublish();
 }
コード例 #9
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (_publishTimer != null)
         {
             _publishTimer.Dispose();
             _publishTimer = null;
         }
     }
 }
コード例 #10
0
 public void DeallocateTimer(LightWeightTimer timer)
 {
     lock (_timers)
         _timers.Remove(timer);
 }
コード例 #11
0
 public LightWeightTimer AllocateTimer()
 {
     LightWeightTimer newTimer = new LightWeightTimer(this, _scheduler);
     lock (_timers)
         _timers.Add(newTimer);
     return newTimer;
 }
コード例 #12
0
 internal void DeallocateTimer(LightWeightTimer timer, LightWeightTimerTimeClass timeClass)
 {
     lock (_timeClasses)
     {
         timeClass.DeallocateTimer(timer);
         if (timeClass.Count == 0)
         {
             _timeClasses.Remove(timeClass);
             _timeClassesByTimeSpan.Remove(timeClass.Interval);
         }
     }
 }
コード例 #13
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (TimerScheduler!= null)
         {
             TimerScheduler.Dispose();
             TimerScheduler = null;
         }
         if (_timerCheckChannelTimedOut != null)
         {
             _timerCheckChannelTimedOut.Dispose();
             _timerCheckChannelTimedOut = null;
         }
         if (_channels != null)
         {
             foreach (var item in _channels.Values)
                 item.Dispose();
             _channels = null;
         }
     }
 }