private TestServiceConnection MockServiceConnection(IConnectionFactory serviceConnectionFactory      = null,
                                                            IClientConnectionFactory clientConnectionFactory = null,
                                                            ILoggerFactory loggerFactory = null,
                                                            GracefulShutdownMode mode    = GracefulShutdownMode.Off)
        {
            clientConnectionFactory ??= new ClientConnectionFactory();
            serviceConnectionFactory ??= new TestConnectionFactory(conn => Task.CompletedTask);
            loggerFactory ??= NullLoggerFactory.Instance;

            var services          = new ServiceCollection();
            var connectionHandler = new EndlessConnectionHandler();

            services.AddSingleton(connectionHandler);
            var builder = new ConnectionBuilder(services.BuildServiceProvider());

            builder.UseConnectionHandler <EndlessConnectionHandler>();
            ConnectionDelegate handler = builder.Build();

            return(new TestServiceConnection(
                       serviceConnectionFactory,
                       clientConnectionFactory,
                       loggerFactory,
                       handler,
                       mode: mode
                       ));
        }
        public ServiceHubDispatcher(
            IServiceProtocol serviceProtocol,
            IHubContext <THub> context,
            IServiceConnectionManager <THub> serviceConnectionManager,
            IClientConnectionManager clientConnectionManager,
            IServiceEndpointManager serviceEndpointManager,
            IOptions <ServiceOptions> options,
            ILoggerFactory loggerFactory,
            IEndpointRouter router,
            IServerNameProvider nameProvider,
            ServerLifetimeManager serverLifetimeManager,
            IClientConnectionFactory clientConnectionFactory,
            IServiceEventHandler serviceEventHandler)
        {
            _serviceProtocol          = serviceProtocol;
            _serviceConnectionManager = serviceConnectionManager;
            _clientConnectionManager  = clientConnectionManager;
            _serviceEndpointManager   = serviceEndpointManager;
            _options = options != null ? options.Value : throw new ArgumentNullException(nameof(options));

            Context = context;

            _router                  = router ?? throw new ArgumentNullException(nameof(router));
            _loggerFactory           = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
            _logger                  = loggerFactory.CreateLogger <ServiceHubDispatcher <THub> >();
            _clientConnectionFactory = clientConnectionFactory;
            _nameProvider            = nameProvider;
            _hubName                 = typeof(THub).Name;
            _serviceEventHandler     = serviceEventHandler;

            serverLifetimeManager?.Register(ShutdownAsync);
        }
Example #3
0
 public TestServiceConnection(TestConnectionContainer container,
                              IServiceProtocol serviceProtocol,
                              TestClientConnectionManager clientConnectionManager,
                              IConnectionFactory connectionFactory,
                              ILoggerFactory loggerFactory,
                              ConnectionDelegate connectionDelegate,
                              IClientConnectionFactory clientConnectionFactory,
                              string serverId,
                              string connectionId,
                              HubServiceEndpoint endpoint,
                              IServiceMessageHandler serviceMessageHandler,
                              IServiceEventHandler serviceEventHandler,
                              ServiceConnectionType connectionType = ServiceConnectionType.Default,
                              GracefulShutdownMode mode            = GracefulShutdownMode.Off,
                              int closeTimeOutMilliseconds         = 10000) : base(
         serviceProtocol,
         clientConnectionManager,
         connectionFactory,
         loggerFactory,
         connectionDelegate,
         clientConnectionFactory,
         serverId,
         connectionId,
         endpoint,
         serviceMessageHandler,
         serviceEventHandler,
         connectionType: connectionType,
         mode: mode,
         closeTimeOutMilliseconds: closeTimeOutMilliseconds)
 {
     _container = container;
     ClientConnectionManager = clientConnectionManager;
 }
