Beispiel #1
0
        /// <summary>
        /// Opens the component.
        /// </summary>
        /// <param name="correlationId">(optional) transaction id to trace execution through call chain.</param>
        /// <returns></returns>
        public async virtual Task OpenAsync(string correlationId)
        {
            if (IsOpen())
            {
                return;
            }

            if (_endpoint == null)
            {
                _endpoint = CreateLocalEndpoint();
                _endpoint.Register(this);
                _localEndpoint = true;
            }

            if (_localEndpoint)
            {
                await _endpoint.OpenAsync(correlationId).ContinueWith(task =>
                {
                    _opened = task.Exception == null;
                });
            }
            else
            {
                _opened = true;
            }
        }
Beispiel #2
0
        public DummyGrpcEndpointTest()
        {
            _ctrl     = new DummyController();
            _service1 = new DummyCommandableGrpcService("dummy1");
            _service2 = new DummyCommandableGrpcService("dummy2");

            _client1 = new DummyCommandableGrpcClient("dummy1");
            _client2 = new DummyCommandableGrpcClient("dummy2");

            _grpcEndpoint = new GrpcEndpoint();

            var references = References.FromTuples(
                new Descriptor("pip-services3-dummies", "controller", "default", "default", "1.0"), _ctrl,
                new Descriptor("pip-services3", "endpoint", "grpc", "default", "1.0"), _grpcEndpoint
                );

            _client1.Configure(grpcConfig);
            _client2.Configure(grpcConfig);

            _grpcEndpoint.Configure(grpcConfig);

            _service1.SetReferences(references);
            _service2.SetReferences(references);

            _grpcEndpoint.OpenAsync(null).Wait();

            _client1.OpenAsync(null).Wait();
            _client2.OpenAsync(null).Wait();
        }
Beispiel #3
0
 /// <summary>
 /// Unsets (clears) previously set references to dependent components.
 /// </summary>
 public virtual void UnsetReferences()
 {
     // Remove registration callback from endpoint
     if (_endpoint != null)
     {
         _endpoint.Unregister(this);
         _endpoint = null;
     }
 }
Beispiel #4
0
        private GrpcEndpoint CreateLocalEndpoint()
        {
            var endpoint = new GrpcEndpoint();

            if (_config != null)
            {
                endpoint.Configure(_config);
            }

            if (_references != null)
            {
                endpoint.SetReferences(_references);
            }

            return(endpoint);
        }
Beispiel #5
0
        /// <summary>
        /// Sets references to dependent components.
        /// </summary>
        /// <param name="references">references to locate the component dependencies.</param>
        public virtual void SetReferences(IReferences references)
        {
            _references = references;

            _logger.SetReferences(references);
            _counters.SetReferences(references);
            _dependencyResolver.SetReferences(references);

            // Get endpoint
            _endpoint      = _dependencyResolver.GetOneOptional("endpoint") as GrpcEndpoint;
            _localEndpoint = _endpoint == null;

            // Or create a local one
            if (_endpoint == null)
            {
                _endpoint = CreateLocalEndpoint();
            }

            // Add registration callback to the endpoint
            _endpoint.Register(this);
        }