internal IListenerChannelCallback MarshalComProxy(IListenerChannelCallback defaultDomainCallback) { IListenerChannelCallback objectForIUnknown = null; IntPtr iUnknownForObject = Marshal.GetIUnknownForObject(defaultDomainCallback); if (IntPtr.Zero == iUnknownForObject) { return(null); } IntPtr zero = IntPtr.Zero; try { Guid gUID = typeof(IListenerChannelCallback).GUID; int errorCode = Marshal.QueryInterface(iUnknownForObject, ref gUID, out zero); if (errorCode < 0) { Marshal.ThrowExceptionForHR(errorCode); } objectForIUnknown = (IListenerChannelCallback)Marshal.GetObjectForIUnknown(zero); } finally { if (IntPtr.Zero != zero) { Marshal.Release(zero); } if (IntPtr.Zero != iUnknownForObject) { Marshal.Release(iUnknownForObject); } } return(objectForIUnknown); }
internal IListenerChannelCallback MarshalComProxy(IListenerChannelCallback defaultDomainCallback) { IListenerChannelCallback objectForIUnknown = null; IntPtr iUnknownForObject = Marshal.GetIUnknownForObject(defaultDomainCallback); if (IntPtr.Zero == iUnknownForObject) { return null; } IntPtr zero = IntPtr.Zero; try { Guid gUID = typeof(IListenerChannelCallback).GUID; int errorCode = Marshal.QueryInterface(iUnknownForObject, ref gUID, out zero); if (errorCode < 0) { Marshal.ThrowExceptionForHR(errorCode); } objectForIUnknown = (IListenerChannelCallback) Marshal.GetObjectForIUnknown(zero); } finally { if (IntPtr.Zero != zero) { Marshal.Release(zero); } if (IntPtr.Zero != iUnknownForObject) { Marshal.Release(iUnknownForObject); } } return objectForIUnknown; }
public override void StartListenerChannel(IListenerChannelCallback listenerChannelCallback, IAdphManager adphManager) { int channelId = listenerChannelCallback.GetId(); AppInstance appInstance; if (!this.appInstanceTable.TryGetValue(channelId, out appInstance)) { lock (ThisLock) { if (!this.appInstanceTable.TryGetValue(channelId, out appInstance)) { int length = listenerChannelCallback.GetBlobLength(); byte[] blob = new byte[length]; listenerChannelCallback.GetBlob(blob, ref length); appInstance = AppInstance.Deserialize(blob); appInstanceTable.Add(channelId, appInstance); } } } if (this.adphManager == null) { this.adphManager = adphManager; } Debug.Assert(channelId == appInstance.Id); this.adphManager.StartAppDomainProtocolListenerChannel(appInstance.AppKey, UdpConstants.Scheme, listenerChannelCallback); }
internal void StartListenerChannel(AppDomainProtocolHandler handler, IListenerChannelCallback listenerCallback) { IListenerChannelCallback listenerChannelCallback = this.MarshalComProxy(listenerCallback); if ((listenerChannelCallback != null) && (handler != null)) { handler.StartListenerChannel(listenerChannelCallback); } }
public override void StartListenerChannel(IListenerChannelCallback listenerChannelCallback) { this.listenerChannelCallback = listenerChannelCallback; // Start the real work here HostedUdpTransportConfigurationImpl.Value.TransportManager.Open(listenerChannelCallback.GetId()); // Report started listenerChannelCallback.ReportStarted(); }
void Stop() { lock (ThisLock) { if (this.listenerChannelCallback != null) { OnStop(); this.listenerChannelCallback.ReportStopped(0); this.listenerChannelCallback = null; } } }
protected void OnMessageReceived() { try { IListenerChannelCallback callback = this.listenerChannelCallback; if (callback != null) { callback.ReportMessageReceived(); } } catch (COMException exception) { DiagnosticUtility.TraceHandledException(exception, TraceEventType.Warning); // The listener adapter might have gone away. Ignore the error. } }
// Start per-process listening for messages public override void StartListenerChannel(IListenerChannelCallback listenerChannelCallback) { Debug.Print("BaseAppDomainProtocolHandler.StartListenerChannel()"); if (listenerChannelCallback == null) { DiagnosticUtility.DebugAssert("listenerChannelCallback is null"); throw DiagnosticUtility.ExceptionUtility.ThrowHelperInternal(false); } this.listenerChannelCallback = listenerChannelCallback; int listenerChannelDataLength = listenerChannelCallback.GetBlobLength(); byte[] listenerChannelData = new byte[listenerChannelDataLength]; listenerChannelCallback.GetBlob(listenerChannelData, ref listenerChannelDataLength); Debug.Print("BaseAppDomainProtocolHandler.StartListenerChannel() GetBlob() contains " + listenerChannelDataLength + " bytes"); listenerChannelContext = ListenerChannelContext.Hydrate(listenerChannelData); Debug.Print("BaseAppDomainProtocolHandler.StartListenerChannel() calling OnStart()"); #if DEBUG // Debug.Print("BaseAppDomainProtocolHandler.StartListenerChannel() waiting for you to attach the debugger to " + Process.GetCurrentProcess().ProcessName + " Pid: " + Process.GetCurrentProcess().Id); // for (int sleepCount = 0; sleepCount < 30 && !Debugger.IsAttached && !ListenerUnsafeNativeMethods.IsDebuggerPresent(); sleepCount++) { Thread.Sleep(500); } Debugger.Break(); #endif try { OnStart(); listenerChannelCallback.ReportStarted(); Debug.Print("BaseAppDomainProtocolHandler.StartListenerChannel() called ReportStarted()"); } catch (CommunicationException exception) { Debug.Print("BaseAppDomainProtocolHandler.StartListenerChannel() failed in OnStart():\r\n" + exception); DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, (ushort)System.Runtime.Diagnostics.EventLogCategory.WebHost, (uint)System.Runtime.Diagnostics.EventLogEventId.WebHostFailedToListen, listenerChannelContext.AppKey, this.protocolId, TraceUtility.CreateSourceString(this), exception.ToString()); throw; } }
// Start per-process listening for messages public override void StartListenerChannel(IListenerChannelCallback listenerChannelCallback, IAdphManager adphManager) { DiagnosticUtility.DebugAssert(listenerChannelCallback != null, "The listenerChannelCallback parameter must not be null"); DiagnosticUtility.DebugAssert(adphManager != null, "The adphManager parameter must not be null"); int channelId = listenerChannelCallback.GetId(); ListenerChannelContext listenerChannelContext; lock (this.listenerChannelIdMapping) { if (!listenerChannelIdMapping.TryGetValue(channelId, out listenerChannelContext)) { int listenerChannelDataLength = listenerChannelCallback.GetBlobLength(); byte[] listenerChannelData = new byte[listenerChannelDataLength]; listenerChannelCallback.GetBlob(listenerChannelData, ref listenerChannelDataLength); Debug.Print("BaseProcessProtocolHandler.StartListenerChannel() GetBlob() contains " + listenerChannelDataLength + " bytes"); listenerChannelContext = ListenerChannelContext.Hydrate(listenerChannelData); this.listenerChannelIdMapping.Add(channelId, listenerChannelContext); Debug.Print("BaseProcessProtocolHandler.StartListenerChannel() listenerChannelContext.ListenerChannelId: " + listenerChannelContext.ListenerChannelId); } } if (this.adphManager == null) { this.adphManager = adphManager; } try { // wether or not a previous AppDomain was running, we're going to start a new one now: Debug.Print("BaseProcessProtocolHandler.StartListenerChannel() calling StartAppDomainProtocolListenerChannel(appKey:" + listenerChannelContext.AppKey + " protocolId:" + protocolId + ")"); adphManager.StartAppDomainProtocolListenerChannel(listenerChannelContext.AppKey, protocolId, listenerChannelCallback); } catch (Exception ex) { if (Fx.IsFatal(ex)) { throw; } DiagnosticUtility.TraceHandledException(ex, TraceEventType.Error); HandleStartListenerChannelError(listenerChannelCallback, ex); } }
public override void StartListenerChannel(IListenerChannelCallback listenerChannelCallback, IAdphManager adphManager) { _adphManager = adphManager; var channelId = listenerChannelCallback.GetId(); Trace.TraceInformation($"{nameof(RabbitMQTaskQueueProcessProtocolHandler)}.{nameof(StartListenerChannel)}: Starting listener channel for channel id [{channelId}]."); var setup = listenerChannelCallback.GetBlobAsListenerChannelSetup(); lock (_appInstanceTable) { if (!_appInstanceTable.ContainsKey(channelId)) { _appInstanceTable.Add(channelId, setup); } } adphManager.StartAppDomainProtocolListenerChannel(setup.ApplicationId, Constants.Scheme, listenerChannelCallback); Trace.TraceInformation($"{nameof(RabbitMQTaskQueueProcessProtocolHandler)}.{nameof(StartListenerChannel)}: Started listener channel for channel id [{channelId}]."); }
public void StartProcessProtocolListenerChannel(string protocolId, IListenerChannelCallback listenerChannelCallback) { try { if (protocolId == null) { throw new ArgumentNullException("protocolId"); } ProtocolElement element = this.ProtocolsConfig.Protocols[protocolId]; if (element == null) { throw new ArgumentException(System.Web.SR.GetString("Unknown_protocol_id", new object[] { protocolId })); } ProcessProtocolHandler handler = null; Type type = null; type = this.ValidateAndGetType(element, element.ProcessHandlerType, typeof(ProcessProtocolHandler), "ProcessHandlerType"); lock (this) { handler = this._protocolHandlers[protocolId] as ProcessProtocolHandler; if (handler == null) { handler = (ProcessProtocolHandler)Activator.CreateInstance(type); this._protocolHandlers[protocolId] = handler; } } if (handler != null) { handler.StartListenerChannel(listenerChannelCallback, this); } } catch (Exception exception) { using (new ProcessImpersonationContext()) { Misc.ReportUnhandledException(exception, new string[] { System.Web.SR.GetString("Invalid_Process_Prot_Type") }); } throw; } }
public abstract void StartListenerChannel(IListenerChannelCallback listenerChannelCallback, IAdphManager AdphManager);
public virtual void StartProcessProtocolListenerChannel(string protocolId, IListenerChannelCallback listenerChannelCallback) { }
public virtual void StartAppDomainProtocolListenerChannel(string appId, string protocolId, IListenerChannelCallback listenerChannelCallback) { }
public override void StartListenerChannel(IListenerChannelCallback listenerChannelCallback) { var listenerChannelId = listenerChannelCallback.GetId(); Trace.TraceInformation($"{nameof(RabbitMQTaskQueueAppDomainProtocolHandler)}.{nameof(StartListenerChannel)}: Starting listener channel for channel id [{listenerChannelId}]."); MessageReceived -= OnMessageReceived; MessageReceived += OnMessageReceived; _listenerChannelCallback = listenerChannelCallback; var setup = listenerChannelCallback.GetBlobAsListenerChannelSetup(); var callback = new WasInteropServiceCallback(_appDomainId); _channelFactory = new DuplexChannelFactory<IWasInteropService>(new InstanceContext(callback), BindingFactory.Create(setup.MessagePublicationNotificationServiceUri), new EndpointAddress(setup.MessagePublicationNotificationServiceUri)); _wasInteropSvc = _channelFactory.CreateChannel(); callback.Service = _wasInteropSvc; _wasInteropSvc.Register(listenerChannelId, _appDomainId, setup.ApplicationPath); if (_autoStartServices) { AutoStartServices(setup.ApplicationPath, callback); } listenerChannelCallback.ReportStarted(); Trace.TraceInformation($"{nameof(RabbitMQTaskQueueAppDomainProtocolHandler)}.{nameof(StartListenerChannel)}: Started listener channel for channel id [{listenerChannelId}]."); }
// this should run in an Hosted app domain (not in the default domain) internal void StartListenerChannel( AppDomainProtocolHandler handler, IListenerChannelCallback listenerCallback ) { Debug.Assert( HostingEnvironment.IsHosted, "HostingEnvironment.IsHosted" ); Debug.Assert( null != handler, "null != handler" ); IListenerChannelCallback unwrappedProxy = MarshalComProxy(listenerCallback); Debug.Assert(null != unwrappedProxy, "null != unwrappedProxy"); if (null != unwrappedProxy && null != handler) { handler.StartListenerChannel(unwrappedProxy); } }
internal virtual void HandleStartListenerChannelError(IListenerChannelCallback listenerChannelCallback, Exception ex) { // This is the workaround to let WAS know that the LC is started and then gracefully stopped. listenerChannelCallback.ReportStarted(); listenerChannelCallback.ReportStopped(0); }
internal override void HandleStartListenerChannelError(IListenerChannelCallback listenerChannelCallback, Exception ex) { listenerChannelCallback.ReportStarted(); listenerChannelCallback.ReportStopped(Marshal.GetHRForException(ex)); }
// // IProcessHostProcessProtocolManager interface implementation // // starts process protocol handler on demand public void StartProcessProtocolListenerChannel(String protocolId, IListenerChannelCallback listenerChannelCallback) { try { if (protocolId == null) throw new ArgumentNullException("protocolId"); // validate protocol id ProtocolElement configEntry = ProtocolsConfig.Protocols[protocolId]; if (configEntry == null) throw new ArgumentException(SR.GetString(SR.Unknown_protocol_id, protocolId)); ProcessProtocolHandler protocolHandler = null; Type protocolHandlerType = null; protocolHandlerType = ValidateAndGetType( configEntry, configEntry.ProcessHandlerType, typeof(ProcessProtocolHandler), "ProcessHandlerType" ); lock (this) { // lookup or create protocol handler protocolHandler = _protocolHandlers[protocolId] as ProcessProtocolHandler; if (protocolHandler == null) { protocolHandler = (ProcessProtocolHandler)Activator.CreateInstance(protocolHandlerType); _protocolHandlers[protocolId] = protocolHandler; } } // call the handler to start listenerChannel if (protocolHandler != null) { protocolHandler.StartListenerChannel(listenerChannelCallback, this); } } catch (Exception e) { using (new ProcessImpersonationContext()) { Misc.ReportUnhandledException(e, new string[] { SR.GetString(SR.Invalid_Process_Prot_Type)} ); } throw; } }
public virtual void StartAppDomainProtocolListenerChannel(string appId, string protocolId, IListenerChannelCallback listenerChannelCallback) {}
public virtual void StartProcessProtocolListenerChannel(string protocolId, IListenerChannelCallback listenerChannelCallback) {}
public abstract virtual void StartListenerChannel(IListenerChannelCallback listenerChannelCallback, IAdphManager AdphManager) {}
public abstract void StartListenerChannel(IListenerChannelCallback listenerChannelCallback);
internal override void HandleStartListenerChannelError(IListenerChannelCallback listenerChannelCallback, Exception ex) { listenerChannelCallback.ReportStarted(); listenerChannelCallback.ReportStopped(System.Runtime.InteropServices.Marshal.GetHRForException(ex)); }
internal IListenerChannelCallback MarshalComProxy(IListenerChannelCallback defaultDomainCallback) { IListenerChannelCallback localProxy = null; // get the underlying COM object IntPtr pUnk = Marshal.GetIUnknownForObject(defaultDomainCallback); // this object isn't a COM object if (IntPtr.Zero == pUnk) { return null; } IntPtr ppv = IntPtr.Zero; try { // QI it for the interface Guid g = typeof(IListenerChannelCallback).GUID; int hresult = Marshal.QueryInterface(pUnk, ref g, out ppv); if (hresult < 0) { Marshal.ThrowExceptionForHR(hresult); } // create a RCW we can hold onto in this domain // this bumps the ref count so we can drop our refs on the raw interfaces localProxy = (IListenerChannelCallback)Marshal.GetObjectForIUnknown(ppv); } finally { // drop our explicit refs and keep the managed instance if (IntPtr.Zero != ppv) { Marshal.Release(ppv); } if (IntPtr.Zero != pUnk) { Marshal.Release(pUnk); } } return localProxy; }
// // IAppDomainProtocolManager // // starts app domain protocol handler on demand (called by process protocol handler public void StartAppDomainProtocolListenerChannel(String appId, String protocolId, IListenerChannelCallback listenerChannelCallback) { try { if (appId == null) throw new ArgumentNullException("appId"); if (protocolId == null) throw new ArgumentNullException("protocolId"); ISAPIApplicationHost appHost = CreateAppHost(appId, null); // get app domaoin protocol handler type from config Type handlerType = GetAppDomainProtocolHandlerType(protocolId); AppDomainProtocolHandler handler = null; LockableAppDomainContext ac = _appManager.GetLockableAppDomainContext(appId); lock (ac) { HostingEnvironmentParameters hostingParameters = new HostingEnvironmentParameters(); hostingParameters.HostingFlags = HostingEnvironmentFlags.ThrowHostingInitErrors; PreloadApplicationIfRequired(appId, appHost, hostingParameters, ac); // call app manager to create the handler handler = (AppDomainProtocolHandler)_appManager.CreateObjectInternal( appId, handlerType, appHost, false /*failIfExists*/, hostingParameters); // create a shim object that we can use for proxy unwrapping ListenerAdapterDispatchShim shim = (ListenerAdapterDispatchShim) _appManager.CreateObjectInternal( appId, typeof(ListenerAdapterDispatchShim), appHost, false /*failIfExists*/, hostingParameters); if (null != shim) { shim.StartListenerChannel(handler, listenerChannelCallback); // remove the shim ((IRegisteredObject)shim).Stop(true); } else { throw new HttpException(SR.GetString(SR.Failure_Create_Listener_Shim)); } } } catch (Exception e) { using (new ProcessImpersonationContext()) { Misc.ReportUnhandledException(e, new string[] { SR.GetString(SR.Failure_Start_AppDomain_Listener)} ); } throw; } }
public void StartAppDomainProtocolListenerChannel(string appId, string protocolId, IListenerChannelCallback listenerChannelCallback) { try { if (appId == null) { throw new ArgumentNullException("appId"); } if (protocolId == null) { throw new ArgumentNullException("protocolId"); } ISAPIApplicationHost appHostParameter = this.CreateAppHost(appId, null); Type appDomainProtocolHandlerType = this.GetAppDomainProtocolHandlerType(protocolId); AppDomainProtocolHandler handler = null; LockableAppDomainContext lockableAppDomainContext = this._appManager.GetLockableAppDomainContext(appId); lock (lockableAppDomainContext) { HostingEnvironmentParameters hostingParameters = new HostingEnvironmentParameters { HostingFlags = HostingEnvironmentFlags.ThrowHostingInitErrors }; this.PreloadApplicationIfRequired(appId, appHostParameter, hostingParameters, lockableAppDomainContext); handler = (AppDomainProtocolHandler)this._appManager.CreateObjectInternal(appId, appDomainProtocolHandlerType, appHostParameter, false, hostingParameters); ListenerAdapterDispatchShim shim = (ListenerAdapterDispatchShim)this._appManager.CreateObjectInternal(appId, typeof(ListenerAdapterDispatchShim), appHostParameter, false, hostingParameters); if (shim == null) { throw new HttpException(System.Web.SR.GetString("Failure_Create_Listener_Shim")); } shim.StartListenerChannel(handler, listenerChannelCallback); ((IRegisteredObject)shim).Stop(true); } } catch (Exception exception) { using (new ProcessImpersonationContext()) { Misc.ReportUnhandledException(exception, new string[] { System.Web.SR.GetString("Failure_Start_AppDomain_Listener") }); } throw; } }