Example #4
0
        public MockServiceHubDispatcher(
            IServiceProtocol serviceProtocol,
            IHubContext <THub> context,
            IServiceConnectionManager <THub> serviceConnectionManager,
            IClientConnectionManager clientConnectionManager,
            IServiceEndpointManager serviceEndpointManager,
            IOptions <ServiceOptions> options,
            ILoggerFactory loggerFactory,
            IEndpointRouter router,
            IServerNameProvider nameProvider,
            ServerLifetimeManager serverLifetimeManager,
            IClientConnectionFactory clientConnectionFactory) : base(
                serviceProtocol,
                context,
                serviceConnectionManager,
                clientConnectionManager,
                serviceEndpointManager,
                options,
                loggerFactory,
                router,
                nameProvider,
                serverLifetimeManager,
                clientConnectionFactory,
                null)
        {
            MockService = new ConnectionTrackingMockService();

            // just store copies of these locally to keep the base class' accessor modifiers intact
            _loggerFactory           = loggerFactory;
            _clientConnectionManager = clientConnectionManager;
            _serviceProtocol         = serviceProtocol;
            _clientConnectionFactory = clientConnectionFactory;
        }
Example #5
0
        public ClientFactory(IClientConnectionFactory clientConnectionFactory, IMessageSerializer messageSerializer)
        {
            Contract.Requires <ArgumentNullException>(clientConnectionFactory != null);
            Contract.Requires <ArgumentNullException>(messageSerializer != null);

            this.clientConnectionFactory = clientConnectionFactory;
            this.messageSerializer       = messageSerializer;
        }
        public ClientFactory(IClientConnectionFactory clientConnectionFactory, IMessageSerializer messageSerializer)
        {
            Contract.Requires<ArgumentNullException>(clientConnectionFactory != null);
            Contract.Requires<ArgumentNullException>(messageSerializer != null);

            this.clientConnectionFactory = clientConnectionFactory;
            this.messageSerializer = messageSerializer;
        }
Example #7
0
        /// <summary>
        ///
        /// </summary>
        private void ScanClientConnectionFactory()
        {
            Log.WriteLine(LogLevel.Info, $"{nameof(TrinityClient)}: scanning for client connection factory.");
            var rank = ExtensionConfig.Instance.ResolveTypePriorities();

            int RankFunc(Type t)
            {
                return(rank.TryGetValue(t, out var r) ? r : 0);
            }

            m_clientfactory = AssemblyUtility.GetBestClassInstance <IClientConnectionFactory, DefaultClientConnectionFactory>(null, RankFunc);
        }
Example #8
0
 public ServiceConnectionFactory(IServiceProtocol serviceProtocol,
                                 IClientConnectionManager clientConnectionManager,
                                 ILoggerFactory loggerFactory,
                                 ConnectionDelegate connectionDelegate,
                                 IClientConnectionFactory clientConnectionFactory)
 {
     _serviceProtocol         = serviceProtocol;
     _clientConnectionManager = clientConnectionManager;
     _loggerFactory           = loggerFactory;
     _connectionDelegate      = connectionDelegate;
     _clientConnectionFactory = clientConnectionFactory;
 }
