Skip to content

Commit 7bd93b7

Browse files
committed
renamed to queryAttempts, etc., JavaDocs
1 parent 6929f74 commit 7bd93b7

File tree

6 files changed

+40
-22
lines changed

6 files changed

+40
-22
lines changed

objectbox-java/src/main/java/io/objectbox/BoxStore.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static native void nativeRegisterCustomType(long store, int entityId, int proper
138138
public static native boolean isObjectBrowserAvailable();
139139

140140
public static String getVersion() {
141-
return "1.3.2-2017-11-30";
141+
return "1.3.3-2017-12-03";
142142
}
143143

144144
private final File directory;
@@ -169,9 +169,9 @@ public static String getVersion() {
169169

170170
private int objectBrowserPort;
171171

172-
private final int defaultQueryAttempts;
172+
private final int queryAttempts;
173173

174-
private final TxCallback defaultFailedReadTxAttemptCallback;
174+
private final TxCallback failedReadTxAttemptCallback;
175175

176176
BoxStore(BoxStoreBuilder builder) {
177177
NativeLibraryLoader.ensureLoaded();
@@ -231,8 +231,8 @@ public static String getVersion() {
231231

232232
objectClassPublisher = new ObjectClassPublisher(this);
233233

234-
defaultFailedReadTxAttemptCallback = builder.defaultFailedReadTxAttemptCallback;
235-
defaultQueryAttempts = builder.defaultQueryAttempts < 1 ? 1 : builder.defaultQueryAttempts;
234+
failedReadTxAttemptCallback = builder.failedReadTxAttemptCallback;
235+
queryAttempts = builder.queryAttempts < 1 ? 1 : builder.queryAttempts;
236236
}
237237

238238
private static void verifyNotAlreadyOpen(String canonicalPath) {
@@ -635,8 +635,8 @@ public <T> T callInReadTxWithRetry(Callable<T> callable, int attempts, int initi
635635
System.runFinalization();
636636
cleanStaleReadTransactions();
637637
}
638-
if (defaultFailedReadTxAttemptCallback != null) {
639-
defaultFailedReadTxAttemptCallback.txFinished(null, new DbException(message + " \n" + diagnose, e));
638+
if (failedReadTxAttemptCallback != null) {
639+
failedReadTxAttemptCallback.txFinished(null, new DbException(message + " \n" + diagnose, e));
640640
}
641641
try {
642642
Thread.sleep(backoffInMs);
@@ -875,13 +875,13 @@ public boolean isDebugRelations() {
875875
}
876876

877877
@Internal
878-
public int internalDefaultQueryAttempts() {
879-
return defaultQueryAttempts;
878+
public int internalQueryAttempts() {
879+
return queryAttempts;
880880
}
881881

882882
@Internal
883-
public TxCallback internalDefaultFailedReadTxAttemptCallback() {
884-
return defaultFailedReadTxAttemptCallback;
883+
public TxCallback internalFailedReadTxAttemptCallback() {
884+
return failedReadTxAttemptCallback;
885885
}
886886

887887
void setDebugFlags(int debugFlags) {

objectbox-java/src/main/java/io/objectbox/BoxStoreBuilder.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ public class BoxStoreBuilder {
7575

7676
int maxReaders;
7777

78-
int defaultQueryAttempts;
78+
int queryAttempts;
7979

80-
TxCallback defaultFailedReadTxAttemptCallback;
80+
TxCallback failedReadTxAttemptCallback;
8181

8282
final List<EntityInfo> entityInfoList = new ArrayList<>();
8383

@@ -269,15 +269,31 @@ public BoxStoreBuilder debugRelations() {
269269
return this;
270270
}
271271

272+
/**
273+
* For massive concurrent setups (app is using a lot of threads), you can enable automatic retries for queries.
274+
* This can resolve situations in which resources are getting sparse (e.g.
275+
* {@link io.objectbox.exception.DbMaxReadersExceededException} or other variations of
276+
* {@link io.objectbox.exception.DbException} are thrown during query execution).
277+
*
278+
* @param queryAttempts number of attempts a query find operation will be executed before failing.
279+
* Recommended values are in the range of 2 to 5, e.g. a value of 3 as a starting point.
280+
*/
272281
@Experimental
273-
public BoxStoreBuilder defaultQueryAttempts(int defaultQueryAttempts) {
274-
this.defaultQueryAttempts = defaultQueryAttempts;
282+
public BoxStoreBuilder queryAttempts(int queryAttempts) {
283+
if (queryAttempts < 1) {
284+
throw new IllegalArgumentException("Query attempts must >= 1");
285+
}
286+
this.queryAttempts = queryAttempts;
275287
return this;
276288
}
277289

290+
/**
291+
* Define a callback for failed read transactions during retires (see also {@link #queryAttempts(int)}).
292+
* Useful for e.g. logging.
293+
*/
278294
@Experimental
279-
public BoxStoreBuilder defaultFailedReadTxAttemptCallback(TxCallback defaultFailedReadTxAttemptCallback) {
280-
this.defaultFailedReadTxAttemptCallback = defaultFailedReadTxAttemptCallback;
295+
public BoxStoreBuilder failedReadTxAttemptCallback(TxCallback failedReadTxAttemptCallback) {
296+
this.failedReadTxAttemptCallback = failedReadTxAttemptCallback;
281297
return this;
282298
}
283299

objectbox-java/src/main/java/io/objectbox/exception/DbMaxReadersExceededException.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package io.objectbox.exception;
22

33
import io.objectbox.BoxStore;
4+
import io.objectbox.BoxStoreBuilder;
45

56
/**
67
* Thrown when the maximum of readers (read transactions) was exceeded.
78
* Verify that you run a reasonable amount of threads only.
89
* <p>
910
* If you intend to work with a very high number of threads (>100), consider increasing the number of maximum readers
10-
* using {@link io.objectbox.BoxStoreBuilder#maxReaders(int)}.
11+
* using {@link BoxStoreBuilder#maxReaders(int)} and enabling query retries using
12+
* {@link BoxStoreBuilder#queryAttempts(int)}.
1113
* <p>
1214
* For debugging issues related to this exception, check {@link BoxStore#diagnose()}.
1315
*/

objectbox-java/src/main/java/io/objectbox/query/Query.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ native void nativeSetParameters(long handle, int propertyId, String parameterAli
8888
Comparator<T> comparator) {
8989
this.box = box;
9090
store = box.getStore();
91-
queryAttempts = store.internalDefaultQueryAttempts();
91+
queryAttempts = store.internalQueryAttempts();
9292
handle = queryHandle;
9393
this.hasOrder = hasOrder;
9494
publisher = new QueryPublisher<>(this, box);

tests/objectbox-java-test/src/main/java/io/objectbox/BoxStoreTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public void testCallInReadTxWithRetry_callback() {
168168
final int[] countHolderCallback = {0};
169169

170170
BoxStoreBuilder builder = new BoxStoreBuilder(createTestModel(false)).directory(boxStoreDir)
171-
.defaultFailedReadTxAttemptCallback(new TxCallback() {
171+
.failedReadTxAttemptCallback(new TxCallback() {
172172
@Override
173173
public void txFinished(@Nullable Object result, @Nullable Throwable error) {
174174
assertNotNull(error);

tests/objectbox-java-test/src/main/java/io/objectbox/query/QueryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,8 @@ public int compare(TestEntity o1, TestEntity o2) {
477477
public void testQueryAttempts() {
478478
store.close();
479479
BoxStoreBuilder builder = new BoxStoreBuilder(createTestModel(false)).directory(boxStoreDir)
480-
.defaultQueryAttempts(5)
481-
.defaultFailedReadTxAttemptCallback(new TxCallback() {
480+
.queryAttempts(5)
481+
.failedReadTxAttemptCallback(new TxCallback() {
482482
@Override
483483
public void txFinished(@Nullable Object result, @Nullable Throwable error) {
484484
error.printStackTrace();

0 commit comments

Comments
 (0)