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

Add configuration to allow deferring the initial Deployment until after Server is started #10667

Merged
merged 14 commits into from
Oct 17, 2023
Merged
4 changes: 4 additions & 0 deletions jetty-deploy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,9 @@
<artifactId>jetty-test-helper</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
</dependency>
Comment on lines +62 to +65
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, wrong missing <scope>test</scope>!

Submitted a PR to correct at #10813

</dependencies>
</project>
1 change: 1 addition & 0 deletions jetty-deploy/src/main/config/etc/jetty-deploy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
</Default>
</Property>
</Set>
<Set name="deferInitialScan"><Property name="jetty.deploy.deferInitialScan" default="false"/></Set>
<Set name="scanInterval"><Property name="jetty.deploy.scanInterval" default="1"/></Set>
<Set name="extractWars"><Property name="jetty.deploy.extractWars" default="true"/></Set>
<Set name="configurationManager">
Expand Down
7 changes: 7 additions & 0 deletions jetty-deploy/src/main/config/modules/deploy.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@ etc/jetty-deploy.xml
# Defaults Descriptor for all deployed webapps
# jetty.deploy.defaultsDescriptorPath=${jetty.base}/etc/webdefault.xml

# Defer Initial Scan
# true to have the initial scan deferred until the Server component is started.
# Note: deploy failures do not fail server startup in a deferred initial scan mode.
# false (default) to have initial scan occur as normal.
# jetty.deploy.deferInitialScan=false

# Monitored directory scan period (seconds)
# jetty.deploy.scanInterval=1

# Whether to extract *.war files
# jetty.deploy.extractWars=true

Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
import org.eclipse.jetty.deploy.App;
import org.eclipse.jetty.deploy.AppProvider;
import org.eclipse.jetty.deploy.DeploymentManager;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.Scanner;
import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.annotation.ManagedObject;
import org.eclipse.jetty.util.annotation.ManagedOperation;
import org.eclipse.jetty.util.component.ContainerLifeCycle;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.util.resource.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -49,6 +51,7 @@ public abstract class ScanningAppProvider extends ContainerLifeCycle implements
private int _scanInterval = 10;
private Scanner _scanner;
private boolean _useRealPaths;
private boolean _deferInitialScan = false;

private final Scanner.DiscreteListener _scannerListener = new Scanner.DiscreteListener()
{
Expand Down Expand Up @@ -152,9 +155,30 @@ protected void doStart() throws Exception
_scanner.setReportDirs(true);
_scanner.setScanDepth(1); //consider direct dir children of monitored dir
_scanner.addListener(_scannerListener);

_scanner.setReportExistingFilesOnStartup(true);
_scanner.setAutoStartScanning(!_deferInitialScan);
addBean(_scanner);

if (isDeferInitialScan())
{
// Setup listener to wait for Server in STARTED state, which
// triggers the first scan of the monitored directories
getDeploymentManager().getServer().addEventListener(
new LifeCycle.Listener()
{
@Override
public void lifeCycleStarted(LifeCycle event)
{
if (event instanceof Server)
{
if (LOG.isDebugEnabled())
LOG.debug("Triggering Deferred Scan of {}", _monitored);
_scanner.startScanning();
}
}
});
}

super.doStart();
}

Expand Down Expand Up @@ -296,6 +320,34 @@ public void setMonitoredDirectories(Collection<String> directories)
}
}

/**
* Test if initial scan should be deferred.
*
* @return true if initial scan is deferred, false to have initial scan occur on startup of ScanningAppProvider.
*/
public boolean isDeferInitialScan()
{
return _deferInitialScan;
}

/**
* Flag to control initial scan behavior.
*
* <ul>
* <li>{@code true} - to have initial scan deferred until the {@link Server} component
* has reached it's STARTED state.<br>
* Note: any failures in a deploy will not fail the Server startup in this mode.</li>
* <li>{@code false} - (default value) to have initial scan occur as normal on
* ScanningAppProvider startup.</li>
* </ul>
*
* @param defer true to defer initial scan, false to have initial scan occur on startup of ScanningAppProvider.
*/
public void setDeferInitialScan(boolean defer)
{
_deferInitialScan = defer;
}

public void setScanInterval(int scanInterval)
{
_scanInterval = scanInterval;
Expand Down
Loading