Example #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static byte[] chunk(int maxChunkSize, byte[][] messages) throws java.io.IOException
        public static sbyte[] Chunk(int maxChunkSize, sbyte[][] messages)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final ByteBuffer outputBuffer = ByteBuffer.allocate(1024 * 8);
            ByteBuffer outputBuffer = ByteBuffer.allocate(1024 * 8);

            Channel ch = mock(typeof(Channel));

            when(ch.alloc()).thenReturn(UnpooledByteBufAllocator.DEFAULT);
            when(ch.writeAndFlush(any(), Null)).then(inv =>
            {
                ByteBuf buf = inv.getArgument(0);
                outputBuffer.limit(outputBuffer.position() + buf.readableBytes());
                buf.readBytes(outputBuffer);
                buf.release();
                return(null);
            });

            int           maxBufferSize = maxChunkSize + CHUNK_HEADER_SIZE;
            ChunkedOutput @out          = new ChunkedOutput(ch, maxBufferSize, maxBufferSize, TransportThrottleGroup.NO_THROTTLE);

            foreach (sbyte[] message in messages)
            {
                @out.BeginMessage();
                @out.WriteBytes(message, 0, message.Length);
                @out.MessageSucceeded();
            }
            @out.Flush();
            @out.Dispose();

            sbyte[] bytes = new sbyte[outputBuffer.limit()];
            outputBuffer.position(0);
            outputBuffer.get(bytes);
            return(bytes);
        }
Example #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRemoveChannelViaCallback()
        public virtual void ShouldRemoveChannelViaCallback()
        {
            // given
            AdvertisedSocketAddress address  = new AdvertisedSocketAddress("localhost", 1984);
            ReconnectingChannels    channels = new ReconnectingChannels();

            channels.PutIfAbsent(address, mock(typeof(ReconnectingChannel)));

            IdleChannelReaperHandler reaper = new IdleChannelReaperHandler(channels);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.net.InetSocketAddress socketAddress = address.socketAddress();
            InetSocketAddress socketAddress = address.SocketAddressConflict();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final io.netty.channel.Channel channel = mock(io.netty.channel.Channel.class);
            Channel channel = mock(typeof(Channel));

            when(channel.remoteAddress()).thenReturn(socketAddress);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final io.netty.channel.ChannelHandlerContext context = mock(io.netty.channel.ChannelHandlerContext.class);
            ChannelHandlerContext context = mock(typeof(ChannelHandlerContext));

            when(context.channel()).thenReturn(channel);

            // when
            reaper.UserEventTriggered(context, IdleStateEvent.ALL_IDLE_STATE_EVENT);

            // then
            assertNull(channels.Get(address));
        }
Example #3
0
 public BoltChannel(string id, string connector, Channel rawChannel)
 {
     this._id          = id;
     this._connectTime = DateTimeHelper.CurrentUnixTimeMillis();
     this._connector   = connector;
     this._rawChannel  = rawChannel;
     this._info        = CreateConnectionInfo();
 }
Example #4
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);
        }
Example #5
0
        public override void Close()
        {
            Channel rawChannel = rawChannel();

            if (rawChannel.Open)
            {
                rawChannel.close().syncUninterruptibly();
            }
        }
Example #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldNotCloseUnderlyingChannelWhenItIsClosed()
        internal virtual void ShouldNotCloseUnderlyingChannelWhenItIsClosed()
        {
            Channel     channel     = ChannelMock(false);
            BoltChannel boltChannel = new BoltChannel("bolt-1", "bolt", channel);

            boltChannel.Close();

            verify(channel, never()).close();
        }
Example #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldCloseUnderlyingChannelWhenItIsOpen()
        internal virtual void ShouldCloseUnderlyingChannelWhenItIsOpen()
        {
            Channel     channel     = ChannelMock(true);
            BoltChannel boltChannel = new BoltChannel("bolt-1", "bolt", channel);

            boltChannel.Close();

            verify(channel).close();
        }
Example #8
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);
        }
Example #9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private <O extends org.neo4j.causalclustering.protocol.ProtocolInstaller_Orientation, BUILDER extends NettyPipelineBuilder<O,BUILDER>> BUILDER create(io.netty.channel.Channel channel, BUILDER nettyPipelineBuilder) throws Exception
        private BUILDER Create <O, BUILDER>(Channel channel, BUILDER nettyPipelineBuilder) where O : Org.Neo4j.causalclustering.protocol.ProtocolInstaller_Orientation where BUILDER : NettyPipelineBuilder <O, BUILDER>
        {
            int i = 0;

            foreach (ChannelHandler handler in _wrapper.handlersFor(channel))
            {
                nettyPipelineBuilder.add(string.Format("{0}_{1:D}", _wrapper.name(), i), handler);
                i++;
            }
            return(nettyPipelineBuilder);
        }
Example #10
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);
                        });
                    }
                });
            }
        }
Example #11
0
 public override void Acquire(Channel channel)
 {
 }
Example #12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public ServerNettyPipelineBuilder server(io.netty.channel.Channel channel, org.neo4j.logging.Log log) throws Exception
        public virtual ServerNettyPipelineBuilder Server(Channel channel, Log log)
        {
            return(Create(channel, NettyPipelineBuilder.Server(channel.pipeline(), log)));
        }
Example #13
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public ClientNettyPipelineBuilder client(io.netty.channel.Channel channel, org.neo4j.logging.Log log) throws Exception
        public virtual ClientNettyPipelineBuilder Client(Channel channel, Log log)
        {
            return(Create(channel, NettyPipelineBuilder.Client(channel.pipeline(), log)));
        }
Example #14
0
 public override void Uninstall(Channel channel)
 {
 }
Example #15
0
 public override void Release(Channel channel)
 {
 }
Example #16
0
 private BoltChannel NewBoltChannel(Channel ch)
 {
     return(new BoltChannel(_connectionTracker.newConnectionId(_connector), _connector, ch));
 }
Example #17
0
 public virtual void Uninstall(Channel channel)
 {
     _writeThrottle.uninstall(channel);
 }
Example #18
0
 public SimpleNettyChannel(io.netty.channel.Channel channel, Log log)
 {
     this._channel = channel;
     this._log     = log;
 }