Skip to content

Commit

Permalink
Avoid UUID.randomUUID() in Verticle deployment startup code
Browse files Browse the repository at this point in the history
This is done because bootstrapping the plumbing
needed by the JDK to produce a UUID value
is expensive, it thus doesn't make sense to
pay this cost when the property isn't actually
needed
  • Loading branch information
geoand committed Jan 31, 2025
1 parent dacd689 commit 41c079e
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;

/**
* @author <a href="http://tfox.org">Tim Fox</a>
Expand All @@ -27,6 +28,8 @@ public class DefaultDeploymentManager implements DeploymentManager {

public static final Logger log = LoggerFactory.getLogger(DefaultDeploymentManager.class);

private static final AtomicLong nextId = new AtomicLong();

private final VertxImpl vertx;
private final Map<String, DeploymentContext> deploying = new HashMap<>();
private final Map<String, DeploymentContext> deployments = new ConcurrentHashMap<>();
Expand All @@ -36,7 +39,11 @@ public DefaultDeploymentManager(VertxImpl vertx) {
}

private String generateDeploymentID() {
return UUID.randomUUID().toString();
if (vertx.isClustered() && vertx.haManager()!=null) {
// in this case we need a globally unique id
return UUID.randomUUID().toString();
}
return Long.valueOf(nextId.incrementAndGet()).toString();
}

public Future<Void> undeploy(String deploymentID) {
Expand Down

0 comments on commit 41c079e

Please sign in to comment.