mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-06 00:38:18 +00:00
Do not allow null objects to be passed to the ServerContext, use Guava stopwatch
This commit is contained in:
@@ -10,6 +10,7 @@ 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;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@@ -25,6 +26,8 @@ import org.apollo.net.release.r317.Release317;
|
|||||||
import org.apollo.util.plugin.PluginContext;
|
import org.apollo.util.plugin.PluginContext;
|
||||||
import org.apollo.util.plugin.PluginManager;
|
import org.apollo.util.plugin.PluginManager;
|
||||||
|
|
||||||
|
import com.google.common.base.Stopwatch;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The core class of the Apollo server.
|
* The core class of the Apollo server.
|
||||||
*
|
*
|
||||||
@@ -43,8 +46,9 @@ public final class Server {
|
|||||||
* @param args The command-line arguments passed to the application.
|
* @param args The command-line arguments passed to the application.
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
Stopwatch stopwatch = Stopwatch.createStarted();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
long start = System.currentTimeMillis();
|
|
||||||
Server server = new Server();
|
Server server = new Server();
|
||||||
server.init(args.length == 1 ? args[0] : Release317.class.getName());
|
server.init(args.length == 1 ? args[0] : Release317.class.getName());
|
||||||
|
|
||||||
@@ -53,10 +57,11 @@ public final class Server {
|
|||||||
SocketAddress jaggrab = new InetSocketAddress(NetworkConstants.JAGGRAB_PORT);
|
SocketAddress jaggrab = new InetSocketAddress(NetworkConstants.JAGGRAB_PORT);
|
||||||
|
|
||||||
server.bind(service, http, jaggrab);
|
server.bind(service, http, jaggrab);
|
||||||
logger.fine("Starting apollo took " + (System.currentTimeMillis() - start) + " ms.");
|
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
logger.log(Level.SEVERE, "Error whilst starting server.", t);
|
logger.log(Level.SEVERE, "Error whilst starting server.", t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.fine("Starting apollo took " + stopwatch.elapsed(TimeUnit.MILLISECONDS) + " ms.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -81,10 +86,8 @@ public final class Server {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the Apollo server.
|
* Creates the Apollo server.
|
||||||
*
|
|
||||||
* @throws Exception If an error occurs whilst creating services.
|
|
||||||
*/
|
*/
|
||||||
public Server() throws Exception {
|
public Server() {
|
||||||
logger.info("Starting Apollo...");
|
logger.info("Starting Apollo...");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,14 +101,14 @@ public final class Server {
|
|||||||
public void bind(SocketAddress serviceAddress, SocketAddress httpAddress, SocketAddress jagGrabAddress) {
|
public void bind(SocketAddress serviceAddress, SocketAddress httpAddress, SocketAddress jagGrabAddress) {
|
||||||
try {
|
try {
|
||||||
logger.fine("Binding service listener to address: " + serviceAddress + "...");
|
logger.fine("Binding service listener to address: " + serviceAddress + "...");
|
||||||
serviceBootstrap.bind(serviceAddress).syncUninterruptibly();
|
serviceBootstrap.bind(serviceAddress).sync();
|
||||||
|
|
||||||
logger.fine("Binding HTTP listener to address: " + httpAddress + "...");
|
logger.fine("Binding HTTP listener to address: " + httpAddress + "...");
|
||||||
httpBootstrap.bind(httpAddress).syncUninterruptibly();
|
httpBootstrap.bind(httpAddress).sync();
|
||||||
|
|
||||||
logger.fine("Binding JAGGRAB listener to address: " + jagGrabAddress + "...");
|
logger.fine("Binding JAGGRAB listener to address: " + jagGrabAddress + "...");
|
||||||
jagGrabBootstrap.bind(jagGrabAddress).syncUninterruptibly();
|
jagGrabBootstrap.bind(jagGrabAddress).sync();
|
||||||
} catch (Exception e) {
|
} catch (InterruptedException e) {
|
||||||
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.", e);
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package org.apollo;
|
package org.apollo;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.apollo.fs.IndexedFileSystem;
|
import org.apollo.fs.IndexedFileSystem;
|
||||||
import org.apollo.net.release.Release;
|
import org.apollo.net.release.Release;
|
||||||
|
|
||||||
@@ -32,12 +34,13 @@ public final class ServerContext {
|
|||||||
*
|
*
|
||||||
* @param release The current release.
|
* @param release The current release.
|
||||||
* @param serviceManager The service manager.
|
* @param serviceManager The service manager.
|
||||||
|
* @param fileSystem The indexed file system.
|
||||||
*/
|
*/
|
||||||
ServerContext(Release release, ServiceManager serviceManager, IndexedFileSystem fileSystem) {
|
protected ServerContext(Release release, ServiceManager serviceManager, IndexedFileSystem fileSystem) {
|
||||||
this.release = release;
|
this.release = Objects.requireNonNull(release);
|
||||||
this.serviceManager = serviceManager;
|
this.serviceManager = Objects.requireNonNull(serviceManager);
|
||||||
this.serviceManager.setContext(this);
|
this.serviceManager.setContext(this);
|
||||||
this.fileSystem = fileSystem;
|
this.fileSystem = Objects.requireNonNull(fileSystem);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user