Example #9
0
 public TrinityClient(string endpoint, IClientConnectionFactory clientConnectionFactory)
 {
     m_endpoint      = endpoint;
     m_clientfactory = clientConnectionFactory;
     RegisterCommunicationModule <TrinityClientModule.TrinityClientModule>();
     ExtensionConfig.Instance.Priority.Add(new ExtensionPriority {
         Name = typeof(ClientMemoryCloud).AssemblyQualifiedName, Priority = int.MaxValue
     });
     ExtensionConfig.Instance.Priority.Add(new ExtensionPriority {
         Name = typeof(HostMemoryCloud).AssemblyQualifiedName, Priority = int.MinValue
     });
     ExtensionConfig.Instance.Priority = ExtensionConfig.Instance.Priority; // trigger update of priority table
 }
 public ServiceConnection(IServiceProtocol serviceProtocol,
                          IClientConnectionManager clientConnectionManager,
                          IConnectionFactory connectionFactory,
                          ILoggerFactory loggerFactory,
                          ConnectionDelegate connectionDelegate,
                          IClientConnectionFactory clientConnectionFactory,
                          string connectionId) :
     base(serviceProtocol, loggerFactory.CreateLogger <ServiceConnection>(), connectionId)
 {
     _clientConnectionManager = clientConnectionManager;
     _connectionFactory       = connectionFactory;
     _connectionDelegate      = connectionDelegate;
     _clientConnectionFactory = clientConnectionFactory;
 }
        private static TestServiceConnection CreateServiceConnection(Action <ConnectionBuilder> use = null,
                                                                     TestClientConnectionManager clientConnectionManager = null,
                                                                     string serverId                                  = null,
                                                                     string connectionId                              = null,
                                                                     GracefulShutdownMode?mode                        = null,
                                                                     IServiceMessageHandler messageHandler            = null,
                                                                     IServiceEventHandler eventHandler                = null,
                                                                     IClientConnectionFactory clientConnectionFactory = null,
                                                                     ILoggerFactory loggerFactory                     = null)
        {
            clientConnectionManager ??= new TestClientConnectionManager();
            clientConnectionFactory ??= new ClientConnectionFactory();

            var container         = new TestConnectionContainer();
            var connectionFactory = new TestConnectionFactory(conn =>
            {
                container.Instance = conn;
                return(Task.CompletedTask);
            });

            var services = new ServiceCollection();
            var builder  = new ConnectionBuilder(services.BuildServiceProvider());

            if (use == null)
            {
                use = (builder) => builder.UseConnectionHandler <TestConnectionHandler>();
            }
            use(builder);

            builder.UseConnectionHandler <TestConnectionHandler>();

            ConnectionDelegate handler = builder.Build();

            return(new TestServiceConnection(
                       container,
                       new ServiceProtocol(),
                       clientConnectionManager,
                       connectionFactory,
                       loggerFactory ?? NullLoggerFactory.Instance,
                       handler,
                       clientConnectionFactory,
                       serverId ?? "serverId",
                       connectionId ?? Guid.NewGuid().ToString("N"),
                       null,
                       messageHandler ?? new TestServiceMessageHandler(),
                       eventHandler ?? new TestServiceEventHandler(),
                       mode: mode ?? GracefulShutdownMode.Off
                       ));
        }
Example #12
0
 public TestServiceConnection(IConnectionFactory serviceConnectionFactory,
                              IClientConnectionFactory clientConnectionFactory,
                              ILoggerFactory loggerFactory,
                              ConnectionDelegate handler) : base(
         new ServiceProtocol(),
         new TestClientConnectionManager(),
         serviceConnectionFactory,
         loggerFactory,
         handler,
         clientConnectionFactory,
         Guid.NewGuid().ToString("N"),
         null,
         null
         )
 {
 }
Example #13
0
 public GrpcClientProxy(IClientConnectionFactory factory,
                        IOptions <NClientOption> nClientOptions,
                        IOptions <ClientMiddlewareOptions> clientMiddlewareOptions,
                        IActionExecutingContextAccessor actionExecutingContextAccessor,
                        IServiceProvider serviceProvider,
                        ILoggerFactory loggerFactory,
                        string?optionsName = null)
     : base(factory,
            nClientOptions,
            clientMiddlewareOptions,
            actionExecutingContextAccessor,
            serviceProvider,
            loggerFactory,
            optionsName)
 {
     ExceptionInvoked += GrpcClientProxy_ExceptionInvoked;
 }
Example #14
0
 public MessageProcessor(
     ILogger <MessageProcessor> logger,
     IClientConnectionFactory connectionFactory,
     IMessageDispatcher dispatcher,
     IProfileTokenProvider profileTokenProvider,
     IMessageMetadataFactory metadataFactory,
     IMessageTypeCache messageTypeCache,
     IAuthenticationService authenticationService)
 {
     _logger                = logger;
     _connectionFactory     = connectionFactory;
     _dispatcher            = dispatcher;
     _profileTokenProvider  = profileTokenProvider;
     _metadataFactory       = metadataFactory;
     _messageTypeCache      = messageTypeCache;
     _authenticationService = authenticationService;
 }
