Пример #1
0
        private void StartMonitorThreads()
        {
            lock (monitor)
            {
                if (monitorStarted.Value || maxInactivityDuration == 0)
                {
                    return;
                }

                Tracer.DebugFormat("Inactivity: Write Check time interval: {0}", maxInactivityDuration);
                Tracer.DebugFormat("Inactivity: Initial Delay time interval: {0}", maxInactivityDurationInitialDelay);

                this.asyncWriteTask = new AsyncWriteTask(this);
                this.asyncTask      = new DedicatedTaskRunner(this.asyncWriteTask);

                monitorStarted.Value = true;

                this.connectionCheckTimer = new Timer(
                    new TimerCallback(WriteCheck),
                    null,
                    maxInactivityDurationInitialDelay,
                    maxInactivityDuration
                    );
            }
        }
        private void StopMonitorThreads()
        {
            lock (monitor)
            {
                if (monitorStarted.CompareAndSet(true, false))
                {
                    AutoResetEvent shutdownEvent = new AutoResetEvent(false);

                    // Attempt to wait for the Timer to shutdown, but don't wait
                    // forever, if they don't shutdown after two seconds, just quit.
                    this.connectionCheckTimer.Dispose(shutdownEvent);
                    if (!shutdownEvent.WaitOne(TimeSpan.FromMilliseconds(3000), false))
                    {
                        Tracer.WarnFormat("InactivityMonitor[{0}]: Timer Task didn't shutdown properly.", instanceId);
                    }

                    this.asyncTasks.RemoveTask(this.asyncWriteTask);
                    this.asyncTasks.RemoveTask(this.asyncErrorTask);

                    this.asyncTasks.Shutdown();
                    this.asyncTasks           = null;
                    this.asyncWriteTask       = null;
                    this.asyncErrorTask       = null;
                    this.connectionCheckTimer = null;
                }
            }

            Tracer.DebugFormat("InactivityMonitor[{0}]: Stopped Monitor Threads.", instanceId);
        }
        private void StartMonitorThreads()
        {
            lock (monitor)
            {
                if (monitorStarted.Value)
                {
                    return;
                }

                if (localWireFormatInfo == null)
                {
                    return;
                }

                if (remoteWireFormatInfo == null)
                {
                    return;
                }

                readCheckTime =
                    Math.Min(
                        localWireFormatInfo.MaxInactivityDuration,
                        remoteWireFormatInfo.MaxInactivityDuration);
                initialDelayTime =
                    Math.Min(
                        localWireFormatInfo.MaxInactivityDurationInitialDelay,
                        remoteWireFormatInfo.MaxInactivityDurationInitialDelay);

                this.asyncTasks = new CompositeTaskRunner();

                this.asyncErrorTask = new AsyncSignalReadErrorkTask(this, next.RemoteAddress);
                this.asyncWriteTask = new AsyncWriteTask(this);

                this.asyncTasks.AddTask(this.asyncErrorTask);
                this.asyncTasks.AddTask(this.asyncWriteTask);

                if (readCheckTime > 0)
                {
                    monitorStarted.Value = true;

                    writeCheckTime = readCheckTime > 3 ? readCheckTime / 3 : readCheckTime;

                    writeCheckTimer = new Timer(
                        new TimerCallback(WriteCheck),
                        null,
                        initialDelayTime,
                        writeCheckTime
                        );
                    readCheckTimer = new Timer(
                        new TimerCallback(ReadCheck),
                        null,
                        initialDelayTime,
                        readCheckTime
                        );
                }
            }
        }
Пример #4
0
        private void StopMonitorThreads()
        {
            lock (monitor)
            {
                if (monitorStarted.CompareAndSet(true, false))
                {
                    // Attempt to wait for the Timer to shutdown, but don't wait
                    // forever, if they don't shutdown after two seconds, just quit.
                    ThreadUtil.DisposeTimer(connectionCheckTimer, 2000);

                    this.asyncTask.Shutdown();
                    this.asyncTask      = null;
                    this.asyncWriteTask = null;
                }
            }
        }
