mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-06 08:40:03 +00:00
Better exception propagation when failing to bind
This commit is contained in:
@@ -1,12 +1,6 @@
|
|||||||
package org.apollo;
|
package org.apollo;
|
||||||
|
|
||||||
import io.netty.bootstrap.ServerBootstrap;
|
import java.net.BindException;
|
||||||
import io.netty.channel.ChannelInitializer;
|
|
||||||
import io.netty.channel.EventLoopGroup;
|
|
||||||
import io.netty.channel.nio.NioEventLoopGroup;
|
|
||||||
import io.netty.channel.socket.SocketChannel;
|
|
||||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
@@ -28,6 +22,13 @@ import org.apollo.net.release.Release;
|
|||||||
|
|
||||||
import com.google.common.base.Stopwatch;
|
import com.google.common.base.Stopwatch;
|
||||||
|
|
||||||
|
import io.netty.bootstrap.ServerBootstrap;
|
||||||
|
import io.netty.channel.ChannelInitializer;
|
||||||
|
import io.netty.channel.EventLoopGroup;
|
||||||
|
import io.netty.channel.nio.NioEventLoopGroup;
|
||||||
|
import io.netty.channel.socket.SocketChannel;
|
||||||
|
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The core class of the Apollo server.
|
* The core class of the Apollo server.
|
||||||
*
|
*
|
||||||
@@ -97,25 +98,38 @@ public final class Server {
|
|||||||
* @param service The service address to bind to.
|
* @param service The service address to bind to.
|
||||||
* @param http The HTTP address to bind to.
|
* @param http The HTTP address to bind to.
|
||||||
* @param jaggrab The JAGGRAB address to bind to.
|
* @param jaggrab The JAGGRAB address to bind to.
|
||||||
|
* @throws BindException If the ServerBootstrap fails to bind to the SocketAddress for any
|
||||||
|
* reason.
|
||||||
*/
|
*/
|
||||||
public void bind(SocketAddress service, SocketAddress http, SocketAddress jaggrab) {
|
public void bind(SocketAddress service, SocketAddress http, SocketAddress jaggrab) throws BindException {
|
||||||
try {
|
logger.info("Binding service listener to address: " + service + "...");
|
||||||
logger.fine("Binding service listener to address: " + service + "...");
|
bind(serviceBootstrap, service);
|
||||||
serviceBootstrap.bind(service).sync();
|
|
||||||
|
|
||||||
logger.fine("Binding HTTP listener to address: " + http + "...");
|
logger.info("Binding HTTP listener to address: " + http + "...");
|
||||||
httpBootstrap.bind(http).sync();
|
bind(httpBootstrap, http);
|
||||||
|
|
||||||
logger.fine("Binding JAGGRAB listener to address: " + jaggrab + "...");
|
logger.info("Binding JAGGRAB listener to address: " + jaggrab + "...");
|
||||||
jaggrabBootstrap.bind(jaggrab).sync();
|
bind(jaggrabBootstrap, jaggrab);
|
||||||
} catch (InterruptedException exception) {
|
|
||||||
logger.log(Level.SEVERE, "Binding to a port failed: ensure apollo isn't already running.", exception);
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("Ready for connections.");
|
logger.info("Ready for connections.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to bind the specified ServerBootstrap to the specified SocketAddress.
|
||||||
|
*
|
||||||
|
* @param bootstrap The ServerBootstrap.
|
||||||
|
* @param address The SocketAddress.
|
||||||
|
* @throws BindException If the ServerBootstrap fails to bind to the SocketAddress for any
|
||||||
|
* reason.
|
||||||
|
*/
|
||||||
|
private void bind(ServerBootstrap bootstrap, SocketAddress address) throws BindException {
|
||||||
|
try {
|
||||||
|
bootstrap.bind(address).sync();
|
||||||
|
} catch (Exception cause) {
|
||||||
|
throw new BindException("Failed to bind to: " + address);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialises the server.
|
* Initialises the server.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user