Search in sources :

Example 1 with Supplier

use of im.actor.runtime.function.Supplier in project actor-platform by actorapp.

the class UpdateProcessor method applyDifferenceUpdate.

// 
// Difference
// 
public Promise<Void> applyDifferenceUpdate(List<Update> updates) {
    CombinedDifference combinedDifference = GetDiffCombiner.buildDiff(updates);
    ArrayList<Supplier<Promise<Void>>> pending = new ArrayList<>();
    pending.add(() -> messagesProcessor.onDifferenceStart());
    for (Peer peer : combinedDifference.getReceived().keySet()) {
        long time = combinedDifference.getReceived().get(peer);
        pending.add(() -> processUpdate(new UpdateMessageReceived(buildApiPeer(peer), time, 0)));
    }
    for (Peer peer : combinedDifference.getRead().keySet()) {
        long time = combinedDifference.getRead().get(peer);
        pending.add(() -> processUpdate(new UpdateMessageRead(buildApiPeer(peer), time, 0)));
    }
    for (Peer peer : combinedDifference.getReadByMe().keySet()) {
        CombinedDifference.ReadByMeValue time = combinedDifference.getReadByMe().get(peer);
        pending.add(() -> processUpdate(new UpdateMessageReadByMe(buildApiPeer(peer), time.getDate(), time.getCounter())));
    }
    for (Peer peer : combinedDifference.getMessages().keySet()) {
        pending.add(() -> messagesProcessor.onDifferenceMessages(buildApiPeer(peer), combinedDifference.getMessages().get(peer)));
    }
    for (Update u : combinedDifference.getOtherUpdates()) {
        pending.add(() -> processUpdate(u));
    }
    pending.add(() -> messagesProcessor.onDifferenceEnd());
    return Promises.traverse(pending).map(v -> null);
}
Also used : CombinedDifference(im.actor.core.modules.sequence.internal.CombinedDifference) Peer(im.actor.core.entity.Peer) ArrayList(java.util.ArrayList) UpdateMessageReadByMe(im.actor.core.api.updates.UpdateMessageReadByMe) Supplier(im.actor.runtime.function.Supplier) UpdateMessageReceived(im.actor.core.api.updates.UpdateMessageReceived) Void(im.actor.runtime.actors.messages.Void) Update(im.actor.core.network.parser.Update) UpdateMessageRead(im.actor.core.api.updates.UpdateMessageRead)

Aggregations

UpdateMessageRead (im.actor.core.api.updates.UpdateMessageRead)1 UpdateMessageReadByMe (im.actor.core.api.updates.UpdateMessageReadByMe)1 UpdateMessageReceived (im.actor.core.api.updates.UpdateMessageReceived)1 Peer (im.actor.core.entity.Peer)1 CombinedDifference (im.actor.core.modules.sequence.internal.CombinedDifference)1 Update (im.actor.core.network.parser.Update)1 Void (im.actor.runtime.actors.messages.Void)1 Supplier (im.actor.runtime.function.Supplier)1 ArrayList (java.util.ArrayList)1