Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deployment API #5086

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/main/java/io/vertx/core/Deployment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2011-2024 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*/
package io.vertx.core;

import io.vertx.core.impl.ContextInternal;

@FunctionalInterface
public interface Deployment {

Future<?> start(Context context) throws Exception;

default Future<?> stop(Context context) throws Exception {
return ((ContextInternal)context).succeededFuture();
}
}
50 changes: 50 additions & 0 deletions src/main/java/io/vertx/core/Vertx.java
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,56 @@ default long setPeriodic(long delay, Handler<Long> handler) {
*/
Future<Void> close();

/**
* Deploy a deployment unit that you have created yourself.
* <p>
* Vert.x will assign the unit a context and start the deployment.
* <p>
* The actual deploy happens asynchronously and may not complete until after the call has returned.
* <p>
* If the deployment is successful the result will contain a string representing the unique deployment ID of the
* unit.
* <p>
* This deployment ID can subsequently be used to undeploy the unit.
*
* @param unit the unit to deploy.
* @return a future completed with the result
*/
@GenIgnore(GenIgnore.PERMITTED_TYPE)
default Future<String> deploy(Deployment unit) {
return deploy(unit, new DeploymentOptions());
}

/**
* Like {@link #deploy(Deployment)} but {@link io.vertx.core.DeploymentOptions} are provided to configure the
* deployment.
*
* @param unit the deployment unit to deploy
* @param options the deployment options.
* @return a future completed with the result
*/
@GenIgnore(GenIgnore.PERMITTED_TYPE)
default Future<String> deploy(Deployment unit, DeploymentOptions options) {
if (options.getInstances() != 1) {
throw new IllegalArgumentException("Can't specify > 1 unit for already created deployment");
}
return deploy(() -> unit, options);
}

/**
* Like {@link #deploy(Deployment, DeploymentOptions)} but {@link Deployment} unit is created by invoking the
* {@code supplier}.
* <p>
* The supplier will be invoked as many times as {@link DeploymentOptions#getInstances()}.
* It must not return the same instance twice.
* <p>
* Note that the supplier will be invoked on the caller thread.
*
* @return a future completed with the result
*/
@GenIgnore(GenIgnore.PERMITTED_TYPE)
Future<String> deploy(Callable<Deployment> supplier, DeploymentOptions options);

/**
* Deploy a verticle instance that you have created yourself.
* <p>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/vertx/core/impl/ContextImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public final class ContextImpl implements ContextInternal {
private final ThreadingModel threadingModel;
private final VertxInternal owner;
private final JsonObject config;
private final Deployment deployment;
private final DeploymentContext deployment;
private final CloseFuture closeFuture;
private final ClassLoader tccl;
private final EventLoop eventLoop;
Expand All @@ -58,7 +58,7 @@ protected ContextImpl(VertxInternal vertx,
WorkerPool internalWorkerPool,
WorkerPool workerPool,
TaskQueue orderedTasks,
Deployment deployment,
DeploymentContext deployment,
CloseFuture closeFuture,
ClassLoader tccl) {
this.threadingModel = threadingModel;
Expand All @@ -75,7 +75,7 @@ protected ContextImpl(VertxInternal vertx,
this.internalOrderedTasks = new TaskQueue();
}

public Deployment getDeployment() {
public DeploymentContext getDeployment() {
return deployment;
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/vertx/core/impl/ContextInternal.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ default <T> Future<T> failedFuture(String message) {
/**
* @return the deployment associated with this context or {@code null}
*/
Deployment getDeployment();
DeploymentContext getDeployment();

@Override
VertxInternal owner();
Expand Down Expand Up @@ -384,12 +384,12 @@ default boolean isDeployment() {
}

default String deploymentID() {
Deployment deployment = getDeployment();
DeploymentContext deployment = getDeployment();
return deployment != null ? deployment.deploymentID() : null;
}

default int getInstanceCount() {
Deployment deployment = getDeployment();
DeploymentContext deployment = getDeployment();

// the no verticle case
if (deployment == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,19 @@

package io.vertx.core.impl;

import io.vertx.core.AsyncResult;
import io.vertx.core.Context;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.Verticle;
import io.vertx.core.*;
import io.vertx.core.json.JsonObject;

import java.util.Set;

/**
* @author <a href="http://tfox.org">Tim Fox</a>
*/
public interface Deployment {
public interface DeploymentContext {

boolean addChild(Deployment deployment);
boolean addChild(DeploymentContext deployment);

void removeChild(Deployment deployment);
void removeChild(DeploymentContext deployment);

Future<Void> doUndeploy(ContextInternal undeployingContext);

Expand All @@ -42,7 +37,7 @@ public interface Deployment {

Set<Context> getContexts();

Set<Verticle> getVerticles();
Set<Deployment> getVerticles();

void undeployHandler(Handler<Void> handler);

Expand Down