Search in sources :

Example 21 with Wrapper

use of de.dytanic.cloudnetcore.network.components.Wrapper in project CloudNet by Dytanic.

the class PacketInUpdateProxyGroup method handleInput.

@Override
public void handleInput(Document data, PacketSender packetSender) {
    ProxyGroup proxyGroup = data.getObject("group", new TypeToken<ProxyGroup>() {
    }.getType());
    CloudNet.getInstance().getConfig().createGroup(proxyGroup);
    try {
        CloudNet.getInstance().getConfig().load();
    } catch (Exception e) {
        e.printStackTrace();
    }
    CloudNet.getInstance().getServerGroups().clear();
    CloudNet.getInstance().getProxyGroups().clear();
    NetworkUtils.addAll(CloudNet.getInstance().getServerGroups(), CloudNet.getInstance().getConfig().getServerGroups(), new Acceptable<ServerGroup>() {

        @Override
        public boolean isAccepted(ServerGroup value) {
            System.out.println("Loading server group: " + value.getName());
            return true;
        }
    });
    NetworkUtils.addAll(CloudNet.getInstance().getProxyGroups(), CloudNet.getInstance().getConfig().getProxyGroups(), new Acceptable<ProxyGroup>() {

        @Override
        public boolean isAccepted(ProxyGroup value) {
            System.out.println("Loading proxy group: " + value.getName());
            return true;
        }
    });
    CloudNet.getInstance().getNetworkManager().reload();
    CloudNet.getInstance().getNetworkManager().updateAll0();
    CloudNet.getInstance().getWrappers().values().forEach(new Consumer<Wrapper>() {

        @Override
        public void accept(Wrapper wrapper) {
            wrapper.updateWrapper();
        }
    });
}
Also used : Wrapper(de.dytanic.cloudnetcore.network.components.Wrapper) ProxyGroup(de.dytanic.cloudnet.lib.server.ProxyGroup) ServerGroup(de.dytanic.cloudnet.lib.server.ServerGroup) TypeToken(com.google.gson.reflect.TypeToken)

Example 22 with Wrapper

use of de.dytanic.cloudnetcore.network.components.Wrapper in project CloudNet by Dytanic.

the class CloudConfig method createWrapper.

public void createWrapper(WrapperMeta wrapperMeta) {
    Collection<WrapperMeta> wrapperMetas = this.serviceDocument.getObject("wrapper", new TypeToken<Collection<WrapperMeta>>() {
    }.getType());
    WrapperMeta is = CollectionWrapper.filter(wrapperMetas, new Acceptable<WrapperMeta>() {

        @Override
        public boolean isAccepted(WrapperMeta wrapperMeta_) {
            return wrapperMeta_.getId().equalsIgnoreCase(wrapperMeta.getId());
        }
    });
    if (is != null)
        wrapperMetas.remove(is);
    wrapperMetas.add(wrapperMeta);
    this.serviceDocument.append("wrapper", wrapperMetas).saveAsConfig(servicePath);
    CloudNet.getInstance().getWrappers().put(wrapperMeta.getId(), new Wrapper(wrapperMeta));
}
Also used : MapWrapper(de.dytanic.cloudnet.lib.utility.MapWrapper) CollectionWrapper(de.dytanic.cloudnet.lib.utility.CollectionWrapper) Wrapper(de.dytanic.cloudnetcore.network.components.Wrapper) WrapperMeta(de.dytanic.cloudnetcore.network.components.WrapperMeta) TypeToken(com.google.gson.reflect.TypeToken)

Example 23 with Wrapper

use of de.dytanic.cloudnetcore.network.components.Wrapper in project CloudNet by Dytanic.

the class CloudFlareModule method onBootstrap.

@Override
public void onBootstrap() {
    configCloudFlare = new ConfigCloudFlare();
    cloudFlareDatabase = new CloudFlareDatabase(getCloud().getDatabaseManager().getDatabase("cloud_internal_cfg"));
    try {
        CloudFlareService cloudFlareAPI = new CloudFlareService(configCloudFlare.load());
        cloudFlareAPI.bootstrap(MapWrapper.transform(getCloud().getWrappers(), new Catcher<String, String>() {

            @Override
            public String doCatch(String key) {
                return key;
            }
        }, new Catcher<SimpledWrapperInfo, Wrapper>() {

            @Override
            public SimpledWrapperInfo doCatch(Wrapper key) {
                return new SimpledWrapperInfo(key.getServerId(), key.getNetworkInfo().getHostName());
            }
        }), getCloud().getProxyGroups(), cloudFlareDatabase);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    getCloud().getEventManager().registerListener(this, new ProxyAddListener());
    getCloud().getEventManager().registerListener(this, new ProxyRemoveListener());
}
Also used : CloudFlareService(de.dytanic.cloudnet.cloudflare.CloudFlareService) Catcher(de.dytanic.cloudnet.lib.utility.Catcher) MapWrapper(de.dytanic.cloudnet.lib.utility.MapWrapper) Wrapper(de.dytanic.cloudnetcore.network.components.Wrapper) CloudFlareDatabase(de.dytanic.cloudnet.cloudflare.database.CloudFlareDatabase) SimpledWrapperInfo(de.dytanic.cloudnet.lib.service.SimpledWrapperInfo) ProxyAddListener(de.dytanic.cloudnetcore.cloudflare.listener.ProxyAddListener) ConfigCloudFlare(de.dytanic.cloudnetcore.cloudflare.config.ConfigCloudFlare) ProxyRemoveListener(de.dytanic.cloudnetcore.cloudflare.listener.ProxyRemoveListener)

Aggregations

Wrapper (de.dytanic.cloudnetcore.network.components.Wrapper)23 TypeToken (com.google.gson.reflect.TypeToken)11 MinecraftServer (de.dytanic.cloudnetcore.network.components.MinecraftServer)9 ProxyServer (de.dytanic.cloudnetcore.network.components.ProxyServer)9 ServerGroup (de.dytanic.cloudnet.lib.server.ServerGroup)5 ServerInfo (de.dytanic.cloudnet.lib.server.info.ServerInfo)5 ProxyGroup (de.dytanic.cloudnet.lib.server.ProxyGroup)4 CloudServer (de.dytanic.cloudnetcore.network.components.CloudServer)4 ServiceId (de.dytanic.cloudnet.lib.service.ServiceId)3 ProxyInfo (de.dytanic.cloudnet.lib.server.info.ProxyInfo)2 CollectionWrapper (de.dytanic.cloudnet.lib.utility.CollectionWrapper)2 MapWrapper (de.dytanic.cloudnet.lib.utility.MapWrapper)2 ScheduledTask (de.dytanic.cloudnet.lib.utility.threading.ScheduledTask)2 PriorityStopTask (de.dytanic.cloudnetcore.network.components.priority.PriorityStopTask)2 CloudFlareService (de.dytanic.cloudnet.cloudflare.CloudFlareService)1 CloudFlareDatabase (de.dytanic.cloudnet.cloudflare.database.CloudFlareDatabase)1 CloudServerMeta (de.dytanic.cloudnet.lib.cloudserver.CloudServerMeta)1 WrapperInfo (de.dytanic.cloudnet.lib.network.WrapperInfo)1 AuthLoginResult (de.dytanic.cloudnet.lib.network.auth.AuthLoginResult)1 PacketOutAuthResult (de.dytanic.cloudnet.lib.network.auth.packetio.PacketOutAuthResult)1