Search in sources :

Example 1 with ProxyProcessMeta

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);
            }
        }
    }
}
Also used : ProxyProcessMeta(de.dytanic.cloudnet.lib.server.ProxyProcessMeta) BungeeCord(de.dytanic.cloudnetwrapper.server.BungeeCord) CloudGameServer(de.dytanic.cloudnetwrapper.server.CloudGameServer) GameServer(de.dytanic.cloudnetwrapper.server.GameServer)

Example 2 with ProxyProcessMeta

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);
}
Also used : Wrapper(de.dytanic.cloudnetcore.network.components.Wrapper) ProxyInfo(de.dytanic.cloudnet.lib.server.info.ProxyInfo) TypeToken(com.google.gson.reflect.TypeToken) ProxyProcessMeta(de.dytanic.cloudnet.lib.server.ProxyProcessMeta) ProxyServer(de.dytanic.cloudnetcore.network.components.ProxyServer)

Example 3 with ProxyProcessMeta

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);
    }
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) ProxyProcessMeta(de.dytanic.cloudnet.lib.server.ProxyProcessMeta)

Aggregations

ProxyProcessMeta (de.dytanic.cloudnet.lib.server.ProxyProcessMeta)3 TypeToken (com.google.gson.reflect.TypeToken)2 ProxyInfo (de.dytanic.cloudnet.lib.server.info.ProxyInfo)1 ProxyServer (de.dytanic.cloudnetcore.network.components.ProxyServer)1 Wrapper (de.dytanic.cloudnetcore.network.components.Wrapper)1 BungeeCord (de.dytanic.cloudnetwrapper.server.BungeeCord)1 CloudGameServer (de.dytanic.cloudnetwrapper.server.CloudGameServer)1 GameServer (de.dytanic.cloudnetwrapper.server.GameServer)1