Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCountDown()
        public virtual void ShouldCountDown()
        {
            PortIterator portIterator = new PortIterator(new int[] { 6005, 6000 });

//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertEquals(6005, ( int )portIterator.Next());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertEquals(6004, ( int )portIterator.Next());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertEquals(6003, ( int )portIterator.Next());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertEquals(6002, ( int )portIterator.Next());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertEquals(6001, ( int )portIterator.Next());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertEquals(6000, ( int )portIterator.Next());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertFalse(portIterator.HasNext());
        }
Example #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public Connection bindToFirstAvailablePortInRange(org.neo4j.helpers.HostnamePort serverAddress) throws org.jboss.netty.channel.ChannelException
        public virtual Connection BindToFirstAvailablePortInRange(HostnamePort serverAddress)
        {
            int[]  ports = serverAddress.Ports;
            string host  = serverAddress.Host;

            Channel           channel;
            InetSocketAddress socketAddress;
            ChannelException  lastException = null;

            PortIterator portIterator = new PortIterator(ports);

            while (portIterator.MoveNext())
            {
                int?port = portIterator.Current;
                if (string.ReferenceEquals(host, null) || host.Equals(ALL_INTERFACES_ADDRESS))
                {
                    socketAddress = new InetSocketAddress(port);
                }
                else
                {
                    socketAddress = new InetSocketAddress(host, port);
                }
                try
                {
                    channel = _bootstrap.bind(socketAddress);
                    return(new Connection(socketAddress, channel));
                }
                catch (ChannelException e)
                {
                    if (lastException != null)
                    {
                        e.addSuppressed(lastException);
                    }
                    lastException = e;
                }
            }

            throw Objects.requireNonNull(lastException);
        }