Search in sources :

Example 1 with GameServer

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);
            }
        }
    }
}
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 GameServer

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

Example 3 with GameServer

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"));
}
Also used : ServerInfo(de.dytanic.cloudnet.lib.server.info.ServerInfo) GameServer(de.dytanic.cloudnetwrapper.server.GameServer)

Example 4 with GameServer

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

Example 5 with GameServer

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

Aggregations

GameServer (de.dytanic.cloudnetwrapper.server.GameServer)7 CloudGameServer (de.dytanic.cloudnetwrapper.server.CloudGameServer)5 BungeeCord (de.dytanic.cloudnetwrapper.server.BungeeCord)4 ServerInfo (de.dytanic.cloudnet.lib.server.info.ServerInfo)2 File (java.io.File)2 IOException (java.io.IOException)2 TypeToken (com.google.gson.reflect.TypeToken)1 NetDispatcher (de.dytanic.cloudnet.lib.network.NetDispatcher)1 ProxyProcessMeta (de.dytanic.cloudnet.lib.server.ProxyProcessMeta)1 PacketOutUpdateWrapperInfo (de.dytanic.cloudnetwrapper.network.packet.out.PacketOutUpdateWrapperInfo)1