/** * Add a callback to be invoked when the proposal is done. * <p> * A proposal is done when it has entered either * {@link org.eclipse.jgit.internal.ketch.Proposal.State#EXECUTED} or * {@link org.eclipse.jgit.internal.ketch.Proposal.State#ABORTED} state. If * the proposal is already done {@code callback.run()} is immediately * invoked on the caller's thread. * * @param callback * method to run after the proposal is done. The callback may be * run on a Ketch system thread and should be completed quickly. */ public void addListener(Runnable callback) { boolean runNow = false; synchronized (state) { if (state.get().isDone()) { runNow = true; } else { listeners.add(callback); } } if (runNow) { callback.run(); } }
/** * Add a callback to be invoked when the proposal is done. * <p> * A proposal is done when it has entered either * {@link org.eclipse.jgit.internal.ketch.Proposal.State#EXECUTED} or * {@link org.eclipse.jgit.internal.ketch.Proposal.State#ABORTED} state. If * the proposal is already done {@code callback.run()} is immediately * invoked on the caller's thread. * * @param callback * method to run after the proposal is done. The callback may be * run on a Ketch system thread and should be completed quickly. */ public void addListener(Runnable callback) { boolean runNow = false; synchronized (state) { if (state.get().isDone()) { runNow = true; } else { listeners.add(callback); } } if (runNow) { callback.run(); } }
/** * Wait for the proposal to be attempted and {@link #isDone()} to be true. * * @param wait * how long to wait. * @param unit * unit describing the wait time. * @return true if the proposal is done; false if the method timed out. * @throws InterruptedException * caller was interrupted before proposal executed. */ public boolean await(long wait, TimeUnit unit) throws InterruptedException { synchronized (state) { if (state.get().isDone()) { return true; } state.wait(unit.toMillis(wait)); return state.get().isDone(); } }
/** * Add a callback to be invoked when the proposal is done. * <p> * A proposal is done when it has entered either {@link State#EXECUTED} or * {@link State#ABORTED} state. If the proposal is already done * {@code callback.run()} is immediately invoked on the caller's thread. * * @param callback * method to run after the proposal is done. The callback may be * run on a Ketch system thread and should be completed quickly. */ public void addListener(Runnable callback) { boolean runNow = false; synchronized (state) { if (state.get().isDone()) { runNow = true; } else { listeners.add(callback); } } if (runNow) { callback.run(); } }
/** * Wait for the proposal to be attempted and {@link #isDone()} to be true. * * @param wait * how long to wait. * @param unit * unit describing the wait time. * @return true if the proposal is done; false if the method timed out. * @throws java.lang.InterruptedException * caller was interrupted before proposal executed. */ public boolean await(long wait, TimeUnit unit) throws InterruptedException { synchronized (state) { if (state.get().isDone()) { return true; } state.wait(unit.toMillis(wait)); return state.get().isDone(); } }
/** * Wait for the proposal to be attempted and {@link #isDone()} to be true. * * @throws InterruptedException * caller was interrupted before proposal executed. */ public void await() throws InterruptedException { synchronized (state) { while (!state.get().isDone()) { state.wait(); } } }
void notifyState(State s) { synchronized (state) { state.set(s); state.notifyAll(); } if (s.isDone()) { for (Runnable callback : listeners) { callback.run(); } listeners.clear(); } }
/** * Wait for the proposal to be attempted and {@link #isDone()} to be true. * * @throws java.lang.InterruptedException * caller was interrupted before proposal executed. */ public void await() throws InterruptedException { synchronized (state) { while (!state.get().isDone()) { state.wait(); } } }
void notifyState(State s) { synchronized (state) { state.set(s); state.notifyAll(); } if (s.isDone()) { for (Runnable callback : listeners) { callback.run(); } listeners.clear(); } }
/** * Whether the proposal was attempted * * @return {@code true} if the proposal was attempted. A true value does not * mean consensus was reached, only that the proposal was considered * and will not be making any more progress beyond its current * state. */ public boolean isDone() { return state.get().isDone(); }
/** * @return {@code true} if the proposal was attempted. A true value does not * mean consensus was reached, only that the proposal was considered * and will not be making any more progress beyond its current * state. */ public boolean isDone() { return state.get().isDone(); }
/** * Wait for the proposal to be attempted and {@link #isDone()} to be true. * * @param wait * how long to wait. * @param unit * unit describing the wait time. * @return true if the proposal is done; false if the method timed out. * @throws java.lang.InterruptedException * caller was interrupted before proposal executed. */ public boolean await(long wait, TimeUnit unit) throws InterruptedException { synchronized (state) { if (state.get().isDone()) { return true; } state.wait(unit.toMillis(wait)); return state.get().isDone(); } }
void notifyState(State s) { synchronized (state) { state.set(s); state.notifyAll(); } if (s.isDone()) { for (Runnable callback : listeners) { callback.run(); } listeners.clear(); } }
/** * Whether the proposal was attempted * * @return {@code true} if the proposal was attempted. A true value does not * mean consensus was reached, only that the proposal was considered * and will not be making any more progress beyond its current * state. */ public boolean isDone() { return state.get().isDone(); }
/** * Wait for the proposal to be attempted and {@link #isDone()} to be true. * * @throws java.lang.InterruptedException * caller was interrupted before proposal executed. */ public void await() throws InterruptedException { synchronized (state) { while (!state.get().isDone()) { state.wait(); } } }