Example #15
0
 public ServiceConnection(IServiceProtocol serviceProtocol,
                          IClientConnectionManager clientConnectionManager,
                          IConnectionFactory connectionFactory,
                          ILoggerFactory loggerFactory,
                          ConnectionDelegate connectionDelegate,
                          IClientConnectionFactory clientConnectionFactory,
                          string connectionId,
                          HubServiceEndpoint endpoint,
                          IServiceMessageHandler serviceMessageHandler,
                          ServerConnectionType connectionType = ServerConnectionType.Default) :
     base(serviceProtocol, connectionId, endpoint, serviceMessageHandler, connectionType, loggerFactory?.CreateLogger <ServiceConnection>())
 {
     _clientConnectionManager = clientConnectionManager;
     _connectionFactory       = connectionFactory;
     _connectionDelegate      = connectionDelegate;
     _clientConnectionFactory = clientConnectionFactory;
 }
Example #16
0
 public ServiceConnection(IServiceProtocol serviceProtocol,
                          IClientConnectionManager clientConnectionManager,
                          IConnectionFactory connectionFactory,
                          ILoggerFactory loggerFactory,
                          ConnectionDelegate connectionDelegate,
                          IClientConnectionFactory clientConnectionFactory,
                          string connectionId,
                          IServiceMessageHandler serviceMessageHandler,
                          ServerConnectionType connectionType = ServerConnectionType.Default) :
     base(serviceProtocol, loggerFactory, connectionId, serviceMessageHandler, connectionType)
 {
     _clientConnectionManager = clientConnectionManager;
     _connectionFactory       = connectionFactory;
     _connectionDelegate      = connectionDelegate;
     _clientConnectionFactory = clientConnectionFactory;
     _logger = loggerFactory?.CreateLogger <ServiceConnection>() ?? NullLogger <ServiceConnection> .Instance;
 }
Example #17
0
        private static TestServiceConnection CreateServiceConnection(ConnectionHandler handler = null,
                                                                     TestClientConnectionManager clientConnectionManager = null,
                                                                     string serverId                                  = null,
                                                                     string connectionId                              = null,
                                                                     GracefulShutdownMode?mode                        = null,
                                                                     IServiceMessageHandler messageHandler            = null,
                                                                     IServiceEventHandler eventHandler                = null,
                                                                     IClientConnectionFactory clientConnectionFactory = null,
                                                                     HubServiceEndpoint hubServiceEndpoint            = null,
                                                                     ILoggerFactory loggerFactory                     = null)
        {
            clientConnectionManager ??= new TestClientConnectionManager();
            clientConnectionFactory ??= new TestClientConnectionFactory();

            var container         = new TestConnectionContainer();
            var connectionFactory = new TestConnectionFactory(conn =>
            {
                container.Instance = conn;
                return(Task.CompletedTask);
            });

            var services = new ServiceCollection();
            var builder  = new ConnectionBuilder(services.BuildServiceProvider());

            if (handler == null)
            {
                handler = new TestConnectionHandler();
            }

            return(new TestServiceConnection(
                       container,
                       new ServiceProtocol(),
                       clientConnectionManager,
                       connectionFactory,
                       loggerFactory ?? NullLoggerFactory.Instance,
                       handler.OnConnectedAsync,
                       clientConnectionFactory,
                       serverId ?? "serverId",
                       connectionId ?? Guid.NewGuid().ToString("N"),
                       hubServiceEndpoint ?? new TestHubServiceEndpoint(),
                       messageHandler ?? new TestServiceMessageHandler(),
                       eventHandler ?? new TestServiceEventHandler(),
                       mode: mode ?? GracefulShutdownMode.Off
                       ));
        }
 public TestServiceConnection(IConnectionFactory serviceConnectionFactory,
                              IClientConnectionFactory clientConnectionFactory,
                              ILoggerFactory loggerFactory,
                              ConnectionDelegate handler) : base(
         new ServiceProtocol(),
         new TestClientConnectionManager(),
         serviceConnectionFactory,
         loggerFactory,
         handler,
         clientConnectionFactory,
         "serverId",
         Guid.NewGuid().ToString("N"),
         null,
         null,
         migrationLevel: ServerConnectionMigrationLevel.ShutdownOnly
         )
 {
 }
