Search in sources :

Example 71 with BindException

use of java.net.BindException in project robovm by robovm.

the class OldDatagramSocketTest method test_setReuseAddressZ.

public void test_setReuseAddressZ() throws Exception {
    // test case were we set it to false
    DatagramSocket theSocket1 = null;
    DatagramSocket theSocket2 = null;
    try {
        InetSocketAddress theAddress = new InetSocketAddress(InetAddress.getLocalHost(), Support_PortManager.getNextPortForUDP());
        theSocket1 = new DatagramSocket((SocketAddress) null);
        theSocket2 = new DatagramSocket((SocketAddress) null);
        theSocket1.setReuseAddress(false);
        theSocket2.setReuseAddress(false);
        theSocket1.bind(theAddress);
        theSocket2.bind(theAddress);
        fail("No exception when trying to connect to do duplicate socket bind with re-useaddr set to false");
    } catch (BindException e) {
    }
    if (theSocket1 != null)
        theSocket1.close();
    if (theSocket2 != null)
        theSocket2.close();
    // test case were we set it to true
    try {
        InetSocketAddress theAddress = new InetSocketAddress(InetAddress.getLocalHost(), Support_PortManager.getNextPortForUDP());
        theSocket1 = new DatagramSocket((SocketAddress) null);
        theSocket2 = new DatagramSocket((SocketAddress) null);
        theSocket1.setReuseAddress(true);
        theSocket2.setReuseAddress(true);
        theSocket1.bind(theAddress);
        theSocket2.bind(theAddress);
    } catch (Exception e) {
        fail("unexpected exception when trying to connect to do duplicate socket bind with re-useaddr set to true");
    }
    if (theSocket1 != null)
        theSocket1.close();
    if (theSocket2 != null)
        theSocket2.close();
    // platforms
    try {
        InetSocketAddress theAddress = new InetSocketAddress(InetAddress.getLocalHost(), Support_PortManager.getNextPortForUDP());
        theSocket1 = new DatagramSocket((SocketAddress) null);
        theSocket2 = new DatagramSocket((SocketAddress) null);
        theSocket1.bind(theAddress);
        theSocket2.bind(theAddress);
        fail("No exception when trying to connect to do duplicate socket bind with re-useaddr left as default");
    } catch (BindException e) {
    }
    if (theSocket1 != null)
        theSocket1.close();
    if (theSocket2 != null)
        theSocket2.close();
    try {
        theSocket1.setReuseAddress(true);
        fail("SocketException was not thrown.");
    } catch (SocketException se) {
    //expected
    }
}
Also used : SocketException(java.net.SocketException) DatagramSocket(java.net.DatagramSocket) InetSocketAddress(java.net.InetSocketAddress) BindException(java.net.BindException) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) BindException(java.net.BindException) InterruptedIOException(java.io.InterruptedIOException) UnknownHostException(java.net.UnknownHostException) SocketException(java.net.SocketException) IllegalBlockingModeException(java.nio.channels.IllegalBlockingModeException) SocketTimeoutException(java.net.SocketTimeoutException) PortUnreachableException(java.net.PortUnreachableException)

Example 72 with BindException

use of java.net.BindException in project spring-boot by spring-projects.

the class JettyWebServer method start.

@Override
public void start() throws WebServerException {
    synchronized (this.monitor) {
        if (this.started) {
            return;
        }
        this.server.setConnectors(this.connectors);
        if (!this.autoStart) {
            return;
        }
        try {
            this.server.start();
            for (Handler handler : this.server.getHandlers()) {
                handleDeferredInitialize(handler);
            }
            Connector[] connectors = this.server.getConnectors();
            for (Connector connector : connectors) {
                try {
                    connector.start();
                } catch (BindException ex) {
                    if (connector instanceof NetworkConnector) {
                        throw new PortInUseException(((NetworkConnector) connector).getPort());
                    }
                    throw ex;
                }
            }
            this.started = true;
            JettyWebServer.logger.info("Jetty started on port(s) " + getActualPortsDescription());
        } catch (WebServerException ex) {
            throw ex;
        } catch (Exception ex) {
            throw new WebServerException("Unable to start embedded Jetty server", ex);
        }
    }
}
Also used : NetworkConnector(org.eclipse.jetty.server.NetworkConnector) Connector(org.eclipse.jetty.server.Connector) PortInUseException(org.springframework.boot.web.server.PortInUseException) WebServerException(org.springframework.boot.web.server.WebServerException) Handler(org.eclipse.jetty.server.Handler) BindException(java.net.BindException) NetworkConnector(org.eclipse.jetty.server.NetworkConnector) WebServerException(org.springframework.boot.web.server.WebServerException) BindException(java.net.BindException) PortInUseException(org.springframework.boot.web.server.PortInUseException)