Пример #5
0
        private void StopMonitorThreads()
        {
            lock (monitor)
            {
                if (monitorStarted.CompareAndSet(true, false))
                {
                    AutoResetEvent shutdownEvent = new AutoResetEvent(false);

                    // Attempt to wait for the Timer to shutdown, but don't wait
                    // forever, if they don't shutdown after two seconds, just quit.
                    this.connectionCheckTimer.Dispose(shutdownEvent);
                    shutdownEvent.WaitOne(TimeSpan.FromMilliseconds(2000), false);

                    this.asyncTasks.Shutdown();
                    this.asyncTasks     = null;
                    this.asyncWriteTask = null;
                    this.asyncErrorTask = null;
                }
            }
        }
Пример #6
0
        private void StartMonitorThreads()
        {
            lock (monitor)
            {
                if (this.IsDisposed || this.disposing)
                {
                    return;
                }

                if (monitorStarted.Value)
                {
                    return;
                }

                if (localWireFormatInfo == null)
                {
                    return;
                }

                if (remoteWireFormatInfo == null)
                {
                    return;
                }

                readCheckTime =
                    Math.Min(
                        localWireFormatInfo.MaxInactivityDuration,
                        remoteWireFormatInfo.MaxInactivityDuration);
                initialDelayTime = remoteWireFormatInfo.MaxInactivityDurationInitialDelay > 0 ?
                                   Math.Min(localWireFormatInfo.MaxInactivityDurationInitialDelay,
                                            remoteWireFormatInfo.MaxInactivityDurationInitialDelay) :
                                   localWireFormatInfo.MaxInactivityDurationInitialDelay;

                if (readCheckTime > 0)
                {
                    Tracer.DebugFormat("InactivityMonitor[{0}]: Read Check time interval: {1}",
                                       instanceId, readCheckTime);
                    Tracer.DebugFormat("InactivityMonitor[{0}]: Initial Delay time interval: {1}",
                                       instanceId, initialDelayTime);

                    monitorStarted.Value = true;
                    this.asyncTasks      = new CompositeTaskRunner("InactivityMonitor[" + instanceId + "].Runner");

                    this.asyncErrorTask = new AsyncSignalReadErrorkTask(this, next.RemoteAddress);
                    this.asyncWriteTask = new AsyncWriteTask(this);

                    this.asyncTasks.AddTask(this.asyncErrorTask);
                    this.asyncTasks.AddTask(this.asyncWriteTask);

                    writeCheckTime = readCheckTime > 3 ? readCheckTime / 3 : readCheckTime;

                    Tracer.DebugFormat("InactivityMonitor[{0}]: Write Check time interval: {1}",
                                       instanceId, writeCheckTime);

                    this.connectionCheckTimer = new Timer(
                        new TimerCallback(CheckConnection),
                        null,
                        initialDelayTime,
                        writeCheckTime
                        );
                }
            }
        }
Пример #7
0
        private void StartMonitorThreads()
        {
            lock (monitor)
            {
                if (this.IsDisposed || this.disposing)
                {
                    return;
                }

                if (monitorStarted.Value)
                {
                    return;
                }

                if (localWireFormatInfo == null)
                {
                    return;
                }

                if (remoteWireFormatInfo == null)
                {
                    return;
                }

                if (localWireFormatInfo.MaxInactivityDuration != 0 &&
                    remoteWireFormatInfo.WriteCheckInterval != 0)
                {
                    readCheckTime =
                        Math.Max(
                            localWireFormatInfo.ReadCheckInterval,
                            remoteWireFormatInfo.WriteCheckInterval);

                    this.asyncErrorTask = new AsyncSignalReadErrorkTask(this, next.RemoteAddress);
                }

                if (localWireFormatInfo.MaxInactivityDuration != 0)
                {
                    if (remoteWireFormatInfo.Version > 1.0)
                    {
                        writeCheckTime =
                            Math.Max(localWireFormatInfo.WriteCheckInterval,
                                     remoteWireFormatInfo.ReadCheckInterval);
                    }
                    else
                    {
                        writeCheckTime = localWireFormatInfo.MaxInactivityDuration;
                    }

                    this.asyncWriteTask = new AsyncWriteTask(this);
                }

                initialDelayTime = localWireFormatInfo.MaxInactivityDurationInitialDelay > 0 ?
                                   localWireFormatInfo.MaxInactivityDurationInitialDelay : writeCheckTime;

                Tracer.DebugFormat("InactivityMonitor[{0}]: Read Check time interval: {1}",
                                   instanceId, readCheckTime);
                Tracer.DebugFormat("InactivityMonitor[{0}]: Initial Delay time interval: {1}",
                                   instanceId, initialDelayTime);

                this.asyncTasks = new CompositeTaskRunner();

                if (this.asyncErrorTask != null)
                {
                    Tracer.DebugFormat("InactivityMonitor[{0}]: Adding the Async Read Check Task to the Runner.", instanceId);
                    this.asyncTasks.AddTask(this.asyncErrorTask);
                }

                if (this.asyncWriteTask != null)
                {
                    Tracer.DebugFormat("InactivityMonitor[{0}]: Write Check time interval: {1}",
                                       instanceId, writeCheckTime);
                    this.asyncTasks.AddTask(this.asyncWriteTask);
                }

                if (this.asyncErrorTask != null || this.asyncWriteTask != null)
                {
                    Tracer.DebugFormat("InactivityMonitor[{0}]: Starting the Monitor Timer.", instanceId);
                    monitorStarted.Value = true;

                    this.connectionCheckTimer = new Timer(
                        new TimerCallback(CheckConnection),
                        null,
                        initialDelayTime,
                        writeCheckTime
                        );
                }
            }
        }