Example #19
0
        private void ScanClientConnectionFactory()
        {
            Log.WriteLine(LogLevel.Info, $"{nameof(TrinityClient)}: scanning for client connection factory.");
            var rank = ExtensionConfig.Instance.ResolveTypePriorities();
            Func <Type, int> rank_func = t =>
            {
                if (rank.TryGetValue(t, out var r))
                {
                    return(r);
                }
                else
                {
                    return(0);
                }
            };

            m_clientfactory = AssemblyUtility.GetBestClassInstance <IClientConnectionFactory, DefaultClientConnectionFactory>(null, rank_func);
        }
 public TestServiceConnection(IConnectionFactory serviceConnectionFactory,
                              IClientConnectionFactory clientConnectionFactory,
                              ILoggerFactory loggerFactory,
                              ConnectionDelegate handler,
                              GracefulShutdownMode mode = GracefulShutdownMode.Off) : base(
         new ServiceProtocol(),
         new TestClientConnectionManager(),
         serviceConnectionFactory,
         loggerFactory,
         handler,
         clientConnectionFactory,
         "serverId",
         Guid.NewGuid().ToString("N"),
         null,
         null,
         mode: mode
         )
 {
 }
 public ServiceConnectionFactory(
     IServiceProtocol serviceProtocol,
     IClientConnectionManager clientConnectionManager,
     IConnectionFactory connectionFactory,
     ILoggerFactory loggerFactory,
     ConnectionDelegate connectionDelegate,
     IClientConnectionFactory clientConnectionFactory,
     IServerNameProvider nameProvider,
     IServiceEventHandler serviceEventHandler)
 {
     _serviceProtocol         = serviceProtocol;
     _clientConnectionManager = clientConnectionManager;
     _connectionFactory       = connectionFactory;
     _loggerFactory           = loggerFactory;
     _connectionDelegate      = connectionDelegate;
     _clientConnectionFactory = clientConnectionFactory;
     _nameProvider            = nameProvider;
     _serviceEventHandler     = serviceEventHandler;
 }
        public ServiceHubDispatcher(IServiceProtocol serviceProtocol,
                                    IServiceConnectionManager <THub> serviceConnectionManager,
                                    IClientConnectionManager clientConnectionManager,
                                    IServiceEndpointProvider serviceEndpointProvider,
                                    IOptions <ServiceOptions> options,
                                    ILoggerFactory loggerFactory,
                                    IClientConnectionFactory clientConnectionFactory)
        {
            _serviceProtocol          = serviceProtocol;
            _serviceConnectionManager = serviceConnectionManager;
            _clientConnectionManager  = clientConnectionManager;
            _serviceEndpointProvider  = serviceEndpointProvider;
            _options = options != null ? options.Value : throw new ArgumentNullException(nameof(options));

            _loggerFactory           = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
            _logger                  = loggerFactory.CreateLogger <ServiceHubDispatcher <THub> >();
            _clientConnectionFactory = clientConnectionFactory;
            _userId                  = GenerateServerName();
        }
Example #23
0
 public MockServiceConnectionFactory(
     IMockService mockService,
     IServiceProtocol serviceProtocol,
     IClientConnectionManager clientConnectionManager,
     IConnectionFactory connectionFactory,
     ILoggerFactory loggerFactory,
     ConnectionDelegate connectionDelegate,
     IClientConnectionFactory clientConnectionFactory,
     IServerNameProvider nameProvider)
     : base(
         serviceProtocol,
         clientConnectionManager,
         new MockServiceConnectionContextFactory(mockService),   // use instead of connectionFactory
         loggerFactory,
         connectionDelegate,
         clientConnectionFactory,
         nameProvider)
 {
     _mockService = mockService;
 }
