Jetty deployers - Webapp Deploy Management component
—
State machine-based deployment lifecycle with standard states, bindings, and transition management. The lifecycle system defines how applications progress through deployment states and provides hooks for custom behavior at each transition.
Manages the lifecycle of an App in the DeploymentManager with a default graph setup. Extends the Graph class to provide a complete state machine for deployment operations.
/**
* Manages the lifecycle of an App in the DeploymentManager with a default graph setup
*/
public class AppLifeCycle extends Graph {
// Standard lifecycle state constants
public static final String UNDEPLOYED = "undeployed";
public static final String DEPLOYING = "deploying";
public static final String DEPLOYED = "deployed";
public static final String STARTING = "starting";
public static final String STARTED = "started";
public static final String STOPPING = "stopping";
public static final String UNDEPLOYING = "undeploying";
public static final String FAILED = "failed";
/** Creates default lifecycle graph with standard states and transitions */
public AppLifeCycle();
/** Adds a lifecycle binding for state transition processing */
public void addBinding(AppLifeCycle.Binding binding);
/** Removes a lifecycle binding */
public void removeBinding(AppLifeCycle.Binding binding);
/** Returns all lifecycle bindings */
public Set<AppLifeCycle.Binding> getBindings();
/** Returns bindings for a specific node */
public Set<AppLifeCycle.Binding> getBindings(Node node);
/** Returns bindings for a specific node name */
public Set<AppLifeCycle.Binding> getBindings(String nodeName);
/** Executes all bindings for a node during app lifecycle transition */
public void runBindings(Node node, App app, DeploymentManager deploymentManager) throws Throwable;
}Usage Examples:
import org.eclipse.jetty.deploy.AppLifeCycle;
import org.eclipse.jetty.deploy.bindings.*;
// Get the lifecycle from deployment manager
AppLifeCycle lifecycle = deploymentManager.getLifeCycle();
// Add custom bindings for specific states
lifecycle.addBinding(new DebugBinding(AppLifeCycle.DEPLOYING, AppLifeCycle.STARTED));
// Custom binding implementation
AppLifeCycle.Binding customBinding = new AppLifeCycle.Binding() {
@Override
public String[] getBindingTargets() {
return new String[] { AppLifeCycle.STARTED };
}
@Override
public void processBinding(Node node, App app) throws Exception {
System.out.println("App started: " + app.getPath());
// Custom initialization logic here
}
};
lifecycle.addBinding(customBinding);
// Check bindings for a specific state
Set<AppLifeCycle.Binding> startBindings = lifecycle.getBindings(AppLifeCycle.STARTED);
System.out.println("Bindings for 'started' state: " + startBindings.size());Interface for objects that process lifecycle state transitions. Bindings are executed when apps transition through lifecycle states.
/**
* Interface for objects that process lifecycle state transitions
*/
public static interface AppLifeCycle.Binding {
/** Returns array of target node names this binding should be executed for */
String[] getBindingTargets();
/** Processes a lifecycle binding when an app transitions to the target state */
void processBinding(Node node, App app) throws Exception;
}Pre-built binding implementations for standard deployment operations.
Debug binding that logs processing information during state transitions.
/**
* Debug binding that logs processing information
*/
public class DebugBinding implements AppLifeCycle.Binding {
/** Creates binding for a single target state */
public DebugBinding(String target);
/** Creates binding for multiple target states */
public DebugBinding(String... targets);
/** Returns binding targets */
public String[] getBindingTargets();
/** Processes binding with debug logging */
public void processBinding(Node node, App app) throws Exception;
}Provides ordered execution of multiple bindings within a declared binding target.
/**
* Provides ordered execution of bindings within a declared binding target
*/
public class OrderedGroupBinding implements AppLifeCycle.Binding {
/** Creates ordered group for specified target states */
public OrderedGroupBinding(String[] bindingTargets);
/** Adds a binding to the ordered execution group */
public void addBinding(AppLifeCycle.Binding binding);
/** Adds multiple bindings to the ordered execution group */
public void addBindings(AppLifeCycle.Binding[] bindings);
/** Returns binding targets */
public String[] getBindingTargets();
/** Processes all bindings in the specified order */
public void processBinding(Node node, App app) throws Exception;
}Standard deployer binding for the "deploying" lifecycle state.
/**
* Standard deployer binding for the "deploying" lifecycle state
*/
public class StandardDeployer implements AppLifeCycle.Binding {
/** Creates standard deployer binding */
public StandardDeployer();
/** Returns ["deploying"] */
public String[] getBindingTargets();
/** Deploys the context handler to the server */
public void processBinding(Node node, App app) throws Exception;
}Standard starter binding for the "starting" lifecycle state.
/**
* Standard starter binding for the "starting" lifecycle state
*/
public class StandardStarter implements AppLifeCycle.Binding {
/** Creates standard starter binding */
public StandardStarter();
/** Returns ["starting"] */
public String[] getBindingTargets();
/** Starts the context handler */
public void processBinding(Node node, App app) throws Exception;
}Standard stopper binding for the "stopping" lifecycle state.
/**
* Standard stopper binding for the "stopping" lifecycle state
*/
public class StandardStopper implements AppLifeCycle.Binding {
/** Creates standard stopper binding */
public StandardStopper();
/** Returns ["stopping"] */
public String[] getBindingTargets();
/** Stops the context handler */
public void processBinding(Node node, App app) throws Exception;
}Standard undeployer binding for the "undeploying" lifecycle state.
/**
* Standard undeployer binding for the "undeploying" lifecycle state
*/
public class StandardUndeployer implements AppLifeCycle.Binding {
/** Creates standard undeployer binding */
public StandardUndeployer();
/** Returns ["undeploying"] */
public String[] getBindingTargets();
/** Undeploys and destroys the context handler */
public void processBinding(Node node, App app) throws Exception;
}Usage Examples:
import org.eclipse.jetty.deploy.bindings.*;
// Use debug binding to trace lifecycle transitions
DebugBinding debugAll = new DebugBinding(
AppLifeCycle.DEPLOYING,
AppLifeCycle.STARTING,
AppLifeCycle.STOPPING,
AppLifeCycle.UNDEPLOYING
);
lifecycle.addBinding(debugAll);
// Create ordered execution group for complex deployment
OrderedGroupBinding deploymentGroup = new OrderedGroupBinding(
new String[] { AppLifeCycle.DEPLOYING }
);
// Add bindings in specific order
deploymentGroup.addBinding(new CustomSecurityBinding());
deploymentGroup.addBinding(new StandardDeployer());
deploymentGroup.addBinding(new CustomLoggingBinding());
lifecycle.addBinding(deploymentGroup);
// Override standard bindings with custom implementations
lifecycle.removeBinding(standardDeployer); // Remove default
lifecycle.addBinding(new CustomDeployer()); // Add custom
// Conditional binding based on app properties
AppLifeCycle.Binding conditionalBinding = new AppLifeCycle.Binding() {
@Override
public String[] getBindingTargets() {
return new String[] { AppLifeCycle.STARTED };
}
@Override
public void processBinding(Node node, App app) throws Exception {
if (app.getProperties().containsKey("enable.monitoring")) {
// Enable monitoring for this app
MonitoringService.register(app);
}
}
};
lifecycle.addBinding(conditionalBinding);The standard lifecycle follows this state progression:
State Descriptions:
Usage Examples:
// Monitor app lifecycle states
App app = deploymentManager.getApp("/path/to/app.war");
DeploymentManager.AppEntry entry = deploymentManager.getAppEntries()
.stream()
.filter(e -> e.getApp().equals(app))
.findFirst()
.orElse(null);
if (entry != null) {
Node currentState = entry.getLifecyleNode();
System.out.println("App state: " + currentState.getName());
// Request state transitions
switch (currentState.getName()) {
case AppLifeCycle.DEPLOYED:
deploymentManager.requestAppGoal(app, AppLifeCycle.STARTED);
break;
case AppLifeCycle.STARTED:
deploymentManager.requestAppGoal(app, AppLifeCycle.STOPPED);
break;
case AppLifeCycle.FAILED:
// Attempt recovery
deploymentManager.requestAppGoal(app, AppLifeCycle.UNDEPLOYED);
break;
}
}Install with Tessl CLI
npx tessl i tessl/maven-org-eclipse-jetty--jetty-deploy