Пример #8
0
		private void StopMonitorThreads()
		{
			lock(monitor)
			{
				if(monitorStarted.CompareAndSet(true, false))
				{
					AutoResetEvent shutdownEvent = new AutoResetEvent(false);

					if(null != connectionCheckTimer)
					{
						// Attempt to wait for the Timer to shutdown, but don't wait
						// forever, if they don't shutdown after two seconds, just quit.
						this.connectionCheckTimer.Dispose(shutdownEvent);
						if(!shutdownEvent.WaitOne(TimeSpan.FromMilliseconds(3000), false))
						{
							Tracer.WarnFormat("InactivityMonitor[{0}]: Timer Task didn't shutdown properly.", instanceId);
						}

						this.connectionCheckTimer = null;
					}

					if(null != this.asyncTasks)
					{
						this.asyncTasks.RemoveTask(this.asyncWriteTask);
						this.asyncTasks.RemoveTask(this.asyncErrorTask);

						this.asyncTasks.Shutdown();
						this.asyncTasks = null;
					}

					this.asyncWriteTask = null;
					this.asyncErrorTask = null;
				}
			}

			Tracer.DebugFormat("InactivityMonitor[{0}]: Stopped Monitor Threads.", instanceId);
		}
Пример #9
0
		private void StartMonitorThreads()
		{
			lock(monitor)
			{
				if(this.IsDisposed || this.disposing)
				{
					return;
				}

				if(monitorStarted.Value)
				{
					return;
				}

				if(localWireFormatInfo == null)
				{
					return;
				}

				if(remoteWireFormatInfo == null)
				{
					return;
				}

				readCheckTime =
					Math.Min(
						localWireFormatInfo.MaxInactivityDuration,
						remoteWireFormatInfo.MaxInactivityDuration);
				initialDelayTime = remoteWireFormatInfo.MaxInactivityDurationInitialDelay > 0 ?
					Math.Min(localWireFormatInfo.MaxInactivityDurationInitialDelay,
						     remoteWireFormatInfo.MaxInactivityDurationInitialDelay) :
                    localWireFormatInfo.MaxInactivityDurationInitialDelay;

				if(readCheckTime > 0)
				{
					Tracer.DebugFormat("InactivityMonitor[{0}]: Read Check time interval: {1}",
								   instanceId, readCheckTime);
					Tracer.DebugFormat("InactivityMonitor[{0}]: Initial Delay time interval: {1}",
									   instanceId, initialDelayTime);

					monitorStarted.Value = true;
					this.asyncTasks = new CompositeTaskRunner("InactivityMonitor[" + instanceId + "].Runner");

					this.asyncErrorTask = new AsyncSignalReadErrorkTask(this, next.RemoteAddress);
					this.asyncWriteTask = new AsyncWriteTask(this);

					this.asyncTasks.AddTask(this.asyncErrorTask);
					this.asyncTasks.AddTask(this.asyncWriteTask);

					writeCheckTime = readCheckTime > 3 ? readCheckTime / 3 : readCheckTime;

					Tracer.DebugFormat("InactivityMonitor[{0}]: Write Check time interval: {1}",
									   instanceId, writeCheckTime);

					this.connectionCheckTimer = new Timer(
						new TimerCallback(CheckConnection),
						null,
						initialDelayTime,
						writeCheckTime
						);
				}
			}
		}