use of de.dytanic.cloudnetwrapper.server.BungeeCord in project CloudNet by Dytanic.
the class ServerProcessQueue method run.
@Override
public void run() {
if (!running)
return;
{
short i = 0;
int memory = CloudNetWrapper.getInstance().getUsedMemory();
while (running && !servers.isEmpty() && (CloudNetWrapper.getInstance().getWrapperConfig().getPercentOfCPUForANewServer() == 0D || NetworkUtils.cpuUsage() <= CloudNetWrapper.getInstance().getWrapperConfig().getPercentOfCPUForANewServer())) {
i++;
if (i == 3)
break;
ServerProcess serverProcess = servers.poll();
if (!CloudNetWrapper.getInstance().getServerGroups().containsKey(serverProcess.getMeta().getServiceId().getGroup())) {
this.servers.add(serverProcess);
continue;
}
if ((memory + serverProcess.getMeta().getMemory()) < CloudNetWrapper.getInstance().getMaxMemory()) {
GameServer gameServer = null;
try {
System.out.println("Fetching entry [" + serverProcess.getMeta().getServiceId() + "]");
gameServer = new GameServer(serverProcess, ServerStage.SETUP, CloudNetWrapper.getInstance().getServerGroups().get(serverProcess.getMeta().getServiceId().getGroup()));
if (!gameServer.bootstrap()) {
this.servers.add(serverProcess);
}
} catch (Exception e) {
System.out.println("Failed to bootstrap the game-server " + serverProcess.getMeta().getServiceId().toString());
e.printStackTrace();
this.servers.add(serverProcess);
}
} else {
this.servers.add(serverProcess);
}
}
}
{
short i = 0;
int memory = CloudNetWrapper.getInstance().getUsedMemory();
while (running && !proxys.isEmpty() && (CloudNetWrapper.getInstance().getWrapperConfig().getPercentOfCPUForANewProxy() == 0 || NetworkUtils.cpuUsage() <= CloudNetWrapper.getInstance().getWrapperConfig().getPercentOfCPUForANewProxy())) {
i++;
if (i == 3)
break;
ProxyProcessMeta serverProcess = proxys.poll();
if (!CloudNetWrapper.getInstance().getProxyGroups().containsKey(serverProcess.getServiceId().getGroup())) {
this.proxys.add(serverProcess);
continue;
}
if ((memory + serverProcess.getMemory()) < CloudNetWrapper.getInstance().getMaxMemory()) {
BungeeCord gameServer = new BungeeCord(serverProcess, CloudNetWrapper.getInstance().getProxyGroups().get(serverProcess.getServiceId().getGroup()));
try {
System.out.println("Fetching entry [" + gameServer.getServiceId() + "]");
if (!gameServer.bootstrap()) {
this.proxys.add(serverProcess);
}
} catch (Exception e) {
System.out.println("Failed to bootstrap the proxy-server " + gameServer.toString());
e.printStackTrace();
this.proxys.add(serverProcess);
}
} else {
this.proxys.add(serverProcess);
}
}
}
}
use of de.dytanic.cloudnetwrapper.server.BungeeCord in project CloudNet by Dytanic.
the class StopTimeHandler method run.
@Override
public void run(CloudNetWrapper wrapper) {
for (GameServer gameServer : CloudNetWrapper.getInstance().getServers().values()) try {
if (!gameServer.isAlive()) {
if (System.currentTimeMillis() > (gameServer.getStartupTimeStamp() + 1600))
gameServer.shutdown();
else
gameServer.restart();
}
} catch (Exception ex) {
}
for (CloudGameServer gameServer : CloudNetWrapper.getInstance().getCloudservers().values()) try {
if (!gameServer.isAlive())
gameServer.shutdown();
} catch (Exception ex) {
}
for (BungeeCord bungeeCord : CloudNetWrapper.getInstance().getProxys().values()) try {
if (!bungeeCord.isAlive())
bungeeCord.shutdown();
} catch (Exception ex) {
}
}
use of de.dytanic.cloudnetwrapper.server.BungeeCord in project CloudNet by Dytanic.
the class ServerProcessQueue method patchAsync.
public void patchAsync(ProxyProcessMeta proxyProcessMeta) {
BungeeCord bungeeCord = new BungeeCord(proxyProcessMeta, CloudNetWrapper.getInstance().getProxyGroups().get(proxyProcessMeta.getServiceId().getGroup()));
if (!CloudNetWrapper.getInstance().getProxyGroups().containsKey(proxyProcessMeta.getServiceId().getGroup())) {
this.proxys.add(proxyProcessMeta);
return;
}
TaskScheduler.runtimeScheduler().schedule(new Runnable() {
@Override
public void run() {
try {
bungeeCord.bootstrap();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
use of de.dytanic.cloudnetwrapper.server.BungeeCord in project CloudNet by Dytanic.
the class CloudNetWrapper method shutdown.
@Override
public boolean shutdown() {
if (!RUNNING)
return false;
System.out.println("Wrapper shutdown...");
TaskScheduler.runtimeScheduler().shutdown();
if (scheduler != null)
scheduler.cancelAllTasks();
if (serverProcessQueue != null)
serverProcessQueue.setRunning(false);
for (GameServer gameServer : servers.values()) gameServer.shutdown();
for (BungeeCord gameServer : proxys.values()) gameServer.shutdown();
for (CloudGameServer gameServer : cloudservers.values()) gameServer.shutdown();
this.cloudNetLogging.shutdownAll();
if (networkConnection.getChannel() != null)
networkConnection.tryDisconnect();
try {
FileUtils.deleteDirectory(new File("temp"));
} catch (IOException e) {
}
System.out.println("\n _ _ _______ _ _ \n" + " _| || |_ |__ __| | | | | \n" + " |_ __ _| | | | |__ __ _ _ __ | | __ ___ \n" + " _| || |_ | | | '_ \\ / _` | | '_ \\ | |/ / / __|\n" + " |_ __ _| | | | | | | | (_| | | | | | | < \\__ \\\n" + " |_||_| |_| |_| |_| \\__,_| |_| |_| |_|\\_\\ |___/\n" + " \n" + " ");
RUNNING = false;
if (x_bnosxo)
System.exit(0);
return true;
}
use of de.dytanic.cloudnetwrapper.server.BungeeCord in project CloudNet by Dytanic.
the class CloudNetWrapper method onShutdownCentral.
@Override
public void onShutdownCentral() throws Exception {
canDeployed = false;
if (serverProcessQueue != null) {
serverProcessQueue.getProxys().clear();
serverProcessQueue.getServers().clear();
serverProcessQueue.setRunning(false);
}
for (GameServer gameServer : servers.values()) gameServer.shutdown();
for (BungeeCord gameServer : proxys.values()) gameServer.shutdown();
proxyGroups.clear();
serverGroups.clear();
System.out.println("Wrapper try to connect to the CloudNet-Core");
try {
FileUtils.deleteDirectory(new File("temp"));
} catch (Exception ex) {
}
new File("temp").mkdir();
while (networkConnection.getChannel() == null) {
networkConnection.tryConnect(optionSet.has("ssl"), new NetDispatcher(networkConnection, false), auth);
if (networkConnection.getChannel() != null) {
networkConnection.sendPacketSynchronized(new PacketOutUpdateWrapperInfo());
break;
}
Thread.sleep(2000);
}
canDeployed = true;
if (serverProcessQueue != null)
serverProcessQueue.setRunning(true);
}
Aggregations