Example 73 with BindException

use of java.net.BindException in project spring-framework by spring-projects.

the class ExceptionHandlerMethodResolverTests method resolveMethodExceptionSubType.

@Test
public void resolveMethodExceptionSubType() {
    ExceptionHandlerMethodResolver resolver = new ExceptionHandlerMethodResolver(ExceptionController.class);
    IOException ioException = new FileNotFoundException();
    assertEquals("handleIOException", resolver.resolveMethod(ioException).getName());
    SocketException bindException = new BindException();
    assertEquals("handleSocketException", resolver.resolveMethod(bindException).getName());
}
Also used : SocketException(java.net.SocketException) FileNotFoundException(java.io.FileNotFoundException) BindException(java.net.BindException) IOException(java.io.IOException) Test(org.junit.Test)

Example 74 with BindException

use of java.net.BindException in project neo4j by neo4j.

the class RaftServer method startNettyServer.

private void startNettyServer() {
    workerGroup = new NioEventLoopGroup(0, threadFactory);
    log.info("Starting server at: " + listenAddress);
    ServerBootstrap bootstrap = new ServerBootstrap().group(workerGroup).channel(NioServerSocketChannel.class).option(ChannelOption.SO_REUSEADDR, true).localAddress(listenAddress.socketAddress()).childHandler(new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ChannelPipeline pipeline = ch.pipeline();
            pipeline.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));
            pipeline.addLast(new LengthFieldPrepender(4));
            pipeline.addLast(new VersionDecoder(logProvider));
            pipeline.addLast(new VersionPrepender());
            pipeline.addLast(new RaftMessageDecoder(marshal));
            pipeline.addLast(new RaftMessageHandler());
            pipeline.addLast(new ExceptionLoggingHandler(log));
            pipeline.addLast(new ExceptionMonitoringHandler(monitors.newMonitor(ExceptionMonitoringHandler.Monitor.class, RaftServer.class)));
            pipeline.addLast(new ExceptionSwallowingHandler());
        }
    });
    try {
        channel = bootstrap.bind().syncUninterruptibly().channel();
    } catch (Exception e) {
        //noinspection ConstantConditions
        if (e instanceof BindException) {
            userLog.error("Address is already bound for setting: " + setting + " with value: " + listenAddress);
            log.error("Address is already bound for setting: " + setting + " with value: " + listenAddress, e);
            throw e;
        }
    }
}
Also used : SocketChannel(io.netty.channel.socket.SocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) ExceptionSwallowingHandler(org.neo4j.causalclustering.handlers.ExceptionSwallowingHandler) VersionPrepender(org.neo4j.causalclustering.VersionPrepender) BindException(java.net.BindException) LengthFieldPrepender(io.netty.handler.codec.LengthFieldPrepender) VersionDecoder(org.neo4j.causalclustering.VersionDecoder) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) BindException(java.net.BindException) ChannelPipeline(io.netty.channel.ChannelPipeline) ExceptionMonitoringHandler(org.neo4j.causalclustering.handlers.ExceptionMonitoringHandler) RaftMessageDecoder(org.neo4j.causalclustering.messaging.marshalling.RaftMessageDecoder) ExceptionLoggingHandler(org.neo4j.causalclustering.handlers.ExceptionLoggingHandler) LengthFieldBasedFrameDecoder(io.netty.handler.codec.LengthFieldBasedFrameDecoder) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 75 with BindException

use of java.net.BindException in project neo4j by neo4j.

the class CatchupServer method start.

