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
}
}
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);
}
}
}
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());
}
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;
}
}
}
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;
}
}
}
Aggregations