Skip to content

Commit 1086a95

Browse files
committed
startObjectBrowser() trying port range
1 parent f285246 commit 1086a95

File tree

1 file changed

+47
-5
lines changed

1 file changed

+47
-5
lines changed

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

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@
3636
import java.util.concurrent.Future;
3737
import java.util.concurrent.TimeUnit;
3838

39+
import javax.annotation.Nullable;
3940
import javax.annotation.concurrent.ThreadSafe;
4041

4142
import io.objectbox.annotation.apihint.Beta;
43+
import io.objectbox.annotation.apihint.Experimental;
4244
import io.objectbox.annotation.apihint.Internal;
4345
import io.objectbox.converter.PropertyConverter;
4446
import io.objectbox.exception.DbException;
@@ -129,12 +131,12 @@ static native void nativeRegisterCustomType(long store, int entityId, int proper
129131

130132
static native int nativeCleanStaleReadTransactions(long store);
131133

132-
static native String startDataBrowser(long store, String urlPath, int port);
134+
static native String startObjectBrowser(long store, String urlPath, int port);
133135

134-
public static native boolean isDataBrowserAvailable();
136+
public static native boolean isObjectBrowserAvailable();
135137

136138
public static String getVersion() {
137-
return "1.0.2-2017-09-26";
139+
return "1.1.0-2017-10-01";
138140
}
139141

140142
private final File directory;
@@ -162,6 +164,8 @@ public static String getVersion() {
162164
// Not atomic because it is read most of the time
163165
volatile int commitCount;
164166

167+
private int objectBrowserPort;
168+
165169
BoxStore(BoxStoreBuilder builder) {
166170
NativeLibraryLoader.ensureLoaded();
167171

@@ -664,8 +668,46 @@ public SubscriptionBuilder<Class> subscribe() {
664668
return new SubscriptionBuilder<>(objectClassPublisher, null, threadPool);
665669
}
666670

667-
public String startDataBrowser(int port) {
668-
return startDataBrowser(handle, null, port);
671+
@Experimental
672+
@Nullable
673+
public String startObjectBrowser() {
674+
verifyObjectBrowserNotRunning();
675+
final int basePort = 8090;
676+
for (int port = basePort; port < basePort + 10; port++) {
677+
try {
678+
String url = startObjectBrowser(port);
679+
if (url != null) {
680+
return url;
681+
}
682+
} catch (DbException e) {
683+
if (e.getMessage() == null || !e.getMessage().contains("port")) {
684+
throw e;
685+
}
686+
}
687+
}
688+
return null;
689+
}
690+
691+
@Experimental
692+
@Nullable
693+
public String startObjectBrowser(int port) {
694+
verifyObjectBrowserNotRunning();
695+
String url = startObjectBrowser(handle, null, port);
696+
if (url != null) {
697+
objectBrowserPort = port;
698+
}
699+
return url;
700+
}
701+
702+
@Experimental
703+
public int getObjectBrowserPort() {
704+
return objectBrowserPort;
705+
}
706+
707+
private void verifyObjectBrowserNotRunning() {
708+
if (objectBrowserPort != 0) {
709+
throw new DbException("ObjectBrowser is already running at port " + objectBrowserPort);
710+
}
669711
}
670712

671713
/**

0 commit comments

Comments
 (0)