initial commit
This commit is contained in:
parent
3c9ee26b06
commit
22186c33b9
1458 changed files with 282792 additions and 0 deletions
41
java/src/game/network/NetHandler.java
Executable file
41
java/src/game/network/NetHandler.java
Executable file
|
@ -0,0 +1,41 @@
|
|||
package game.network;
|
||||
|
||||
public abstract class NetHandler {
|
||||
private static final ThreadQuickExitException EXIT = new ThreadQuickExitException();
|
||||
|
||||
public static final class ThreadQuickExitException extends RuntimeException {
|
||||
private ThreadQuickExitException() {
|
||||
this.setStackTrace(new StackTraceElement[0]);
|
||||
}
|
||||
|
||||
public synchronized Throwable fillInStackTrace() {
|
||||
this.setStackTrace(new StackTraceElement[0]);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void onDisconnect(String reason);
|
||||
|
||||
public void update() {
|
||||
}
|
||||
|
||||
public static <T extends NetHandler> void checkThread(final Packet<T> packet, final T handler, IThreadListener listener)
|
||||
throws ThreadQuickExitException {
|
||||
if(!listener.isMainThread()) {
|
||||
listener.schedule(new Runnable() {
|
||||
public void run() {
|
||||
packet.processPacket(handler);
|
||||
}
|
||||
});
|
||||
throw EXIT;
|
||||
}
|
||||
}
|
||||
|
||||
public static <T extends NetHandler> void checkThread(final Packet<T> packet, final T handler, IThreadListener listener, Object check)
|
||||
throws ThreadQuickExitException {
|
||||
if(check == null && listener.isMainThread()) {
|
||||
throw EXIT;
|
||||
}
|
||||
checkThread(packet, handler, listener);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue