Example #1
0
        protected override void OnApplicationPoolAllQueueInstancesStopped(string appPoolId, int queueId)
        {
            Debug.Print("ListenerAdapter[" + ProtocolName + "]::OnApplicationPoolAllQueueInstancesStopped(" + appPoolId + ", " + queueId + ")");

            if (!isOpen)
            {
                if (closingProcessStatus != ClosingProcessBlocked)
                {
                    // OnConfigManagerDisconnected was already called. We should just return.
                    return;
                }
            }

            try
            {
                AppPool appPool = null;
                lock (appManager)
                {
                    if (!appManager.AppPools.TryGetValue(appPoolId, out appPool))
                    {
                        // Ignore this notification if we received OnApplicationPoolDeleted.
                        return;
                    }
                }

                IActivatedMessageQueue queue = activationService.FindQueue(queueId);
                if (queue == null)
                {
                    // This is the belated notification. Ignore it.
                    return;
                }

                Fx.Assert(queue.App.AppPool.AppPoolId == appPoolId, "OnApplicationPoolAllQueueInstancesStopped: unexpected pool id");
                queue.OnQueueInstancesStopped();

                App app = queue.App;

                try
                {
                    if (app.PendingAction.ActionType == AppActionType.Deleted)
                    {
                        CompleteDeleteApp(app);
                        SignalCleanupForNoApps();
                    }
                    else if (app.PendingAction.ActionType == AppActionType.SettingsChanged)
                    {
                        CompleteAppSettingsChanged(app);
                    }
                }
                finally
                {
                    // Reset the action
                    app.SetPendingAction(null);
                }
            }
            catch (Exception exception)
            {
                HandleUnknownError(exception);
            }
        }
Example #2
0
        void OnLaunchQueueInstance(object state)
        {
            IActivatedMessageQueue queue = state as IActivatedMessageQueue;

            Fx.Assert(queue != null, "OnLaunchQueueInstance: queue is null");

            queue.LaunchQueueInstance();
        }
Example #3
0
File: App.cs Project: JianwenSun/cc
 internal void RegisterQueue(IActivatedMessageQueue messageQueue)
 {
     if (this.messageQueue != null)
     {
         throw Fx.AssertAndThrow("a message queue was already registered");
     }
     this.messageQueue = messageQueue;
 }
 internal void RegisterQueue(IActivatedMessageQueue messageQueue)
 {
     if (this.messageQueue != null)
     {
         throw Fx.AssertAndThrow("a message queue was already registered");
     }
     this.messageQueue = messageQueue;
 }
Example #5
0
        void ScheduleLaunchingQueueInstance(IActivatedMessageQueue queue)
        {
            if (launchQueueInstanceCallback == null)
            {
                launchQueueInstanceCallback = new Action <object>(OnLaunchQueueInstance);
            }

            ActionItem.Schedule(launchQueueInstanceCallback, queue);
        }
Example #6
0
        void CompleteAppCreation(App app, string[] bindings)
        {
            IActivatedMessageQueue queue = activationService.CreateQueue(this, app);

            app.RegisterQueue(queue);

            bool success = RegisterBindings(app.MessageQueue, app.SiteId, bindings, app.Path);

            app.OnInvalidBinding(!success);
        }
Example #7
0
        protected override void OnApplicationPoolCanLaunchQueueInstance(string appPoolId, int queueId)
        {
            Debug.Print("ListenerAdapter[" + ProtocolName + "]::OnApplicationPoolCanLaunchQueueInstance(" + appPoolId + ", " + queueId + ")");

            try
            {
                IActivatedMessageQueue queue = activationService.FindQueue(queueId);
                if (queue != null)
                {
                    if (queue.App.AppPool.AppPoolId != appPoolId)
                    {
                        throw Fx.AssertAndThrow("OnApplicationPoolCanLaunchQueueInstance: unexpected pool id");
                    }

                    ScheduleLaunchingQueueInstance(queue);
                }
            }
            catch (Exception exception)
            {
                HandleUnknownError(exception);
            }
        }
Example #8
0
        internal bool OpenListenerChannelInstance(IActivatedMessageQueue queue)
        {
            byte[] queueBlob = queue.ListenerChannelContext.Dehydrate();
            Debug.Print("ListenerAdapter[" + ProtocolName + "]::ListenerAdapter.OpenListenerChannelInstance(appPoolId:" + queue.App.AppPool.AppPoolId + " appKey:" + queue.ListenerChannelContext.AppKey + " queueId:" + queue.ListenerChannelContext.ListenerChannelId + ")");
            int hresult = OpenListenerChannelInstance(queue.App.AppPool.AppPoolId, queue.ListenerChannelContext.ListenerChannelId, queueBlob);

            if (hresult != 0)
            {
                if (DiagnosticUtility.ShouldTraceError)
                {
                    ListenerTraceUtility.TraceEvent(TraceEventType.Error, ListenerTraceCode.WasWebHostAPIFailed, SR.GetString(SR.TraceCodeWasWebHostAPIFailed),
                                                    new StringTraceRecord("HRESULT", SR.GetString(SR.TraceCodeWasWebHostAPIFailed,
                                                                                                  "WebhostOpenListenerChannelInstance", hresult.ToString(CultureInfo.CurrentCulture))), this, null);
                }
                if (TD.OpenListenerChannelInstanceFailedIsEnabled())
                {
                    TD.OpenListenerChannelInstanceFailed(this.EventTraceActivity, hresult.ToString(CultureInfo.CurrentCulture));
                }

                return(false);
            }

            return(true);
        }
        void ScheduleLaunchingQueueInstance(IActivatedMessageQueue queue)
        {
            if (launchQueueInstanceCallback == null)
            {
                launchQueueInstanceCallback = new Action<object>(OnLaunchQueueInstance);
            }

            ActionItem.Schedule(launchQueueInstanceCallback, queue);
        }
        internal bool OpenListenerChannelInstance(IActivatedMessageQueue queue)
        {
            byte[] queueBlob = queue.ListenerChannelContext.Dehydrate();
            Debug.Print("ListenerAdapter[" + ProtocolName + "]::ListenerAdapter.OpenListenerChannelInstance(appPoolId:" + queue.App.AppPool.AppPoolId + " appKey:" + queue.ListenerChannelContext.AppKey + " queueId:" + queue.ListenerChannelContext.ListenerChannelId + ")");
            int hresult = OpenListenerChannelInstance(queue.App.AppPool.AppPoolId, queue.ListenerChannelContext.ListenerChannelId, queueBlob);
            if (hresult != 0)
            {
                if (DiagnosticUtility.ShouldTraceError)
                {
                    ListenerTraceUtility.TraceEvent(TraceEventType.Error, ListenerTraceCode.WasWebHostAPIFailed, SR.GetString(SR.TraceCodeWasWebHostAPIFailed),
                        new StringTraceRecord("HRESULT", SR.GetString(SR.TraceCodeWasWebHostAPIFailed,
                        "WebhostOpenListenerChannelInstance", hresult.ToString(CultureInfo.CurrentCulture))), this, null);
                }
                if (TD.OpenListenerChannelInstanceFailedIsEnabled())
                {
                    TD.OpenListenerChannelInstanceFailed(this.EventTraceActivity, hresult.ToString(CultureInfo.CurrentCulture));
                }

                return false;
            }

            return true;
        }
        bool RegisterBindings(IActivatedMessageQueue queue, int siteId, string[] bindings, string path)
        {
            Debug.Print("ListenerAdapter[" + ProtocolName + "]::RegisterBindings() bindings#: " + bindings.Length);
            BaseUriWithWildcard[] baseAddresses = new BaseUriWithWildcard[bindings.Length];
            // first make sure all the bindings are valid for this protocol
            for (int i = 0; i < bindings.Length; i++)
            {
                string binding = bindings[i];
                int index = binding.IndexOf(':');
                string protocol = binding.Substring(0, index);
                if (string.Compare(this.ProtocolName, protocol, StringComparison.OrdinalIgnoreCase) != 0)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                        SR.GetString(SR.LAProtocolMismatch, protocol, path, this.ProtocolName)));
                }

                binding = binding.Substring(index + 1);
                try
                {
                    baseAddresses[i] = BaseUriWithWildcard.CreateHostedUri(ProtocolName, binding, path);
                    Debug.Print("ListenerAdapter[" + ProtocolName + "]::RegisterBindings() CreateUrlFromBinding(binding: " + binding + " path: " + path + ") returned baseAddress: " + baseAddresses[i]);
                }
                catch (UriFormatException exception)
                {
                    Debug.Print("ListenerAdapter[" + ProtocolName + "]::RegisterBindings() CreateUrlFromBinding(binding: " + binding + " path: " + path + ") failed with UriFormatException: " + exception.Message);
                    DiagnosticUtility.TraceHandledException(exception, TraceEventType.Error);

                    // We only log the event for the site root.
                    if (string.Compare(path, SiteRootPath, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error,
                            (ushort)EventLogCategory.ListenerAdapter,
                            (uint)EventLogEventId.BindingError,
                            protocol,
                            binding,
                            siteId.ToString(NumberFormatInfo.CurrentInfo),
                            bindings[i],
                            ListenerTraceUtility.CreateSourceString(this),
                            exception.ToString());
                    }

                    return false;
                }
            }

            // now make sure all the bindings can be listened on or roll back
            for (int i = 0; i < bindings.Length; i++)
            {
                ListenerExceptionStatus status = ListenerExceptionStatus.FailedToListen;
                Exception exception = null;
                try
                {
                    status = queue.Register(baseAddresses[i]);
                    Debug.Print("ListenerAdapter[" + ProtocolName + "]::RegisterBindings() registering baseAddress: " + baseAddresses[i] + " with queue returned: " + status);
                }
                catch (Exception ex)
                {
                    if (Fx.IsFatal(ex))
                    {
                        throw;
                    }

                    DiagnosticUtility.TraceHandledException(exception, TraceEventType.Error);

                    exception = ex;
                }

                if (status != ListenerExceptionStatus.Success)
                {
                    // We only log the event for the site root.
                    if (string.Compare(path, SiteRootPath, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error,
                            (ushort)EventLogCategory.ListenerAdapter,
                            (uint)EventLogEventId.LAFailedToListenForApp,
                            activationService.ActivationServiceName,
                            ProtocolName,
                            siteId.ToString(NumberFormatInfo.CurrentInfo),
                            baseAddresses[i].ToString(),
                            status.ToString(),
                            exception == null ? string.Empty : exception.ToString());
                    }

                    queue.UnregisterAll();
                    return false;
                }
            }

            return true;
        }
