void ActivateServiceType(Type serviceType) { //DESIGN NOTE: //Use the first manifest for initialization. For all Fabric-based interactions, ServiceContext sent in message updates context. ApplicationManifestAttribute[] manifests = serviceType.GetCustomAttributes <ApplicationManifestAttribute>().ToArray(); StatelessServiceContext serviceContext = new StatelessServiceContext { ServiceName = new Uri("fabric:/" + manifests[0].ApplicationName + "/" + manifests[0].ServiceName) }; StatelessService service = Activator.CreateInstance(serviceType, serviceContext) as StatelessService; foreach (ServiceInstanceListener instanceListener in service.ServiceInstanceListeners) { ICommunicationListener listener = instanceListener.CreateCommunicationListener(serviceContext); if (listener is WcfCommunicationListener) { ActivateWcfService(serviceType, listener as WcfCommunicationListener); } else { listener.OpenAsync(new System.Threading.CancellationToken()).Wait(); AppDomain.CurrentDomain.ProcessExit += delegate { try { listener.CloseAsync(new System.Threading.CancellationToken()).Wait(); } catch {} }; } } }
public ICommunicationListener ValidateBuildFunction(TService service, KestrelListenerBuilder <MockStartup, TService, TContext> builder) { ICommunicationListener listener = builder.Build(service); Assert.IsNotNull(listener, "Listener should not be null"); return(listener); }
public async Task AddListenerAsync(string Name, ICommunicationListener listener) { try { if (null == listener) { throw new ArgumentNullException("listener"); } if (this.listeners.ContainsKey(Name)) { throw new InvalidOperationException(string.Format("Listener with the name {0} already exists", Name)); } this.listenerLock.WaitOne(); this.listeners.Add(Name, listener); await this._OpenListener(listener, CancellationToken.None); } finally { this.listenerLock.Set(); } }
public async Task CloseAsyncAndAbort_NotFailing() { ICommunicationListener listener = CreateListener(addresses: "https://localhost:80"); await listener.CloseAsync(CancellationToken.None); listener.Abort(); }
/// <summary> /// This method causes the communication listener to be opened. Once the Open /// completes, the communication listener becomes usable - accepts and sends messages. /// </summary> /// <param name="cancellationToken">Cancellation token</param> /// <returns> /// A <see cref="T:System.Threading.Tasks.Task">Task</see> that represents outstanding operation. The result of the Task is /// the endpoint string. /// </returns> public Task <string> OpenAsync(CancellationToken cancellationToken) { _wrappedCommunicationListener = new WcfCommunicationListener <ISubscriberService>(_serviceContext, _subscriberService, CreateBinding(), EndpointResourceName); return(_wrappedCommunicationListener.OpenAsync(cancellationToken)); }
/// <summary> /// Starts replicating outgoing operations. /// </summary> /// <param name="cancellationToken"> /// The cancellation token. /// </param> /// <remarks> /// This should be called on transition into the <see cref="ReplicaRole.Primary"/> role. /// </remarks> private async Task <string> StartReplicatingOutgoingOperations(CancellationToken cancellationToken) { this.logger.Log(nameof(this.StartReplicatingOutgoingOperations)); this.operationReplicator = new OperationReplicator <TOperation>( this.fabricReplicator.StateReplicator2, this.stateProvider, this.logger, this.serializer); // Open the service. this.reliableJournal = new ReliableJournal <TOperation>(this.operationReplicator, this.service); this.listener = this.service.CreateCommunicationListener(this.serviceParameters); await this.service.Open(this.reliableJournal, cancellationToken); // Apply existing events foreach (var entry in this.stateProvider.GetOperations()) { var operationRecord = this.serializer.Deserialize <Record>(entry.Data) as OperationCommittedRecord <TOperation>; if (operationRecord == null) { continue; } var eventOperation = operationRecord.Operation; if (eventOperation != null) { //this.logger.Log($"Applying stored event {eventOperation.Event}"); await this.service.Apply(eventOperation, cancellationToken); } } this.logger.Log("Completed " + nameof(this.StartReplicatingOutgoingOperations)); return(await this.listener.OpenAsync(cancellationToken)); }
private async Task <string> _OpenListener( ICommunicationListener listener, CancellationToken canceltoken) { string sAddress = await listener.OpenAsync(canceltoken); return(sAddress); }
public StartupHostedService( ICommunicationModel communicationModel, IDomainServiceProvider domainServiceProvider, ICommunicationListener communicationListener) { _communicationModel = communicationModel; _domainServiceProvider = domainServiceProvider; _communicationListener = communicationListener; }
private void AddCommunicationListener(ICommunicationListener communicationListener) { if (this.communicationListeners == null) { this.communicationListeners = new List <ICommunicationListener>(); } this.communicationListeners.Add(communicationListener); }
private void _AbortListener( string ListenerName, ICommunicationListener listener) { this.statuses[ListenerName] = ICommunicationListenerStatus.Aborting; listener.Abort(); this.statuses[ListenerName] = ICommunicationListenerStatus.Aborted; this.traceWriter.TraceMessage(string.Format("Composite listener - listener {0} aborted", ListenerName)); }
private void Initialize(ServiceContext serviceContext, IServiceRemotingMessageHandler messageHandler, Binding listenerBinding, string endpointResourceName, ServiceRemotingMessageSerializersManager serializerManager) { this.messageHandler = messageHandler; this.wcfListener = new WcfCommunicationListener <IServiceRemotingContract>( serviceContext, new WcfRemotingService(this.messageHandler, serializerManager), listenerBinding, endpointResourceName); }
protected override IEnumerable <ServiceInstanceListener> CreateServiceInstanceListeners() { logger.LogInfo("Creating Service Instance Listener For Audit.DataLockService"); var listeners = new List <ServiceInstanceListener> { new ServiceInstanceListener(context => listener = lifetimeScope.Resolve <IStatelessServiceBusBatchCommunicationListener>()) }; logger.LogInfo("Created Service Instance Listener For Audit.DataLockService"); return(listeners); }
/// <summary> /// Constructs a WCF based service remoting listener. /// </summary> /// <param name="serviceContext">The context of the service for which the remoting listener is being constructed.</param> /// <param name="messageHandler">The handler for receiving and processing remoting messages. As the messages are received /// the listener delivers the messages to the handler. /// </param> /// <param name="listenerBinding">WCF binding to use for the listener. If the listener binding is not specified or null, /// a default listener binding is created using <see cref="WcfUtility.CreateTcpListenerBinding"/> method which creates /// a <see cref="System.ServiceModel.NetTcpBinding"/> with no security. /// </param> /// <param name="endpointResourceName">The name of the endpoint resource defined in the service manifest that /// should be used to create the address for the listener. If the endpointResourceName is not specified or it is null, /// the default value "ServiceEndpoint" is used. /// </param> public WcfServiceRemotingListener( ServiceContext serviceContext, IServiceRemotingMessageHandler messageHandler, Binding listenerBinding = null, string endpointResourceName = "ServiceEndpoint") { this.wcfListener = new WcfCommunicationListener <IServiceRemotingContract>( serviceContext, new WcfRemotingService(messageHandler), listenerBinding, endpointResourceName); }
private async Task _CloseListener( string ListenerName, ICommunicationListener listener, CancellationToken cancelToken) { this.statuses[ListenerName] = ICommunicationListenerStatus.Closing; await listener.CloseAsync(cancelToken); this.statuses[ListenerName] = ICommunicationListenerStatus.Closed; this.traceWriter.TraceMessage(string.Format("Composite listener - listener {0} closed", ListenerName)); }
/// <summary> /// Constructs a WCF based service remoting listener. /// </summary> /// <param name="serviceContext">The context of the service for which the remoting listener is being constructed.</param> /// <param name="serviceImplementation">The service implementation object.</param> /// <param name="listenerBinding">WCF binding to use for the listener. If the listener binding is not specified or null, /// a default listener binding is created using <see cref="WcfUtility.CreateTcpListenerBinding"/> method which creates /// a <see cref="System.ServiceModel.NetTcpBinding"/> with no security. /// </param> /// <param name="endpointResourceName">The name of the endpoint resource defined in the service manifest that /// should be used to create the address for the listener. If the endpointResourceName is not specified or null, /// the default value "ServiceEndpoint" is used. /// </param> public WcfServiceRemotingListener( ServiceContext serviceContext, IService serviceImplementation, Binding listenerBinding = null, string endpointResourceName = "ServiceEndpoint") { this.wcfListener = new WcfCommunicationListener <IServiceRemotingContract>( serviceContext, new WcfRemotingService( new ServiceRemotingDispatcher(serviceContext, serviceImplementation)), listenerBinding, endpointResourceName); }
private async Task <string> _OpenListener( string ListenerName, ICommunicationListener listener, CancellationToken canceltoken) { this.statuses[ListenerName] = ICommunicationListenerStatus.Opening; string sAddress = await listener.OpenAsync(canceltoken); this.statuses[ListenerName] = ICommunicationListenerStatus.Opened; this.traceWriter.TraceMessage(string.Format("Composite listener - listener {0} opened on {1}", ListenerName, sAddress)); return(sAddress); }
public async Task RemoveListenerAsync(string Name) { ICommunicationListener listener = null; try { if (!this.listeners.ContainsKey(Name)) { throw new InvalidOperationException(string.Format("Listener with the name {0} does not exists", Name)); } listener = this.listeners[Name]; this.listenerLock.WaitOne(); await this._CloseListener(Name, listener, CancellationToken.None); } catch (AggregateException aex) { AggregateException ae = aex.Flatten(); this.traceWriter.TraceMessage( string.Format( "Compsite listen failed to close (for removal) listener:{0} it will be forcefully aborted E:{1} StackTrace:{2}", Name, ae.GetCombinedExceptionMessage(), ae.GetCombinedExceptionStackTrace())); // force abkrted if (null != listener) { try { listener.Abort(); } catch { /*no op*/ } } } finally { this.listeners.Remove(Name); this.statuses.Remove(Name); this.listenerLock.Set(); } }
public void AddRemotingListener_ToStatelessServiceUsingIServiceTypeThatHasNoDependencies_BuildDoesNotThrow() { string expectedName = nameof(AddRemotingListener_ToStatelessServiceUsingIServiceType_RegisterType); FabricTransportRemotingListenerSettings settings = new FabricTransportRemotingListenerSettings(); HostBuilder builder = new HostBuilder(); ServiceFabricHostBuilder <OmexStatelessService, StatelessServiceContext> sfBuilder = MockServiceFabricHostBuilder.CreateMockBuilder <OmexStatelessService, StatelessServiceContext>(builder); sfBuilder.AddRemotingListener <MockService>(expectedName, settings); IListenerBuilder <OmexStatelessService> value = builder.Build().Services.GetRequiredService <IListenerBuilder <OmexStatelessService> >(); ICommunicationListener service = value.Build(MockServiceFabricServices.MockOmexStatelessService); Assert.IsNotNull(service); Assert.AreEqual(expectedName, value.Name); Assert.AreEqual(settings, GetSettings(value)); }
public MainForm() { InitializeComponent(); Logger.Log = (message) => { textBox1.Invoke((MethodInvoker) delegate { textBox1.Text += message + Environment.NewLine; }); }; clients = new List <ICommunicationClient>(); devices = new List <DeviceClient>(); listener = new SocketCommunicationListener(); listener.ClientAvailable += Listener_ClientAvailable; listenerThread = new Thread(new ThreadStart(() => { listener.Start(); })); }
public void AddServiceListener_UsingFunc_RegisterInstance() { ICommunicationListener listener = new Mock <ICommunicationListener>().Object; ICommunicationListener listenerBuilder(IServiceProvider provider, object context) => listener; HostBuilder hostBuilder = new HostBuilder(); new ServiceFabricHostBuilder <IServiceFabricService <ServiceContext>, ServiceContext>(hostBuilder) .AddServiceListener("testName", listenerBuilder); IListenerBuilder <IServiceFabricService <ServiceContext> > resolvedBuilder = hostBuilder .Build().Services .GetService <IListenerBuilder <IServiceFabricService <ServiceContext> > >(); IServiceFabricService <ServiceContext> mockService = new Mock <IServiceFabricService <ServiceContext> >().Object; ICommunicationListener resultedListener = resolvedBuilder.Build(mockService); ReferenceEquals(listener, resultedListener); }
public async Task RemoveListenerAsync(string Name) { ICommunicationListener listener = null; try { if (!this.listeners.ContainsKey(Name)) { throw new InvalidOperationException(string.Format("Listener with the name {0} does not exists", Name)); } listener = this.listeners[Name]; this.listenerLock.WaitOne(); await this._CloseListener(listener, CancellationToken.None); } catch (AggregateException aex) { AggregateException ae = aex.Flatten(); // force abkrted if (null != listener) { try { listener.Abort(); } catch { /*no op*/ } } } finally { this.listeners.Remove(Name); this.listenerLock.Set(); } }
/// <summary> /// Constructs a WCF based service remoting listener. /// </summary> /// <param name="serviceContext">The context of the service for which the remoting listener is being constructed.</param> /// <param name="messageHandler">The handler for receiving and processing remoting messages. As the messages are received /// the listener delivers the messages to the handler. /// </param> /// <param name="listenerBinding">WCF binding to use for the listener. If the listener binding is not specified or null, /// a default listener binding is created using <see cref="WcfUtility.CreateTcpListenerBinding"/> method. /// </param> /// <param name="address">The endpoint address to use for the WCF listener. If not specified or null, the endpoint /// address is created using the default endpoint resource named "ServiceEndpoint" defined in the service manifest. /// </param> public WcfServiceRemotingListener( ServiceContext serviceContext, IServiceRemotingMessageHandler messageHandler, Binding listenerBinding = null, EndpointAddress address = null) { if (address != null) { this.wcfListener = new WcfCommunicationListener <IServiceRemotingContract>( serviceContext, new WcfRemotingService(messageHandler), listenerBinding, address); } else { this.wcfListener = new WcfCommunicationListener <IServiceRemotingContract>( serviceContext, new WcfRemotingService(messageHandler), listenerBinding, "ServiceEndpoint"); } }
/// <summary> /// Constructs a WCF based service remoting listener. /// </summary> /// <param name="serviceContext">The context of the service for which the remoting listener is being constructed.</param> /// <param name="serviceImplementation">The service implementation object.</param> /// <param name="listenerBinding">WCF binding to use for the listener. If the listener binding is not specified or null, /// a default listener binding is created using <see cref="WcfUtility.CreateTcpListenerBinding"/> method which creates /// a <see cref="System.ServiceModel.NetTcpBinding"/> with no security. /// </param> /// <param name="serializationProvider"></param> /// <param name="endpointResourceName">The name of the endpoint resource defined in the service manifest that /// should be used to create the address for the listener. If the endpointResourceName is not specified or null, /// the default value "ServiceEndpointV2" is used. /// </param> public WcfServiceRemotingListener( ServiceContext serviceContext, IService serviceImplementation, Binding listenerBinding = null, IServiceRemotingMessageSerializationProvider serializationProvider = null, string endpointResourceName = "ServiceEndpointV2") { if (serializationProvider == null) { serializationProvider = new BasicDataContractSerializationProvider(); } var serializerManager = new ServiceRemotingMessageSerializersManager(serializationProvider, new BasicDataContractHeaderSerializer()); this.messageHandler = new ServiceRemotingMessageDispatcher(serviceContext, serviceImplementation, serializerManager.GetSerializationProvider().CreateMessageBodyFactory()); this.wcfListener = new WcfCommunicationListener <IServiceRemotingContract>( serviceContext, new WcfRemotingService( this.messageHandler, serializerManager), listenerBinding, endpointResourceName); }
private void Initialize(ServiceContext serviceContext, Binding listenerBinding, EndpointAddress address, ServiceRemotingMessageSerializersManager serializerManager, IServiceRemotingMessageHandler messageHandler) { this.messageHandler = messageHandler; if (address != null) { this.wcfListener = new WcfCommunicationListener <IServiceRemotingContract>( serviceContext, new WcfRemotingService(this.messageHandler, serializerManager), listenerBinding, address); } else { this.wcfListener = new WcfCommunicationListener <IServiceRemotingContract>( serviceContext, new WcfRemotingService(this.messageHandler, serializerManager), listenerBinding, "ServiceEndpointV2"); } }
public async Task AddListenerAsync(string Name, ICommunicationListener listener) { try { if (null == listener) { throw new ArgumentNullException("listener"); } if (this.listeners.ContainsKey(Name)) { throw new InvalidOperationException(string.Format("Listener with the name {0} already exists", Name)); } this.listenerLock.WaitOne(); this.listeners.Add(Name, listener); this.statuses.Add(Name, ICommunicationListenerStatus.Closed); this.traceWriter.TraceMessage(string.Format("Composite listener added a new listener name:{0}", Name)); if (ICommunicationListenerStatus.Opened == this.CompsiteListenerStatus) { if (ICommunicationListenerStatus.Opened == this.CompsiteListenerStatus) { await this._OpenListener(Name, listener, CancellationToken.None); } } } finally { this.listenerLock.Set(); } }
public async Task AddListenerAsync(string listenerName, ICommunicationListener listener) { try { if (null == listener) { throw new ArgumentNullException(nameof(listener)); } if (_listeners.ContainsKey(listenerName)) { throw new InvalidOperationException($"Listener with the name {listenerName} already exists"); } _listenerLock.WaitOne(); _listeners.Add(listenerName, listener); _statuses.Add(listenerName, CommunicationListenerStatus.Closed); if (CommunicationListenerStatus.Opened == Status) { await OpenListener(listenerName, listener, CancellationToken.None); } } finally { _listenerLock.Set(); } }
public WcfServiceRemotingListener(IServiceRemotingMessageHandler remotingMessageHandler, Type serviceType, Func<object, ICommunicationListener> factory) { _innerListener = factory(new WcfRemotingService(remotingMessageHandler, serviceType)); }
private async Task<string> _OpenListener( string ListenerName, ICommunicationListener listener, CancellationToken canceltoken) { this.statuses[ListenerName] = ICommunicationListenerStatus.Opening; string sAddress = await listener.OpenAsync(canceltoken); this.statuses[ListenerName] = ICommunicationListenerStatus.Opened; this.traceWriter.TraceMessage(string.Format("Composite listener - listener {0} opened on {1}", ListenerName, sAddress)); return sAddress; }
private async Task CloseListener( string listenerName, ICommunicationListener listener, CancellationToken cancelToken) { _statuses[listenerName] = CommunicationListenerStatus.Closing; await listener.CloseAsync(cancelToken); _statuses[listenerName] = CommunicationListenerStatus.Closed; }
private void AbortListener( string listenerName, ICommunicationListener listener) { _statuses[listenerName] = CommunicationListenerStatus.Aborting; listener.Abort(); _statuses[listenerName] = CommunicationListenerStatus.Aborted; }
private async Task _CloseListener( ICommunicationListener listener, CancellationToken cancelToken) { await listener.CloseAsync(cancelToken); }
private void _AbortListener( ICommunicationListener listener) { listener.Abort(); }
private async Task<string> OpenListener( string listenerName, ICommunicationListener listener, CancellationToken canceltoken) { _statuses[listenerName] = CommunicationListenerStatus.Opening; var address = await listener.OpenAsync(canceltoken); _statuses[listenerName] = CommunicationListenerStatus.Opened; return address; }