Implement toString for Release.

This commit is contained in:
Major-
2015-08-01 14:17:39 +01:00
parent 02fb07b871
commit 02a3170382
2 changed files with 33 additions and 28 deletions
+28 -28
View File
@@ -72,7 +72,7 @@ public final class Server {
/** /**
* The {@link ServerBootstrap} for the JAGGRAB listener. * The {@link ServerBootstrap} for the JAGGRAB listener.
*/ */
private final ServerBootstrap jagGrabBootstrap = new ServerBootstrap(); private final ServerBootstrap jaggrabBootstrap = new ServerBootstrap();
/** /**
* The {@link ServerBootstrap} for the service listener. * The {@link ServerBootstrap} for the service listener.
@@ -94,22 +94,22 @@ public final class Server {
/** /**
* Binds the server to the specified address. * Binds the server to the specified address.
* *
* @param serviceAddress The service address to bind to. * @param service The service address to bind to.
* @param httpAddress The HTTP address to bind to. * @param http The HTTP address to bind to.
* @param jagGrabAddress The JAGGRAB address to bind to. * @param jaggrab The JAGGRAB address to bind to.
*/ */
public void bind(SocketAddress serviceAddress, SocketAddress httpAddress, SocketAddress jagGrabAddress) { public void bind(SocketAddress service, SocketAddress http, SocketAddress jaggrab) {
try { try {
logger.fine("Binding service listener to address: " + serviceAddress + "..."); logger.fine("Binding service listener to address: " + service + "...");
serviceBootstrap.bind(serviceAddress).sync(); serviceBootstrap.bind(service).sync();
logger.fine("Binding HTTP listener to address: " + httpAddress + "..."); logger.fine("Binding HTTP listener to address: " + http + "...");
httpBootstrap.bind(httpAddress).sync(); httpBootstrap.bind(http).sync();
logger.fine("Binding JAGGRAB listener to address: " + jagGrabAddress + "..."); logger.fine("Binding JAGGRAB listener to address: " + jaggrab + "...");
jagGrabBootstrap.bind(jagGrabAddress).sync(); jaggrabBootstrap.bind(jaggrab).sync();
} catch (InterruptedException e) { } catch (InterruptedException exception) {
logger.log(Level.SEVERE, "Binding to a port failed: ensure apollo isn't already running.", e); logger.log(Level.SEVERE, "Binding to a port failed: ensure apollo isn't already running.", exception);
System.exit(1); System.exit(1);
} }
@@ -119,42 +119,42 @@ public final class Server {
/** /**
* Initialises the server. * Initialises the server.
* *
* @param releaseClassName The class name of the current active {@link Release}. * @param releaseName The class name of the current active {@link Release}.
* @throws Exception If an error occurs. * @throws Exception If an error occurs.
*/ */
public void init(String releaseClassName) throws Exception { public void init(String releaseName) throws Exception {
Class<?> clazz = Class.forName(releaseClassName); Class<?> clazz = Class.forName(releaseName);
Release release = (Release) clazz.newInstance(); Release release = (Release) clazz.newInstance();
int releaseNo = release.getReleaseNumber(); int version = release.getReleaseNumber();
logger.info("Initialized release #" + releaseNo + "."); logger.info("Initialized " + release + ".");
serviceBootstrap.group(loopGroup); serviceBootstrap.group(loopGroup);
httpBootstrap.group(loopGroup); httpBootstrap.group(loopGroup);
jagGrabBootstrap.group(loopGroup); jaggrabBootstrap.group(loopGroup);
World world = new World(); World world = new World();
ServiceManager services = new ServiceManager(world); ServiceManager services = new ServiceManager(world);
IndexedFileSystem fs = new IndexedFileSystem(Paths.get("data/fs", Integer.toString(releaseNo)), true); IndexedFileSystem fs = new IndexedFileSystem(Paths.get("data/fs", Integer.toString(version)), true);
ServerContext context = new ServerContext(release, services, fs); ServerContext context = new ServerContext(release, services, fs);
ApolloHandler handler = new ApolloHandler(context); ApolloHandler handler = new ApolloHandler(context);
ChannelInitializer<SocketChannel> serviceInitializer = new ServiceChannelInitializer(handler); ChannelInitializer<SocketChannel> service = new ServiceChannelInitializer(handler);
serviceBootstrap.channel(NioServerSocketChannel.class); serviceBootstrap.channel(NioServerSocketChannel.class);
serviceBootstrap.childHandler(serviceInitializer); serviceBootstrap.childHandler(service);
ChannelInitializer<SocketChannel> httpInitializer = new HttpChannelInitializer(handler); ChannelInitializer<SocketChannel> http = new HttpChannelInitializer(handler);
httpBootstrap.channel(NioServerSocketChannel.class); httpBootstrap.channel(NioServerSocketChannel.class);
httpBootstrap.childHandler(httpInitializer); httpBootstrap.childHandler(http);
ChannelInitializer<SocketChannel> jagGrabInitializer = new JagGrabChannelInitializer(handler); ChannelInitializer<SocketChannel> jaggrab = new JagGrabChannelInitializer(handler);
jagGrabBootstrap.channel(NioServerSocketChannel.class); jaggrabBootstrap.channel(NioServerSocketChannel.class);
jagGrabBootstrap.childHandler(jagGrabInitializer); jaggrabBootstrap.childHandler(jaggrab);
PluginManager manager = new PluginManager(world, new PluginContext(context)); PluginManager manager = new PluginManager(world, new PluginContext(context));
services.startAll(); services.startAll();
world.init(releaseNo, fs, manager); world.init(version, fs, manager);
} }
} }
@@ -111,4 +111,9 @@ public abstract class Release {
decoders[opcode] = decoder; decoders[opcode] = decoder;
} }
@Override
public final String toString() {
return Release.class.getSimpleName() + " " + releaseNumber;
}
} }