Пример #1
0
        /// <summary>
        /// BeginShutdown initiates the termination of the Acd Agent Match Maker.
        /// </summary>
        internal IAsyncResult BeginShutdown(AsyncCallback callback, object state)
        {
            ShutdownAsyncResult asyncResult = new ShutdownAsyncResult(callback, state, this);

            bool firstTime = false;

            lock (_syncRoot)
            {
                if (_matchMakerState < MatchMakerState.Terminating)
                {
                    firstTime = true;
                    this.UpdateState(MatchMakerState.Terminating);
                }
                else if (_matchMakerState == MatchMakerState.Terminating)
                {
                    _listOfShutdownAsyncResults.Add(asyncResult);
                }
                else if (_matchMakerState == MatchMakerState.Terminated)
                {
                    asyncResult.SetAsCompleted(null, true);
                }
            }

            if (true == firstTime)
            {
                ThreadPool.QueueUserWorkItem((waitState) =>
                {
                    var tempAr = waitState as ShutdownAsyncResult;
                    tempAr.Process();
                }, asyncResult);
            }

            return(asyncResult);
        }
Пример #2
0
        /// <summary>
        /// Initiates the portal shutdown.
        /// </summary>
        internal IAsyncResult BeginShutdown(AsyncCallback userCallback, object state)
        {
            var shutdownAsyncResult = new ShutdownAsyncResult(userCallback, state, this);

            lock (_syncRoot)
            {
                if (_portalState < PortalState.Draining)
                {
                    _logger.Log(String.Format("AcdPortal:AcdPortal {0} is draining.", this.Uri));


                    //Entering Draining and setting the endpoint Draining Mode.

                    try
                    {
                        _endpoint.BeginDrain(sd =>
                        {
                            _endpoint.EndDrain(sd);
                        },
                                             null);
                    }
                    catch (InvalidOperationException ivoex)
                    {
                        _logger.Log("AcdPortal: the endpoint is not in the right state for draining.", ivoex);
                    }
                    this.UpdatePortalState(PortalState.Draining);

                    //verify if there is anything to drain
                    if (_sessions.Count == 0)
                    {
                        //process the async result right away
                        ThreadPool.QueueUserWorkItem((waitState) =>
                        {
                            var tempAr = waitState as ShutdownAsyncResult;
                            tempAr.Process();
                        }, shutdownAsyncResult);
                    }

                    _shutdownAsyncResult = shutdownAsyncResult;
                }
                else if (_portalState == PortalState.Terminated)
                {
                    //completes the request synchronously
                    shutdownAsyncResult.SetAsCompleted(null, true);
                }
                else if (_portalState == PortalState.Draining || _portalState == PortalState.Terminating)
                {
                    _listOfShutdownAsyncResults.Add(shutdownAsyncResult);
                }
            }
            return(shutdownAsyncResult);
        }
Пример #3
0
		internal IAsyncResult BeginShutdown (AsyncCallback asyncCallback, object asyncState)
		{
			var shutdownResult = new ShutdownAsyncResult (this, asyncState, asyncCallback);

			if (Interlocked.CompareExchange (ref _SentShutdown, 1, 0) == 1) {
				shutdownResult.InvokeCallback ();
				return shutdownResult;
			}

			try
			{
				CheckThrow (false);
				shutdownResult.SentShutdown = true;
				SecureStream.BeginShutdown (shutdownResult);
				return shutdownResult;
			} catch (Exception e) {
				if (e is IOException)
					throw;
				throw new IOException (SR.GetString (SR.mono_net_io_shutdown), e);
			}
		}
Пример #4
0
        internal IAsyncResult BeginShutdown(AsyncCallback asyncCallback, object asyncState)
        {
            var shutdownResult = new ShutdownAsyncResult(this, asyncState, asyncCallback);

            if (Interlocked.CompareExchange(ref _SentShutdown, 1, 0) == 1)
            {
                shutdownResult.InvokeCallback();
                return(shutdownResult);
            }

            try
            {
                CheckThrow(false);
                shutdownResult.SentShutdown = true;
                SecureStream.BeginShutdown(shutdownResult);
                return(shutdownResult);
            } catch (Exception e) {
                if (e is IOException)
                {
                    throw;
                }
                throw new IOException(SR.GetString(SR.mono_net_io_shutdown), e);
            }
        }
Пример #5
0
        public IAsyncResult BeginShutdown(AsyncCallback userCallBack, object state)
        {
            var  asyncResult = new ShutdownAsyncResult(userCallBack, state, this);
            bool firstTime   = false;

            lock (_syncRoot)
            {
                if (_acdPlatformState < AcdPlatformState.Terminating)
                {
                    this.UpdateAcdPlatformState(AcdPlatformState.Terminating);
                    firstTime = true;
                }
                else if (_acdPlatformState == AcdPlatformState.Terminating)
                {
                    _listOfShutdownAsyncResults.Add(asyncResult);
                }
                else if (_acdPlatformState == AcdPlatformState.Terminated)
                {
                    asyncResult.SetAsCompleted(null, true);
                    return(asyncResult);
                }
            }

            if (firstTime == true)
            {
                UnregisterForPlatformAutoProvisioningEvents();

                ThreadPool.QueueUserWorkItem((waitState) =>
                {
                    var tempAr = waitState as ShutdownAsyncResult;
                    tempAr.Process();
                }, asyncResult);
            }

            return(asyncResult);
        }
Пример #6
0
        internal void EndShutdown(IAsyncResult result)
        {
            ShutdownAsyncResult asyncResult = result as ShutdownAsyncResult;

            asyncResult.EndInvoke();
        }