/** * Constructs a new channel. The channel is initially disconnected until it * receives a first wavelet update. The channel must be * {@link #reset(org.waveprotocol.wave.concurrencycontrol.channel.WaveletDeltaChannel.Receiver)} * to install a receiver before any messages may be received. * * @param channel channel on which to submit deltas * @param logger logger for the channel */ public WaveletDeltaChannelImpl(WaveletChannel channel, LoggerBundle logger) { this.channel = channel; this.logger = logger; logTrace("New delta channel created"); }
/** * Resets this channel, ready to receive another connection message. */ private void internalReset() { logTrace("Delta channel reset"); state = State.INITIAL; transmitter = null; transmitDelta = null; lastServerVersion = NO_VERSION; queue.clear(); }
/** * Logs the ops from a delta message. * * @param prefix message to print before each op message * @param delta delta to log */ private void logDelta(String prefix, TransformedWaveletDelta delta) { if (logger.trace().shouldLog()) { logTrace(prefix + summariseDelta(delta)); } }
/** * Delivers queued messages from the server to the wave client in version * order. If there are missing versions (should mean that messages are * reordered and messages with the missing numbers are still in flight) we * hold back the queued messages with larger versions. */ private void flushServerMessages() throws ChannelException { while (!queue.isEmpty() && queue.get(0).startVersion() == lastServerVersion) { ServerMessage message = queue.remove(0); if (message.endVersion < lastServerVersion) { Preconditions.illegalState("Delta channel queue is out of order. Message endVersion " + message.endVersion + ", lastServerVersion " + lastServerVersion); } lastServerVersion = message.endVersion(); if (receiver != null) { logTrace("Releasing message ", message); message.deliverTo(receiver); } } tryTransmit(); }
/** * Processes the first incoming stream message, if it's a snapshot * * @param wavelet connection information * @param lastCommittedVersion committed version at connection * @param currentSignedVersion current wavelet version, when reconnecting at * an older version */ private void processConnectSnapshotMessage(ObservableWaveletData wavelet, HashedVersion lastCommittedVersion, HashedVersion currentSignedVersion) throws ChannelException { if (wavelet == null) { throw new ChannelException("Delta channel: invalid first wave stream message: null" + ", last committed version: " + lastCommittedVersion + "currentSignedVersion: " + currentSignedVersion, NOT_RECOVERABLE); } HashedVersion connectVersion; // This stream has connected at the latest version of the wavelet. connectVersion = wavelet.getHashedVersion(); logTrace("Delta channel connecting, wavelet id ", wavelet.getWaveId(), "/", wavelet.getWaveletId(), ", version ", connectVersion.getVersion()); processConnect(connectVersion, lastCommittedVersion, currentSignedVersion); }
logTrace("Delta channel reconnecting, connect version ", connectVersion.getVersion(), " current version ", currentSignedVersion != null ? currentSignedVersion.getVersion() : connectVersion.getVersion());
logTrace("Outgoing " + summariseDelta(delta));