use of de.dytanic.cloudnet.lib.server.ProxyProcessMeta 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.cloudnet.lib.server.ProxyProcessMeta in project CloudNet by Dytanic.
the class PacketInAddProxy method handleInput.
@Override
public void handleInput(Document data, PacketSender packetSender) {
if (!(packetSender instanceof Wrapper))
return;
Wrapper cn = ((Wrapper) packetSender);
ProxyInfo nullServerInfo = data.getObject("proxyInfo", new TypeToken<ProxyInfo>() {
}.getType());
ProxyProcessMeta proxyProcessMeta = data.getObject("proxyProcess", new TypeToken<ProxyProcessMeta>() {
}.getType());
ProxyServer minecraftServer = new ProxyServer(proxyProcessMeta, cn, nullServerInfo);
cn.getProxys().put(proxyProcessMeta.getServiceId().getServerId(), minecraftServer);
cn.getWaitingServices().remove(minecraftServer.getServerId());
CloudNet.getInstance().getNetworkManager().handleProxyAdd(minecraftServer);
}
use of de.dytanic.cloudnet.lib.server.ProxyProcessMeta in project CloudNet by Dytanic.
the class PacketInStartProxy method handleInput.
@Override
public void handleInput(Document data, PacketSender packetSender) {
ProxyProcessMeta proxyProcessMeta = data.getObject("proxyProcess", new TypeToken<ProxyProcessMeta>() {
}.getType());
if (!data.contains("async")) {
System.out.println("Proxy process is now in queue [" + proxyProcessMeta.getServiceId() + "]");
CloudNetWrapper.getInstance().getServerProcessQueue().putProcess(proxyProcessMeta);
} else {
CloudNetWrapper.getInstance().getServerProcessQueue().patchAsync(proxyProcessMeta);
}
}
Aggregations