@Test public void testSync() throws Exception { final CountDownLatch signal = new CountDownLatch(1); final long waitTimeout = 5; final MirroredIndex index = client.getIndex(Helpers.safeIndexName(Helpers.getMethodName())); sync(index, new SyncCompletionHandler() { @Override public void syncCompleted(@Nullable Throwable error) { try { assertNull(error); listener = new SyncListener() { @Override public void syncDidStart(MirroredIndex index) { fail("The sync should not have been started again"); } @Override public void syncDidFinish(MirroredIndex index, Throwable error, MirroredIndex.SyncStats stats) { } }; final CountDownLatch signal2 = new CountDownLatch(1); index.addSyncListener(listener); index.syncIfNeeded(); assertFalse(signal2.await(waitTimeout, TimeUnit.SECONDS)); index.removeSyncListener(listener); index.setDataSelectionQueries(new MirroredIndex.DataSelectionQuery(new Query(), 6)); listener = new SyncListener() { @Override public void syncDidStart(MirroredIndex index) { } @Override public void syncDidFinish(MirroredIndex index, Throwable error, MirroredIndex.SyncStats stats) { index.removeSyncListener(listener); assertNull(error); signal.countDown(); } }; index.addSyncListener(listener); index.syncIfNeeded(); } catch (InterruptedException e) { fail(e.getMessage()); } } }); }
public void sync() { if (getDataSelectionQueries().length == 0) { throw new IllegalStateException("Cannot sync with empty data selection queries"); } synchronized (this) { if (syncing) return; syncing = true; } getClient().localBuildExecutorService.submit(new Runnable() { @Override public void run() { _sync(); } }); }
MirroredIndex extends Index { public void sync() { if (getDataSelectionQueries().length == 0) { throw new IllegalStateException("Cannot sync with empty data selection queries"); } synchronized (this) { if (syncing) return; syncing = true; } getClient().localBuildExecutorService.submit(new Runnable() { @Override public void run() { _sync(); } }); } }
MirroredIndex extends Index { public void sync() { if (getDataSelectionQueries().length == 0) { throw new IllegalStateException("Cannot sync with empty data selection queries"); } synchronized (this) { if (syncing) return; syncing = true; } getClient().localBuildExecutorService.submit(new Runnable() { @Override public void run() { _sync(); } }); } protected  MirroredIndex(@NonNull OfflineClient client, @NonNull String indexName); }
MirroredIndex extends Index { public void sync() { if (getDataSelectionQueries().length == 0) { throw new IllegalStateException("Cannot sync with empty data selection queries"); } synchronized (this) { if (syncing) return; syncing = true; } getClient().localBuildExecutorService.submit(new Runnable() { @Override public void run() { _sync(); } }); } protected  MirroredIndex(@NonNull OfflineClient client, @NonNull String indexName); OfflineClient getClient(); boolean isMirrored(); void setMirrored(boolean mirrored); void addDataSelectionQuery(@NonNull DataSelectionQuery query); void setDataSelectionQueries(@NonNull DataSelectionQuery... queries); @NonNull DataSelectionQuery[] getDataSelectionQueries(); long getDelayBetweenSyncs(); void setDelayBetweenSyncs(long delayBetweenSyncs); long getDelayBetweenSyncs(@NonNull TimeUnit unit); void setDelayBetweenSyncs(long duration, @NonNull TimeUnit unit); void sync(); void syncIfNeeded(); boolean hasOfflineData(); Request buildOfflineFromFiles(@NonNull final File settingsFile, @NonNull final File[] objectFiles, @Nullable CompletionHandler completionHandler); Request buildOfflineFromFiles(@NonNull final File settingsFile, @NonNull final File... objectFiles); Request buildOfflineFromRawResources(@NonNull final Resources resources, @NonNull final int settingsResId, @NonNull final int[] objectsResIds, @Nullable CompletionHandler completionHandler); Request buildOfflineFromRawResources(@NonNull final Resources resources, @NonNull final int settingsResId, @NonNull final int... objectsResIds); Strategy getRequestStrategy(); void setRequestStrategy(Strategy requestStrategy); long getOfflineFallbackTimeout(); void setOfflineFallbackTimeout(long offlineFallbackTimeout); void setOfflineFallbackTimeout(long offlineFallbackTimeout, TimeUnit unit); @Override Request searchAsync(@NonNull Query query, @Nullable RequestOptions requestOptions, @NonNull CompletionHandler completionHandler); Request searchOnlineAsync(@NonNull Query query, @NonNull final CompletionHandler completionHandler); Request searchOnlineAsync(@NonNull Query query, @Nullable final RequestOptions requestOptions, @NonNull final CompletionHandler completionHandler); Request searchOfflineAsync(@NonNull Query query, @NonNull CompletionHandler completionHandler); @Override Request multipleQueriesAsync(@NonNull Collection<Query> queries, final Client.MultipleQueriesStrategy strategy, @Nullable RequestOptions requestOptions, @NonNull CompletionHandler completionHandler); Request multipleQueriesOnlineAsync(@NonNull List<Query> queries, final Client.MultipleQueriesStrategy strategy, final @NonNull CompletionHandler completionHandler); Request multipleQueriesOnlineAsync(@NonNull List<Query> queries, final Client.MultipleQueriesStrategy strategy, @Nullable final RequestOptions requestOptions, final @NonNull CompletionHandler completionHandler); Request multipleQueriesOfflineAsync(final @NonNull List<Query> queries, final Client.MultipleQueriesStrategy strategy, @NonNull CompletionHandler completionHandler); Request browseMirrorAsync(@NonNull Query query, @NonNull CompletionHandler completionHandler); Request browseMirrorFromAsync(@NonNull String cursor, @NonNull CompletionHandler completionHandler); @Override Request getObjectAsync(final @NonNull String objectID, final @Nullable Collection<String> attributesToRetrieve, @Nullable RequestOptions requestOptions, @NonNull CompletionHandler completionHandler); Request getObjectOnlineAsync(@NonNull final String objectID, final @Nullable List<String> attributesToRetrieve, @NonNull final CompletionHandler completionHandler); Request getObjectOnlineAsync(@NonNull final String objectID, final @Nullable List<String> attributesToRetrieve, @Nullable RequestOptions requestOptions, @NonNull final CompletionHandler completionHandler); Request getObjectOnlineAsync(@NonNull final String objectID, @NonNull final CompletionHandler completionHandler); Request getObjectOfflineAsync(@NonNull final String objectID, final @Nullable List<String> attributesToRetrieve, @NonNull CompletionHandler completionHandler); Request getObjectOfflineAsync(@NonNull final String objectID, @NonNull final CompletionHandler completionHandler); @Override Request getObjectsAsync(final @NonNull Collection<String> objectIDs, final @Nullable Collection<String> attributesToRetrieve, @Nullable RequestOptions requestOptions, @NonNull CompletionHandler completionHandler); Request getObjectsOnlineAsync(@NonNull final List<String> objectIDs, final @Nullable List<String> attributesToRetrieve, @NonNull final CompletionHandler completionHandler); Request getObjectsOnlineAsync(@NonNull final List<String> objectIDs, final @Nullable List<String> attributesToRetrieve, @Nullable final RequestOptions requestOptions, @NonNull final CompletionHandler completionHandler); Request getObjectsOnlineAsync(@NonNull final List<String> objectIDs, @NonNull final CompletionHandler completionHandler); Request getObjectsOfflineAsync(@NonNull final List<String> objectIDs, final @Nullable List<String> attributesToRetrieve, @NonNull CompletionHandler completionHandler); Request getObjectsOfflineAsync(@NonNull final List<String> objectIDs, @NonNull final CompletionHandler completionHandler); @Override Request searchForFacetValuesAsync(@NonNull String facetName, @NonNull String text, @Nullable Query query, @Nullable RequestOptions requestOptions, @NonNull final CompletionHandler completionHandler); Request searchForFacetValuesOnline(@NonNull String facetName, @NonNull String text, @Nullable Query query, @NonNull final CompletionHandler completionHandler); Request searchForFacetValuesOnline(@NonNull String facetName, @NonNull String text, @Nullable Query query, @Nullable RequestOptions requestOptions, @NonNull final CompletionHandler completionHandler); Request searchForFacetValuesOffline(final @NonNull String facetName, final @NonNull String text, @Nullable Query query, @NonNull final CompletionHandler completionHandler); void addSyncListener(@NonNull SyncListener listener); void removeSyncListener(@NonNull SyncListener listener); void addBuildListener(@NonNull BuildListener listener); void removeBuildListener(@NonNull BuildListener listener); }
MirroredIndex extends Index { public void sync() { if (getDataSelectionQueries().length == 0) { throw new IllegalStateException("Cannot sync with empty data selection queries"); } synchronized (this) { if (syncing) return; syncing = true; } getClient().localBuildExecutorService.submit(new Runnable() { @Override public void run() { _sync(); } }); } protected  MirroredIndex(@NonNull OfflineClient client, @NonNull String indexName); OfflineClient getClient(); boolean isMirrored(); void setMirrored(boolean mirrored); void addDataSelectionQuery(@NonNull DataSelectionQuery query); void setDataSelectionQueries(@NonNull DataSelectionQuery... queries); @NonNull DataSelectionQuery[] getDataSelectionQueries(); long getDelayBetweenSyncs(); void setDelayBetweenSyncs(long delayBetweenSyncs); long getDelayBetweenSyncs(@NonNull TimeUnit unit); void setDelayBetweenSyncs(long duration, @NonNull TimeUnit unit); void sync(); void syncIfNeeded(); boolean hasOfflineData(); Request buildOfflineFromFiles(@NonNull final File settingsFile, @NonNull final File[] objectFiles, @Nullable CompletionHandler completionHandler); Request buildOfflineFromFiles(@NonNull final File settingsFile, @NonNull final File... objectFiles); Request buildOfflineFromRawResources(@NonNull final Resources resources, @NonNull final int settingsResId, @NonNull final int[] objectsResIds, @Nullable CompletionHandler completionHandler); Request buildOfflineFromRawResources(@NonNull final Resources resources, @NonNull final int settingsResId, @NonNull final int... objectsResIds); Strategy getRequestStrategy(); void setRequestStrategy(Strategy requestStrategy); long getOfflineFallbackTimeout(); void setOfflineFallbackTimeout(long offlineFallbackTimeout); void setOfflineFallbackTimeout(long offlineFallbackTimeout, TimeUnit unit); @Override Request searchAsync(@NonNull Query query, @Nullable RequestOptions requestOptions, @NonNull CompletionHandler completionHandler); Request searchOnlineAsync(@NonNull Query query, @NonNull final CompletionHandler completionHandler); Request searchOnlineAsync(@NonNull Query query, @Nullable final RequestOptions requestOptions, @NonNull final CompletionHandler completionHandler); Request searchOfflineAsync(@NonNull Query query, @NonNull CompletionHandler completionHandler); @Override Request multipleQueriesAsync(@NonNull Collection<Query> queries, final Client.MultipleQueriesStrategy strategy, @Nullable RequestOptions requestOptions, @NonNull CompletionHandler completionHandler); Request multipleQueriesOnlineAsync(@NonNull List<Query> queries, final Client.MultipleQueriesStrategy strategy, final @NonNull CompletionHandler completionHandler); Request multipleQueriesOnlineAsync(@NonNull List<Query> queries, final Client.MultipleQueriesStrategy strategy, @Nullable final RequestOptions requestOptions, final @NonNull CompletionHandler completionHandler); Request multipleQueriesOfflineAsync(final @NonNull List<Query> queries, final Client.MultipleQueriesStrategy strategy, @NonNull CompletionHandler completionHandler); Request browseMirrorAsync(@NonNull Query query, @NonNull CompletionHandler completionHandler); Request browseMirrorFromAsync(@NonNull String cursor, @NonNull CompletionHandler completionHandler); @Override Request getObjectAsync(final @NonNull String objectID, final @Nullable Collection<String> attributesToRetrieve, @Nullable RequestOptions requestOptions, @NonNull CompletionHandler completionHandler); Request getObjectOnlineAsync(@NonNull final String objectID, final @Nullable List<String> attributesToRetrieve, @NonNull final CompletionHandler completionHandler); Request getObjectOnlineAsync(@NonNull final String objectID, final @Nullable List<String> attributesToRetrieve, @Nullable RequestOptions requestOptions, @NonNull final CompletionHandler completionHandler); Request getObjectOnlineAsync(@NonNull final String objectID, @NonNull final CompletionHandler completionHandler); Request getObjectOfflineAsync(@NonNull final String objectID, final @Nullable List<String> attributesToRetrieve, @NonNull CompletionHandler completionHandler); Request getObjectOfflineAsync(@NonNull final String objectID, @NonNull final CompletionHandler completionHandler); @Override Request getObjectsAsync(final @NonNull Collection<String> objectIDs, final @Nullable Collection<String> attributesToRetrieve, @Nullable RequestOptions requestOptions, @NonNull CompletionHandler completionHandler); Request getObjectsOnlineAsync(@NonNull final List<String> objectIDs, final @Nullable List<String> attributesToRetrieve, @NonNull final CompletionHandler completionHandler); Request getObjectsOnlineAsync(@NonNull final List<String> objectIDs, final @Nullable List<String> attributesToRetrieve, @Nullable final RequestOptions requestOptions, @NonNull final CompletionHandler completionHandler); Request getObjectsOnlineAsync(@NonNull final List<String> objectIDs, @NonNull final CompletionHandler completionHandler); Request getObjectsOfflineAsync(@NonNull final List<String> objectIDs, final @Nullable List<String> attributesToRetrieve, @NonNull CompletionHandler completionHandler); Request getObjectsOfflineAsync(@NonNull final List<String> objectIDs, @NonNull final CompletionHandler completionHandler); @Override Request searchForFacetValuesAsync(@NonNull String facetName, @NonNull String text, @Nullable Query query, @Nullable RequestOptions requestOptions, @NonNull final CompletionHandler completionHandler); Request searchForFacetValuesOnline(@NonNull String facetName, @NonNull String text, @Nullable Query query, @NonNull final CompletionHandler completionHandler); Request searchForFacetValuesOnline(@NonNull String facetName, @NonNull String text, @Nullable Query query, @Nullable RequestOptions requestOptions, @NonNull final CompletionHandler completionHandler); Request searchForFacetValuesOffline(final @NonNull String facetName, final @NonNull String text, @Nullable Query query, @NonNull final CompletionHandler completionHandler); void addSyncListener(@NonNull SyncListener listener); void removeSyncListener(@NonNull SyncListener listener); void addBuildListener(@NonNull BuildListener listener); void removeBuildListener(@NonNull BuildListener listener); static final String JSON_KEY_ORIGIN; static final String JSON_VALUE_ORIGIN_LOCAL; static final String JSON_VALUE_ORIGIN_REMOTE; static final long DEFAULT_DELAY_BETWEEN_SYNCS; static final long DEFAULT_OFFLINE_FALLBACK_TIMEOUT; }