use of de.dytanic.cloudnet.lib.network.protocol.packet.result.Result in project CloudNet by Dytanic.
the class DatabaseImpl method loadDocuments.
@Override
public Database loadDocuments() {
Result result = CloudAPI.getInstance().getNetworkConnection().getPacketManager().sendQuery(new PacketDBOutGetDocument(name), CloudAPI.getInstance().getNetworkConnection());
this.docs = result.getResult().getObject("docs", new TypeToken<Map<String, Document>>() {
}.getType());
return this;
}
use of de.dytanic.cloudnet.lib.network.protocol.packet.result.Result in project CloudNet by Dytanic.
the class PacketManager method sendQuery.
public Result sendQuery(Packet packet, PacketSender packetSender) {
UUID uniq = UUID.randomUUID();
packet.uniqueId = uniq;
Value<Result> handled = new Value<>(null);
synchronizedHandlers.put(uniq, handled);
executorService.execute(new Runnable() {
@Override
public void run() {
packetSender.sendPacket(packet);
}
});
short i = 0;
while (synchronizedHandlers.get(uniq).getValue() == null && i++ < 5000) {
try {
Thread.sleep(0, 300000);
} catch (InterruptedException e) {
}
}
if (i >= 200) {
synchronizedHandlers.get(uniq).setValue(new Result(uniq, new Document()));
}
Value<Result> values = synchronizedHandlers.get(uniq);
synchronizedHandlers.remove(uniq);
return values.getValue();
}
use of de.dytanic.cloudnet.lib.network.protocol.packet.result.Result in project CloudNet by Dytanic.
the class PacketManager method dispatchPacket.
public boolean dispatchPacket(Packet incoming, PacketSender packetSender) {
if (incoming.uniqueId != null && synchronizedHandlers.containsKey(incoming.uniqueId)) {
Result result = new Result(incoming.uniqueId, incoming.data);
Value<Result> x = synchronizedHandlers.get(incoming.uniqueId);
x.setValue(result);
return false;
}
Collection<PacketInHandler> handlers = buildHandlers(incoming.id);
CollectionWrapper.iterator(handlers, new Runnabled<PacketInHandler>() {
@Override
public void run(PacketInHandler handler) {
if (incoming.uniqueId != null)
handler.packetUniqueId = incoming.uniqueId;
if (handler != null) {
handler.handleInput(incoming.data, packetSender);
}
}
});
return true;
}
Aggregations