Back to project page DistributedMemory.
The source code is released under:
Apache License
If you think the Android project DistributedMemory listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package org.faudroids.distributedmemory.core; /* w w w .j av a 2 s.co m*/ import android.os.Handler; import android.os.Looper; import org.faudroids.distributedmemory.network.BroadcastMessage; /** * Manages the transition from one state to another by processing acks and setting * the new state once all clients have acknowledge the new state. */ final class HostStateTransition { // Used to postpone callbacks to the listener private static final Handler handler = new Handler(Looper.myLooper()); private final HostStateTransitionListener transitionListener; private final GameState nextState; private final BroadcastMessage<?> broadcastMessage; public HostStateTransition(HostStateTransitionListener transitionListener, GameState nextState, BroadcastMessage<?> broadcastMessage) { this.transitionListener = transitionListener; this.nextState = nextState; this.broadcastMessage = broadcastMessage; } public void startTransition() { broadcastMessage.sendMessage(); } public boolean onAckReceived() { boolean allAcksReceived = broadcastMessage.onAckReceived(); if (allAcksReceived) handler.post(new Runnable() { @Override public void run() { transitionListener.onTransitionFinished(nextState); } }); return allAcksReceived; } public boolean isComplete() { return broadcastMessage.allAcksReceived(); } }