예제 #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private boolean canConnect() throws InterruptedException
        private bool CanConnect()
        {
            ListenSocketAddress socketAddress = _server.address();
            ChannelFuture       channelFuture = _bootstrap.connect(socketAddress.Hostname, socketAddress.Port);

            _channel = channelFuture.channel();
            return(channelFuture.await().Success);
        }
예제 #2
0
        private static Channel ChannelMock(bool open)
        {
            Channel channel = mock(typeof(Channel));

            when(channel.Open).thenReturn(open);
            ChannelFuture channelFuture = mock(typeof(ChannelFuture));

            when(channel.close()).thenReturn(channelFuture);
            return(channel);
        }
예제 #3
0
 /// <summary>
 /// Chains a channel future to a promise. Used when the returned promise
 /// was not allocated through the channel and cannot be used as the
 /// first-hand promise for the I/O operation.
 /// </summary>
 private static void Chain(ChannelFuture when, Promise <Void> then)
 {
     when.addListener(f =>
     {
         if (f.Success)
         {
             then.Success = when.get();
         }
         else
         {
             then.Failure = when.cause();
         }
     });
 }
예제 #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRespondWithCompleteStreamOfTransactions() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRespondWithCompleteStreamOfTransactions()
        {
            // given
            when(_transactionIdStore.LastCommittedTransactionId).thenReturn(15L);
            when(_logicalTransactionStore.getTransactions(14L)).thenReturn(TxCursor(cursor(Tx(14), Tx(15))));
            ChannelFuture channelFuture = mock(typeof(ChannelFuture));

            when(_context.writeAndFlush(any())).thenReturn(channelFuture);

            // when
            _txPullRequestHandler.channelRead0(_context, new TxPullRequest(13, _storeId));

            // then
            verify(_context).writeAndFlush(isA(typeof(ChunkedTransactionStream)));
        }
예제 #5
0
 /// <summary>
 /// Will try to reconnect once before giving up on a send. The reconnection *must* happen
 /// after write was scheduled. This is necessary to provide proper ordering when a message
 /// is sent right after the non-blocking channel was setup and before the server is ready
 /// to accept a connection. This happens frequently in tests.
 /// </summary>
 private void DeferredWrite(object msg, ChannelFuture channelFuture, Promise <Void> promise, bool firstAttempt, System.Action <io.netty.channel.Channel, object> writer)
 {
     channelFuture.addListener((ChannelFutureListener)f =>
     {
         if (f.Success)
         {
             writer(f.channel(), msg);
         }
         else if (firstAttempt)
         {
             TryConnect();
             DeferredWrite(msg, _fChannel, promise, false, writer);
         }
         else
         {
             promise.Failure = f.cause();
         }
     });
 }
예제 #6
0
        private void TryConnect()
        {
            lock (this)
            {
                if (_disposed)
                {
                    return;
                }
                else if (_fChannel != null && !_fChannel.Done)
                {
                    return;
                }

                _fChannel = _bootstrap.connect(_destination.socketAddress());
                _channel  = _fChannel.channel();

                _fChannel.addListener((ChannelFuture f) =>
                {
                    if (!f.Success)
                    {
                        long millis = _connectionBackoff.Millis;
                        _cappedLogger.warn("Failed to connect to: " + _destination.socketAddress() + ". Retrying in " + millis + " ms");
                        f.channel().eventLoop().schedule(this.tryConnect, millis, MILLISECONDS);
                        _connectionBackoff.increment();
                    }
                    else
                    {
                        _log.info("Connected: " + f.channel());
                        f.channel().closeFuture().addListener(closed =>
                        {
                            _log.warn(string.Format("Lost connection to: {0} ({1})", _destination, _channel.remoteAddress()));
                            _connectionBackoff = _connectionBackoffStrategy.newTimeout();
                            f.channel().eventLoop().schedule(this.tryConnect, 0, MILLISECONDS);
                        });
                    }
                });
            }
        }