@Override
public synchronized void start() throws Throwable {
    if (channel != null) {
        return;
    }
    workerGroup = new NioEventLoopGroup(0, threadFactory);
    ServerBootstrap bootstrap = new ServerBootstrap().group(workerGroup).channel(NioServerSocketChannel.class).localAddress(listenAddress.socketAddress()).childHandler(new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(SocketChannel ch) {
            CatchupServerProtocol protocol = new CatchupServerProtocol();
            ChannelPipeline pipeline = ch.pipeline();
            pipeline.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));
            pipeline.addLast(new LengthFieldPrepender(4));
            pipeline.addLast(new VersionDecoder(logProvider));
            pipeline.addLast(new VersionPrepender());
            pipeline.addLast(new ResponseMessageTypeEncoder());
            pipeline.addLast(new RequestMessageTypeEncoder());
            pipeline.addLast(new TxPullResponseEncoder());
            pipeline.addLast(new CoreSnapshotEncoder());
            pipeline.addLast(new GetStoreIdResponseEncoder());
            pipeline.addLast(new StoreCopyFinishedResponseEncoder());
            pipeline.addLast(new TxStreamFinishedResponseEncoder());
            pipeline.addLast(new FileChunkEncoder());
            pipeline.addLast(new FileHeaderEncoder());
            pipeline.addLast(new ServerMessageTypeHandler(protocol, logProvider));
            pipeline.addLast(decoders(protocol));
            pipeline.addLast(new TxPullRequestHandler(protocol, storeIdSupplier, dataSourceAvailabilitySupplier, transactionIdStoreSupplier, logicalTransactionStoreSupplier, txPullBatchSize, monitors, logProvider));
            pipeline.addLast(new ChunkedWriteHandler());
            pipeline.addLast(new GetStoreRequestHandler(protocol, dataSourceSupplier, checkPointerSupplier, fs, pageCache, logProvider, storeCopyCheckPointMutex));
            pipeline.addLast(new GetStoreIdRequestHandler(protocol, storeIdSupplier));
            if (coreState != null) {
                pipeline.addLast(new CoreSnapshotRequestHandler(protocol, coreState));
            }
            pipeline.addLast(new ExceptionLoggingHandler(log));
            pipeline.addLast(new ExceptionMonitoringHandler(monitors.newMonitor(ExceptionMonitoringHandler.Monitor.class, CatchupServer.class)));
            pipeline.addLast(new ExceptionSwallowingHandler());
        }
    });
    try {
        channel = bootstrap.bind().syncUninterruptibly().channel();
    } catch (Exception e) {
        //noinspection ConstantConditions
        if (e instanceof BindException) {
            userLog.error("Address is already bound for setting: " + CausalClusteringSettings.transaction_listen_address + " with value: " + listenAddress);
            log.error("Address is already bound for setting: " + CausalClusteringSettings.transaction_listen_address + " with value: " + listenAddress, e);
            throw e;
        }
    }
}
Also used : SocketChannel(io.netty.channel.socket.SocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) ExceptionSwallowingHandler(org.neo4j.causalclustering.handlers.ExceptionSwallowingHandler) VersionPrepender(org.neo4j.causalclustering.VersionPrepender) TxStreamFinishedResponseEncoder(org.neo4j.causalclustering.catchup.tx.TxStreamFinishedResponseEncoder) GetStoreIdResponseEncoder(org.neo4j.causalclustering.catchup.storecopy.GetStoreIdResponseEncoder) LengthFieldPrepender(io.netty.handler.codec.LengthFieldPrepender) CoreSnapshotRequestHandler(org.neo4j.causalclustering.core.state.snapshot.CoreSnapshotRequestHandler) ExceptionLoggingHandler(org.neo4j.causalclustering.handlers.ExceptionLoggingHandler) FileHeaderEncoder(org.neo4j.causalclustering.catchup.storecopy.FileHeaderEncoder) LengthFieldBasedFrameDecoder(io.netty.handler.codec.LengthFieldBasedFrameDecoder) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) TxPullRequestHandler(org.neo4j.causalclustering.catchup.tx.TxPullRequestHandler) GetStoreRequestHandler(org.neo4j.causalclustering.catchup.storecopy.GetStoreRequestHandler) FileChunkEncoder(org.neo4j.causalclustering.catchup.storecopy.FileChunkEncoder) BindException(java.net.BindException) VersionDecoder(org.neo4j.causalclustering.VersionDecoder) TxPullResponseEncoder(org.neo4j.causalclustering.catchup.tx.TxPullResponseEncoder) StoreCopyFinishedResponseEncoder(org.neo4j.causalclustering.catchup.storecopy.StoreCopyFinishedResponseEncoder) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ChannelPipeline(io.netty.channel.ChannelPipeline) BindException(java.net.BindException) ExceptionMonitoringHandler(org.neo4j.causalclustering.handlers.ExceptionMonitoringHandler) CoreSnapshotEncoder(org.neo4j.causalclustering.core.state.snapshot.CoreSnapshotEncoder) ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) GetStoreIdRequestHandler(org.neo4j.causalclustering.catchup.storecopy.GetStoreIdRequestHandler)

Aggregations

BindException (java.net.BindException)104 IOException (java.io.IOException)34 InetSocketAddress (java.net.InetSocketAddress)25 ServerSocket (java.net.ServerSocket)22 Test (org.junit.Test)22 File (java.io.File)12 SocketException (java.net.SocketException)10 Configuration (org.apache.hadoop.conf.Configuration)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 InterruptedIOException (java.io.InterruptedIOException)5 MiniDFSNNTopology (org.apache.hadoop.hdfs.MiniDFSNNTopology)5 InetAddress (java.net.InetAddress)4 UnknownHostException (java.net.UnknownHostException)4 RemoteException (java.rmi.RemoteException)4 NIOServerCnxnFactory (org.apache.zookeeper.server.NIOServerCnxnFactory)4 ZooKeeperServer (org.apache.zookeeper.server.ZooKeeperServer)4 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)3 Socket (java.net.Socket)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3