[java] Resetting the port to zero after using a service builder to allow reusing the same Builder
It is required for the grid that uses the single builder instantiated by service loader.
@@ -356,9 +356,8 @@ protected File getLogFile() {
* @return The new service object.
*/
public DS build() {
- int portToUse = port;
- if (portToUse == 0) {
- portToUse = PortProber.findFreePort();
+ if (port == 0) {
+ port = PortProber.findFreePort();
}
if (exe == null) {
@@ -367,7 +366,10 @@ public DS build() {
ImmutableList<String> args = createArgs();
- return createDriverService(exe, portToUse, args, environment);
+ DS service = createDriverService(exe, port, args, environment);
+ port = 0; // reset port to allow reusing this builder
+
+ return service;
}
protected abstract File findDefaultExecutable();
