// Path: src/main/java/uk/ac/ic/wlgitbridge/snapshot/push/exception/PostbackTimeoutException.java
// public class PostbackTimeoutException extends SevereSnapshotPostException {
// 
//     @Override
//     public String getMessage() {
//         return "timeout (60s)";
//     }
// 
//     @Override
//     public List<String> getDescriptionLines() {
//         return Arrays.asList(
//                 "The "
//                         + Util.getServiceName()
//                         + " server is currently unavailable.",
//                 "Please try again later."
//         );
//     }
// 
//     @Override
//     public void fromJSON(JsonElement json) {}
// 
// }
// 
// Path: src/main/java/uk/ac/ic/wlgitbridge/snapshot/push/exception/InvalidPostbackKeyException.java
// public class InvalidPostbackKeyException extends Exception {}


import uk.ac.ic.wlgitbridge.snapshot.push.exception.InternalErrorException;
import uk.ac.ic.wlgitbridge.snapshot.push.exception.PostbackTimeoutException;
import uk.ac.ic.wlgitbridge.snapshot.push.exception.SnapshotPostException;
import uk.ac.ic.wlgitbridge.snapshot.push.exception.InvalidPostbackKeyException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
package uk.ac.ic.wlgitbridge.snapshot.push;



/**
 * Created by Winston on 17/11/14.
 */
public class PostbackPromise {

    private final String postbackKey;
    private final ReentrantLock lock;
    private final Condition cond;

    private boolean received;
    private int versionID;
    private SnapshotPostException exception;

    public PostbackPromise(String postbackKey) {
        this.postbackKey = postbackKey;
        lock = new ReentrantLock();
        cond = lock.newCondition();
        received = false;
        exception = null;
    }

    public int waitForPostback() throws SnapshotPostException {
        lock.lock();
        try {
            while (!received) {
                try {
                    if (!cond.await(60, TimeUnit.SECONDS)) {
                        throw new PostbackTimeoutException();
                    }
                } catch (InterruptedException e) {
                    throw new InternalErrorException();
                }
            }
// Path: src/main/java/uk/ac/ic/wlgitbridge/snapshot/push/exception/PostbackTimeoutException.java
// public class PostbackTimeoutException extends SevereSnapshotPostException {
// 
//     @Override
//     public String getMessage() {
//         return "timeout (60s)";
//     }
// 
//     @Override
//     public List<String> getDescriptionLines() {
//         return Arrays.asList(
//                 "The "
//                         + Util.getServiceName()
//                         + " server is currently unavailable.",
//                 "Please try again later."
//         );
//     }
// 
//     @Override
//     public void fromJSON(JsonElement json) {}
// 
// }
// 
// Path: src/main/java/uk/ac/ic/wlgitbridge/snapshot/push/exception/InvalidPostbackKeyException.java
// public class InvalidPostbackKeyException extends Exception {}


// Path: src/main/java/uk/ac/ic/wlgitbridge/snapshot/push/PostbackPromise.java
import uk.ac.ic.wlgitbridge.snapshot.push.exception.InternalErrorException;
import uk.ac.ic.wlgitbridge.snapshot.push.exception.PostbackTimeoutException;
import uk.ac.ic.wlgitbridge.snapshot.push.exception.SnapshotPostException;
import uk.ac.ic.wlgitbridge.snapshot.push.exception.InvalidPostbackKeyException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

package uk.ac.ic.wlgitbridge.snapshot.push;



/**
 * Created by Winston on 17/11/14.
 */
public class PostbackPromise {

    private final String postbackKey;
    private final ReentrantLock lock;
    private final Condition cond;

    private boolean received;
    private int versionID;
    private SnapshotPostException exception;

    public PostbackPromise(String postbackKey) {
        this.postbackKey = postbackKey;
        lock = new ReentrantLock();
        cond = lock.newCondition();
        received = false;
        exception = null;
    }

    public int waitForPostback() throws SnapshotPostException {
        lock.lock();
        try {
            while (!received) {
                try {
                    if (!cond.await(60, TimeUnit.SECONDS)) {
                        throw new PostbackTimeoutException();
                    }
                } catch (InterruptedException e) {
                    throw new InternalErrorException();
                }
            }
            if (exception != null) {