/** * Creates new instance of {@link WaveletInfo}. * * @param hashFactory the factory for hashed versions. * @param provider the {@link WaveletProvider}. * @return new {@link WaveletInfo} instance. */ public static WaveletInfo create(HashedVersionFactory hashFactory, WaveletProvider provider) { return new WaveletInfo(hashFactory, provider); }
@Override public void waveletCommitted(WaveletName waveletName, HashedVersion version) { for (ParticipantId participant : waveletInfo.getWaveletParticipants(waveletName)) { waveletInfo.getUserManager(participant).onCommit(waveletName, version); } }
/** * @param waveletName the waveletName. * @return the wavelet participants. */ public Set<ParticipantId> getWaveletParticipants(WaveletName waveletName) { PerWavelet waveletInfo = getWavelet(waveletName); synchronized (waveletInfo) { return ImmutableSet.copyOf(waveletInfo.explicitParticipants); } }
private static void initializeFrontend(Injector injector, ServerRpcProvider server, WaveBus waveBus) throws WaveServerException { HashedVersionFactory hashFactory = injector.getInstance(HashedVersionFactory.class); WaveletProvider provider = injector.getInstance(WaveletProvider.class); WaveletInfo waveletInfo = WaveletInfo.create(hashFactory, provider); ClientFrontend frontend = ClientFrontendImpl.create(provider, waveBus, waveletInfo); ProtocolWaveClientRpc.Interface rpcImpl = WaveClientRpcImpl.create(frontend, false); server.registerService(ProtocolWaveClientRpc.newReflectiveService(rpcImpl)); }
waveletInfo.initialiseWave(waveId); } catch (WaveServerException e) { LOG.severe("Wave server failed lookup for " + waveId, e); UserManager userManager = waveletInfo.getUserManager(loggedInUser); WaveViewSubscription subscription = userManager.subscribe(waveId, waveletIdFilter, channelId, openListener); waveletIds = waveletInfo.visibleWaveletsFor(subscription, loggedInUser); } catch (WaveServerException e1) { waveletIds = Sets.newHashSet(); waveletInfo.notifyAddedImplcitParticipant(waveletName, loggedInUser);
/** * Sends new deltas to a particular user on a particular wavelet. * Updates the participants of the specified wavelet if the participant was added or removed. * * @param waveletName the waveletName which the deltas belong to. * @param participant on the wavelet. * @param newDeltas newly arrived deltas of relevance for participant. Must * not be empty. * @param add whether the participant is added by the first delta. * @param remove whether the participant is removed by the last delta. */ private void participantUpdate(WaveletName waveletName, ParticipantId participant, DeltaSequence newDeltas, boolean add, boolean remove) { if(LOG.isFineLoggable()) { LOG.fine("Notifying " + participant + " for " + waveletName); } if (add) { waveletInfo.notifyAddedExplicitWaveletParticipant(waveletName, participant); } waveletInfo.getUserManager(participant).onUpdate(waveletName, newDeltas); if (remove) { waveletInfo.notifyRemovedExplicitWaveletParticipant(waveletName, participant); } }
if(waveletInfo.getCurrentWaveletVersion(waveletName).getVersion() == 0 && LOG.isWarningLoggable()) { LOG.warning("Wavelet does not appear to have been initialized by client. Continuing anyway."); waveletInfo.syncWaveletVersion(waveletName, newDeltas); Sets.newHashSet(waveletInfo.getWaveletParticipants(waveletName));
@Override public void onSuccess(int operationsApplied, HashedVersion hashedVersionAfterApplication, long applicationTimestamp) { listener.onSuccess(operationsApplied, hashedVersionAfterApplication, applicationTimestamp); waveletInfo.getUserManager(author).submitResponse(channelId, waveletName, hashedVersionAfterApplication); }
@Override protected void setUp() throws Exception { super.setUp(); waveletProvider = mock(WaveletProvider.class); when(waveletProvider.getWaveletIds(any(WaveId.class))).thenReturn(ImmutableSet.<WaveletId>of()); WaveletInfo waveletInfo = WaveletInfo.create(HASH_FACTORY, waveletProvider); clientFrontend = new ClientFrontendImpl(waveletProvider, waveletInfo); }
@Override public void onFailure(String error) { listener.onFailure(error); waveletInfo.getUserManager(author).submitResponse(channelId, waveletName, null); } });
@Override protected void setUp() throws Exception { super.setUp(); waveletProvider = mock(WaveletProvider.class); when(waveletProvider.getWaveletIds(any(WaveId.class))).thenReturn(ImmutableSet.<WaveletId>of()); WaveletInfo waveletInfo = WaveletInfo.create(HASH_FACTORY, waveletProvider); clientFrontend = new ClientFrontendImpl(waveletProvider, waveletInfo, "example.com"); }
/** * Notifies that the participant was added from the wavelet. * * @param waveletName the wavelet name. * @param participant the participant. */ public void notifyAddedExplicitWaveletParticipant(WaveletName waveletName, ParticipantId participant) { PerWavelet waveletInfo = getWavelet(waveletName); synchronized (waveletInfo) { waveletInfo.explicitParticipants.add(participant); } }
@Override public void submitRequest(ParticipantId loggedInUser, final WaveletName waveletName, final ProtocolWaveletDelta delta, final String channelId, final SubmitRequestListener listener) { final ParticipantId author = new ParticipantId(delta.getAuthor()); if (!author.equals(loggedInUser)) { listener.onFailure("Author field on delta must match logged in user"); return; } waveletInfo.getUserManager(author).submitRequest(channelId, waveletName); waveletProvider.submitRequest(waveletName, delta, new SubmitRequestListener() { @Override public void onSuccess(int operationsApplied, HashedVersion hashedVersionAfterApplication, long applicationTimestamp) { listener.onSuccess(operationsApplied, hashedVersionAfterApplication, applicationTimestamp); waveletInfo.getUserManager(author).submitResponse(channelId, waveletName, hashedVersionAfterApplication); } @Override public void onFailure(String error) { listener.onFailure(error); waveletInfo.getUserManager(author).submitResponse(channelId, waveletName, null); } }); }
/** * Notifies that the participant was removed from the wavelet. * * @param waveletName the wavelet name. * @param participant the participant. */ public void notifyRemovedExplicitWaveletParticipant(WaveletName waveletName, ParticipantId participant) { PerWavelet waveletInfo = getWavelet(waveletName); synchronized (waveletInfo) { waveletInfo.explicitParticipants.remove(participant); } }
/** * @param waveletName the waveletName. * @return the implicit wavelet participants. An implicit participant is not a * "strict" participant on the wavelet, but rather only opened the * wave and listens on updates. For example, anyone can open a shared * wave without becoming explicit participant. */ public Set<ParticipantId> getImplicitWaveletParticipants(WaveletName waveletName) { PerWavelet waveletInfo = getWavelet(waveletName); synchronized (waveletInfo) { return ImmutableSet.copyOf(waveletInfo.explicitParticipants); } }
/** * Notifies that an implicit participant opened the wave. * * @param waveletName the wavelet name. * @param participant the participant. */ public void notifyAddedImplcitParticipant(WaveletName waveletName, ParticipantId participant) { PerWavelet waveletInfo = getWavelet(waveletName); synchronized (waveletInfo) { if (!waveletInfo.explicitParticipants.contains(participant)) { waveletInfo.implicitParticipants.add(participant); } } }
/** * Returns the current wavelet version. */ public HashedVersion getCurrentWaveletVersion(WaveletName waveletName) { PerWavelet waveletInfo = getWavelet(waveletName); synchronized (waveletInfo) { return waveletInfo.getCurrentVersion(); } }
/** * Synchronizes the wavelet version and ensures that the deltas are * contiguous. * * @param waveletName the wavelet name. * @param newDeltas the new deltas. */ public void syncWaveletVersion(WaveletName waveletName, DeltaSequence newDeltas) { HashedVersion expectedVersion; PerWavelet waveletInfo = getWavelet(waveletName); synchronized (waveletInfo) { expectedVersion = waveletInfo.getCurrentVersion(); Preconditions.checkState(expectedVersion.getVersion() == newDeltas.getStartVersion(), "Expected deltas starting at version %s, got %s", expectedVersion, newDeltas.getStartVersion()); waveletInfo.setCurrentVersion(newDeltas.getEndVersion()); } }