Ejemplo n.º 1
0
 /// <summary>
 /// Start a new client to the parent chain
 /// </summary>
 /// <returns></returns>
 /// <exception cref="ChainInfoNotFoundException"></exception>
 private async Task CreateClientToParentChain()
 {
     if (!GrpcLocalConfig.Instance.ClientToParentChain)
     {
         return;
     }
     try
     {
         // do not use cache since configuration is managed by cluster
         var parent = GrpcRemoteConfig.Instance.ParentChain;
         if (parent == null || parent.Count == 0)
         {
             throw new ChainInfoNotFoundException("Unable to get parent chain info.");
         }
         _clientToParentChain =
             (ClientToParentChain)CreateClient(parent.ElementAt(0).Value, parent.ElementAt(0).Key, false);
         var targetHeight = GetParentChainTargetHeight();
         _clientToParentChain.StartDuplexStreamingCall(_tokenSourceToParentChain.Token, targetHeight)
         .ConfigureAwait(false);
         _logger?.Info($"Created client to parent chain {parent.ElementAt(0).Key}");
     }
     catch (Exception e)
     {
         _logger?.Error(e, "Exception while create client to parent chain.");
         throw;
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// close and clear clients to parent chain
        /// </summary>
        public void CloseClientToParentChain()
        {
            _tokenSourceToParentChain?.Cancel();
            _tokenSourceToParentChain?.Dispose();

            //Todo: probably not needed
            _clientToParentChain = null;
        }
Ejemplo n.º 3
0
        private void GrpcRemoteConfigOnConfigChanged(object sender, EventArgs e)
        {
            _tokenSourceToSideChain?.Cancel();
            _tokenSourceToSideChain?.Dispose();
            _tokenSourceToParentChain?.Cancel();
            _tokenSourceToParentChain?.Dispose();

            // reset
            _tokenSourceToSideChain   = new CancellationTokenSource();
            _tokenSourceToParentChain = new CancellationTokenSource();

            // client cache would be cleared since configuration has been changed
            // Todo: only clear clients which is needed
            _clientsToSideChains.Clear();
            _clientToParentChain = null;
            Init();
        }