/** * Verify that a NOP state change is allowed (this is used when there are * multiple committers for a distributed transaction since (as a * convenience) more than one may instruct us to make the same state * change). */ public void test_selfTransitionOk() { assertTrue(RunState.Active.isTransitionAllowed(RunState.Active)); assertTrue(RunState.Prepared.isTransitionAllowed(RunState.Prepared)); assertTrue(RunState.Committed.isTransitionAllowed(RunState.Committed)); assertTrue(RunState.Aborted.isTransitionAllowed(RunState.Aborted)); }
/** * Verify that a NOP state change is allowed (this is used when there are * multiple committers for a distributed transaction since (as a * convenience) more than one may instruct us to make the same state * change). */ public void test_selfTransitionOk() { assertTrue(RunState.Active.isTransitionAllowed(RunState.Active)); assertTrue(RunState.Prepared.isTransitionAllowed(RunState.Prepared)); assertTrue(RunState.Committed.isTransitionAllowed(RunState.Committed)); assertTrue(RunState.Aborted.isTransitionAllowed(RunState.Aborted)); }
/** * Change the {@link RunState}. * * @param newval * The new {@link RunState}. * * @throws IllegalArgumentException * if the argument is <code>null</code>. * @throws IllegalStateException * if the state transition is not allowed. * * @see RunState#isTransitionAllowed(RunState) */ public void setRunState(final RunState newval) { if (!lock.isHeldByCurrentThread()) throw new IllegalMonitorStateException(); if (newval == null) throw new IllegalArgumentException(); if (!runState.isTransitionAllowed(newval)) { throw new IllegalStateException("runState=" + runState + ", newValue=" + newval); } this.runState = newval; }
/** * Change the {@link RunState}. * * @param newval * The new {@link RunState}. * * @throws IllegalArgumentException * if the argument is <code>null</code>. * @throws IllegalStateException * if the state transition is not allowed. * * @see RunState#isTransitionAllowed(RunState) */ public void setRunState(final RunState newval) { if (!lock.isHeldByCurrentThread()) throw new IllegalMonitorStateException(); if (newval == null) throw new IllegalArgumentException(); if (!runState.isTransitionAllowed(newval)) { throw new IllegalStateException("runState=" + runState + ", newValue=" + newval); } this.runState = newval; }
/** * Change the {@link RunState}. * * @param newval * The new {@link RunState}. * * @throws IllegalArgumentException * if the argument is <code>null</code>. * @throws IllegalStateException * if the state transition is not allowed. * * @see RunState#isTransitionAllowed(RunState) */ public void setRunState(final RunState newval) { if (!lock.isHeldByCurrentThread()) throw new IllegalMonitorStateException(); if (newval == null) throw new IllegalArgumentException(); if (!runState.get().isTransitionAllowed(newval)) { throw new IllegalStateException("runState=" + runState + ", newValue=" + newval); } this.runState.set(newval); }
/** * Unit tests for legal and illegal state transitions. */ public void test_stateMachine() { assertTrue(RunState.Active.isTransitionAllowed(RunState.Prepared)); assertTrue(RunState.Active.isTransitionAllowed(RunState.Committed)); assertTrue(RunState.Active.isTransitionAllowed(RunState.Aborted)); assertFalse(RunState.Prepared.isTransitionAllowed(RunState.Active)); assertTrue(RunState.Prepared.isTransitionAllowed(RunState.Committed)); assertTrue(RunState.Prepared.isTransitionAllowed(RunState.Aborted)); assertFalse(RunState.Committed.isTransitionAllowed(RunState.Active)); assertFalse(RunState.Committed.isTransitionAllowed(RunState.Prepared)); assertFalse(RunState.Committed.isTransitionAllowed(RunState.Aborted)); assertFalse(RunState.Aborted.isTransitionAllowed(RunState.Active)); assertFalse(RunState.Aborted.isTransitionAllowed(RunState.Prepared)); assertFalse(RunState.Aborted.isTransitionAllowed(RunState.Committed)); }
/** * Change the {@link RunState}. * * @param newval * The new {@link RunState}. * * @throws IllegalArgumentException * if the argument is <code>null</code>. * @throws IllegalStateException * if the state transition is not allowed. * * @see RunState#isTransitionAllowed(RunState) */ public void setRunState(final RunState newval) { if (!lock.isHeldByCurrentThread()) throw new IllegalMonitorStateException(); if (newval == null) throw new IllegalArgumentException(); if (!runState.get().isTransitionAllowed(newval)) { throw new IllegalStateException("runState=" + runState + ", newValue=" + newval); } this.runState.set(newval); }
/** * Unit tests for legal and illegal state transitions. */ public void test_stateMachine() { assertTrue(RunState.Active.isTransitionAllowed(RunState.Prepared)); assertTrue(RunState.Active.isTransitionAllowed(RunState.Committed)); assertTrue(RunState.Active.isTransitionAllowed(RunState.Aborted)); assertFalse(RunState.Prepared.isTransitionAllowed(RunState.Active)); assertTrue(RunState.Prepared.isTransitionAllowed(RunState.Committed)); assertTrue(RunState.Prepared.isTransitionAllowed(RunState.Aborted)); assertFalse(RunState.Committed.isTransitionAllowed(RunState.Active)); assertFalse(RunState.Committed.isTransitionAllowed(RunState.Prepared)); assertFalse(RunState.Committed.isTransitionAllowed(RunState.Aborted)); assertFalse(RunState.Aborted.isTransitionAllowed(RunState.Active)); assertFalse(RunState.Aborted.isTransitionAllowed(RunState.Prepared)); assertFalse(RunState.Aborted.isTransitionAllowed(RunState.Committed)); }