use of de.dytanic.cloudnetwrapper.server.GameServer 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.GameServer 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.GameServer in project CloudNet by Dytanic.
the class PacketInCopyDirectory method handleInput.
@Override
public void handleInput(Document data, PacketSender packetSender) {
if (!data.contains("directory") || !data.contains("serverInfo"))
return;
ServerInfo serverInfo = data.getObject("serverInfo", ServerInfo.TYPE);
GameServer gameServer = CloudNetWrapper.getInstance().getServers().get(serverInfo.getServiceId().getServerId());
if (gameServer == null)
return;
if (gameServer.getServerProcess().getMeta().getTemplate().getBackend().equals(TemplateResource.LOCAL))
gameServer.copyDirectory(data.getString("directory"));
}
use of de.dytanic.cloudnetwrapper.server.GameServer in project CloudNet by Dytanic.
the class PacketInCopyServer method handleInput.
@Override
public void handleInput(Document data, PacketSender packetSender) {
ServerInfo serverInfo = data.getObject("serverInfo", new TypeToken<ServerInfo>() {
}.getType());
GameServer gameServer = CloudNetWrapper.getInstance().getServers().get(serverInfo.getServiceId().getServerId());
if (gameServer != null) {
if (!data.contains("template")) {
CloudNetWrapper.getInstance().getScheduler().runTaskAsync(new Runnable() {
@Override
public void run() {
gameServer.copy();
}
});
} else {
CloudNetWrapper.getInstance().getScheduler().runTaskAsync(new Runnable() {
@Override
public void run() {
gameServer.copy(data.getObject("template", new TypeToken<Template>() {
}.getType()));
}
});
}
}
}
use of de.dytanic.cloudnetwrapper.server.GameServer in project CloudNet by Dytanic.
the class ServerProcessQueue method patchAsync.
public void patchAsync(ServerProcessMeta process) {
if (!CloudNetWrapper.getInstance().getServerGroups().containsKey(process.getServiceId().getGroup())) {
this.servers.add(new ServerProcess(process, ServerStage.SETUP));
return;
}
GameServer gameServer = new GameServer(new ServerProcess(process, ServerStage.SETUP), ServerStage.SETUP, CloudNetWrapper.getInstance().getServerGroups().get(process.getServiceId().getGroup()));
TaskScheduler.runtimeScheduler().schedule(new Runnable() {
@Override
public void run() {
try {
gameServer.bootstrap();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
Aggregations