cleanup
This commit is contained in:
parent
c126bdd8b0
commit
318a8885ba
53 changed files with 990 additions and 5887 deletions
|
@ -23,11 +23,6 @@ import java.util.Locale;
|
|||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.FutureTask;
|
||||
|
||||
import common.Version;
|
||||
import common.collect.Lists;
|
||||
import common.collect.Maps;
|
||||
|
@ -38,10 +33,6 @@ import common.effect.StatusEffect;
|
|||
import common.entity.Entity;
|
||||
import common.entity.npc.EntityHuman;
|
||||
import common.entity.npc.EntityNPC;
|
||||
import common.future.Futures;
|
||||
import common.future.ListenableFuture;
|
||||
import common.future.ListenableFutureTask;
|
||||
import common.future.ThreadFactoryBuilder;
|
||||
import common.init.EntityRegistry;
|
||||
import common.init.Registry;
|
||||
import common.init.UniverseRegistry;
|
||||
|
@ -86,7 +77,6 @@ import common.tags.TagObject;
|
|||
import common.util.BlockPos;
|
||||
import common.util.EncryptUtil;
|
||||
import common.util.ExtMath;
|
||||
import common.util.LazyLoader;
|
||||
import common.util.Pair;
|
||||
import common.util.PortalType;
|
||||
import common.util.Position;
|
||||
|
@ -109,19 +99,14 @@ import server.world.Region;
|
|||
import server.world.WorldServer;
|
||||
|
||||
public final class Server implements IThreadListener, Executor {
|
||||
private static final LazyLoader<NioEventLoopGroup> SERVER_NIO_EVENTLOOP = new LazyLoader<NioEventLoopGroup>() {
|
||||
protected NioEventLoopGroup load() {
|
||||
return new NioEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Server IO #%d").setDaemon(true).build());
|
||||
}
|
||||
};
|
||||
|
||||
private final Thread serverThread = Thread.currentThread();
|
||||
private final Thread thread = Thread.currentThread();
|
||||
private final NioEventLoopGroup eventGroup = new NioEventLoopGroup(0, Util.getThreadFactory("Netty Server IO"));
|
||||
private final Map<String, SVar> variables = Maps.newTreeMap();
|
||||
private final List<NetConnection> clients = Collections.<NetConnection>synchronizedList(Lists.<NetConnection>newArrayList());
|
||||
private final List<Player> players = Lists.<Player>newArrayList();
|
||||
private final Map<String, Player> online = Maps.<String, Player>newHashMap();
|
||||
private final Map<String, User> users = Maps.newTreeMap();
|
||||
private final Queue<FutureTask<?>> queue = new ArrayDeque<FutureTask<?>>();
|
||||
private final Queue<Runnable> queue = new ArrayDeque<Runnable>();
|
||||
private final long[] tickTimes = new long[100];
|
||||
private final Map<Integer, WorldServer> dimensions = Maps.newTreeMap();
|
||||
private final List<WorldServer> worlds = Lists.<WorldServer>newArrayList();
|
||||
|
@ -512,17 +497,13 @@ public final class Server implements IThreadListener, Executor {
|
|||
long now = System.currentTimeMillis();
|
||||
synchronized(this.queue) {
|
||||
while(!this.queue.isEmpty()) {
|
||||
FutureTask<?> task = this.queue.poll();
|
||||
Runnable task = this.queue.poll();
|
||||
try {
|
||||
task.run();
|
||||
task.get();
|
||||
}
|
||||
catch(ExecutionException e1) {
|
||||
if(!(e1.getCause() instanceof ThreadQuickExitException))
|
||||
Log.SYSTEM.error(e1, "Fehler beim Ausführen von Server-Task " + task); // throw new RuntimeException(e1);
|
||||
}
|
||||
catch(InterruptedException e2) {
|
||||
Log.SYSTEM.error(e2, "Fehler beim Ausführen von Server-Task " + task);
|
||||
catch(Throwable e) {
|
||||
if(!(e instanceof ThreadQuickExitException))
|
||||
Log.SYSTEM.error(e, "Fehler beim Ausführen von Server-Task " + task);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -649,32 +630,25 @@ public final class Server implements IThreadListener, Executor {
|
|||
public User getUser(String user) {
|
||||
return this.users.get(user);
|
||||
}
|
||||
|
||||
private <V> ListenableFuture<V> callFromMainThread(Callable<V> callable) {
|
||||
|
||||
public void schedule(Runnable task) {
|
||||
if(!this.isMainThread() && !this.stopped) {
|
||||
ListenableFutureTask<V> task = ListenableFutureTask.<V>create(callable);
|
||||
synchronized(this.queue) {
|
||||
this.queue.add(task);
|
||||
return task;
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
return Futures.<V>immediateFuture(callable.call());
|
||||
task.run();
|
||||
}
|
||||
catch(Exception exception) {
|
||||
Log.SYSTEM.error(exception, "Fehler beim sofortigen Ausführen von Server-Task " + callable);
|
||||
return Futures.immediateFailedFuture(exception);
|
||||
catch(Throwable e) {
|
||||
Log.SYSTEM.error(e, "Fehler beim sofortigen Ausführen von Server-Task " + task);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ListenableFuture<Object> schedule(Runnable run) {
|
||||
return this.<Object>callFromMainThread(Executors.callable(run));
|
||||
}
|
||||
|
||||
public boolean isMainThread() {
|
||||
return Thread.currentThread() == this.serverThread;
|
||||
return Thread.currentThread() == this.thread;
|
||||
}
|
||||
|
||||
public Position getRandomSpawnPosition(WorldPos origin) {
|
||||
|
@ -1024,7 +998,7 @@ public final class Server implements IThreadListener, Executor {
|
|||
for(Player conn : Lists.newArrayList(this.players)) {
|
||||
conn.disconnect(message);
|
||||
}
|
||||
synchronized(this.serverThread) {
|
||||
synchronized(this.thread) {
|
||||
if(this.endpoint != null) {
|
||||
Log.NETWORK.info("Schließe Port");
|
||||
try {
|
||||
|
@ -1084,7 +1058,7 @@ public final class Server implements IThreadListener, Executor {
|
|||
}
|
||||
|
||||
public void bind(int port) {
|
||||
synchronized(this.serverThread) {
|
||||
synchronized(this.thread) {
|
||||
if(port >= 0) {
|
||||
try {
|
||||
if(this.endpoint != null)
|
||||
|
@ -1107,7 +1081,7 @@ public final class Server implements IThreadListener, Executor {
|
|||
channel.pipeline().addLast((String)"packet_handler", (ChannelHandler)manager);
|
||||
manager.setNetHandler(new HandshakeHandler(Server.this, manager));
|
||||
}
|
||||
}).group(SERVER_NIO_EVENTLOOP.getValue()).localAddress((InetAddress)null, port)).bind().syncUninterruptibly();
|
||||
}).group(this.eventGroup).localAddress((InetAddress)null, port)).bind().syncUninterruptibly();
|
||||
}
|
||||
catch(Throwable e) {
|
||||
Log.NETWORK.error(e, "**** KONNTE NICHT AN PORT " + port + " ANBINDEN!");
|
||||
|
|
|
@ -26,7 +26,6 @@ import common.entity.npc.EntityNPC;
|
|||
import common.entity.npc.PlayerCharacter;
|
||||
import common.entity.projectile.EntityArrow;
|
||||
import common.entity.types.EntityLiving;
|
||||
import common.future.Futures;
|
||||
import common.init.BlockRegistry;
|
||||
import common.init.Blocks;
|
||||
import common.init.EntityRegistry;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue