/** * @return The response code whose getValue() is the specified integer. * @throws IndexOutOfBoundsException if there is no such response code. */ public static ResponseCode of(int value) { // NOTE: This implementation assumes that the response codes have consecutive // integer values beginning with -1. return values()[value + 1]; } }
private void triggerUnsavedDataListener() { if (unsavedDataListener != null) { unsavedDataListener.onUpdate(unsavedDataInfo); } }
/** * Wraps a channel exception in another providing wave and wavelet id context. */ private ChannelException exceptionWithContext(ChannelException e, WaveletId waveletId) { return new ChannelException(e.getResponseCode(), "Nested ChannelException", e, e.getRecoverable(), waveId, waveletId); }
@Override public void onUpdate(UnsavedDataInfo unsavedDataInfo) { this.unacknowledgedSize = unsavedDataInfo.estimateUnacknowledgedSize(); this.uncommittedSize = unsavedDataInfo.estimateUncommittedSize(); this.inFlight = unsavedDataInfo.inFlightSize(); this.lastAckVersion = unsavedDataInfo.laskAckVersion(); this.lastCommitVersion = unsavedDataInfo.lastCommitVersion(); }
public void testOf() { for (int i = -1; i < ResponseCode.values().length - 1; i++) { assertEquals(String.valueOf(i), ResponseCode.values()[i + 1], ResponseCode.of(i)); assertEquals(String.valueOf(i), i, ResponseCode.of(i).getValue()); } }
/** * Tests that the system clock returns a timestamp approximately equal to * the current system time. */ public void testGetCurrentTime() { assertEquals(System.currentTimeMillis(), clock.getCurrentTime(), 100); } }
@Override public void onNack(ResponseCode responseCode, String errorString, long version) throws ChannelException { throw new ChannelException(responseCode, "Operation channel failed on nack: code=" + responseCode + ", " + errorString + ", " + this + ", " + deltaChannel + ", " + cc, null, Recoverable.NOT_RECOVERABLE, null, null); }
/** * Handles failure of the view channel or an operation channel. * * @param e The exception that caused the channel to fail. */ private void onChannelException(ChannelException e) { if (e.getRecoverable() != Recoverable.RECOVERABLE) { shutdown(e.getResponseCode(), "Channel Exception", e); } else { reconnect(e); } }
/** * Gets the client/server delta pair that will be output by an appropriately * timed and parameterised call to this expected transform. */ DeltaPair getOutput() { assertNotNull("No output client delta specified", outputClientDelta); return new DeltaPair(outputClientDelta, outputServerDelta); }
@Override protected void setUp() throws Exception { super.setUp(); clock = new SystemClock(); }
public CorruptionDetail(ResponseCode errorCode, String message, Throwable cause) { super(addErrorToMessage(errorCode, message), cause); this.errorCode = errorCode; } }
/** * Shuts down this multiplexer permanently after an exception. */ private void shutdown(String message, ChannelException e) { shutdown(e.getResponseCode(), message, e); }
@Override public void onUpdate(UnsavedDataInfo unsavedDataInfo) { this.unacknowledgedSize = unsavedDataInfo.estimateUnacknowledgedSize(); this.uncommittedSize = unsavedDataInfo.estimateUncommittedSize(); this.inFlight = unsavedDataInfo.inFlightSize(); this.lastAckVersion = unsavedDataInfo.laskAckVersion(); this.lastCommitVersion = unsavedDataInfo.lastCommitVersion(); }
public void testOf() { for (int i = -1; i < ResponseCode.values().length - 1; i++) { assertEquals(String.valueOf(i), ResponseCode.values()[i + 1], ResponseCode.of(i)); assertEquals(String.valueOf(i), i, ResponseCode.of(i).getValue()); } }
/** * Tests that the system clock returns a timestamp approximately equal to * the current system time. */ public void testGetCurrentTime() { assertEquals(System.currentTimeMillis(), clock.getCurrentTime(), 100); } }
@Override public void onFailure(String reason) throws ChannelException { if (connectionIsCurrent()) { throw new ChannelException("Delta channel: submission failed: " + reason, RECOVERABLE); } }
@Override public void onAck(int opsApplied, HashedVersion signature) throws ChannelException { try { cc.onSuccess(opsApplied, signature); } catch (TransformException e) { throw new ChannelException(ResponseCode.INVALID_OPERATION, "Operation channel failed on ack: " + this + ", " + deltaChannel + ", " + cc, e, Recoverable.NOT_RECOVERABLE, null, null); } }