void ConfigureRegistrar(IListenerFactory factory, IListenerFactoryProcessor processor) { var r = new ListenerRegistrar(processor, factory); r.Add(new ReflectionListenerRegistrar()); _registrar = r; }
public async Task <IListener> CreateAsync(CancellationToken cancellationToken) { List <IListener> listeners = new List <IListener>(); foreach (IFunctionDefinition functionDefinition in _functionDefinitions) { IListenerFactory listenerFactory = functionDefinition.ListenerFactory; if (listenerFactory == null) { continue; } // Determine if the function is disabled MethodInfo method = functionDefinition.Descriptor.Method; if (IsDisabled(method, _nameResolver, _activator)) { _trace.Info(string.Format("Function '{0}' is disabled", functionDefinition.Descriptor.ShortName), TraceSource.Host); continue; } IListener listener = await listenerFactory.CreateAsync(cancellationToken); // if the listener is a Singleton, wrap it with our SingletonListener SingletonAttribute singletonAttribute = SingletonManager.GetListenerSingletonOrNull(listener.GetType(), method); if (singletonAttribute != null) { listener = new SingletonListener(method, singletonAttribute, _singletonManager, listener); } listeners.Add(listener); } return(new CompositeListener(listeners)); }
public AbortListenerFunctionExecutor(IListenerFactory abortListenerFactory, IFunctionExecutor abortExecutor, IFunctionExecutor innerExecutor) { _abortListenerFactory = abortListenerFactory; _abortExecutor = abortExecutor; _innerExecutor = innerExecutor; }
/// <summary> /// 启动监听 /// </summary> /// <returns></returns> private Task <bool> StartListenAsync() { _listeners = new List <IListener>(); var serverOptions = _serverOptions.Value; foreach (ListenOptions listenOptions in serverOptions.Listeners) { IListenerFactory _listenerFactory = _listenerFactorys[0]; if (listenOptions.ProtocolType == Baize.IPlugin.SuperSocket.ProtocolType.UDP) { _listenerFactory = _listenerFactorys[1]; } var listener = _listenerFactory.CreateListener(_appSessions, listenOptions, _loggerFactory); listener.NewClientAccepted += OnNewClientAccept; if (listener is UdpSocketListener) { UdpSocketListener udpSocketListener = (UdpSocketListener)listener; udpSocketListener.UDPData += Listener_UDPDataHandler; } if (!listener.Start()) { _logger.LogError($"Failed to listen {listener}."); } _listeners.Add(listener); } return(Task.FromResult(true)); }
protected internal virtual IBaseTaskListener CreateTaskListener(ActivitiListener activitiListener) { IBaseTaskListener taskListener = null; IListenerFactory listenerFactory = Context.ProcessEngineConfiguration.ListenerFactory; if (ImplementationType.IMPLEMENTATION_TYPE_CLASS.Equals(activitiListener.ImplementationType, StringComparison.CurrentCultureIgnoreCase)) { taskListener = listenerFactory.CreateClassDelegateTaskListener(activitiListener); } else if (ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION.Equals(activitiListener.ImplementationType, StringComparison.CurrentCultureIgnoreCase)) { taskListener = listenerFactory.CreateExpressionTaskListener(activitiListener); } else if (ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION.Equals(activitiListener.ImplementationType, StringComparison.CurrentCultureIgnoreCase)) { if (activitiListener.OnTransaction is object) { taskListener = listenerFactory.CreateTransactionDependentDelegateExpressionTaskListener(activitiListener); } else { taskListener = listenerFactory.CreateDelegateExpressionTaskListener(activitiListener); } } else if (ImplementationType.IMPLEMENTATION_TYPE_INSTANCE.Equals(activitiListener.ImplementationType, StringComparison.CurrentCultureIgnoreCase)) { taskListener = (ITaskListener)activitiListener.Instance; } return(taskListener); }
public async Task <IListener> CreateAsync(CancellationToken cancellationToken) { List <IListener> listeners = new List <IListener>(); foreach (IFunctionDefinition functionDefinition in _functionDefinitions) { IListenerFactory listenerFactory = functionDefinition.ListenerFactory; if (listenerFactory == null) { continue; } IListener listener = await listenerFactory.CreateAsync(cancellationToken); // if the listener is a Singleton, wrap it with our SingletonListener SingletonAttribute singletonAttribute = listener.GetType().GetCustomAttribute <SingletonAttribute>(); if (singletonAttribute != null) { if (!string.IsNullOrEmpty(singletonAttribute.Scope)) { throw new InvalidOperationException("SingletonAttribute.Scope values are not supported for singleton listeners."); } listener = new SingletonListener(functionDefinition.Descriptor.Method, singletonAttribute, _singletonManager, listener); } listeners.Add(listener); } return(new CompositeListener(listeners)); }
internal static IListener CreateHostListener(IListenerFactory allFunctionsListenerFactory, SharedQueueHandler sharedQueue, IRecurrentCommand heartbeatCommand, IWebJobsExceptionHandler exceptionHandler, CancellationToken shutdownToken) { IListener factoryListener = new ListenerFactoryListener(allFunctionsListenerFactory, sharedQueue); IListener heartbeatListener = new HeartbeatListener(heartbeatCommand, exceptionHandler, factoryListener); IListener shutdownListener = new ShutdownListener(shutdownToken, heartbeatListener); return(shutdownListener); }
public virtual void ExecuteExecutionListeners(IHasExecutionListeners elementWithExecutionListeners, IExecutionEntity execution, string eventType) { IList <ActivitiListener> listeners = elementWithExecutionListeners.ExecutionListeners; if (listeners != null && listeners.Count > 0) { IListenerFactory listenerFactory = Context.ProcessEngineConfiguration.ListenerFactory; foreach (ActivitiListener activitiListener in listeners) { if (eventType.Equals(activitiListener.Event)) { IBaseExecutionListener executionListener = null; if (ImplementationType.IMPLEMENTATION_TYPE_CLASS.Equals(activitiListener.ImplementationType, StringComparison.CurrentCultureIgnoreCase)) { executionListener = listenerFactory.CreateClassDelegateExecutionListener(activitiListener); } else if (ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION.Equals(activitiListener.ImplementationType, StringComparison.CurrentCultureIgnoreCase)) { executionListener = listenerFactory.CreateExpressionExecutionListener(activitiListener); } else if (ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION.Equals(activitiListener.ImplementationType, StringComparison.CurrentCultureIgnoreCase)) { if (activitiListener.OnTransaction is object) { executionListener = listenerFactory.CreateTransactionDependentDelegateExpressionExecutionListener(activitiListener); } else { executionListener = listenerFactory.CreateDelegateExpressionExecutionListener(activitiListener); } } else if (ImplementationType.IMPLEMENTATION_TYPE_INSTANCE.Equals(activitiListener.ImplementationType, StringComparison.CurrentCultureIgnoreCase)) { executionListener = (IExecutionListener)activitiListener.Instance; } if (executionListener != null) { if (activitiListener.OnTransaction is object) { PlanTransactionDependentExecutionListener(listenerFactory, execution, (ITransactionDependentExecutionListener)executionListener, activitiListener); } else { execution.EventName = eventType; // eventName is used to differentiate the event when reusing an execution listener for various events execution.CurrentActivitiListener = activitiListener; ((IExecutionListener)executionListener).Notify(execution); execution.EventName = null; execution.CurrentActivitiListener = null; } } } } } }
protected internal virtual void PlanTransactionDependentExecutionListener(IListenerFactory listenerFactory, IExecutionEntity execution, ITransactionDependentExecutionListener executionListener, ActivitiListener activitiListener) { IDictionary <string, object> executionVariablesToUse = execution.Variables; ICustomPropertiesResolver customPropertiesResolver = CreateCustomPropertiesResolver(activitiListener); IDictionary <string, object> customPropertiesMapToUse = InvokeCustomPropertiesResolver(execution, customPropertiesResolver); TransactionDependentExecutionListenerExecutionScope scope = new TransactionDependentExecutionListenerExecutionScope(execution.ProcessInstanceId, execution.Id, execution.CurrentFlowElement, executionVariablesToUse, customPropertiesMapToUse); AddTransactionListener(activitiListener, new ExecuteExecutionListenerTransactionListener(executionListener, scope)); }
private static IListener CreateHostListener(IListenerFactory allFunctionsListenerFactory, IRecurrentCommand heartbeatCommand, IBackgroundExceptionDispatcher backgroundExceptionDispatcher, CancellationToken shutdownToken) { IListener factoryListener = new ListenerFactoryListener(allFunctionsListenerFactory); IListener heartbeatListener = new HeartbeatListener(heartbeatCommand, backgroundExceptionDispatcher, factoryListener); IListener shutdownListener = new ShutdownListener(shutdownToken, heartbeatListener); return(shutdownListener); }
public SuperSocketService(IServiceProvider serviceProvider, IOptions <ServerOptions> serverOptions, ILoggerFactory loggerFactory, IListenerFactory listenerFactory, Func <IAppSession, TReceivePackageInfo, Task> packageHandler) { Name = _serverOptions.Value.Name; _serviceProvider = serviceProvider; _serverOptions = serverOptions; _loggerFactory = loggerFactory; _logger = _loggerFactory.CreateLogger("SuperSocketService"); _listenerFactory = listenerFactory; _packageHandler = packageHandler; }
public bool Init(IFunctionIndex functions, IListenerFactory functionsListenerFactory, out IFunctionExecutor hostCallExecutor, out IListener listener, out HostOutputMessage hostOutputMessage, string hostId, CancellationToken shutdownToken) { hostCallExecutor = new ShutdownFunctionExecutor(shutdownToken, _functionExecutor); IListener factoryListener = new ListenerFactoryListener(functionsListenerFactory, _sharedQueueHandler); IListener shutdownListener = new ShutdownListener(shutdownToken, factoryListener); listener = shutdownListener; hostOutputMessage = new DataOnlyHostOutputMessage(); return(false); }
internal static IFunctionExecutor CreateHostCallExecutor(IListenerFactory instanceQueueListenerFactory, IRecurrentCommand heartbeatCommand, IWebJobsExceptionHandler exceptionHandler, CancellationToken shutdownToken, IFunctionExecutor innerExecutor) { IFunctionExecutor heartbeatExecutor = new HeartbeatFunctionExecutor(heartbeatCommand, exceptionHandler, innerExecutor); IFunctionExecutor abortListenerExecutor = new AbortListenerFunctionExecutor(instanceQueueListenerFactory, heartbeatExecutor); IFunctionExecutor shutdownFunctionExecutor = new ShutdownFunctionExecutor(shutdownToken, abortListenerExecutor); return(shutdownFunctionExecutor); }
private static IFunctionExecutor CreateHostCallExecutor(IListenerFactory instanceQueueListenerFactory, IRecurrentCommand heartbeatCommand, IBackgroundExceptionDispatcher backgroundExceptionDispatcher, CancellationToken shutdownToken, IFunctionExecutor innerExecutor) { IFunctionExecutor heartbeatExecutor = new HeartbeatFunctionExecutor(heartbeatCommand, backgroundExceptionDispatcher, innerExecutor); IFunctionExecutor abortListenerExecutor = new AbortListenerFunctionExecutor(instanceQueueListenerFactory, heartbeatExecutor); IFunctionExecutor shutdownFunctionExecutor = new ShutdownFunctionExecutor(shutdownToken, abortListenerExecutor); return(shutdownFunctionExecutor); }
public async Task StartAsync(CancellationToken cancellationToken) { _pipelineFilterFactory = _serviceProvider.GetRequiredService <IPipelineFilterFactory <TReceivePackageInfo> >(); _listenerFactory = _serviceProvider.GetService <IListenerFactory>(); if (_listenerFactory == null) { _listenerFactory = new TcpSocketListenerFactory(); } await StartListenAsync(); }
public Task <IListener> CreateListenerAsync(ListenerFactoryContext context) { if (context == null) { throw new ArgumentNullException("context"); } IListenerFactory factory = null; if (_queueName != null) { factory = new ServiceBusQueueListenerFactory(_account, _queueName, context.Executor, _config); } else { factory = new ServiceBusSubscriptionListenerFactory(_account, _topicName, _subscriptionName, context.Executor, _config); } return(factory.CreateAsync(context.CancellationToken)); }
protected internal virtual ICustomPropertiesResolver CreateCustomPropertiesResolver(ActivitiListener activitiListener) { ICustomPropertiesResolver customPropertiesResolver = null; IListenerFactory listenerFactory = Context.ProcessEngineConfiguration.ListenerFactory; if (ImplementationType.IMPLEMENTATION_TYPE_CLASS.Equals(activitiListener.CustomPropertiesResolverImplementationType, StringComparison.CurrentCultureIgnoreCase)) { customPropertiesResolver = listenerFactory.CreateClassDelegateCustomPropertiesResolver(activitiListener); } else if (ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION.Equals(activitiListener.CustomPropertiesResolverImplementationType, StringComparison.CurrentCultureIgnoreCase)) { customPropertiesResolver = listenerFactory.CreateExpressionCustomPropertiesResolver(activitiListener); } else if (ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION.Equals(activitiListener.CustomPropertiesResolverImplementationType, StringComparison.CurrentCultureIgnoreCase)) { customPropertiesResolver = listenerFactory.CreateDelegateExpressionCustomPropertiesResolver(activitiListener); } return(customPropertiesResolver); }
public async Task <IListener> CreateAsync(IFunctionExecutor executor, CancellationToken cancellationToken) { List <IListener> listeners = new List <IListener>(); foreach (IFunctionDefinition functionDefinition in _functionDefinitions) { IListenerFactory listenerFactory = functionDefinition.ListenerFactory; if (listenerFactory == null) { continue; } IListener listener = await listenerFactory.CreateAsync(executor, cancellationToken); listeners.Add(listener); } return(new CompositeListener(listeners)); }
public async Task <IListener> CreateListenerAsync(ListenerFactoryContext context) { if (context == null) { throw new ArgumentNullException("context"); } IListenerFactory factory = null; if (_queueName != null) { factory = new ServiceBusQueueListenerFactory(_account, _queueName, context.Executor, _options, _messagingProvider); } else { factory = new ServiceBusSubscriptionListenerFactory(_account, _topicName, _subscriptionName, context.Executor, _options, _messagingProvider); } _listener = (ServiceBusListener)(await factory.CreateAsync(context.CancellationToken)); return(_listener); }
public async Task <IListener> CreateAsync(CancellationToken cancellationToken) { List <IListener> listeners = new List <IListener>(); foreach (IFunctionDefinition functionDefinition in _functionDefinitions) { // Determine if the function is disabled if (functionDefinition.Descriptor.IsDisabled) { string msg = string.Format("Function '{0}' is disabled", functionDefinition.Descriptor.ShortName); _trace.Info(msg, TraceSource.Host); _logger?.LogInformation(msg); continue; } IListenerFactory listenerFactory = functionDefinition.ListenerFactory; if (listenerFactory == null) { continue; } IListener listener = await listenerFactory.CreateAsync(cancellationToken); // if the listener is a Singleton, wrap it with our SingletonListener SingletonAttribute singletonAttribute = SingletonManager.GetListenerSingletonOrNull(listener.GetType(), functionDefinition.Descriptor); if (singletonAttribute != null) { listener = new SingletonListener(functionDefinition.Descriptor, singletonAttribute, _singletonManager, listener, _trace, _loggerFactory); } // wrap the listener with a function listener to handle exceptions listener = new FunctionListener(listener, functionDefinition.Descriptor, _trace, _loggerFactory); listeners.Add(listener); } return(new CompositeListener(listeners)); }
public SocketServer( IServerConfiguration configuration, IListenerFactory listenerFactory, IScheduler scheduler ) { Configuration = configuration; Scheduler = scheduler; ListenerFactory = listenerFactory; }
public AbortListenerFunctionExecutor(IListenerFactory abortListenerFactory, IFunctionExecutor innerExecutor) { _abortListenerFactory = abortListenerFactory; _innerExecutor = innerExecutor; }
/// <summary> /// Constructor to be called by the <seealso cref="BpmnParser"/>. /// </summary> public BpmnParse(BpmnParser parser) { this.activityBehaviorFactory = parser.ActivityBehaviorFactory; this.listenerFactory = parser.ListenerFactory; this.bpmnParserHandlers = parser.BpmnParserHandlers; }
public bool Setup( IFunctionIndex functions, IListenerFactory functionsListenerFactory, out IFunctionExecutor hostCallExecutor, out IListener listener, out HostOutputMessage hostOutputMessage, string hostId, CancellationToken shutdownToken) { string sharedQueueName = HostQueueNames.GetHostQueueName(hostId); var sharedQueue = sharedQueueName; IListenerFactory sharedQueueListenerFactory = new HostMessageListenerFactory(_storageServices, sharedQueue, _exceptionHandler, _loggerFactory, functions, _functionInstanceLogger, _functionExecutor); Guid hostInstanceId = Guid.NewGuid(); string instanceQueueName = HostQueueNames.GetHostQueueName(hostInstanceId.ToString("N")); var instanceQueue = instanceQueueName; IListenerFactory instanceQueueListenerFactory = new HostMessageListenerFactory(_storageServices, instanceQueue, _exceptionHandler, _loggerFactory, functions, _functionInstanceLogger, _functionExecutor); HeartbeatDescriptor heartbeatDescriptor = new HeartbeatDescriptor { SharedContainerName = HostContainerNames.Hosts, SharedDirectoryName = HostDirectoryNames.Heartbeats + "/" + hostId, InstanceBlobName = hostInstanceId.ToString("N"), ExpirationInSeconds = (int)HeartbeatIntervals.ExpirationInterval.TotalSeconds }; var dashboardAccount = _storageAccountOptions.GetDashboardStorageAccount(); var blob = dashboardAccount.CreateCloudBlobClient() .GetContainerReference(heartbeatDescriptor.SharedContainerName) .GetBlockBlobReference(heartbeatDescriptor.SharedDirectoryName + "/" + heartbeatDescriptor.InstanceBlobName); IRecurrentCommand heartbeatCommand = new UpdateHostHeartbeatCommand(new HeartbeatCommand(blob)); IEnumerable <MethodInfo> indexedMethods = functions.ReadAllMethods(); Assembly hostAssembly = JobHostContextFactory.GetHostAssembly(indexedMethods); string displayName = hostAssembly != null?AssemblyNameCache.GetName(hostAssembly).Name : "Unknown"; hostOutputMessage = new JobHostContextFactory.DataOnlyHostOutputMessage { HostInstanceId = hostInstanceId, HostDisplayName = displayName, SharedQueueName = sharedQueueName, InstanceQueueName = instanceQueueName, Heartbeat = heartbeatDescriptor, WebJobRunIdentifier = WebJobRunIdentifier.Current }; hostCallExecutor = JobHostContextFactory.CreateHostCallExecutor(instanceQueueListenerFactory, heartbeatCommand, _exceptionHandler, shutdownToken, _functionExecutor); IListenerFactory hostListenerFactory = new CompositeListenerFactory(functionsListenerFactory, sharedQueueListenerFactory, instanceQueueListenerFactory); listener = JobHostContextFactory.CreateHostListener(hostListenerFactory, _sharedQueueHandler, heartbeatCommand, _exceptionHandler, shutdownToken); return(true); }
public ListenerFactoryListener(IListenerFactory factory) { _factory = factory; _cancellationSource = new CancellationTokenSource(); }
public ListenerFactoryListener(IListenerFactory factory, IFunctionExecutor executor) { _factory = factory; _executor = executor; _cancellationSource = new CancellationTokenSource(); }
public FunctionDefinition(IFunctionInstanceFactory instanceFactory, IListenerFactory listenerFactory) { _instanceFactory = instanceFactory; _listenerFactory = listenerFactory; }
public SuperSocketService(IServiceProvider serviceProvider, IOptions <ServerOptions> serverOptions, ILoggerFactory loggerFactory, IListenerFactory listenerFactory, Func <IAppSession, TReceivePackageInfo, Task> packageHandler) : base(serviceProvider, serverOptions, loggerFactory, listenerFactory, packageHandler) { }
public ListenerFactoryProcessor(IListenerFactory factory) : base("Listener Factory Processor") { _factory = factory; }
private static IFunctionExecutor CreateHostCallExecutor(IListenerFactory instanceQueueListenerFactory, IRecurrentCommand heartbeatCommand, IBackgroundExceptionDispatcher backgroundExceptionDispatcher, CancellationToken shutdownToken, IFunctionExecutor innerExecutor) { IFunctionExecutor heartbeatExecutor = new HeartbeatFunctionExecutor(heartbeatCommand, backgroundExceptionDispatcher, innerExecutor); IFunctionExecutor abortListenerExecutor = new AbortListenerFunctionExecutor(instanceQueueListenerFactory, heartbeatExecutor); IFunctionExecutor shutdownFunctionExecutor = new ShutdownFunctionExecutor(shutdownToken, abortListenerExecutor); return shutdownFunctionExecutor; }
public FunctionDefinition(FunctionDescriptor descriptor, IFunctionInstanceFactory instanceFactory, IListenerFactory listenerFactory) { _descriptor = descriptor; _instanceFactory = instanceFactory; _listenerFactory = listenerFactory; }
public ListenerFactoryListener(IListenerFactory factory, SharedQueueHandler sharedQueue) { _factory = factory; _sharedQueue = sharedQueue; _cancellationSource = new CancellationTokenSource(); }
public SuperSocketService(IServiceProvider serviceProvider, IOptions <ServerOptions> serverOptions, ILoggerFactory loggerFactory, IListenerFactory listenerFactory) : base(serviceProvider, serverOptions, loggerFactory, listenerFactory) { }
private static IListener CreateHostListener(IListenerFactory allFunctionsListenerFactory, IRecurrentCommand heartbeatCommand, IBackgroundExceptionDispatcher backgroundExceptionDispatcher, CancellationToken shutdownToken) { IListener factoryListener = new ListenerFactoryListener(allFunctionsListenerFactory); IListener heartbeatListener = new HeartbeatListener(heartbeatCommand, backgroundExceptionDispatcher, factoryListener); IListener shutdownListener = new ShutdownListener(shutdownToken, heartbeatListener); return shutdownListener; }
public WorkflowEngineBuilder WithListenerFactory(IListenerFactory listenerFactory) { ListenerFactory = listenerFactory; return(this); }