Example #12
0
        bool RegisterBindings(IActivatedMessageQueue queue, int siteId, string[] bindings, string path)
        {
            Debug.Print("ListenerAdapter[" + ProtocolName + "]::RegisterBindings() bindings#: " + bindings.Length);
            BaseUriWithWildcard[] baseAddresses = new BaseUriWithWildcard[bindings.Length];
            // first make sure all the bindings are valid for this protocol
            for (int i = 0; i < bindings.Length; i++)
            {
                string binding  = bindings[i];
                int    index    = binding.IndexOf(':');
                string protocol = binding.Substring(0, index);
                if (string.Compare(this.ProtocolName, protocol, StringComparison.OrdinalIgnoreCase) != 0)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                                                                                  SR.GetString(SR.LAProtocolMismatch, protocol, path, this.ProtocolName)));
                }

                binding = binding.Substring(index + 1);
                try
                {
                    baseAddresses[i] = BaseUriWithWildcard.CreateHostedUri(ProtocolName, binding, path);
                    Debug.Print("ListenerAdapter[" + ProtocolName + "]::RegisterBindings() CreateUrlFromBinding(binding: " + binding + " path: " + path + ") returned baseAddress: " + baseAddresses[i]);
                }
                catch (UriFormatException exception)
                {
                    Debug.Print("ListenerAdapter[" + ProtocolName + "]::RegisterBindings() CreateUrlFromBinding(binding: " + binding + " path: " + path + ") failed with UriFormatException: " + exception.Message);
                    DiagnosticUtility.TraceHandledException(exception, TraceEventType.Error);

                    // We only log the event for the site root.
                    if (string.Compare(path, SiteRootPath, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error,
                                                            (ushort)EventLogCategory.ListenerAdapter,
                                                            (uint)EventLogEventId.BindingError,
                                                            protocol,
                                                            binding,
                                                            siteId.ToString(NumberFormatInfo.CurrentInfo),
                                                            bindings[i],
                                                            ListenerTraceUtility.CreateSourceString(this),
                                                            exception.ToString());
                    }

                    return(false);
                }
            }

            // now make sure all the bindings can be listened on or roll back
            for (int i = 0; i < bindings.Length; i++)
            {
                ListenerExceptionStatus status = ListenerExceptionStatus.FailedToListen;
                Exception exception            = null;
                try
                {
                    status = queue.Register(baseAddresses[i]);
                    Debug.Print("ListenerAdapter[" + ProtocolName + "]::RegisterBindings() registering baseAddress: " + baseAddresses[i] + " with queue returned: " + status);
                }
                catch (Exception ex)
                {
                    if (Fx.IsFatal(ex))
                    {
                        throw;
                    }

                    DiagnosticUtility.TraceHandledException(exception, TraceEventType.Error);

                    exception = ex;
                }

                if (status != ListenerExceptionStatus.Success)
                {
                    // We only log the event for the site root.
                    if (string.Compare(path, SiteRootPath, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error,
                                                            (ushort)EventLogCategory.ListenerAdapter,
                                                            (uint)EventLogEventId.LAFailedToListenForApp,
                                                            activationService.ActivationServiceName,
                                                            ProtocolName,
                                                            siteId.ToString(NumberFormatInfo.CurrentInfo),
                                                            baseAddresses[i].ToString(),
                                                            status.ToString(),
                                                            exception == null ? string.Empty : exception.ToString());
                    }

                    queue.UnregisterAll();
                    return(false);
                }
            }

            return(true);
        }