Example #24
0
 public ServiceConnection(IServiceProtocol serviceProtocol,
                          IClientConnectionManager clientConnectionManager,
                          IConnectionFactory connectionFactory,
                          ILoggerFactory loggerFactory,
                          ConnectionDelegate connectionDelegate,
                          IClientConnectionFactory clientConnectionFactory,
                          string connectionId,
                          HubServiceEndpoint endpoint,
                          IServiceMessageHandler serviceMessageHandler,
                          ServiceConnectionType connectionType = ServiceConnectionType.Default,
                          int closeTimeOutMilliseconds         = DefaultCloseTimeoutMilliseconds) :
     base(serviceProtocol, connectionId, endpoint, serviceMessageHandler, connectionType, loggerFactory?.CreateLogger <ServiceConnection>())
 {
     _clientConnectionManager   = clientConnectionManager;
     _connectionFactory         = connectionFactory;
     _connectionDelegate        = connectionDelegate;
     _clientConnectionFactory   = clientConnectionFactory;
     _closeTimeOutMilliseconds  = closeTimeOutMilliseconds;
     _enableConnectionMigration = false;
 }
 public ServiceConnection(IServiceProtocol serviceProtocol,
                          IClientConnectionManager clientConnectionManager,
                          IConnectionFactory connectionFactory,
                          ILoggerFactory loggerFactory,
                          ConnectionDelegate connectionDelegate,
                          IClientConnectionFactory clientConnectionFactory,
                          string serverId,
                          string connectionId,
                          HubServiceEndpoint endpoint,
                          IServiceMessageHandler serviceMessageHandler,
                          ServiceConnectionType connectionType = ServiceConnectionType.Default,
                          GracefulShutdownMode mode            = GracefulShutdownMode.Off,
                          int closeTimeOutMilliseconds         = DefaultCloseTimeoutMilliseconds
                          ) : base(serviceProtocol, serverId, connectionId, endpoint, serviceMessageHandler, connectionType, loggerFactory?.CreateLogger <ServiceConnection>(), mode)
 {
     _clientConnectionManager  = clientConnectionManager;
     _connectionFactory        = connectionFactory;
     _connectionDelegate       = connectionDelegate;
     _clientConnectionFactory  = clientConnectionFactory;
     _closeTimeOutMilliseconds = closeTimeOutMilliseconds;
 }
        public ServiceHubDispatcher(IServiceProtocol serviceProtocol,
                                    IServiceConnectionManager <THub> serviceConnectionManager,
                                    IClientConnectionManager clientConnectionManager,
                                    IServiceEndpointManager serviceEndpointManager,
                                    IOptions <ServiceOptions> options,
                                    ILoggerFactory loggerFactory,
                                    IEndpointRouter router,
                                    IClientConnectionFactory clientConnectionFactory)
        {
            _serviceProtocol          = serviceProtocol;
            _serviceConnectionManager = serviceConnectionManager;
            _clientConnectionManager  = clientConnectionManager;
            _serviceEndpointManager   = serviceEndpointManager;
            _options = options != null ? options.Value : throw new ArgumentNullException(nameof(options));

            _router                  = router ?? throw new ArgumentNullException(nameof(router));
            _loggerFactory           = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
            _logger                  = loggerFactory.CreateLogger <ServiceHubDispatcher <THub> >();
            _clientConnectionFactory = clientConnectionFactory;
            _hubName                 = typeof(THub).Name;
        }
Example #27
0
 public ClientConnectionPool(ILoggerFactory loggerFactory,
                             IClientConnectionFactory clientConnectionFactory)
 {
     this.logger            = loggerFactory.CreateLogger("Network");
     this.connectionFactory = clientConnectionFactory;
 }
Example #28
0
 public OnceCallFactory(IClientConnectionFactory factory, ILoggerFactory loggerFactory)
 {
     _factory = factory;
     _logger  = loggerFactory.CreateLogger("NetRpc");
 }
Example #29
0
 public GrpcClientProxy(IClientConnectionFactory factory, IOptions <NetRpcClientOption> options, IServiceProvider serviceProvider,
                        ILoggerFactory loggerFactory, string optionsName = null)
     : base(factory, options, serviceProvider, loggerFactory, optionsName)
 {
     ExceptionInvoked += GrpcClientProxy_ExceptionInvoked;
 }
Example #30
0
 public Server(int port, int backlog, IClientConnectionFactory connectionFactory)
 {
     _port              = port;
     _backlog           = backlog;
     _connectionFactory = connectionFactory;
 }