Skip to content

Commit

Permalink
Issue #5086 Add blocking method for immediate scan.
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Bartel <janb@webtide.com>
  • Loading branch information
janbartel committed Dec 2, 2020
1 parent c776eeb commit 8fe8cb8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
29 changes: 29 additions & 0 deletions jetty-util/src/main/java/org/eclipse/jetty/util/Scanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,36 @@ public void nudge()

}, 0, TimeUnit.MILLISECONDS);
}

/**
* Get the scanner to perform a scan cycle as soon as possible
* and call the Callback when the scan is finished or failed.
*
* @param complete called when the scan cycle finishes or fails.
*/
public void scan(Callback complete)
{
Scheduler s = _scheduler;

if (!isRunning() || s == null)
complete.failed(new IllegalStateException("Scanner not running"));

s.schedule(() ->
{
try
{
scan();
complete.succeeded();
}
catch (Throwable t)
{
complete.failed(t);
}

}, 0, TimeUnit.MILLISECONDS);
}


/**
* Perform a pass of the scanner and report changes
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@

import java.io.File;
import java.io.IOException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;

import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.Scanner;
import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.annotation.ManagedOperation;
Expand Down Expand Up @@ -121,8 +124,24 @@ public void scan()
if (LOG.isDebugEnabled())
LOG.debug("scanning");

_scanner.nudge();
_scanner.nudge();
try
{
CountDownLatch complete = new CountDownLatch(2);
Callback callback = Callback.from(complete::countDown, t ->
{
LOG.warn("Scan fail", t);
complete.countDown();
});

_scanner.scan(callback);
_scanner.scan(callback);
complete.await(10, TimeUnit.SECONDS);

}
catch (Exception e)
{
throw new RuntimeException(e);
}
}

@ManagedOperation(value = "Reload the SSL Keystore", impact = "ACTION")
Expand Down

0 comments on commit 8fe8cb8

Please sign in to comment.