Skip to content

Commit 128cd77

Browse files
committed
Keep track of bound EndpointConfigs
Warn on failure, and return a failed CompletableFuture only if no endpoints were successfully bound.
1 parent 8a7eb05 commit 128cd77

File tree

1 file changed

+28
-6
lines changed
  • opc-ua-sdk/sdk-server/src/main/java/org/eclipse/milo/opcua/sdk/server

1 file changed

+28
-6
lines changed

opc-ua-sdk/sdk-server/src/main/java/org/eclipse/milo/opcua/sdk/server/OpcUaServer.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@
2828
import java.util.Optional;
2929
import java.util.Random;
3030
import java.util.Set;
31-
import java.util.concurrent.CompletableFuture;
32-
import java.util.concurrent.ConcurrentHashMap;
33-
import java.util.concurrent.ExecutorService;
34-
import java.util.concurrent.ScheduledExecutorService;
31+
import java.util.concurrent.*;
3532
import java.util.concurrent.atomic.AtomicLong;
3633
import java.util.stream.Collectors;
3734
import java.util.stream.Stream;
@@ -135,6 +132,8 @@ public class OpcUaServer extends AbstractServiceHandler {
135132

136133
private final ServerDiagnosticsSummary diagnosticsSummary = new ServerDiagnosticsSummary(this);
137134

135+
private final List<EndpointConfig> boundEndpoints = new CopyOnWriteArrayList<>();
136+
138137
/**
139138
* SecureChannel id sequence, starting at a random value in [1..{@link Integer#MAX_VALUE}], and
140139
* wrapping back to 1 after {@link UInteger#MAX_VALUE}.
@@ -257,15 +256,29 @@ public CompletableFuture<OpcUaServer> startup() {
257256
transport.bind(applicationContext, bindAddress);
258257

259258
transports.put(transportProfile, transport);
259+
260+
boundEndpoints.add(endpoint);
260261
} catch (Exception e) {
261-
throw new RuntimeException(e);
262+
logger.warn(
263+
"Failed to bind endpoint {} to {}:{} [{}/{}]",
264+
endpoint.getEndpointUrl(),
265+
endpoint.getBindAddress(),
266+
endpoint.getBindPort(),
267+
endpoint.getSecurityPolicy(),
268+
endpoint.getSecurityMode(),
269+
e);
262270
}
263271
} else {
264272
logger.warn("No OpcServerTransport for TransportProfile: {}", transportProfile);
265273
}
266274
});
267275

268-
return CompletableFuture.completedFuture(this);
276+
if (boundEndpoints.isEmpty()) {
277+
return CompletableFuture.failedFuture(
278+
new UaException(StatusCodes.Bad_ConfigurationError, "No endpoints bound"));
279+
} else {
280+
return CompletableFuture.completedFuture(this);
281+
}
269282
}
270283

271284
public CompletableFuture<OpcUaServer> shutdown() {
@@ -458,6 +471,15 @@ public Optional<RoleMapper> getRoleMapper() {
458471
return config.getRoleMapper();
459472
}
460473

474+
/**
475+
* Get the {@link EndpointConfig}s that were successfully bound during {@link #startup()}.
476+
*
477+
* @return the {@link EndpointConfig}s that were successfully bound during {@link #startup()}.
478+
*/
479+
public List<EndpointConfig> getBoundEndpoints() {
480+
return List.copyOf(boundEndpoints);
481+
}
482+
461483
private class ServerApplicationContextImpl implements ServerApplicationContext {
462484

463485
@Override

0 commit comments

Comments
 (0)