use of de.dytanic.cloudnet.lib.service.ServiceId in project CloudNet by Dytanic.
the class PacketInDisableScreen method handleInput.
@Override
public void handleInput(Document data, PacketSender packetSender) {
ServiceId serviceId = data.getObject("serviceId", new TypeToken<ServiceId>() {
}.getType());
CloudNet.getInstance().getScreenProvider().handleDisableScreen(serviceId);
}
use of de.dytanic.cloudnet.lib.service.ServiceId in project CloudNet by Dytanic.
the class PacketInEnableScreen method handleInput.
@Override
public void handleInput(Document data, PacketSender packetSender) {
if (!(packetSender instanceof Wrapper))
return;
ServiceId serviceId = data.getObject("serviceId", new TypeToken<ServiceId>() {
}.getType());
CloudNet.getInstance().getScreenProvider().handleEnableScreen(serviceId, ((Wrapper) packetSender));
}
use of de.dytanic.cloudnet.lib.service.ServiceId in project CloudNet by Dytanic.
the class Wrapper method getUsedMemoryAndWaitings.
public int getUsedMemoryAndWaitings() {
AtomicInteger integer = new AtomicInteger(getUsedMemory());
CollectionWrapper.iterator(this.waitingServices.values(), new Runnabled<Quad<Integer, Integer, ServiceId, Template>>() {
@Override
public void run(Quad<Integer, Integer, ServiceId, Template> obj) {
integer.addAndGet(obj.getSecond());
}
});
return integer.get();
}
use of de.dytanic.cloudnet.lib.service.ServiceId in project CloudNet by Dytanic.
the class CloudNet method startGameServerAsync.
public void startGameServerAsync(Wrapper wrapper, String serverId, ServerGroup serverGroup, ServerConfig config, int memory, boolean prioritystop, String url, String[] processParameters, boolean onlineMode, Collection<ServerInstallablePlugin> plugins, String customServerName, Properties serverProperties) {
if (wrapper == null)
return;
if (serverGroup.getTemplates().size() == 0)
return;
Map<String, Integer> templateMap = new WeakHashMap<>();
Collection<Integer> collection = CollectionWrapper.getCollection(wrapper.getServers(), new Catcher<Integer, MinecraftServer>() {
@Override
public Integer doCatch(MinecraftServer key) {
return key.getServerInfo().getPort();
}
});
collection.addAll(wrapper.getBinndedPorts());
CollectionWrapper.iterator(getServers(serverGroup.getName()), new Runnabled<MinecraftServer>() {
@Override
public void run(MinecraftServer obj) {
Template template = obj.getProcessMeta().getTemplate();
if (!templateMap.containsKey(template.getName()))
templateMap.put(template.getName(), 1);
else
templateMap.put(template.getName(), templateMap.get(template.getName()) + 1);
}
});
CollectionWrapper.iterator(wrapper.getWaitingServices().values(), new Runnabled<Quad<Integer, Integer, ServiceId, Template>>() {
@Override
public void run(Quad<Integer, Integer, ServiceId, Template> obj) {
Template template = obj.getFourth();
if (template != null) {
if (!templateMap.containsKey(template.getName()))
templateMap.put(template.getName(), 1);
else
templateMap.put(template.getName(), templateMap.get(template.getName()) + 1);
}
}
});
for (Template template : serverGroup.getTemplates()) {
if (!templateMap.containsKey(template.getName()))
templateMap.put(template.getName(), 1);
else
templateMap.put(template.getName(), templateMap.get(template.getName()) + 1);
}
Map.Entry<String, Integer> entry = null;
for (Map.Entry<String, Integer> values : templateMap.entrySet()) {
if (entry == null) {
entry = values;
} else {
if (entry.getValue() >= values.getValue()) {
entry = values;
}
}
}
Template template = null;
for (Template t : serverGroup.getTemplates()) {
if (entry.getKey().equalsIgnoreCase(t.getName())) {
template = t;
break;
}
}
if (template == null)
return;
int startport = wrapper.getWrapperInfo().getStartPort();
startport = (startport + NetworkUtils.RANDOM.nextInt(20) + 1);
while (collection.contains(startport)) {
startport = (startport + NetworkUtils.RANDOM.nextInt(20) + 1);
}
List<Template> templates = CollectionWrapper.transform(serverGroup.getTemplates());
if (templates.size() == 0)
return;
ServerProcessMeta serverProcessMeta = new ServerProcessMeta(newServiceId(serverGroup, wrapper, serverId), memory, prioritystop, url, processParameters, onlineMode, plugins, config, customServerName, startport, serverProperties, template);
wrapper.startGameServerAsync(serverProcessMeta);
}
Aggregations