blob: 80dba88e9df27df88afb12bad569f9f2e96ce50d [file] [log] [blame]
// ========================================================================
// Copyright (c) Webtide LLC
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.apache.org/licenses/LICENSE-2.0.txt
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.deploy;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* The lifecycle of an App in the {@link DeploymentManager}.
* <p>
* <img src="doc-files/AppLifeCycle.png">
*/
public class AppLifeCycle
{
/**
* State that an {@link App} can be in, as a result of traversal via the {@link AppLifeCycle}
* <p>
* <img src="doc-files/AppLifeCycle.png">
*/
public enum State
{
/**
* The web app is not available.
*
* It has likely not been deployed, or has failed deployment.
*/
UNAVAILABLE,
/**
* The web app has been deployed, but not yet made available for incoming requests.
*/
DEPLOYED,
/**
* The web app has been started and is ready to accept requests on the expected context.
*/
STARTED;
}
public enum Phase
{
DEPLOY, START, STOP, UNDEPLOY;
}
public class Step
{
private State from;
private Phase phase;
private State to;
public Step(State from, Phase phase, State to)
{
this.from = from;
this.phase = phase;
this.to = to;
}
public State getFrom()
{
return from;
}
public Phase getPhase()
{
return phase;
}
public State getTo()
{
return to;
}
}
public List<Step> getSteps(State from, State to)
{
if (from == to)
{
return Collections.emptyList();
}
List<Step> steps = new ArrayList<Step>();
/*
* This nastiness can be replaced with a simple BFS Graph impl w/ edge defs.
*/
switch (from)
{
case UNAVAILABLE:
switch (to)
{
case DEPLOYED:
steps.add(new Step(from,Phase.DEPLOY,to));
return steps;
case STARTED:
steps.add(new Step(from,Phase.DEPLOY,State.DEPLOYED));
steps.add(new Step(State.DEPLOYED,Phase.START,to));
return steps;
}
break;
case DEPLOYED:
switch (to)
{
case UNAVAILABLE:
steps.add(new Step(from,Phase.UNDEPLOY,to));
return steps;
case STARTED:
steps.add(new Step(from,Phase.START,to));
return steps;
}
case STARTED:
switch (to)
{
case DEPLOYED:
steps.add(new Step(from,Phase.STOP,to));
return steps;
case UNAVAILABLE:
steps.add(new Step(from,Phase.STOP,State.DEPLOYED));
steps.add(new Step(State.DEPLOYED,Phase.UNDEPLOY,to));
return steps;
}
}
return steps;
}
}