/** * Tries to fetch the wavelet as remote, if not found - fetches as local * wavelet. * * @param waveletName the wavelet name * @return the local or remote wavelet. * @throws WaveletStateException if something goes wrong */ public WaveletContainer getWavelet(WaveletName waveletName) throws WaveletStateException { WaveletContainer waveletContainer = null; try { waveletContainer = getRemoteWavelet(waveletName); } catch (WaveletStateException | NullPointerException e) { // Ignored. } if (waveletContainer == null) { waveletContainer = getLocalWavelet(waveletName); } return waveletContainer; }
public void testGetOrCreateCreatesWavelets() throws WaveletStateException, PersistenceException { when(waveletStore.lookup(WAVE_ID)).thenReturn(ImmutableSet.<WaveletId>of()); LocalWaveletContainer wavelet = waveMap.getOrCreateLocalWavelet(WAVELET_NAME); assertSame(wavelet, waveMap.getLocalWavelet(WAVELET_NAME)); }
@Override public ExceptionalIterator<WaveId, WaveServerException> getWaveIds() { Preconditions.checkState(initialized, "Wave server not yet initialized"); return waveMap.getWaveIds(); }
@Override protected void setUp() throws Exception { super.setUp(); LocalWaveletContainer.Factory localFactory = mock(LocalWaveletContainer.Factory.class); WaveletNotificationSubscriber notifiee = mock(WaveletNotificationSubscriber.class); SettableFuture<ImmutableSet<WaveletId>> lookedupWavelets = SettableFuture.create(); lookedupWavelets.set(ImmutableSet.of(WAVELET_NAME.waveletId)); Wave wave = new Wave(WAVELET_NAME.waveId, lookedupWavelets, notifiee, localFactory, null, WAVELET_NAME.waveId.getDomain()); Map<WaveId, Wave> waves = Maps.newHashMap(); waves.put(WAVELET_NAME.waveId, wave); when(waveMap.getWaves()).thenReturn(waves); ImmutableSet<WaveletId> wavelets = ImmutableSet.of(WAVELET_NAME.waveletId); when(waveMap.lookupWavelets(WAVELET_NAME.waveId)).thenReturn(wavelets); LocalWaveletContainer c = mock(LocalWaveletContainer.class); when(c.hasParticipant(PARTICIPANT)).thenReturn(true); when(waveMap.getLocalWavelet(WAVELET_NAME)).thenReturn(c); }
public void testWaveletAvailableAfterLoad() throws WaveletStateException, PersistenceException { when(waveletStore.getWaveIdIterator()).thenReturn(eitr(WAVE_ID)); when(waveletStore.lookup(WAVE_ID)).thenReturn(ImmutableSet.<WaveletId>of(WAVELET_ID)); waveMap.loadAllWavelets(); assertNotNull(waveMap.getLocalWavelet(WAVELET_NAME)); }
public void testWaveAvailableAfterLoad() throws PersistenceException, WaveServerException { when(waveletStore.getWaveIdIterator()).thenReturn(eitr(WAVE_ID)); waveMap.loadAllWavelets(); ExceptionalIterator<WaveId, WaveServerException> waves = waveMap.getWaveIds(); assertTrue(waves.hasNext()); assertEquals(WAVE_ID, waves.next()); }
/** * Returns a container for a local wavelet. If it doesn't exist, it will be created. * * @param waveletName name of wavelet * @return an existing or new instance. * @throws IllegalArgumentException if the name refers to a remote wavelet. */ private LocalWaveletContainer getOrCreateLocalWavelet(WaveletName waveletName) { Preconditions.checkArgument(isLocalWavelet(waveletName), "%s is not local", waveletName); return waveMap.getOrCreateLocalWavelet(waveletName); }
); waveMap = new WaveMap(waveletStore, notifiee, localWaveletContainerFactory, remoteWaveletContainerFactory, "example.com", config, storageContinuationExecutor);
@Override public ImmutableSet<WaveletId> getWaveletIds(WaveId waveId) throws WaveServerException { Preconditions.checkState(initialized, "Wave server not yet initialized"); return waveMap.lookupWavelets(waveId); }
private LocalWaveletContainer getLocalWavelet(WaveletName waveletName) throws WaveletStateException { Preconditions.checkArgument(isLocalWavelet(waveletName), "%s is not local", waveletName); return waveMap.getLocalWavelet(waveletName); }
private RemoteWaveletContainer getRemoteWavelet(WaveletName waveletName) throws WaveletStateException { Preconditions.checkArgument(!isLocalWavelet(waveletName), "%s is not remote", waveletName); return waveMap.getRemoteWavelet(waveletName); }
@Override public Multimap<WaveId, WaveletId> load(final ParticipantId user) { Multimap<WaveId, WaveletId> userView = HashMultimap.create(); // Create initial per user waves view by looping over all waves // in the waves store. Map<WaveId, Wave> waves = waveMap.getWaves(); for (Map.Entry<WaveId, Wave> entry : waves.entrySet()) { Wave wave = entry.getValue(); for (WaveletContainer c : wave) { WaveletId waveletId = c.getWaveletName().waveletId; try { if (!c.hasParticipant(user)) { continue; } // Add this wave to the user view. userView.put(entry.getKey(), waveletId); } catch (WaveletStateException e) { LOG.warning("Failed to access wavelet " + c.getWaveletName(), e); } } } LOG.info("Initalized waves view for user: " + user.getAddress() + ", number of waves in view: " + userView.size()); return userView; } });
/** * Forces all waves to be loaded into memory and processes each wavelet. */ @Override public synchronized void remakeIndex() throws WaveletStateException, WaveServerException { waveMap.loadAllWavelets(); ExceptionalIterator<WaveId, WaveServerException> witr = waveletProvider.getWaveIds(); while (witr.hasNext()) { WaveId waveId = witr.next(); for (WaveletId waveletId : waveletProvider.getWaveletIds(waveId)) { WaveletName waveletName = WaveletName.of(waveId, waveletId); // Required to call this method to load the wavelet into memory. waveletProvider.getSnapshot(waveletName); processWavelet(waveletName); } } }
/** * Returns a container for a remote wavelet. If it doesn't exist, it will be created. * This method is only called in response to a Federation Remote doing an update * or commit on this wavelet. * * @param waveletName name of wavelet * @return an existing or new instance. * @throws IllegalArgumentException if the name refers to a local wavelet. */ private RemoteWaveletContainer getOrCreateRemoteWavelet(WaveletName waveletName) { Preconditions.checkArgument(!isLocalWavelet(waveletName), "%s is not remote", waveletName); return waveMap.getOrCreateRemoteWavelet(waveletName); }
@Override protected void setUp() throws Exception { super.setUp(); LocalWaveletContainer.Factory localFactory = mock(LocalWaveletContainer.Factory.class); WaveletNotificationSubscriber notifiee = mock(WaveletNotificationSubscriber.class); SettableFuture<ImmutableSet<WaveletId>> lookedupWavelets = SettableFuture.create(); lookedupWavelets.set(ImmutableSet.of(WAVELET_NAME.waveletId)); Wave wave = new Wave(WAVELET_NAME.waveId, lookedupWavelets, notifiee, localFactory, null, WAVELET_NAME.waveId.getDomain()); Map<WaveId, Wave> waves = Maps.newHashMap(); waves.put(WAVELET_NAME.waveId, wave); when(waveMap.getWaves()).thenReturn(waves); ImmutableSet<WaveletId> wavelets = ImmutableSet.of(WAVELET_NAME.waveletId); when(waveMap.lookupWavelets(WAVELET_NAME.waveId)).thenReturn(wavelets); LocalWaveletContainer c = mock(LocalWaveletContainer.class); when(c.hasParticipant(PARTICIPANT)).thenReturn(true); when(waveMap.getLocalWavelet(WAVELET_NAME)).thenReturn(c); }
public void testWaveletAvailableAfterLoad() throws WaveletStateException, PersistenceException { when(waveletStore.getWaveIdIterator()).thenReturn(eitr(WAVE_ID)); when(waveletStore.lookup(WAVE_ID)).thenReturn(ImmutableSet.<WaveletId>of(WAVELET_ID)); waveMap.loadAllWavelets(); assertNotNull(waveMap.getLocalWavelet(WAVELET_NAME)); }
public void testWaveAvailableAfterLoad() throws PersistenceException, WaveServerException { when(waveletStore.getWaveIdIterator()).thenReturn(eitr(WAVE_ID)); waveMap.loadAllWavelets(); ExceptionalIterator<WaveId, WaveServerException> waves = waveMap.getWaveIds(); assertTrue(waves.hasNext()); assertEquals(WAVE_ID, waves.next()); }
public void testWaveIdsList() throws WaveServerException { waveMap.getOrCreateLocalWavelet(WAVELET_NAME); ExceptionalIterator<WaveId, WaveServerException> waves = waveServer.getWaveIds(); assertTrue(waves.hasNext()); assertEquals(WAVE_ID, waves.next()); }
); waveMap = new WaveMap(waveletStore, notifiee, localWaveletContainerFactory, remoteWaveletContainerFactory, "example.com", config, storageContinuationExecutor);
/** * Loads all wavelets from storage. * * @throws WaveletStateException if storage access fails. */ public void loadAllWavelets() throws WaveletStateException { try { ExceptionalIterator<WaveId, PersistenceException> itr = store.getWaveIdIterator(); while (itr.hasNext()) { WaveId waveId = itr.next(); lookupWavelets(waveId); } } catch (PersistenceException e) { throw new WaveletStateException("Failed to scan waves", e); } }