diff --git a/VERSION.txt b/VERSION.txt index 74b2bf0d283..0810246f61c 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1,3 +1,6 @@ +jetty-7.4.0-SNAPSHOT + + 342504 Scanner Listener + jetty-7.4.0.RC0 + 324110 Added test harnesses for merging of QueryStrings. + 337685 Update websocket API in preparation for draft -07 diff --git a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ScanningAppProvider.java b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ScanningAppProvider.java index ab92209f69f..e4d2e71832c 100644 --- a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ScanningAppProvider.java +++ b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ScanningAppProvider.java @@ -175,12 +175,6 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A return _deploymentManager; } - /* ------------------------------------------------------------ */ - @Deprecated - public Resource getMonitoredDir() - { - return _monitoredDir; - } /* ------------------------------------------------------------ */ public Resource getMonitoredDirResource() @@ -211,30 +205,18 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A { _deploymentManager = deploymentManager; } - - /* ------------------------------------------------------------ */ - /** - * @deprecated use {@link #setMonitoredDirResource(Resource)} - */ - public void setMonitoredDir(Resource dir) - { - setMonitoredDirResource(dir); - } - - /* ------------------------------------------------------------ */ - /** - * @deprecated use {@link #setMonitoredDirName(String)} - */ - public void setMonitoredDir(String dir) - { - setMonitoredDirName(dir); - } /* ------------------------------------------------------------ */ public void setMonitoredDirResource(Resource contextsDir) { _monitoredDir = contextsDir; } + + /* ------------------------------------------------------------ */ + public void addScannerListener(Scanner.Listener listener) + { + _scanner.addListener(listener); + } /* ------------------------------------------------------------ */ /** diff --git a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ScanningAppProviderRuntimeUpdatesTest.java b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ScanningAppProviderRuntimeUpdatesTest.java index 846a84e44c0..7c4a8ffedb0 100644 --- a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ScanningAppProviderRuntimeUpdatesTest.java +++ b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ScanningAppProviderRuntimeUpdatesTest.java @@ -16,9 +16,14 @@ package org.eclipse.jetty.deploy.providers; import java.io.IOException; +import java.util.concurrent.atomic.AtomicInteger; +import org.eclipse.jetty.deploy.AppProvider; +import org.eclipse.jetty.deploy.DeploymentManager; import org.eclipse.jetty.deploy.test.XmlConfiguredJetty; import org.eclipse.jetty.toolchain.test.TestingDir; +import org.eclipse.jetty.util.Scanner; +import org.eclipse.jetty.util.log.Log; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -30,9 +35,11 @@ import org.junit.Test; */ public class ScanningAppProviderRuntimeUpdatesTest { - @Rule - public TestingDir testdir = new TestingDir(); + @Rule + public TestingDir testdir = new TestingDir(); private static XmlConfiguredJetty jetty; + private final AtomicInteger _scans = new AtomicInteger(); + private int _providers; @Before public void setupEnvironment() throws Exception @@ -46,6 +53,24 @@ public class ScanningAppProviderRuntimeUpdatesTest // Start it jetty.start(); + + // monitor tick + DeploymentManager dm = jetty.getServer().getBeans(DeploymentManager.class).get(0); + for (AppProvider provider : dm.getAppProviders()) + { + if (provider instanceof ScanningAppProvider) + { + _providers++; + ((ScanningAppProvider)provider).addScannerListener(new Scanner.ScanListener() + { + public void scan() + { + _scans.incrementAndGet(); + } + }); + } + } + } @After @@ -55,6 +80,23 @@ public class ScanningAppProviderRuntimeUpdatesTest jetty.stop(); } + public void waitForDirectoryScan() + { + int scan=_scans.get()+2*_providers; + do + { + try + { + Thread.sleep(200); + } + catch(InterruptedException e) + { + Log.warn(e); + } + } + while(_scans.get() - /contexts + /contexts 1 @@ -28,7 +28,7 @@ - /webapps + /webapps 1 /contexts diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/Scanner.java b/jetty-util/src/main/java/org/eclipse/jetty/util/Scanner.java index 08e030815bb..8040d1d82c8 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/Scanner.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/Scanner.java @@ -104,6 +104,10 @@ public class Scanner extends AbstractLifeCycle { } + public interface ScanListener extends Listener + { + public void scan(); + } public interface DiscreteListener extends Listener { @@ -391,6 +395,23 @@ public class Scanner extends AbstractLifeCycle _prevScan.clear(); _prevScan.putAll(_currentScan); reportScanEnd(_scanCount); + + for (Listener l : _listeners) + { + try + { + if (l instanceof ScanListener) + ((ScanListener)l).scan(); + } + catch (Exception e) + { + Log.warn(e); + } + catch (Error e) + { + Log.warn(e); + } + } } /** diff --git a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/TestServer.java b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/TestServer.java index c0fc51d633e..f53eb20bc1c 100644 --- a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/TestServer.java +++ b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/TestServer.java @@ -6,6 +6,7 @@ import java.util.concurrent.ConcurrentLinkedQueue; import javax.servlet.http.HttpServletRequest; import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.handler.ResourceHandler; import org.eclipse.jetty.server.nio.SelectChannelConnector; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.TypeUtil; @@ -18,8 +19,9 @@ public class TestServer extends Server WebSocket _websocket; SelectChannelConnector _connector; - WebSocketHandler _handler; - ConcurrentLinkedQueue _webSockets = new ConcurrentLinkedQueue(); + WebSocketHandler _wsHandler; + ResourceHandler _rHandler; + ConcurrentLinkedQueue _broadcast = new ConcurrentLinkedQueue(); public TestServer(int port) { @@ -27,7 +29,7 @@ public class TestServer extends Server _connector.setPort(port); addConnector(_connector); - _handler = new WebSocketHandler() + _wsHandler = new WebSocketHandler() { public WebSocket doWebSocketConnect(HttpServletRequest request, String protocol) { @@ -56,19 +58,38 @@ public class TestServer extends Server } }; - setHandler(_handler); + setHandler(_wsHandler); + + _rHandler=new ResourceHandler(); + _rHandler.setDirectoriesListed(true); + _rHandler.setResourceBase("."); + _wsHandler.setHandler(_rHandler); + } - + /* ------------------------------------------------------------ */ public boolean isVerbose() { return _verbose; } + /* ------------------------------------------------------------ */ public void setVerbose(boolean verbose) { _verbose = verbose; } + + /* ------------------------------------------------------------ */ + public void setResourceBase(String dir) + { + _rHandler.setResourceBase(dir); + } + + /* ------------------------------------------------------------ */ + public String getResourceBase() + { + return _rHandler.getResourceBase(); + } /* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */ @@ -84,12 +105,14 @@ public class TestServer extends Server public void onConnect(Connection connection) { _connection = connection; - _webSockets.add(this); + if (_verbose) + System.err.printf("%s#onConnect %s\n",this.getClass().getSimpleName(),connection); } public void onDisconnect(int code,String message) { - _webSockets.remove(this); + if (_verbose) + System.err.printf("%s#onDisonnect %d %s\n",this.getClass().getSimpleName(),code,message); } public boolean onFrame(byte flags, byte opcode, byte[] data, int offset, int length) @@ -160,11 +183,25 @@ public class TestServer extends Server /* ------------------------------------------------------------ */ class TestEchoBroadcastWebSocket extends TestWebSocket { + @Override + public void onConnect(Connection connection) + { + super.onConnect(connection); + _broadcast.add(this); + } + + @Override + public void onDisconnect(int code,String message) + { + super.onDisconnect(code,message); + _broadcast.remove(this); + } + @Override public void onMessage(byte[] data, int offset, int length) { super.onMessage(data,offset,length); - for (TestWebSocket ws : _webSockets) + for (TestWebSocket ws : _broadcast) { try { @@ -172,6 +209,7 @@ public class TestServer extends Server } catch (IOException e) { + _broadcast.remove(ws); e.printStackTrace(); } } @@ -181,7 +219,7 @@ public class TestServer extends Server public void onMessage(final String data) { super.onMessage(data); - for (TestWebSocket ws : _webSockets) + for (TestWebSocket ws : _broadcast) { try { @@ -189,6 +227,7 @@ public class TestServer extends Server } catch (IOException e) { + _broadcast.remove(ws); e.printStackTrace(); } } @@ -286,17 +325,19 @@ public class TestServer extends Server private static void usage() { System.err.println("java -cp CLASSPATH "+TestServer.class+" [ OPTIONS ]"); - System.err.println(" -p|--port PORT "); + System.err.println(" -p|--port PORT (default 8080)"); System.err.println(" -v|--verbose "); + System.err.println(" -d|--docroot file (default '.')"); System.exit(1); } - public static void main(String[] args) + public static void main(String... args) { try { int port=8080; boolean verbose=false; + String docroot="."; for (int i=0;i + WebSocket Chat + + + +
+
+
+ Username:  +
+ +
+ + +

+This is a demonstration of the Jetty websocket server. +

+ + + +