Merge branch 'dev-osgi' into dev-webconsole
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
group = 'asys'
|
||||
version = '0.5-SNAPSHOT'
|
||||
version = '0.5.1-SNAPSHOT'
|
||||
|
||||
repositories {
|
||||
maven { url 'https://hub.spigotmc.org/nexus/content/groups/public/' }
|
||||
|
||||
@@ -28,19 +28,7 @@ public class BridgePlugin extends JavaPlugin {
|
||||
INSTANCE = this;
|
||||
saveDefaultConfig();
|
||||
|
||||
client = new Client();
|
||||
ses = Executors.newScheduledThreadPool(2);
|
||||
sesFuture = ses.scheduleAtFixedRate(() -> {
|
||||
getLogger().info(String.format("Connect(%d) to ASys...", ++tryConnect));
|
||||
client.connect(getConfig().getString("host"), getConfig().getInt("port"));
|
||||
if (client.isConnected()) {
|
||||
sesFuture.cancel(false);
|
||||
sesFuture = null;
|
||||
} else {
|
||||
getLogger().warning(
|
||||
String.format("Connection(%d) fail. Try reconnect...", tryConnect));
|
||||
}
|
||||
}, 0L, 5L, TimeUnit.SECONDS);
|
||||
startReconnect();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -65,12 +53,47 @@ public class BridgePlugin extends JavaPlugin {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void startReconnect() {
|
||||
client = new Client();
|
||||
ses = Executors.newScheduledThreadPool(2);
|
||||
sesFuture = ses.scheduleAtFixedRate(() -> {
|
||||
getLogger().info(String.format("Connect(%d) to ASys...", ++tryConnect));
|
||||
client.connect(getConfig().getString("host"), getConfig().getInt("port"));
|
||||
if (client.isConnected()) {
|
||||
stopReconnect();
|
||||
} else {
|
||||
getLogger().warning(
|
||||
String.format("Connection(%d) fail. Try reconnect...", tryConnect));
|
||||
}
|
||||
}, 0L, 5L, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
public void stopReconnect() {
|
||||
if (sesFuture != null) {
|
||||
sesFuture.cancel(false);
|
||||
sesFuture = null;
|
||||
tryConnect = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void startPing(Channel channel) {
|
||||
sesPingFuture = ses.scheduleAtFixedRate(() -> channel.writeAndFlush(new CS_Ping(
|
||||
System.currentTimeMillis(),
|
||||
20.0D, //FIXME
|
||||
BridgePlugin.INSTANCE.getServer().getOnlinePlayers().size()
|
||||
)), 0L, 5L, TimeUnit.SECONDS);
|
||||
sesPingFuture = ses.scheduleAtFixedRate(() -> {
|
||||
channel.write(new CS_Ping(
|
||||
System.currentTimeMillis(),
|
||||
20.0D, //FIXME
|
||||
getServer().getOnlinePlayers().size()
|
||||
));
|
||||
if (channel.isWritable()) {
|
||||
channel.flush();
|
||||
} else {
|
||||
getLogger().warning("Lost connection!");
|
||||
channel.close();
|
||||
stopPing();
|
||||
|
||||
getLogger().warning("Try reconnect...");
|
||||
startReconnect();
|
||||
}
|
||||
}, 0L, 5L, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
public void stopPing() {
|
||||
|
||||
@@ -53,8 +53,10 @@ public class ClientPacketHandler extends ChannelInboundHandlerAdapter implements
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext context) throws Exception {
|
||||
if (BridgePlugin.INSTANCE != null) {
|
||||
BridgePlugin.INSTANCE.getLogger().info("channelInactive");
|
||||
BridgePlugin.INSTANCE.getLogger().warning("Lost connection!");
|
||||
BridgePlugin.INSTANCE.stopPing();
|
||||
BridgePlugin.INSTANCE.getLogger().warning("Try reconnect...");
|
||||
BridgePlugin.INSTANCE.startReconnect();
|
||||
}
|
||||
context.channel().attr(KNOWN_PACKETS).remove();
|
||||
context.channel().attr(KNOWN_HANDLERS).remove();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
group = 'asys'
|
||||
version = '0.3.1-SNAPSHOT'
|
||||
version = '0.3.2-SNAPSHOT'
|
||||
|
||||
apply plugin: 'application'
|
||||
|
||||
|
||||
@@ -14,8 +14,11 @@ public class Main {
|
||||
private static final Logger logger = LoggerFactory.getLogger("Launcher");
|
||||
|
||||
public static void main(String[] args) {
|
||||
Core asysCore = new Core();
|
||||
final Core asysCore = new Core();
|
||||
asysCore.setConfiguration(getProperties());
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(asysCore::stop));
|
||||
|
||||
asysCore.start();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user