Search in sources :

Example 6 with Result

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;
}
Also used : Map(java.util.Map) Result(de.dytanic.cloudnet.lib.network.protocol.packet.result.Result)

Example 7 with Result

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();
}
Also used : Value(de.dytanic.cloudnet.lib.Value) Document(de.dytanic.cloudnet.lib.utility.document.Document) Result(de.dytanic.cloudnet.lib.network.protocol.packet.result.Result)

Example 8 with Result

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;
}
Also used : Result(de.dytanic.cloudnet.lib.network.protocol.packet.result.Result)

Aggregations

Result (de.dytanic.cloudnet.lib.network.protocol.packet.result.Result)8 CloudPlayer (de.dytanic.cloudnet.lib.player.CloudPlayer)4 TypeToken (com.google.gson.reflect.TypeToken)3 Document (de.dytanic.cloudnet.lib.utility.document.Document)2 Value (de.dytanic.cloudnet.lib.Value)1 Map (java.util.Map)1