diff --git a/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/ManyConnectors.java b/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/ManyConnectors.java index 3548d7f19f5..4dc4411c806 100644 --- a/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/ManyConnectors.java +++ b/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/ManyConnectors.java @@ -41,7 +41,6 @@ public class ManyConnectors SelectChannelConnector connector1 = new SelectChannelConnector(server); connector1.setHost("127.0.0.1"); connector1.setPort(8888); - connector1.setName("admin"); String jetty_home = System.getProperty("jetty.home","../jetty-distribution/target/distribution"); System.setProperty("jetty.home", jetty_home); diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java index ee12cbabc9c..e1706d4e59f 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java @@ -72,7 +72,7 @@ public class HttpParser private boolean _host; /* ------------------------------------------------------------------------------- */ - private State _state=State.START; + private volatile State _state=State.START; private HttpMethod _method; private String _methodString; private HttpVersion _version; @@ -217,7 +217,7 @@ public class HttpParser { _methodString = _method.asString(); buffer.position(buffer.position()+_methodString.length()+1); - _state=State.SPACE1; + setState(State.SPACE1); return; } } @@ -227,7 +227,7 @@ public class HttpParser if (_version!=null) { buffer.position(buffer.position()+_version.asString().length()+1); - _state=State.SPACE1; + setState(State.SPACE1); return; } } @@ -245,7 +245,7 @@ public class HttpParser { _string.setLength(0); _string.append((char)ch); - _state=_requestHandler!=null?State.METHOD:State.RESPONSE_VERSION; + setState(_requestHandler!=null?State.METHOD:State.RESPONSE_VERSION); return; } } @@ -314,7 +314,7 @@ public class HttpParser HttpMethod method=HttpMethod.CACHE.get(_methodString); if (method!=null) _methodString=method.asString(); - _state=State.SPACE1; + setState(State.SPACE1); } else if (ch < HttpTokens.SPACE && ch>=0) { @@ -335,7 +335,7 @@ public class HttpParser badMessage(buffer,HttpStatus.BAD_REQUEST_400,"Unknown Version"); return true; } - _state=State.SPACE1; + setState(State.SPACE1); } else if (ch < HttpTokens.SPACE && ch>=0) { @@ -351,12 +351,12 @@ public class HttpParser { if (_responseHandler!=null) { - _state=State.STATUS; + setState(State.STATUS); _responseStatus=ch-'0'; } else { - _state=State.URI; + setState(State.URI); _utf8.reset(); _utf8.append(ch); } @@ -371,7 +371,7 @@ public class HttpParser case STATUS: if (ch == HttpTokens.SPACE) { - _state=State.SPACE2; + setState(State.SPACE2); } else if (ch>='0' && ch<='9') { @@ -381,7 +381,7 @@ public class HttpParser { return_from_parse|=_responseHandler.startResponse(_version, _responseStatus, null); _eol=ch; - _state=State.HEADER; + setState(State.HEADER); } else { @@ -394,7 +394,7 @@ public class HttpParser { _uri=_utf8.toString(); _utf8.reset(); - _state=State.SPACE2; + setState(State.SPACE2); } else if (ch < HttpTokens.SPACE && ch>=0) { @@ -402,7 +402,7 @@ public class HttpParser _uri=_utf8.toString(); _utf8.reset(); return_from_parse|=_requestHandler.startRequest(_method,_methodString,_uri,null); - _state=State.END; + setState(State.END); BufferUtil.clear(buffer); return_from_parse|=_handler.headerComplete(); return_from_parse|=_handler.messageComplete(_contentPosition); @@ -419,11 +419,11 @@ public class HttpParser if (_responseHandler!=null) { _length=1; - _state=State.REASON; + setState(State.REASON); } else { - _state=State.REQUEST_VERSION; + setState(State.REQUEST_VERSION); // try quick look ahead if (buffer.position()>0 && buffer.hasArray()) @@ -434,7 +434,7 @@ public class HttpParser _string.setLength(0); buffer.position(buffer.position()+_version.asString().length()-1); _eol=buffer.get(); - _state=State.HEADER; + setState(State.HEADER); return_from_parse|=_requestHandler.startRequest(_method,_methodString, _uri, _version); } } @@ -446,13 +446,13 @@ public class HttpParser { return_from_parse|=_responseHandler.startResponse(_version, _responseStatus, null); _eol=ch; - _state=State.HEADER; + setState(State.HEADER); } else { // HTTP/0.9 return_from_parse|=_requestHandler.startRequest(_method,_methodString, _uri, null); - _state=State.END; + setState(State.END); BufferUtil.clear(buffer); return_from_parse|=_handler.headerComplete(); return_from_parse|=_handler.messageComplete(_contentPosition); @@ -472,7 +472,7 @@ public class HttpParser } _eol=ch; - _state=State.HEADER; + setState(State.HEADER); return_from_parse|=_requestHandler.startRequest(_method,_methodString, _uri, _version); continue; } @@ -487,7 +487,7 @@ public class HttpParser String reason=takeLengthString(); _eol=ch; - _state=State.HEADER; + setState(State.HEADER); return_from_parse|=_responseHandler.startResponse(_version, _responseStatus, reason); continue; } @@ -547,7 +547,7 @@ public class HttpParser // header value without name - continuation? _length=-1; _string.setLength(0); - _state=State.HEADER_VALUE; + setState(State.HEADER_VALUE); break; } @@ -673,23 +673,23 @@ public class HttpParser switch (_endOfContent) { case EOF_CONTENT: - _state=State.EOF_CONTENT; + setState(State.EOF_CONTENT); return_from_parse|=_handler.headerComplete(); break; case CHUNKED_CONTENT: - _state=State.CHUNKED_CONTENT; + setState(State.CHUNKED_CONTENT); return_from_parse|=_handler.headerComplete(); break; case NO_CONTENT: return_from_parse|=_handler.headerComplete(); - _state=State.END; + setState(State.END); return_from_parse|=_handler.messageComplete(_contentPosition); break; default: - _state=State.CONTENT; + setState(State.CONTENT); return_from_parse|=_handler.headerComplete(); break; } @@ -705,13 +705,13 @@ public class HttpParser { _headerString=_header.asString(); buffer.position(buffer.position()+_headerString.length()); - _state=buffer.get(buffer.position()-1)==':'?State.HEADER_VALUE:State.HEADER_NAME; + setState(buffer.get(buffer.position()-1)==':'?State.HEADER_VALUE:State.HEADER_NAME); break; } } // New header - _state=State.HEADER_NAME; + setState(State.HEADER_NAME); _string.setLength(0); _string.append((char)ch); _length=1; @@ -729,7 +729,7 @@ public class HttpParser consumeCRLF(ch,buffer); _headerString=takeLengthString(); _header=HttpHeader.CACHE.get(_headerString); - _state=State.HEADER; + setState(State.HEADER); break; @@ -739,7 +739,7 @@ public class HttpParser _headerString=takeLengthString(); _header=HttpHeader.CACHE.get(_headerString); } - _state=State.HEADER_VALUE; + setState(State.HEADER_VALUE); break; case HttpTokens.SPACE: case HttpTokens.TAB: @@ -758,7 +758,7 @@ public class HttpParser } _string.append((char)ch); _length=_string.length(); - _state=State.HEADER_IN_NAME; + setState(State.HEADER_IN_NAME); } } @@ -773,7 +773,7 @@ public class HttpParser _headerString=takeString(); _length=-1; _header=HttpHeader.CACHE.get(_headerString); - _state=State.HEADER; + setState(State.HEADER); break; case HttpTokens.COLON: @@ -783,11 +783,11 @@ public class HttpParser _header=HttpHeader.CACHE.get(_headerString); } _length=-1; - _state=State.HEADER_VALUE; + setState(State.HEADER_VALUE); break; case HttpTokens.SPACE: case HttpTokens.TAB: - _state=State.HEADER_NAME; + setState(State.HEADER_NAME); _string.append((char)ch); break; default: @@ -821,7 +821,7 @@ public class HttpParser _valueString=takeLengthString(); } } - _state=State.HEADER; + setState(State.HEADER); break; case HttpTokens.SPACE: case HttpTokens.TAB: @@ -830,7 +830,7 @@ public class HttpParser { _string.append((char)ch); _length=_string.length(); - _state=State.HEADER_IN_VALUE; + setState(State.HEADER_IN_VALUE); } } break; @@ -861,12 +861,12 @@ public class HttpParser } _length=-1; } - _state=State.HEADER; + setState(State.HEADER); break; case HttpTokens.SPACE: case HttpTokens.TAB: _string.append((char)ch); - _state=State.HEADER_VALUE; + setState(State.HEADER_VALUE); break; default: _string.append((char)ch); @@ -919,7 +919,7 @@ public class HttpParser case CONTENT: if (_contentPosition==_contentLength) { - _state=State.END; + setState(State.END); if(_handler.messageComplete(_contentPosition)) return true; } @@ -936,7 +936,7 @@ public class HttpParser { String chars = BufferUtil.toDetailString(buffer); BufferUtil.clear(buffer); - throw new IllegalStateException(this+" Extra data after oshut: "+chars); + throw new IllegalStateException(this+" data when CLOSED: "+chars); } BufferUtil.clear(buffer); } @@ -955,7 +955,7 @@ public class HttpParser // Handle HEAD response if (_responseStatus>0 && _headResponse) { - _state=State.END; + setState(State.END); if (_handler.messageComplete(_contentLength)) return true; } @@ -987,7 +987,7 @@ public class HttpParser long remaining=_contentLength - _contentPosition; if (remaining == 0) { - _state=State.END; + setState(State.END); if (_handler.messageComplete(_contentPosition)) return true; } @@ -1011,7 +1011,7 @@ public class HttpParser if(_contentPosition == _contentLength) { - _state=State.END; + setState(State.END); if (_handler.messageComplete(_contentPosition)) return true; } @@ -1030,7 +1030,7 @@ public class HttpParser { _chunkLength=0; _chunkPosition=0; - _state=State.CHUNK_SIZE; + setState(State.CHUNK_SIZE); } break; } @@ -1046,15 +1046,15 @@ public class HttpParser { if (_eol==HttpTokens.CARRIAGE_RETURN && buffer.hasRemaining() && buffer.get(buffer.position())==HttpTokens.LINE_FEED) _eol=buffer.get(); - _state=State.END; + setState(State.END); if (_handler.messageComplete(_contentPosition)) return true; } else - _state=State.CHUNK; + setState(State.CHUNK); } else if (ch <= HttpTokens.SPACE || ch == HttpTokens.SEMI_COLON) - _state=State.CHUNK_PARAMS; + setState(State.CHUNK_PARAMS); else if (ch >= '0' && ch <= '9') _chunkLength=_chunkLength * 16 + (ch - '0'); else if (ch >= 'a' && ch <= 'f') @@ -1076,12 +1076,12 @@ public class HttpParser { if (_eol==HttpTokens.CARRIAGE_RETURN && buffer.hasRemaining() && buffer.get(buffer.position())==HttpTokens.LINE_FEED) _eol=buffer.get(); - _state=State.END; + setState(State.END); if (_handler.messageComplete(_contentPosition)) return true; } else - _state=State.CHUNK; + setState(State.CHUNK); } break; } @@ -1091,7 +1091,7 @@ public class HttpParser int remaining=_chunkLength - _chunkPosition; if (remaining == 0) { - _state=State.CHUNKED_CONTENT; + setState(State.CHUNKED_CONTENT); } else { @@ -1136,7 +1136,7 @@ public class HttpParser private void badMessage(ByteBuffer buffer, int status, String reason) { BufferUtil.clear(buffer); - _state=State.CLOSED; + setState(State.CLOSED); _handler.badMessage(status, reason); } @@ -1150,12 +1150,15 @@ public class HttpParser break; case EOF_CONTENT: - _state=State.END; + setState(State.END); _handler.messageComplete(_contentPosition); break; + case CLOSED: + break; + default: - _state=State.END; + setState(State.END); if (!_headResponse) _handler.earlyEOF(); _handler.messageComplete(_contentPosition); @@ -1176,7 +1179,7 @@ public class HttpParser default: LOG.warn("Closing {}",this); } - _state=State.CLOSED; + setState(State.CLOSED); _endOfContent=EndOfContent.UNKNOWN_CONTENT; _contentPosition=0; _responseStatus=0; @@ -1188,7 +1191,7 @@ public class HttpParser public void reset() { // reset state - _state=State.START; + setState(State.START); _endOfContent=EndOfContent.UNKNOWN_CONTENT; _contentPosition=0; _responseStatus=0; @@ -1198,10 +1201,11 @@ public class HttpParser } /* ------------------------------------------------------------------------------- */ - public void setState(State state) + private void setState(State state) { - this._state=state; - _endOfContent=EndOfContent.UNKNOWN_CONTENT; + if (_state==State.CLOSED && state==State.END) + new Throwable().printStackTrace(); + _state=state; } /* ------------------------------------------------------------------------------- */ diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/AbstractEndPoint.java b/jetty-io/src/main/java/org/eclipse/jetty/io/AbstractEndPoint.java index 04a1c9cf891..9506ca90f83 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/AbstractEndPoint.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/AbstractEndPoint.java @@ -21,8 +21,6 @@ package org.eclipse.jetty.io; import java.io.IOException; import java.net.InetSocketAddress; import java.nio.ByteBuffer; -import java.util.concurrent.Future; -import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicReference; @@ -30,6 +28,7 @@ import java.util.concurrent.atomic.AtomicReference; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.util.thread.Scheduler; public abstract class AbstractEndPoint implements EndPoint { @@ -38,8 +37,8 @@ public abstract class AbstractEndPoint implements EndPoint private final InetSocketAddress _local; private final InetSocketAddress _remote; - private final ScheduledExecutorService _scheduler; - private final AtomicReference> _timeout = new AtomicReference<>(); + private final Scheduler _scheduler; + private final AtomicReference _timeout = new AtomicReference<>(); private final Runnable _idleTask = new Runnable() { @Override @@ -73,7 +72,7 @@ public abstract class AbstractEndPoint implements EndPoint } }; - protected AbstractEndPoint(ScheduledExecutorService scheduler,InetSocketAddress local,InetSocketAddress remote) + protected AbstractEndPoint(Scheduler scheduler,InetSocketAddress local,InetSocketAddress remote) { _local=local; _remote=remote; @@ -176,12 +175,12 @@ public abstract class AbstractEndPoint implements EndPoint protected void scheduleIdleTimeout(long delay) { - Future newTimeout = null; + Scheduler.Task newTimeout = null; if (isOpen() && delay > 0 && _scheduler!=null) newTimeout = _scheduler.schedule(_idleTask, delay, TimeUnit.MILLISECONDS); - Future oldTimeout = _timeout.getAndSet(newTimeout); + Scheduler.Task oldTimeout = _timeout.getAndSet(newTimeout); if (oldTimeout != null) - oldTimeout.cancel(false); + oldTimeout.cancel(); } protected long checkIdleTimeout() diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/ArrayByteBufferPool.java b/jetty-io/src/main/java/org/eclipse/jetty/io/ArrayByteBufferPool.java index 468f2aa62e6..1946ba3f22c 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/ArrayByteBufferPool.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/ArrayByteBufferPool.java @@ -21,7 +21,6 @@ package org.eclipse.jetty.io; import java.nio.ByteBuffer; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.ConcurrentMap; import org.eclipse.jetty.util.BufferUtil; diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/ByteArrayEndPoint.java b/jetty-io/src/main/java/org/eclipse/jetty/io/ByteArrayEndPoint.java index 63d4af63db3..2ee62812a46 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/ByteArrayEndPoint.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/ByteArrayEndPoint.java @@ -23,12 +23,12 @@ import java.net.InetSocketAddress; import java.nio.ByteBuffer; import java.nio.channels.ClosedChannelException; import java.nio.charset.Charset; -import java.util.concurrent.ScheduledExecutorService; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.util.thread.Scheduler; /* ------------------------------------------------------------ */ @@ -76,25 +76,25 @@ public class ByteArrayEndPoint extends AbstractEndPoint } /* ------------------------------------------------------------ */ - public ByteArrayEndPoint(ScheduledExecutorService timer, long idleTimeoutMs) + public ByteArrayEndPoint(Scheduler scheduler, long idleTimeoutMs) { - this(timer,idleTimeoutMs,null,null); + this(scheduler,idleTimeoutMs,null,null); } /* ------------------------------------------------------------ */ - public ByteArrayEndPoint(ScheduledExecutorService timer, long idleTimeoutMs, byte[] input, int outputSize) + public ByteArrayEndPoint(Scheduler timer, long idleTimeoutMs, byte[] input, int outputSize) { this(timer,idleTimeoutMs,input!=null?BufferUtil.toBuffer(input):null,BufferUtil.allocate(outputSize)); } /* ------------------------------------------------------------ */ - public ByteArrayEndPoint(ScheduledExecutorService timer, long idleTimeoutMs, String input, int outputSize) + public ByteArrayEndPoint(Scheduler timer, long idleTimeoutMs, String input, int outputSize) { this(timer,idleTimeoutMs,input!=null?BufferUtil.toBuffer(input):null,BufferUtil.allocate(outputSize)); } /* ------------------------------------------------------------ */ - public ByteArrayEndPoint(ScheduledExecutorService timer, long idleTimeoutMs, ByteBuffer input, ByteBuffer output) + public ByteArrayEndPoint(Scheduler timer, long idleTimeoutMs, ByteBuffer input, ByteBuffer output) { super(timer,NOIP,NOIP); _in=input==null?BufferUtil.EMPTY_BUFFER:input; diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/ChannelEndPoint.java b/jetty-io/src/main/java/org/eclipse/jetty/io/ChannelEndPoint.java index ce413d9d6cb..4f3563b6569 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/ChannelEndPoint.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/ChannelEndPoint.java @@ -28,11 +28,11 @@ import java.nio.channels.ByteChannel; import java.nio.channels.ClosedChannelException; import java.nio.channels.GatheringByteChannel; import java.nio.channels.SocketChannel; -import java.util.concurrent.ScheduledExecutorService; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.util.thread.Scheduler; /** * Channel End Point. @@ -47,7 +47,7 @@ public class ChannelEndPoint extends AbstractEndPoint private volatile boolean _ishut; private volatile boolean _oshut; - public ChannelEndPoint(ScheduledExecutorService scheduler,SocketChannel channel) throws IOException + public ChannelEndPoint(Scheduler scheduler,SocketChannel channel) throws IOException { super(scheduler, (InetSocketAddress)channel.socket().getLocalSocketAddress(), diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/NetworkTrafficSelectChannelEndPoint.java b/jetty-io/src/main/java/org/eclipse/jetty/io/NetworkTrafficSelectChannelEndPoint.java index 38ea8d7efeb..3451a077c58 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/NetworkTrafficSelectChannelEndPoint.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/NetworkTrafficSelectChannelEndPoint.java @@ -23,10 +23,10 @@ import java.nio.ByteBuffer; import java.nio.channels.SelectionKey; import java.nio.channels.SocketChannel; import java.util.List; -import java.util.concurrent.ScheduledExecutorService; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.util.thread.Scheduler; public class NetworkTrafficSelectChannelEndPoint extends SelectChannelEndPoint { @@ -34,7 +34,7 @@ public class NetworkTrafficSelectChannelEndPoint extends SelectChannelEndPoint private final List listeners; - public NetworkTrafficSelectChannelEndPoint(SocketChannel channel, SelectorManager.ManagedSelector selectSet, SelectionKey key, ScheduledExecutorService scheduler, long idleTimeout, List listeners) throws IOException + public NetworkTrafficSelectChannelEndPoint(SocketChannel channel, SelectorManager.ManagedSelector selectSet, SelectionKey key, Scheduler scheduler, long idleTimeout, List listeners) throws IOException { super(channel, selectSet, key, scheduler, idleTimeout); this.listeners = listeners; diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/SelectChannelEndPoint.java b/jetty-io/src/main/java/org/eclipse/jetty/io/SelectChannelEndPoint.java index f27e011cec3..1b5c3171f35 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/SelectChannelEndPoint.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/SelectChannelEndPoint.java @@ -22,12 +22,12 @@ import java.io.IOException; import java.nio.channels.CancelledKeyException; import java.nio.channels.SelectionKey; import java.nio.channels.SocketChannel; -import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.atomic.AtomicBoolean; import org.eclipse.jetty.io.SelectorManager.ManagedSelector; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.util.thread.Scheduler; /** * An ChannelEndpoint that can be scheduled by {@link SelectorManager}. @@ -75,7 +75,7 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements SelectorMa */ private volatile int _interestOps; - public SelectChannelEndPoint(SocketChannel channel, ManagedSelector selector, SelectionKey key, ScheduledExecutorService scheduler, long idleTimeout) throws IOException + public SelectChannelEndPoint(SocketChannel channel, ManagedSelector selector, SelectionKey key, Scheduler scheduler, long idleTimeout) throws IOException { super(scheduler,channel); _selector = selector; diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java b/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java index 656eee240e7..bc11ef74aff 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.util.Arrays; import java.util.concurrent.Executor; + import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLEngineResult; import javax.net.ssl.SSLEngineResult.HandshakeStatus; diff --git a/jetty-io/src/test/java/org/eclipse/jetty/io/ArrayByteBufferPoolTest.java b/jetty-io/src/test/java/org/eclipse/jetty/io/ArrayByteBufferPoolTest.java index 250922a4845..bfeebd81bb0 100644 --- a/jetty-io/src/test/java/org/eclipse/jetty/io/ArrayByteBufferPoolTest.java +++ b/jetty-io/src/test/java/org/eclipse/jetty/io/ArrayByteBufferPoolTest.java @@ -18,16 +18,16 @@ package org.eclipse.jetty.io; -import java.nio.ByteBuffer; - -import org.hamcrest.Matchers; -import org.junit.Test; - import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; +import java.nio.ByteBuffer; + +import org.hamcrest.Matchers; +import org.junit.Test; + public class ArrayByteBufferPoolTest { @Test diff --git a/jetty-io/src/test/java/org/eclipse/jetty/io/ByteArrayEndPointTest.java b/jetty-io/src/test/java/org/eclipse/jetty/io/ByteArrayEndPointTest.java index 30243eee426..5a329cd2a87 100644 --- a/jetty-io/src/test/java/org/eclipse/jetty/io/ByteArrayEndPointTest.java +++ b/jetty-io/src/test/java/org/eclipse/jetty/io/ByteArrayEndPointTest.java @@ -18,22 +18,6 @@ package org.eclipse.jetty.io; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeoutException; - -import org.eclipse.jetty.toolchain.test.AdvancedRunner; -import org.eclipse.jetty.toolchain.test.annotation.Slow; -import org.eclipse.jetty.util.BufferUtil; -import org.eclipse.jetty.util.FutureCallback; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - import static junit.framework.Assert.assertEquals; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.greaterThan; @@ -43,21 +27,38 @@ import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; + +import org.eclipse.jetty.toolchain.test.AdvancedRunner; +import org.eclipse.jetty.toolchain.test.annotation.Slow; +import org.eclipse.jetty.util.BufferUtil; +import org.eclipse.jetty.util.FutureCallback; +import org.eclipse.jetty.util.thread.Scheduler; +import org.eclipse.jetty.util.thread.SimpleScheduler; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + @RunWith(AdvancedRunner.class) public class ByteArrayEndPointTest { - private ScheduledExecutorService _scheduler; + private Scheduler _scheduler; @Before - public void before() + public void before() throws Exception { - _scheduler = Executors.newSingleThreadScheduledExecutor(); + _scheduler = new SimpleScheduler(); + _scheduler.start(); } @After - public void after() + public void after() throws Exception { - _scheduler.shutdownNow(); + _scheduler.stop(); } @Test diff --git a/jetty-io/src/test/java/org/eclipse/jetty/io/EndPointTest.java b/jetty-io/src/test/java/org/eclipse/jetty/io/EndPointTest.java index e15283324cd..4b7e453ece7 100644 --- a/jetty-io/src/test/java/org/eclipse/jetty/io/EndPointTest.java +++ b/jetty-io/src/test/java/org/eclipse/jetty/io/EndPointTest.java @@ -18,15 +18,15 @@ package org.eclipse.jetty.io; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import java.nio.ByteBuffer; import org.eclipse.jetty.util.BufferUtil; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - public abstract class EndPointTest { public static class EndPointPair diff --git a/jetty-io/src/test/java/org/eclipse/jetty/io/IOTest.java b/jetty-io/src/test/java/org/eclipse/jetty/io/IOTest.java index 6ab3fd9a18c..e96c67e8c22 100644 --- a/jetty-io/src/test/java/org/eclipse/jetty/io/IOTest.java +++ b/jetty-io/src/test/java/org/eclipse/jetty/io/IOTest.java @@ -18,6 +18,11 @@ package org.eclipse.jetty.io; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -39,11 +44,6 @@ import org.eclipse.jetty.util.IO; import org.junit.Assert; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - public class IOTest { @Test diff --git a/jetty-io/src/test/java/org/eclipse/jetty/io/MappedByteBufferPoolTest.java b/jetty-io/src/test/java/org/eclipse/jetty/io/MappedByteBufferPoolTest.java index 0d6e481561b..52ee4d7c9c9 100644 --- a/jetty-io/src/test/java/org/eclipse/jetty/io/MappedByteBufferPoolTest.java +++ b/jetty-io/src/test/java/org/eclipse/jetty/io/MappedByteBufferPoolTest.java @@ -18,18 +18,18 @@ package org.eclipse.jetty.io; -import java.nio.ByteBuffer; -import java.util.Queue; -import java.util.concurrent.ConcurrentMap; - -import org.junit.Test; - import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; +import java.nio.ByteBuffer; +import java.util.Queue; +import java.util.concurrent.ConcurrentMap; + +import org.junit.Test; + public class MappedByteBufferPoolTest { @Test diff --git a/jetty-io/src/test/java/org/eclipse/jetty/io/NIOTest.java b/jetty-io/src/test/java/org/eclipse/jetty/io/NIOTest.java index 56f60227cea..c062a403607 100644 --- a/jetty-io/src/test/java/org/eclipse/jetty/io/NIOTest.java +++ b/jetty-io/src/test/java/org/eclipse/jetty/io/NIOTest.java @@ -18,6 +18,10 @@ package org.eclipse.jetty.io; +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertFalse; +import static junit.framework.Assert.assertTrue; + import java.net.ServerSocket; import java.net.Socket; import java.nio.ByteBuffer; @@ -27,10 +31,6 @@ import java.nio.channels.SocketChannel; import org.junit.Test; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertFalse; -import static junit.framework.Assert.assertTrue; - /** * */ diff --git a/jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointInterestsTest.java b/jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointInterestsTest.java index ba4c2e88782..f8f30e90cd0 100644 --- a/jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointInterestsTest.java +++ b/jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointInterestsTest.java @@ -28,8 +28,6 @@ import java.nio.channels.SelectionKey; import java.nio.channels.ServerSocketChannel; import java.nio.channels.SocketChannel; import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; @@ -38,6 +36,8 @@ import java.util.concurrent.atomic.AtomicReference; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.thread.QueuedThreadPool; +import org.eclipse.jetty.util.thread.Scheduler; +import org.eclipse.jetty.util.thread.SimpleScheduler; import org.junit.After; import org.junit.Assert; import org.junit.Test; @@ -45,7 +45,7 @@ import org.junit.Test; public class SelectChannelEndPointInterestsTest { private QueuedThreadPool threadPool; - private ScheduledExecutorService scheduler; + private Scheduler scheduler; private ServerSocketChannel connector; private SelectorManager selectorManager; @@ -54,7 +54,8 @@ public class SelectChannelEndPointInterestsTest threadPool = new QueuedThreadPool(); threadPool.start(); - scheduler = Executors.newSingleThreadScheduledExecutor(); + scheduler = new SimpleScheduler(); + scheduler.start(); connector = ServerSocketChannel.open(); connector.bind(new InetSocketAddress("localhost", 0)); @@ -107,12 +108,12 @@ public class SelectChannelEndPointInterestsTest @After public void destroy() throws Exception { + if (scheduler!=null) + scheduler.stop(); if (selectorManager != null) selectorManager.stop(); if (connector != null) connector.close(); - if (scheduler != null) - scheduler.shutdownNow(); if (threadPool != null) threadPool.stop(); } diff --git a/jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointSslTest.java b/jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointSslTest.java index dfb5181c730..55e1e8e9ed7 100644 --- a/jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointSslTest.java +++ b/jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointSslTest.java @@ -18,6 +18,12 @@ package org.eclipse.jetty.io; +import static org.hamcrest.Matchers.greaterThan; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + import java.io.File; import java.io.IOException; import java.io.OutputStream; @@ -25,6 +31,7 @@ import java.net.Socket; import java.nio.ByteBuffer; import java.nio.channels.SocketChannel; import java.util.concurrent.TimeUnit; + import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLEngineResult; import javax.net.ssl.SSLEngineResult.HandshakeStatus; @@ -40,12 +47,6 @@ import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; -import static org.hamcrest.Matchers.greaterThan; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - public class SelectChannelEndPointSslTest extends SelectChannelEndPointTest { diff --git a/jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointTest.java b/jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointTest.java index 9e2c39f1803..01f22ca4d07 100644 --- a/jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointTest.java +++ b/jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointTest.java @@ -18,6 +18,12 @@ package org.eclipse.jetty.io; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.IOException; @@ -31,32 +37,26 @@ import java.nio.channels.ServerSocketChannel; import java.nio.channels.SocketChannel; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.FutureCallback; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.thread.QueuedThreadPool; +import org.eclipse.jetty.util.thread.Scheduler; +import org.eclipse.jetty.util.thread.SimpleScheduler; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - public class SelectChannelEndPointTest { protected CountDownLatch _lastEndPointLatch; protected volatile EndPoint _lastEndPoint; protected ServerSocketChannel _connector; protected QueuedThreadPool _threadPool = new QueuedThreadPool(); - protected ScheduledExecutorService _scheduler = Executors.newSingleThreadScheduledExecutor(); + protected Scheduler _scheduler = new SimpleScheduler(); protected SelectorManager _manager = new SelectorManager() { @Override @@ -93,6 +93,7 @@ public class SelectChannelEndPointTest _lastEndPointLatch = new CountDownLatch(1); _connector = ServerSocketChannel.open(); _connector.socket().bind(null); + _scheduler.start(); _threadPool.start(); _manager.start(); } @@ -100,6 +101,7 @@ public class SelectChannelEndPointTest @After public void stopManager() throws Exception { + _scheduler.stop(); _manager.stop(); _threadPool.stop(); _connector.close(); diff --git a/jetty-io/src/test/java/org/eclipse/jetty/io/SslConnectionTest.java b/jetty-io/src/test/java/org/eclipse/jetty/io/SslConnectionTest.java index 5d75622adfb..d271061d504 100644 --- a/jetty-io/src/test/java/org/eclipse/jetty/io/SslConnectionTest.java +++ b/jetty-io/src/test/java/org/eclipse/jetty/io/SslConnectionTest.java @@ -28,13 +28,13 @@ import java.nio.channels.SelectionKey; import java.nio.channels.ServerSocketChannel; import java.nio.channels.SocketChannel; import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; + import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLSocket; import junit.framework.Assert; + import org.eclipse.jetty.io.ssl.SslConnection; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.util.BufferUtil; @@ -42,6 +42,8 @@ import org.eclipse.jetty.util.FutureCallback; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.ssl.SslContextFactory; import org.eclipse.jetty.util.thread.QueuedThreadPool; +import org.eclipse.jetty.util.thread.Scheduler; +import org.eclipse.jetty.util.thread.SimpleScheduler; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; @@ -58,7 +60,7 @@ public class SslConnectionTest private volatile FutureCallback _writeCallback; protected ServerSocketChannel _connector; protected QueuedThreadPool _threadPool = new QueuedThreadPool(); - protected ScheduledExecutorService _scheduler = Executors.newSingleThreadScheduledExecutor(); + protected Scheduler _scheduler = new SimpleScheduler(); protected SelectorManager _manager = new SelectorManager() { @Override @@ -112,6 +114,7 @@ public class SslConnectionTest _connector = ServerSocketChannel.open(); _connector.socket().bind(null); _threadPool.start(); + _scheduler.start(); _manager.start(); } @@ -121,6 +124,7 @@ public class SslConnectionTest if (_lastEndp.isOpen()) _lastEndp.close(); _manager.stop(); + _scheduler.stop(); _threadPool.stop(); _connector.close(); } diff --git a/jetty-io/src/test/java/org/eclipse/jetty/io/WriteFlusherTest.java b/jetty-io/src/test/java/org/eclipse/jetty/io/WriteFlusherTest.java index 4ad43309895..16a6dafddab 100644 --- a/jetty-io/src/test/java/org/eclipse/jetty/io/WriteFlusherTest.java +++ b/jetty-io/src/test/java/org/eclipse/jetty/io/WriteFlusherTest.java @@ -18,6 +18,15 @@ package org.eclipse.jetty.io; +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertFalse; +import static junit.framework.Assert.assertTrue; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.when; + import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.WritePendingException; @@ -45,15 +54,6 @@ import org.mockito.invocation.InvocationOnMock; import org.mockito.runners.MockitoJUnitRunner; import org.mockito.stubbing.Answer; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertFalse; -import static junit.framework.Assert.assertTrue; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.when; - @RunWith(MockitoJUnitRunner.class) public class WriteFlusherTest { diff --git a/jetty-io/src/test/resources/jetty-logging.properties b/jetty-io/src/test/resources/jetty-logging.properties index 55f088b8656..cce2bbacbd3 100644 --- a/jetty-io/src/test/resources/jetty-logging.properties +++ b/jetty-io/src/test/resources/jetty-logging.properties @@ -1,2 +1,2 @@ org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog -org.eclipse.jetty.io.LEVEL=DEBUG +org.eclipse.jetty.io.LEVEL=INFO diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnector.java b/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnector.java index 7de823ebb86..bfc8bdfb58b 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnector.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnector.java @@ -24,10 +24,7 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Executor; -import java.util.concurrent.Executors; import java.util.concurrent.Future; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; import org.eclipse.jetty.io.ByteBufferPool; @@ -41,6 +38,8 @@ import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.ssl.SslContextFactory; +import org.eclipse.jetty.util.thread.Scheduler; +import org.eclipse.jetty.util.thread.SimpleScheduler; /** *

Partial implementation of {@link Connector}

@@ -55,11 +54,10 @@ public abstract class AbstractConnector extends AggregateLifeCycle implements Co private final Server _server; private final SslContextFactory _sslContextFactory; private final Executor _executor; - private final ScheduledExecutorService _scheduler; + private final Scheduler _scheduler; private final ByteBufferPool _byteBufferPool; private final Thread[] _acceptors; private volatile CountDownLatch _stopping; - private volatile String _name; private volatile long _idleTimeout = 200000; private volatile ConnectionFactory defaultConnectionFactory; @@ -74,30 +72,23 @@ public abstract class AbstractConnector extends AggregateLifeCycle implements Co public AbstractConnector( Server server, Executor executor, - ScheduledExecutorService scheduler, + Scheduler scheduler, ByteBufferPool pool, SslContextFactory sslContextFactory, int acceptors) { _server=server; _executor=executor!=null?executor:_server.getThreadPool(); - _scheduler=scheduler!=null?scheduler:Executors.newSingleThreadScheduledExecutor(new ThreadFactory() - { - @Override - public Thread newThread(Runnable r) - { - return new Thread(r, "Scheduler-" + getName()); - } - }); + _scheduler=scheduler!=null?scheduler:new SimpleScheduler(); _byteBufferPool = pool!=null?pool:new MappedByteBufferPool(); _sslContextFactory = sslContextFactory; addBean(_server,false); addBean(_executor); if (executor==null) - unmanage(_executor); - addBean(_scheduler,scheduler==null); - addBean(_byteBufferPool,pool==null); + unmanage(_executor); // inherited from server + addBean(_scheduler); + addBean(_byteBufferPool); addBean(_sslContextFactory); addBean(_stats,true); @@ -341,18 +332,6 @@ public abstract class AbstractConnector extends AggregateLifeCycle implements Co } } - @Override - @ManagedAttribute("name of the connector") - public String getName() - { - return _name; - } - - public void setName(String name) - { - _name = name; - } - protected void connectionOpened(Connection connection) { _stats.connectionOpened(); @@ -373,7 +352,8 @@ public abstract class AbstractConnector extends AggregateLifeCycle implements Co _stats.connectionClosed(duration, requests, requests); } - public ScheduledExecutorService getScheduler() + @Override + public Scheduler getScheduler() { return _scheduler; } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractNetworkConnector.java b/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractNetworkConnector.java index c4fc3799cc6..21fafc7a50c 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractNetworkConnector.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractNetworkConnector.java @@ -21,10 +21,10 @@ package org.eclipse.jetty.server; import java.io.IOException; import java.util.concurrent.Executor; import java.util.concurrent.Future; -import java.util.concurrent.ScheduledExecutorService; import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.util.ssl.SslContextFactory; +import org.eclipse.jetty.util.thread.Scheduler; /** *

Partial implementation of {@link NetworkConnector}.

@@ -34,7 +34,7 @@ public abstract class AbstractNetworkConnector extends AbstractConnector impleme private volatile String _host; private volatile int _port = 0; - public AbstractNetworkConnector(Server server, Executor executor, ScheduledExecutorService scheduler, ByteBufferPool pool, SslContextFactory sslContextFactory, int acceptors) + public AbstractNetworkConnector(Server server, Executor executor, Scheduler scheduler, ByteBufferPool pool, SslContextFactory sslContextFactory, int acceptors) { super(server, executor, scheduler, pool, sslContextFactory, acceptors); } @@ -70,13 +70,7 @@ public abstract class AbstractNetworkConnector extends AbstractConnector impleme @Override protected void doStart() throws Exception { - if (getName() == null) - setName(getHost() == null ? "0.0.0.0" : getHost() + ":" + getPort()); - open(); - - setName(getName() + "/" + getLocalPort()); - super.doStart(); } @@ -84,12 +78,7 @@ public abstract class AbstractNetworkConnector extends AbstractConnector impleme protected void doStop() throws Exception { close(); - super.doStop(); - - int i = getName().lastIndexOf("/"); - if (i > 0) - setName(getName().substring(0, i)); } @Override diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Connector.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Connector.java index 99a877c8b45..908abd0db07 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Connector.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Connector.java @@ -19,7 +19,6 @@ package org.eclipse.jetty.server; import java.util.concurrent.Executor; -import java.util.concurrent.ScheduledExecutorService; import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.util.annotation.ManagedAttribute; @@ -27,6 +26,7 @@ import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.component.Graceful; import org.eclipse.jetty.util.component.LifeCycle; import org.eclipse.jetty.util.ssl.SslContextFactory; +import org.eclipse.jetty.util.thread.Scheduler; /** *

A {@link Connector} accept connections and data from remote peers, @@ -36,11 +36,6 @@ import org.eclipse.jetty.util.ssl.SslContextFactory; @ManagedObject("Connector Interface") public interface Connector extends LifeCycle, Graceful { - /** - * @return the name of the connector, defaulting to host:port - */ - public String getName(); - /** * @return the {@link Server} instance associated with this {@link Connector} */ @@ -52,9 +47,9 @@ public interface Connector extends LifeCycle, Graceful public Executor getExecutor(); /** - * @return the {@link ScheduledExecutorService} used to schedule tasks + * @return the {@link Scheduler} used to schedule tasks */ - public ScheduledExecutorService getScheduler(); + public Scheduler getScheduler(); /** * @return the {@link ByteBufferPool} to acquire buffers from and release buffers to diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Dispatcher.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Dispatcher.java index 90954666c6f..9919323211b 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Dispatcher.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Dispatcher.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.util.Collections; import java.util.Enumeration; import java.util.HashSet; + import javax.servlet.DispatcherType; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Handler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Handler.java index b2715a9c634..1a6205f59ef 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Handler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Handler.java @@ -19,6 +19,7 @@ package org.eclipse.jetty.server; import java.io.IOException; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java index a0c8c420e22..9069c5cff08 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java @@ -21,9 +21,9 @@ package org.eclipse.jetty.server; import java.io.IOException; import java.net.InetSocketAddress; import java.nio.ByteBuffer; -import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; + import javax.servlet.DispatcherType; import javax.servlet.RequestDispatcher; @@ -47,6 +47,7 @@ import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.URIUtil; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.util.thread.Scheduler; /* ------------------------------------------------------------ */ @@ -617,7 +618,7 @@ public class HttpChannel implements HttpParser.RequestHandler, Runnable _connector.getExecutor().execute(task); } - public ScheduledExecutorService getScheduler() + public Scheduler getScheduler() { return _connector.getScheduler(); } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelState.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelState.java index f2b3780ca97..04c3b7008b1 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelState.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelState.java @@ -20,9 +20,8 @@ package org.eclipse.jetty.server; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.Future; -import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; + import javax.servlet.AsyncContext; import javax.servlet.AsyncEvent; import javax.servlet.AsyncListener; @@ -41,6 +40,7 @@ import org.eclipse.jetty.server.handler.ContextHandler.Context; import org.eclipse.jetty.util.URIUtil; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.util.thread.Scheduler; /* ------------------------------------------------------------ */ /** Implementation of Continuation and AsyncContext interfaces @@ -723,7 +723,7 @@ public class HttpChannelState implements AsyncContext, Continuation /* ------------------------------------------------------------ */ protected void scheduleTimeout() { - ScheduledExecutorService scheduler = _channel.getScheduler(); + Scheduler scheduler = _channel.getScheduler(); if (scheduler!=null) _event._timeout=scheduler.schedule(new AsyncTimeout(),_timeoutMs,TimeUnit.MILLISECONDS); } @@ -734,9 +734,9 @@ public class HttpChannelState implements AsyncContext, Continuation AsyncEventState event=_event; if (event!=null) { - Future task=event._timeout; + Scheduler.Task task=event._timeout; if (task!=null) - task.cancel(false); + task.cancel(); } } @@ -1038,7 +1038,7 @@ public class HttpChannelState implements AsyncContext, Continuation /* ------------------------------------------------------------ */ public class AsyncEventState extends AsyncEvent { - private Future _timeout; + private Scheduler.Task _timeout; private final ServletContext _suspendedContext; private ServletContext _dispatchContext; private String _pathInContext; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConfiguration.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConfiguration.java index 266b22f3e8b..2c321c4dc5f 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConfiguration.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConfiguration.java @@ -20,6 +20,7 @@ package org.eclipse.jetty.server; import java.io.IOException; import java.net.InetSocketAddress; + import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLSession; import javax.servlet.ServletRequest; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpInput.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpInput.java index 3fad5007748..98a86b8a017 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpInput.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpInput.java @@ -20,6 +20,7 @@ package org.eclipse.jetty.server; import java.io.IOException; import java.io.InterruptedIOException; + import javax.servlet.ServletInputStream; import org.eclipse.jetty.io.EofException; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpOutput.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpOutput.java index 1a0b845f58e..44901e51317 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpOutput.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpOutput.java @@ -22,6 +22,7 @@ import java.io.EOFException; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; + import javax.servlet.RequestDispatcher; import javax.servlet.ServletOutputStream; import javax.servlet.ServletRequest; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpServerConnector.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpServerConnector.java index 46748c4f56b..19db4db28e8 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpServerConnector.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpServerConnector.java @@ -19,11 +19,11 @@ package org.eclipse.jetty.server; import java.util.concurrent.Executor; -import java.util.concurrent.ScheduledExecutorService; import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.util.annotation.Name; import org.eclipse.jetty.util.ssl.SslContextFactory; +import org.eclipse.jetty.util.thread.Scheduler; public class HttpServerConnector extends SelectChannelConnector { @@ -37,7 +37,7 @@ public class HttpServerConnector extends SelectChannelConnector this(server, null, null, null, sslContextFactory, 0, 0); } - public HttpServerConnector(@Name("server") Server server, @Name("executor") Executor executor, @Name("scheduler") ScheduledExecutorService scheduler, @Name("bufferPool") ByteBufferPool pool, @Name("sslContextFactory") SslContextFactory sslContextFactory, @Name("acceptors") int acceptors, @Name("selectors") int selectors) + public HttpServerConnector(@Name("server") Server server, @Name("executor") Executor executor, @Name("scheduler") Scheduler scheduler, @Name("bufferPool") ByteBufferPool pool, @Name("sslContextFactory") SslContextFactory sslContextFactory, @Name("acceptors") int acceptors, @Name("selectors") int selectors) { super(server, executor, scheduler, pool, sslContextFactory, acceptors, selectors); setDefaultConnectionFactory(new HttpServerConnectionFactory(this)); diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/LocalConnector.java b/jetty-server/src/main/java/org/eclipse/jetty/server/LocalConnector.java index c265a7ea48d..6f5cd7c497b 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/LocalConnector.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/LocalConnector.java @@ -24,8 +24,8 @@ import java.util.concurrent.BlockingQueue; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Executor; import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; + import javax.net.ssl.SSLEngine; import org.eclipse.jetty.io.ByteArrayEndPoint; @@ -36,6 +36,7 @@ import org.eclipse.jetty.io.ssl.SslConnection; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.ssl.SslContextFactory; +import org.eclipse.jetty.util.thread.Scheduler; public class LocalConnector extends AbstractConnector { @@ -51,7 +52,7 @@ public class LocalConnector extends AbstractConnector this(server, null, null, null, sslContextFactory, 0); } - public LocalConnector(Server server, Executor executor, ScheduledExecutorService scheduler, ByteBufferPool pool, + public LocalConnector(Server server, Executor executor, Scheduler scheduler, ByteBufferPool pool, SslContextFactory sslContextFactory, int acceptors) { super(server,executor,scheduler,pool, sslContextFactory, acceptors); diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/NCSARequestLog.java b/jetty-server/src/main/java/org/eclipse/jetty/server/NCSARequestLog.java index dadf023485c..02594402957 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/NCSARequestLog.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/NCSARequestLog.java @@ -24,6 +24,7 @@ import java.io.OutputStreamWriter; import java.io.Writer; import java.util.Locale; import java.util.TimeZone; + import javax.servlet.http.Cookie; import org.eclipse.jetty.http.HttpHeader; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java index 29ce8e5a972..d53011fe79e 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java @@ -37,6 +37,7 @@ import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; + import javax.servlet.AsyncContext; import javax.servlet.AsyncListener; import javax.servlet.DispatcherType; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java index 831719b1c53..d145e2173ad 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java @@ -25,6 +25,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Locale; import java.util.concurrent.atomic.AtomicInteger; + import javax.servlet.RequestDispatcher; import javax.servlet.ServletOutputStream; import javax.servlet.http.Cookie; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/SelectChannelConnector.java b/jetty-server/src/main/java/org/eclipse/jetty/server/SelectChannelConnector.java index cf6eb5971b9..9d2fb53001c 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/SelectChannelConnector.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/SelectChannelConnector.java @@ -29,7 +29,7 @@ import java.nio.channels.ServerSocketChannel; import java.nio.channels.SocketChannel; import java.util.concurrent.Executor; import java.util.concurrent.Future; -import java.util.concurrent.ScheduledExecutorService; + import javax.net.ssl.SSLEngine; import org.eclipse.jetty.io.ByteBufferPool; @@ -42,6 +42,7 @@ import org.eclipse.jetty.io.ssl.SslConnection; import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.annotation.Name; import org.eclipse.jetty.util.ssl.SslContextFactory; +import org.eclipse.jetty.util.thread.Scheduler; /** *

Implementation of {@link NetworkConnector} based on NIO classes.

@@ -77,7 +78,7 @@ public class SelectChannelConnector extends AbstractNetworkConnector public SelectChannelConnector( @Name("server") Server server, @Name("executor") Executor executor, - @Name("scheduler") ScheduledExecutorService scheduler, + @Name("scheduler") Scheduler scheduler, @Name("bufferPool") ByteBufferPool pool, @Name("sslContextFactory") SslContextFactory sslContextFactory, @Name("acceptors") int acceptors, diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java index 7e7b7f7c100..5084ff72035 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java @@ -20,7 +20,6 @@ package org.eclipse.jetty.server; import java.io.IOException; import java.net.InetSocketAddress; -import java.net.SocketException; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; @@ -30,7 +29,6 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -51,7 +49,6 @@ import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.component.Container; import org.eclipse.jetty.util.component.Destroyable; -import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.component.Graceful; import org.eclipse.jetty.util.component.LifeCycle; import org.eclipse.jetty.util.log.Log; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/ServletRequestHttpWrapper.java b/jetty-server/src/main/java/org/eclipse/jetty/server/ServletRequestHttpWrapper.java index f3ca9dcd06b..242a27b441f 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/ServletRequestHttpWrapper.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/ServletRequestHttpWrapper.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.security.Principal; import java.util.Collection; import java.util.Enumeration; + import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletRequestWrapper; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/ServletResponseHttpWrapper.java b/jetty-server/src/main/java/org/eclipse/jetty/server/ServletResponseHttpWrapper.java index 502ef1f7c7e..91278460b70 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/ServletResponseHttpWrapper.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/ServletResponseHttpWrapper.java @@ -20,6 +20,7 @@ package org.eclipse.jetty.server; import java.io.IOException; import java.util.Collection; + import javax.servlet.ServletResponse; import javax.servlet.ServletResponseWrapper; import javax.servlet.http.Cookie; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/SessionManager.java b/jetty-server/src/main/java/org/eclipse/jetty/server/SessionManager.java index 83825648679..76a2eaacdd4 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/SessionManager.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/SessionManager.java @@ -20,6 +20,7 @@ package org.eclipse.jetty.server; import java.util.EventListener; import java.util.Set; + import javax.servlet.SessionCookieConfig; import javax.servlet.SessionTrackingMode; import javax.servlet.http.Cookie; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/UserIdentity.java b/jetty-server/src/main/java/org/eclipse/jetty/server/UserIdentity.java index 5c39e7f5084..90f072619dd 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/UserIdentity.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/UserIdentity.java @@ -20,6 +20,7 @@ package org.eclipse.jetty.server; import java.security.Principal; import java.util.Map; + import javax.security.auth.Subject; /* ------------------------------------------------------------ */ diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java index 0aa7cc4304f..d6346dcfde4 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java @@ -36,10 +36,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; -import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; import javax.servlet.DispatcherType; import javax.servlet.Filter; @@ -67,7 +64,6 @@ import org.eclipse.jetty.http.MimeTypes; import org.eclipse.jetty.server.Dispatcher; import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.HandlerContainer; -import org.eclipse.jetty.server.HttpChannel; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.util.ArrayUtil; @@ -151,7 +147,6 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu private String[] _vhosts; - private Set _connectors; private EventListener[] _eventListeners; private Logger _logger; @@ -396,36 +391,6 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu return _vhosts; } - /* ------------------------------------------------------------ */ - /** - * @return an array of connector names that this context will accept a request from. - */ - @ManagedAttribute("Names and ports of accepted connectors") - public String[] getConnectorNames() - { - if (_connectors == null || _connectors.size() == 0) - return null; - - return _connectors.toArray(new String[_connectors.size()]); - } - - /* ------------------------------------------------------------ */ - /** - * Set the names of accepted connectors. - * - * Names are either "host:port" or a specific configured name for a connector. - * - * @param connectors - * If non null, an array of connector names that this context will accept a request from. - */ - public void setConnectorNames(String[] connectors) - { - if (connectors == null || connectors.length == 0) - _connectors = null; - else - _connectors = new HashSet(Arrays.asList(connectors)); - } - /* ------------------------------------------------------------ */ /* * @see javax.servlet.ServletContext#getAttribute(java.lang.String) @@ -903,14 +868,6 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu return false; } - // Check the connector - if (_connectors != null && _connectors.size() > 0) - { - String connector = HttpChannel.getCurrentHttpChannel().getConnector().getName(); - if (connector == null || !_connectors.contains(connector)) - return false; - } - // Are we not the root context? if (_contextPath.length() > 1) { diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandlerCollection.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandlerCollection.java index b68575878e6..f5ced00d3ff 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandlerCollection.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandlerCollection.java @@ -21,6 +21,7 @@ package org.eclipse.jetty.server.handler; import java.io.IOException; import java.util.HashMap; import java.util.Map; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/DebugHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/DebugHandler.java index 1664aa0b94d..a9c86c13f6b 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/DebugHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/DebugHandler.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; import java.util.Locale; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/DefaultHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/DefaultHandler.java index f1298dba67b..436040eada7 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/DefaultHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/DefaultHandler.java @@ -21,6 +21,7 @@ package org.eclipse.jetty.server.handler; import java.io.IOException; import java.io.OutputStream; import java.net.URL; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ErrorHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ErrorHandler.java index 71e66990161..e8d7311fe75 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ErrorHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ErrorHandler.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; import java.io.Writer; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/GzipHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/GzipHandler.java index c84b8dbf6f2..9768d1fa092 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/GzipHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/GzipHandler.java @@ -28,6 +28,7 @@ import java.util.Set; import java.util.StringTokenizer; import java.util.zip.DeflaterOutputStream; import java.util.zip.GZIPOutputStream; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerCollection.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerCollection.java index b9e15f19c3d..2a2d8e3ba36 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerCollection.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerCollection.java @@ -21,6 +21,7 @@ package org.eclipse.jetty.server.handler; import java.io.IOException; import java.util.List; import java.util.concurrent.CountDownLatch; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerList.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerList.java index 3dca6423057..e295516198f 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerList.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerList.java @@ -19,6 +19,7 @@ package org.eclipse.jetty.server.handler; import java.io.IOException; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerWrapper.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerWrapper.java index a18b937e7d8..dd5dd51fe8e 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerWrapper.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerWrapper.java @@ -20,6 +20,7 @@ package org.eclipse.jetty.server.handler; import java.io.IOException; import java.util.List; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HotSwapHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HotSwapHandler.java index ff5ce0c735f..a930c35a27d 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HotSwapHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HotSwapHandler.java @@ -20,6 +20,7 @@ package org.eclipse.jetty.server.handler; import java.io.IOException; import java.util.List; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/IPAccessHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/IPAccessHandler.java index cd5000bd809..71024db947b 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/IPAccessHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/IPAccessHandler.java @@ -23,6 +23,7 @@ import java.net.InetSocketAddress; import java.util.Collections; import java.util.List; import java.util.Map; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/MovedContextHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/MovedContextHandler.java index f57ef9fbae1..c21f256c562 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/MovedContextHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/MovedContextHandler.java @@ -19,6 +19,7 @@ package org.eclipse.jetty.server.handler; import java.io.IOException; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/RequestLogHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/RequestLogHandler.java index e6ca16b7948..6131e3b3cd0 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/RequestLogHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/RequestLogHandler.java @@ -19,6 +19,7 @@ package org.eclipse.jetty.server.handler; import java.io.IOException; + import javax.servlet.DispatcherType; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ResourceHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ResourceHandler.java index f7ae5eaae6d..28a81149bcd 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ResourceHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ResourceHandler.java @@ -21,6 +21,7 @@ package org.eclipse.jetty.server.handler; import java.io.IOException; import java.io.OutputStream; import java.net.MalformedURLException; + import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ScopedHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ScopedHandler.java index a3ceb46a400..60a049dc545 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ScopedHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ScopedHandler.java @@ -19,6 +19,7 @@ package org.eclipse.jetty.server.handler; import java.io.IOException; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ShutdownHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ShutdownHandler.java index 972ac8ba64c..3ddfad8b2f1 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ShutdownHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ShutdownHandler.java @@ -19,6 +19,7 @@ package org.eclipse.jetty.server.handler; import java.io.IOException; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/StatisticsHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/StatisticsHandler.java index 8d802eb73ab..b982b914e2e 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/StatisticsHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/StatisticsHandler.java @@ -21,6 +21,7 @@ package org.eclipse.jetty.server.handler; import java.io.IOException; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSession.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSession.java index 3dd69f4530a..79dba9b601e 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSession.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSession.java @@ -27,6 +27,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; + import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSessionActivationListener; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionIdManager.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionIdManager.java index 0d9aa45a4ec..e26ae62ed5c 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionIdManager.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionIdManager.java @@ -20,6 +20,7 @@ package org.eclipse.jetty.server.session; import java.security.SecureRandom; import java.util.Random; + import javax.servlet.http.HttpServletRequest; import org.eclipse.jetty.server.SessionIdManager; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionManager.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionManager.java index 191836f502b..cca7aaf9109 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionManager.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionManager.java @@ -18,6 +18,8 @@ package org.eclipse.jetty.server.session; +import static java.lang.Math.round; + import java.util.Arrays; import java.util.Collections; import java.util.Enumeration; @@ -28,6 +30,7 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.CopyOnWriteArrayList; + import javax.servlet.SessionCookieConfig; import javax.servlet.SessionTrackingMode; import javax.servlet.http.HttpServletRequest; @@ -51,8 +54,6 @@ import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.statistic.CounterStatistic; import org.eclipse.jetty.util.statistic.SampleStatistic; -import static java.lang.Math.round; - /* ------------------------------------------------------------ */ /** * An Abstract implementation of SessionManager. The partial implementation of diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/HashSessionIdManager.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/HashSessionIdManager.java index d98e353569b..b4e7850c570 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/HashSessionIdManager.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/HashSessionIdManager.java @@ -28,6 +28,7 @@ import java.util.Iterator; import java.util.Map; import java.util.Random; import java.util.Set; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/HashSessionManager.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/HashSessionManager.java index 7d88eae893e..878365e0517 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/HashSessionManager.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/HashSessionManager.java @@ -31,6 +31,7 @@ import java.util.Timer; import java.util.TimerTask; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; + import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/HashedSession.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/HashedSession.java index 7db59d1aa92..550d0520404 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/HashedSession.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/HashedSession.java @@ -27,6 +27,7 @@ import java.io.IOException; import java.io.ObjectOutputStream; import java.io.OutputStream; import java.util.Enumeration; + import javax.servlet.http.HttpServletRequest; import org.eclipse.jetty.util.IO; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionIdManager.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionIdManager.java index b759b815e30..2e82d7e5c28 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionIdManager.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionIdManager.java @@ -35,6 +35,7 @@ import java.util.List; import java.util.Random; import java.util.Timer; import java.util.TimerTask; + import javax.naming.InitialContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionManager.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionManager.java index fe32a93688f..e5d1712a593 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionManager.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionManager.java @@ -35,6 +35,7 @@ import java.util.ListIterator; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicReference; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSessionEvent; import javax.servlet.http.HttpSessionListener; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionHandler.java index cc18ab03302..bb3f020ec3d 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionHandler.java @@ -21,6 +21,7 @@ package org.eclipse.jetty.server.session; import java.io.IOException; import java.util.EnumSet; import java.util.EventListener; + import javax.servlet.DispatcherType; import javax.servlet.ServletException; import javax.servlet.SessionTrackingMode; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/ssl/SslCertificates.java b/jetty-server/src/main/java/org/eclipse/jetty/server/ssl/SslCertificates.java index a1829ef5cdb..8b337e9597e 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/ssl/SslCertificates.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/ssl/SslCertificates.java @@ -21,6 +21,7 @@ package org.eclipse.jetty.server.ssl; import java.io.ByteArrayInputStream; import java.io.IOException; import java.security.cert.X509Certificate; + import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLPeerUnverifiedException; import javax.net.ssl.SSLSession; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/ssl/SslConnector.java b/jetty-server/src/main/java/org/eclipse/jetty/server/ssl/SslConnector.java index 19f40ba0f9b..073080a0d37 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/ssl/SslConnector.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/ssl/SslConnector.java @@ -21,6 +21,7 @@ package org.eclipse.jetty.server.ssl; import java.io.File; import java.security.SecureRandom; import java.security.Security; + import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLEngine; diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java index f7b2aa04d8c..a29197abd59 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java @@ -18,6 +18,9 @@ package org.eclipse.jetty.server; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; @@ -25,6 +28,7 @@ import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.net.Socket; import java.net.URISyntaxException; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -37,9 +41,6 @@ import org.eclipse.jetty.util.log.StdErrLog; import org.junit.After; import org.junit.Before; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - public abstract class AbstractHttpTest { protected static Server server; @@ -66,8 +67,8 @@ public abstract class AbstractHttpTest @After public void tearDown() throws Exception { - ((StdErrLog)Log.getLogger(HttpChannel.class)).setHideStacks(false); server.stop(); + ((StdErrLog)Log.getLogger(HttpChannel.class)).setHideStacks(false); } protected SimpleHttpResponse executeRequest() throws URISyntaxException, IOException diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/AsyncRequestReadTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/AsyncRequestReadTest.java index c84fd06fe6e..7d092665969 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/AsyncRequestReadTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/AsyncRequestReadTest.java @@ -18,6 +18,9 @@ package org.eclipse.jetty.server; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -25,6 +28,7 @@ import java.net.Socket; import java.util.Arrays; import java.util.concurrent.Exchanger; import java.util.concurrent.TimeUnit; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -39,9 +43,6 @@ import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - public class AsyncRequestReadTest { private static Server server; diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/AsyncStressTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/AsyncStressTest.java index 409fcbbef6b..33c267fe3bc 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/AsyncStressTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/AsyncStressTest.java @@ -18,6 +18,8 @@ package org.eclipse.jetty.server; +import static org.junit.Assert.assertEquals; + import java.io.IOException; import java.io.InputStream; import java.net.InetAddress; @@ -25,6 +27,7 @@ import java.net.Socket; import java.util.Random; import java.util.Timer; import java.util.TimerTask; + import javax.servlet.AsyncContext; import javax.servlet.AsyncEvent; import javax.servlet.AsyncListener; @@ -44,8 +47,6 @@ import org.junit.Before; import org.junit.Ignore; import org.junit.Test; -import static org.junit.Assert.assertEquals; - public class AsyncStressTest { private static final Logger LOG = Log.getLogger(AsyncStressTest.class); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/CheckReverseProxyHeadersTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/CheckReverseProxyHeadersTest.java index 2c0f72dff19..0d82fb43c27 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/CheckReverseProxyHeadersTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/CheckReverseProxyHeadersTest.java @@ -18,7 +18,12 @@ package org.eclipse.jetty.server; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import java.io.IOException; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -26,10 +31,6 @@ import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.server.handler.AbstractHandler; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - /** * */ diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorCloseTestBase.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorCloseTestBase.java index 73ddc0ca1ff..f7409ea175c 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorCloseTestBase.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorCloseTestBase.java @@ -18,6 +18,8 @@ package org.eclipse.jetty.server; +import static org.junit.Assert.assertTrue; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; @@ -28,8 +30,6 @@ import java.util.concurrent.TimeUnit; import org.junit.Test; -import static org.junit.Assert.assertTrue; - /** * HttpServer Tester. */ diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorTimeoutTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorTimeoutTest.java index 0a1e019e171..d8959694b15 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorTimeoutTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorTimeoutTest.java @@ -18,6 +18,10 @@ package org.eclipse.jetty.server; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.matchers.JUnitMatchers.containsString; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -25,6 +29,7 @@ import java.net.Socket; import java.net.SocketException; import java.util.concurrent.Exchanger; import java.util.concurrent.TimeUnit; + import javax.net.ssl.SSLException; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -37,10 +42,6 @@ import org.eclipse.jetty.util.IO; import org.junit.Assert; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.matchers.JUnitMatchers.containsString; - public abstract class ConnectorTimeoutTest extends HttpServerTestFixture { protected static final int MAX_IDLE_TIME=500; diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/DumpHandler.java b/jetty-server/src/test/java/org/eclipse/jetty/server/DumpHandler.java index f44487fa063..393cd658271 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/DumpHandler.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/DumpHandler.java @@ -25,6 +25,7 @@ import java.io.OutputStreamWriter; import java.io.Reader; import java.io.Writer; import java.util.Enumeration; + import javax.servlet.ServletException; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpConnectionTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpConnectionTest.java index ba8e942b965..a310027e191 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpConnectionTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpConnectionTest.java @@ -24,10 +24,16 @@ */ package org.eclipse.jetty.server; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.startsWith; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.io.PrintWriter; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -44,11 +50,6 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - /** * */ diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitBadBehaviourTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitBadBehaviourTest.java index da54ce2afbf..06159cb9740 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitBadBehaviourTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitBadBehaviourTest.java @@ -18,6 +18,9 @@ package org.eclipse.jetty.server; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + import java.io.IOException; import java.util.Arrays; import java.util.Collection; @@ -25,6 +28,7 @@ import java.util.concurrent.BrokenBarrierException; import java.util.concurrent.CyclicBarrier; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; + import javax.servlet.AsyncContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -36,11 +40,9 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - //TODO: reset buffer tests //TODO: add protocol specific tests for connection: close and/or chunking + @RunWith(value = Parameterized.class) public class HttpManyWaysToAsyncCommitBadBehaviourTest extends AbstractHttpTest { diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitTest.java index 8fec13bcb30..664fc9b21da 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitTest.java @@ -18,9 +18,14 @@ package org.eclipse.jetty.server; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertThat; + import java.io.IOException; import java.util.Arrays; import java.util.Collection; + import javax.servlet.AsyncContext; import javax.servlet.ServletException; import javax.servlet.ServletResponse; @@ -33,10 +38,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertThat; - //TODO: reset buffer tests //TODO: add protocol specific tests for connection: close and/or chunking @RunWith(value = Parameterized.class) diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToCommitTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToCommitTest.java index 1e83f0103d7..2cc34f748ee 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToCommitTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToCommitTest.java @@ -18,9 +18,14 @@ package org.eclipse.jetty.server; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.junit.Assert.assertThat; + import java.io.IOException; import java.util.Arrays; import java.util.Collection; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -31,10 +36,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertThat; - //TODO: reset buffer tests //TODO: add protocol specific tests for connection: close and/or chunking @RunWith(value = Parameterized.class) diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java index 839c1b858fb..fbf0bc4a0f6 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java @@ -18,6 +18,12 @@ package org.eclipse.jetty.server; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -30,6 +36,7 @@ import java.net.URL; import java.util.Arrays; import java.util.Random; import java.util.concurrent.Exchanger; + import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; @@ -46,12 +53,6 @@ import org.junit.Assert; import org.junit.Test; import org.junit.matchers.JUnitMatchers; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - /** * */ diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestFixture.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestFixture.java index 3d97de32e91..cfa4121056e 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestFixture.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestFixture.java @@ -25,6 +25,7 @@ import java.io.OutputStream; import java.io.PrintWriter; import java.io.Writer; import java.net.Socket; + import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLSession; import javax.servlet.ServletException; diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpURITest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpURITest.java index dc3a21e470d..2b1bfae001a 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpURITest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpURITest.java @@ -18,22 +18,23 @@ package org.eclipse.jetty.server; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.net.URLEncoder; import java.nio.charset.Charset; import junit.framework.Assert; + import org.eclipse.jetty.http.HttpURI; import org.eclipse.jetty.util.MultiMap; import org.eclipse.jetty.util.StringUtil; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - public class HttpURITest { private final String[][] partial_tests= diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpWriterTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpWriterTest.java index 5a055858e26..8382abcfcf9 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpWriterTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpWriterTest.java @@ -18,6 +18,8 @@ package org.eclipse.jetty.server; +import static org.junit.Assert.assertEquals; + import java.io.IOException; import java.nio.ByteBuffer; @@ -30,8 +32,6 @@ import org.eclipse.jetty.util.Utf8StringBuilder; import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.assertEquals; - public class HttpWriterTest { private HttpOutput _httpOut; diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/InclusiveByteRangeTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/InclusiveByteRangeTest.java index 08b94975b2a..43e46f0b82c 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/InclusiveByteRangeTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/InclusiveByteRangeTest.java @@ -18,15 +18,15 @@ package org.eclipse.jetty.server; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + import java.util.List; import java.util.Vector; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - public class InclusiveByteRangeTest { @SuppressWarnings("unchecked") diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/LocalAsyncContextTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/LocalAsyncContextTest.java index 3b178c10ac4..7b1c0e9ce2e 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/LocalAsyncContextTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/LocalAsyncContextTest.java @@ -18,9 +18,12 @@ package org.eclipse.jetty.server; +import static org.junit.Assert.assertEquals; + import java.io.IOException; import java.io.InputStream; import java.util.concurrent.atomic.AtomicInteger; + import javax.servlet.AsyncContext; import javax.servlet.AsyncEvent; import javax.servlet.AsyncListener; @@ -37,8 +40,6 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.assertEquals; - public class LocalAsyncContextTest { protected Server _server = new Server(); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/LocalConnectorTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/LocalConnectorTest.java index 817eb6509de..5191aaa7738 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/LocalConnectorTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/LocalConnectorTest.java @@ -18,13 +18,13 @@ package org.eclipse.jetty.server; +import static org.hamcrest.Matchers.containsString; +import static org.junit.Assert.assertThat; + import org.junit.After; import org.junit.Before; import org.junit.Test; -import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertThat; - public class LocalConnectorTest { private Server _server; diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/NetworkTrafficListenerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/NetworkTrafficListenerTest.java index bb9d20a1846..80885c74940 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/NetworkTrafficListenerTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/NetworkTrafficListenerTest.java @@ -18,6 +18,9 @@ package org.eclipse.jetty.server; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; @@ -27,6 +30,7 @@ import java.nio.ByteBuffer; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; + import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; @@ -41,9 +45,6 @@ import org.junit.After; import org.junit.Ignore; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - @Ignore public class NetworkTrafficListenerTest { diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/PartialRFC2616Test.java b/jetty-server/src/test/java/org/eclipse/jetty/server/PartialRFC2616Test.java index de65ba3c81d..11887164f33 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/PartialRFC2616Test.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/PartialRFC2616Test.java @@ -24,6 +24,11 @@ */ package org.eclipse.jetty.server; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.not; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.util.Date; import java.util.Enumeration; import java.util.List; @@ -37,11 +42,6 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - /** * */ diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java index f2ffab3e23b..b143214fc74 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java @@ -18,6 +18,14 @@ package org.eclipse.jetty.server; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + import java.io.BufferedReader; import java.io.File; import java.io.FileReader; @@ -29,6 +37,7 @@ import java.util.Arrays; import java.util.Enumeration; import java.util.Map; import java.util.concurrent.TimeUnit; + import javax.servlet.ServletException; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; @@ -48,14 +57,6 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - public class RequestTest { private static final Logger LOG = Log.getLogger(RequestTest.class); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ResourceCacheTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ResourceCacheTest.java index 5f2d81ea21a..3566366b799 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ResourceCacheTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ResourceCacheTest.java @@ -18,6 +18,9 @@ package org.eclipse.jetty.server; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; @@ -30,9 +33,6 @@ import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.ResourceCollection; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - public class ResourceCacheTest { @Test diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java index a1ce4cfc12d..54cedc7df2f 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java @@ -18,6 +18,11 @@ package org.eclipse.jetty.server; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.IOException; import java.io.InputStreamReader; import java.io.LineNumberReader; @@ -26,8 +31,7 @@ import java.net.Socket; import java.nio.ByteBuffer; import java.util.Iterator; import java.util.Locale; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledThreadPoolExecutor; + import javax.servlet.ServletException; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; @@ -43,34 +47,31 @@ import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.server.session.HashSessionIdManager; import org.eclipse.jetty.server.session.HashSessionManager; import org.eclipse.jetty.server.session.HashedSession; +import org.eclipse.jetty.util.thread.Scheduler; +import org.eclipse.jetty.util.thread.SimpleScheduler; import org.hamcrest.Matchers; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - public class ResponseTest { private Server _server; private HttpChannel _channel; - private ScheduledExecutorService _timer; + private Scheduler _scheduler; @Before public void init() throws Exception { _server = new Server(); - _timer = new ScheduledThreadPoolExecutor(1); - LocalConnector connector = new LocalConnector(_server, null, _timer, null, null, 1); + _scheduler = new SimpleScheduler(); + LocalConnector connector = new LocalConnector(_server, null, _scheduler, null, null, 1); _server.addConnector(connector); _server.setHandler(new DumpHandler()); _server.start(); - AbstractEndPoint endp = new ByteArrayEndPoint(_timer, 5000); + AbstractEndPoint endp = new ByteArrayEndPoint(_scheduler, 5000); ByteBufferHttpInput input = new ByteBufferHttpInput(); _channel = new HttpChannel(connector, new HttpConfiguration(null, false), endp, new HttpTransport() { @@ -96,7 +97,6 @@ public class ResponseTest { _server.stop(); _server.join(); - _timer.shutdownNow(); } @Test diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelStatisticsTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelStatisticsTest.java index b57e593833e..faa824b12fb 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelStatisticsTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelStatisticsTest.java @@ -18,6 +18,9 @@ package org.eclipse.jetty.server; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; @@ -25,6 +28,7 @@ import java.io.PrintWriter; import java.net.Socket; import java.util.concurrent.CountDownLatch; import java.util.concurrent.CyclicBarrier; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -41,9 +45,6 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - public class SelectChannelStatisticsTest { private static final Logger LOG = Log.getLogger(SelectChannelStatisticsTest.class); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelTimeoutTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelTimeoutTest.java index a7cdfc94310..d91cf2cb539 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelTimeoutTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelTimeoutTest.java @@ -18,6 +18,8 @@ package org.eclipse.jetty.server; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; @@ -28,8 +30,6 @@ import org.eclipse.jetty.util.IO; import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.assertTrue; - public class SelectChannelTimeoutTest extends ConnectorTimeoutTest { @Before diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/SlowClientWithPipelinedRequestTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/SlowClientWithPipelinedRequestTest.java index bf55b5a7a78..9f079837079 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/SlowClientWithPipelinedRequestTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/SlowClientWithPipelinedRequestTest.java @@ -18,6 +18,8 @@ package org.eclipse.jetty.server; +import static org.hamcrest.Matchers.lessThan; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -26,6 +28,7 @@ import java.nio.ByteBuffer; import java.nio.channels.SocketChannel; import java.util.Arrays; import java.util.concurrent.atomic.AtomicInteger; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -38,8 +41,6 @@ import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; -import static org.hamcrest.Matchers.lessThan; - public class SlowClientWithPipelinedRequestTest { private final AtomicInteger handles = new AtomicInteger(); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/StressTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/StressTest.java index 31f237d5e6f..6e3dc8eeb1c 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/StressTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/StressTest.java @@ -18,12 +18,17 @@ package org.eclipse.jetty.server; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeTrue; + import java.io.IOException; import java.net.Socket; import java.util.Queue; import java.util.Random; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.atomic.AtomicInteger; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -41,11 +46,7 @@ import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; - -@Ignore("Ignore until other tests are working") +@Ignore public class StressTest { private static final Logger LOG = Log.getLogger(StressTest.class); @@ -119,6 +120,13 @@ public class StressTest q.clear(); } + + @Test + public void testMinNonPersistent() throws Throwable + { + doThreads(2,2,false); + } + @Test public void testNonPersistent() throws Throwable { diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/SuspendHandler.java b/jetty-server/src/test/java/org/eclipse/jetty/server/SuspendHandler.java index aafaef02ff3..c15ab9ca64f 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/SuspendHandler.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/SuspendHandler.java @@ -20,6 +20,7 @@ package org.eclipse.jetty.server; import java.io.IOException; import java.io.InputStream; + import javax.servlet.AsyncContext; import javax.servlet.AsyncEvent; import javax.servlet.AsyncListener; diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ContextHandlerCollectionTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ContextHandlerCollectionTest.java index 895375d340d..589b7a08821 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ContextHandlerCollectionTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ContextHandlerCollectionTest.java @@ -18,7 +18,12 @@ package org.eclipse.jetty.server.handler; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import java.io.IOException; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -29,10 +34,6 @@ import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Server; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - public class ContextHandlerCollectionTest { @Test diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ContextHandlerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ContextHandlerTest.java index 49562d89d89..0831e44d9b7 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ContextHandlerTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ContextHandlerTest.java @@ -18,12 +18,18 @@ package org.eclipse.jetty.server.handler; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.List; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -37,11 +43,6 @@ import org.hamcrest.Matchers; import org.junit.Assert; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - /** * @version $Revision$ */ diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/IPAccessHandlerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/IPAccessHandlerTest.java index 19d2d2a4fb6..c9e412d0e29 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/IPAccessHandlerTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/IPAccessHandlerTest.java @@ -18,6 +18,9 @@ package org.eclipse.jetty.server.handler; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.io.BufferedReader; import java.io.EOFException; import java.io.IOException; @@ -30,6 +33,7 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -47,9 +51,6 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - @RunWith(Parameterized.class) public class IPAccessHandlerTest { diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ResourceHandlerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ResourceHandlerTest.java index f5a84b756a5..ac6f360e885 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ResourceHandlerTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ResourceHandlerTest.java @@ -22,6 +22,7 @@ import java.net.URI; import junit.framework.Assert; import junit.framework.TestCase; + import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.SelectChannelConnector; import org.eclipse.jetty.server.Server; diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ScopedHandlerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ScopedHandlerTest.java index 4c8f98ab355..3199ab82495 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ScopedHandlerTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ScopedHandlerTest.java @@ -18,7 +18,10 @@ package org.eclipse.jetty.server.handler; +import static org.junit.Assert.assertEquals; + import java.io.IOException; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -27,8 +30,6 @@ import org.eclipse.jetty.server.Request; import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.assertEquals; - public class ScopedHandlerTest { private StringBuilder _history=new StringBuilder(); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ShutdownHandlerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ShutdownHandlerTest.java index fa519bbfbfd..b5c32d77df7 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ShutdownHandlerTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ShutdownHandlerTest.java @@ -18,8 +18,13 @@ package org.eclipse.jetty.server.handler; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; + import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -31,10 +36,6 @@ import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.when; - public class ShutdownHandlerTest { @Mock private HttpServletRequest request; diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/StatisticsHandlerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/StatisticsHandlerTest.java index c18d438ac94..c8adcab2901 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/StatisticsHandlerTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/StatisticsHandlerTest.java @@ -18,11 +18,17 @@ package org.eclipse.jetty.server.handler; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.IOException; import java.util.concurrent.CountDownLatch; import java.util.concurrent.CyclicBarrier; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -37,11 +43,6 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - public class StatisticsHandlerTest { private Server _server; diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/session/SessionCookieTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/session/SessionCookieTest.java index 71f4030b5d2..17193fcd5e8 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/session/SessionCookieTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/session/SessionCookieTest.java @@ -18,15 +18,15 @@ package org.eclipse.jetty.server.session; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import javax.servlet.SessionCookieConfig; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.eclipse.jetty.http.HttpCookie; import org.junit.Test; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; /** * SessionCookieTest * diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLCloseTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLCloseTest.java index a9fb86689e9..b01aca39f42 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLCloseTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLCloseTest.java @@ -26,6 +26,7 @@ import java.io.OutputStream; import java.net.Socket; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; + import javax.net.ssl.SSLContext; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; @@ -34,6 +35,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import junit.framework.TestCase; + import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Request; diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLEngineTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLEngineTest.java index bee5e1826bc..595d9d06863 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLEngineTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLEngineTest.java @@ -23,6 +23,11 @@ package org.eclipse.jetty.server.ssl; +import static org.hamcrest.Matchers.greaterThan; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -33,6 +38,7 @@ import java.net.HttpURLConnection; import java.net.Socket; import java.net.SocketTimeoutException; import java.net.URL; + import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLContext; @@ -56,11 +62,6 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; -import static org.hamcrest.Matchers.greaterThan; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; - /** * */ diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLSelectChannelConnectorLoadTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLSelectChannelConnectorLoadTest.java index 246e0955b84..f7bdbc83c5e 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLSelectChannelConnectorLoadTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLSelectChannelConnectorLoadTest.java @@ -32,6 +32,7 @@ import java.util.concurrent.SynchronousQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; + import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSocket; import javax.net.ssl.TrustManagerFactory; diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SelectChannelServerSslTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SelectChannelServerSslTest.java index 81ef6f254b2..f75da937278 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SelectChannelServerSslTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SelectChannelServerSslTest.java @@ -18,12 +18,15 @@ package org.eclipse.jetty.server.ssl; +import static org.junit.Assert.assertEquals; + import java.io.FileInputStream; import java.io.OutputStream; import java.net.Socket; import java.net.SocketException; import java.security.KeyStore; import java.util.Arrays; + import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLContext; import javax.net.ssl.TrustManagerFactory; @@ -37,8 +40,6 @@ import org.junit.Before; import org.junit.Ignore; import org.junit.Test; -import static org.junit.Assert.assertEquals; - /** * HttpServer Tester. */ diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslBytesServerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslBytesServerTest.java index 77908e9de69..e5afb0b8e71 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslBytesServerTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslBytesServerTest.java @@ -38,6 +38,7 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import java.util.regex.Matcher; import java.util.regex.Pattern; + import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSocket; import javax.servlet.ServletException; diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslSelectChannelTimeoutTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslSelectChannelTimeoutTest.java index 036727da2e3..84ad857d23f 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslSelectChannelTimeoutTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslSelectChannelTimeoutTest.java @@ -21,6 +21,7 @@ package org.eclipse.jetty.server.ssl; import java.io.FileInputStream; import java.net.Socket; import java.security.KeyStore; + import javax.net.ssl.SSLContext; import javax.net.ssl.TrustManagerFactory; diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslUploadTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslUploadTest.java index acea0dda80d..f6dbb4f3ded 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslUploadTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslUploadTest.java @@ -18,12 +18,16 @@ package org.eclipse.jetty.server.ssl; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.security.KeyStore; import java.util.Arrays; + import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSocket; import javax.net.ssl.TrustManagerFactory; @@ -42,9 +46,6 @@ import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - /** */ public class SslUploadTest diff --git a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/StandardSession.java b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/StandardSession.java index ec42f28003a..479c07125fe 100644 --- a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/StandardSession.java +++ b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/StandardSession.java @@ -33,7 +33,7 @@ import java.util.concurrent.ConcurrentMap; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.Executor; import java.util.concurrent.Future; -import java.util.concurrent.ScheduledExecutorService; + import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -76,6 +76,7 @@ import org.eclipse.jetty.util.component.AggregateLifeCycle; import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.util.thread.Scheduler; public class StandardSession implements ISession, Parser.Listener, Callback, Dumpable { @@ -95,7 +96,7 @@ public class StandardSession implements ISession, Parser.Listener, Callback queue = new LinkedList<>(); private final ByteBufferPool bufferPool; private final Executor threadPool; - private final ScheduledExecutorService scheduler; + private final Scheduler scheduler; private final short version; private final Controller controller; private final IdleListener idleListener; @@ -110,10 +111,12 @@ public class StandardSession implements ISession, Parser.Listener, Callback controller, IdleListener idleListener, int initialStreamId, SessionFrameListener listener, Generator generator, FlowControlStrategy flowControlStrategy) { + // TODO this should probably be an aggregate lifecycle + this.version = version; this.bufferPool = bufferPool; this.threadPool = threadPool; @@ -1145,7 +1148,7 @@ public class StandardSession implements ISession, Parser.Listener, Callback callback; private final C context; - protected volatile ScheduledFuture task; + protected volatile Scheduler.Task task; protected AbstractFrameBytes(IStream stream, Callback callback, C context) { @@ -1192,9 +1195,9 @@ public class StandardSession implements ISession, Parser.Listener, Callback task = this.task; + Scheduler.Task task = this.task; if (task != null) - task.cancel(false); + task.cancel(); } @Override diff --git a/jetty-spdy/spdy-core/src/test/java/org/eclipse/jetty/spdy/AsyncTimeoutTest.java b/jetty-spdy/spdy-core/src/test/java/org/eclipse/jetty/spdy/AsyncTimeoutTest.java index 324a5074480..60d60ac917b 100644 --- a/jetty-spdy/spdy-core/src/test/java/org/eclipse/jetty/spdy/AsyncTimeoutTest.java +++ b/jetty-spdy/spdy-core/src/test/java/org/eclipse/jetty/spdy/AsyncTimeoutTest.java @@ -22,7 +22,7 @@ import java.nio.ByteBuffer; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Executor; import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; + import java.util.concurrent.TimeUnit; import org.eclipse.jetty.io.ByteBufferPool; @@ -37,6 +37,8 @@ import org.eclipse.jetty.spdy.generator.Generator; import org.eclipse.jetty.toolchain.test.AdvancedRunner; import org.eclipse.jetty.toolchain.test.annotation.Slow; import org.eclipse.jetty.util.Callback; +import org.eclipse.jetty.util.thread.Scheduler; +import org.eclipse.jetty.util.thread.SimpleScheduler; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -53,7 +55,8 @@ public class AsyncTimeoutTest ByteBufferPool bufferPool = new MappedByteBufferPool(); Executor threadPool = Executors.newCachedThreadPool(); - ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); + Scheduler scheduler = new SimpleScheduler(); + scheduler.start(); // TODO need to use jetty lifecycles better here Generator generator = new Generator(bufferPool, new StandardCompressionFactory.StandardCompressor()); Session session = new StandardSession(SPDY.V2, bufferPool, threadPool, scheduler, new TestController(), null, 1, null, generator, new FlowControlStrategy.None()) { @@ -99,7 +102,8 @@ public class AsyncTimeoutTest ByteBufferPool bufferPool = new MappedByteBufferPool(); Executor threadPool = Executors.newCachedThreadPool(); - ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); + Scheduler scheduler = new SimpleScheduler(); + scheduler.start(); Generator generator = new Generator(bufferPool, new StandardCompressionFactory.StandardCompressor()); Session session = new StandardSession(SPDY.V2, bufferPool, threadPool, scheduler, new TestController(), null, 1, null, generator, new FlowControlStrategy.None()) { diff --git a/jetty-spdy/spdy-core/src/test/java/org/eclipse/jetty/spdy/StandardSessionTest.java b/jetty-spdy/spdy-core/src/test/java/org/eclipse/jetty/spdy/StandardSessionTest.java index 83fb82c4702..45ee8828745 100644 --- a/jetty-spdy/spdy-core/src/test/java/org/eclipse/jetty/spdy/StandardSessionTest.java +++ b/jetty-spdy/spdy-core/src/test/java/org/eclipse/jetty/spdy/StandardSessionTest.java @@ -24,7 +24,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executor; import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; + import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -48,6 +48,9 @@ import org.eclipse.jetty.spdy.frames.SynReplyFrame; import org.eclipse.jetty.spdy.frames.SynStreamFrame; import org.eclipse.jetty.spdy.generator.Generator; import org.eclipse.jetty.util.Callback; +import org.eclipse.jetty.util.thread.Scheduler; +import org.eclipse.jetty.util.thread.SimpleScheduler; +import org.junit.After; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -76,7 +79,7 @@ public class StandardSessionTest private Executor threadPool; private StandardSession session; private Generator generator; - private ScheduledExecutorService scheduler; + private Scheduler scheduler; private Headers headers; @Before @@ -84,11 +87,18 @@ public class StandardSessionTest { bufferPool = new MappedByteBufferPool(); threadPool = Executors.newCachedThreadPool(); - scheduler = Executors.newSingleThreadScheduledExecutor(); + scheduler = new SimpleScheduler(); + scheduler.start(); generator = new Generator(bufferPool, new StandardCompressionFactory.StandardCompressor()); session = new StandardSession(SPDY.V2,bufferPool,threadPool,scheduler,controller,null,1,null,generator,new FlowControlStrategy.None()); headers = new Headers(); } + + @After + public void after() throws Exception + { + scheduler.stop(); + } @SuppressWarnings("unchecked") private void setControllerWriteExpectationToFail(final boolean fail) diff --git a/jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/http/ServerHTTPSPDYConnectionFactory.java b/jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/http/ServerHTTPSPDYConnectionFactory.java index 12db87c674a..d35ad348053 100644 --- a/jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/http/ServerHTTPSPDYConnectionFactory.java +++ b/jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/http/ServerHTTPSPDYConnectionFactory.java @@ -20,7 +20,7 @@ package org.eclipse.jetty.spdy.http; import java.util.concurrent.Executor; -import java.util.concurrent.ScheduledExecutorService; + import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.EndPoint; @@ -37,6 +37,7 @@ import org.eclipse.jetty.spdy.api.SynInfo; import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.util.thread.Scheduler; public class ServerHTTPSPDYConnectionFactory extends ServerSPDYConnectionFactory { @@ -47,7 +48,7 @@ public class ServerHTTPSPDYConnectionFactory extends ServerSPDYConnectionFactory private final PushStrategy pushStrategy; private final HttpConfiguration configuration; - public ServerHTTPSPDYConnectionFactory(short version, ByteBufferPool bufferPool, Executor threadPool, ScheduledExecutorService scheduler, Connector connector, PushStrategy pushStrategy) + public ServerHTTPSPDYConnectionFactory(short version, ByteBufferPool bufferPool, Executor threadPool, Scheduler scheduler, Connector connector, PushStrategy pushStrategy) { super(version, bufferPool, threadPool, scheduler); this.connector = connector; diff --git a/jetty-spdy/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/SPDYClient.java b/jetty-spdy/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/SPDYClient.java index ed7f0e251f5..11e3b13b0c6 100644 --- a/jetty-spdy/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/SPDYClient.java +++ b/jetty-spdy/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/SPDYClient.java @@ -31,7 +31,7 @@ import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.Executor; import java.util.concurrent.Executors; import java.util.concurrent.Future; -import java.util.concurrent.ScheduledExecutorService; + import javax.net.ssl.SSLEngine; import org.eclipse.jetty.io.ByteBufferPool; @@ -50,6 +50,8 @@ import org.eclipse.jetty.spdy.parser.Parser; import org.eclipse.jetty.util.component.AggregateLifeCycle; import org.eclipse.jetty.util.ssl.SslContextFactory; import org.eclipse.jetty.util.thread.QueuedThreadPool; +import org.eclipse.jetty.util.thread.Scheduler; +import org.eclipse.jetty.util.thread.SimpleScheduler; public class SPDYClient { @@ -165,7 +167,7 @@ public class SPDYClient { private final Queue sessions = new ConcurrentLinkedQueue<>(); private final ByteBufferPool bufferPool = new MappedByteBufferPool(); - private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); + private final Scheduler scheduler = new SimpleScheduler(); private final Executor executor; private final SslContextFactory sslContextFactory; private final SelectorManager selector; @@ -193,6 +195,9 @@ public class SPDYClient public Factory(Executor executor, SslContextFactory sslContextFactory, long idleTimeout) { + // TODO make this injectable + addBean(scheduler); + this.idleTimeout = idleTimeout; if (executor == null) executor = new QueuedThreadPool(); @@ -205,6 +210,7 @@ public class SPDYClient selector = new ClientSelectorManager(); addBean(selector); + } public SPDYClient newSPDYClient(short version) diff --git a/jetty-spdy/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/ServerSPDYConnectionFactory.java b/jetty-spdy/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/ServerSPDYConnectionFactory.java index 01ba3b14822..be0f777dc85 100644 --- a/jetty-spdy/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/ServerSPDYConnectionFactory.java +++ b/jetty-spdy/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/ServerSPDYConnectionFactory.java @@ -20,7 +20,7 @@ package org.eclipse.jetty.spdy; import java.nio.channels.SocketChannel; import java.util.concurrent.Executor; -import java.util.concurrent.ScheduledExecutorService; + import java.util.concurrent.atomic.AtomicBoolean; import org.eclipse.jetty.io.ByteBufferPool; @@ -30,21 +30,22 @@ import org.eclipse.jetty.server.ConnectionFactory; import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener; import org.eclipse.jetty.spdy.generator.Generator; import org.eclipse.jetty.spdy.parser.Parser; +import org.eclipse.jetty.util.thread.Scheduler; public class ServerSPDYConnectionFactory implements ConnectionFactory { private final ByteBufferPool bufferPool; private final Executor executor; - private final ScheduledExecutorService scheduler; + private final Scheduler scheduler; private final short version; private final ServerSessionFrameListener listener; - public ServerSPDYConnectionFactory(short version, ByteBufferPool bufferPool, Executor executor, ScheduledExecutorService scheduler) + public ServerSPDYConnectionFactory(short version, ByteBufferPool bufferPool, Executor executor, Scheduler scheduler) { this(version, bufferPool, executor, scheduler, null); } - public ServerSPDYConnectionFactory(short version, ByteBufferPool bufferPool, Executor executor, ScheduledExecutorService scheduler, ServerSessionFrameListener listener) + public ServerSPDYConnectionFactory(short version, ByteBufferPool bufferPool, Executor executor, Scheduler scheduler, ServerSessionFrameListener listener) { this.version = version; this.bufferPool = bufferPool; @@ -98,7 +99,7 @@ public class ServerSPDYConnectionFactory implements ConnectionFactory return executor; } - public ScheduledExecutorService getScheduler() + public Scheduler getScheduler() { return scheduler; } diff --git a/jetty-spdy/spdy-jetty/src/test/java/org/eclipse/jetty/spdy/AbstractTest.java b/jetty-spdy/spdy-jetty/src/test/java/org/eclipse/jetty/spdy/AbstractTest.java index 39768d73b12..c5ba9af3860 100644 --- a/jetty-spdy/spdy-jetty/src/test/java/org/eclipse/jetty/spdy/AbstractTest.java +++ b/jetty-spdy/spdy-jetty/src/test/java/org/eclipse/jetty/spdy/AbstractTest.java @@ -100,6 +100,7 @@ public abstract class AbstractTest clientFactory = newSPDYClientFactory(threadPool); clientFactory.start(); } + return clientFactory.newSPDYClient(version).connect(socketAddress, listener).get(5, TimeUnit.SECONDS); } diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/ExecutorCallback.java b/jetty-util/src/main/java/org/eclipse/jetty/util/ExecutorCallback.java index 806cafd1471..657e021043d 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/ExecutorCallback.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/ExecutorCallback.java @@ -103,6 +103,14 @@ public abstract class ExecutorCallback implements Callback { @Override public void run() { onFailed(context,x);} + @Override + public String toString() + { + System.err.println(_executor); + new Throwable().printStackTrace(); + x.printStackTrace(); + return String.format("ExecutorCallback@%x{%s,%s}",hashCode(),context,x); + } }; if (_executor==null) diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/MultiPartInputStream.java b/jetty-util/src/main/java/org/eclipse/jetty/util/MultiPartInputStream.java index f22d0dcc38b..9fc88bea23e 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/MultiPartInputStream.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/MultiPartInputStream.java @@ -33,6 +33,7 @@ import java.io.OutputStream; import java.util.ArrayList; import java.util.Collection; import java.util.List; + import javax.servlet.MultipartConfigElement; import javax.servlet.ServletException; import javax.servlet.http.Part; diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java index 9ed7d113d6f..bc91ddc0c36 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java @@ -348,6 +348,7 @@ public class StdErrLog extends AbstractLogger * Legacy interface where a programmatic configuration of the logger level * is done as a wholesale approach. */ + @Override public void setDebugEnabled(boolean enabled) { if (enabled) diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/AliasedX509ExtendedKeyManager.java b/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/AliasedX509ExtendedKeyManager.java index 98d50494978..6e5bd761e12 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/AliasedX509ExtendedKeyManager.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/AliasedX509ExtendedKeyManager.java @@ -22,6 +22,7 @@ import java.net.Socket; import java.security.Principal; import java.security.PrivateKey; import java.security.cert.X509Certificate; + import javax.net.ssl.SSLEngine; import javax.net.ssl.X509ExtendedKeyManager; import javax.net.ssl.X509KeyManager; diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/AliasedX509KeyManager.java b/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/AliasedX509KeyManager.java index 488aad37885..9155bd667fe 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/AliasedX509KeyManager.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/AliasedX509KeyManager.java @@ -22,6 +22,7 @@ import java.net.Socket; import java.security.Principal; import java.security.PrivateKey; import java.security.cert.X509Certificate; + import javax.net.ssl.X509KeyManager; diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/SslContextFactory.java b/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/SslContextFactory.java index 999e3a12542..530f2742777 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/SslContextFactory.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/SslContextFactory.java @@ -41,6 +41,7 @@ import java.util.Collections; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; + import javax.net.ssl.CertPathTrustManagerParameters; import javax.net.ssl.KeyManager; import javax.net.ssl.KeyManagerFactory; diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ConcurrentScheduler.java b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ConcurrentScheduler.java new file mode 100644 index 00000000000..4fdbefd7b7a --- /dev/null +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ConcurrentScheduler.java @@ -0,0 +1,519 @@ +package org.eclipse.jetty.util.thread; + +import java.nio.channels.IllegalSelectorException; +import java.util.Comparator; +import java.util.Iterator; +import java.util.concurrent.ConcurrentSkipListSet; +import java.util.concurrent.Executor; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; + +import org.eclipse.jetty.util.component.AggregateLifeCycle; +import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.log.Logger; + +/*------------------------------------------------------------ */ +/** + * This is an experimental no-lock scheduler. + * It is optimized on the assumption that most timers either get cancelled quickly or last to expiry, thus + * events are initially queued in a constant time queue implemented with a no-lock FIFO. Events + * that are likely to be cancelled quickly will be removed from the delay list when they are cancelled. + * The events that survive the delay list are then queued for executiong using a ConcurrentSkipListSet to + * keep them ordered, but also to support cheap cancellations. + * + * More work is needed to see if this class is correct and really more efficient than the + * SimpleScheduler based on Timeout. + */ +public class ConcurrentScheduler extends AggregateLifeCycle implements Runnable, Scheduler +{ + private static final Logger LOG = Log.getLogger(ConcurrentScheduler.class); + private static final int MAX_SLEEP=1024; + private final Executor _executor; + private volatile Thread _runner; + + private final ConcurrentSkipListSet _timerQ=new ConcurrentSkipListSet<>(new Comparator() + { + @Override + public int compare(Event e1, Event e2) + { + return e1==e2?0:(e1._executeAt0 && interval>_delayQ._delay) + { + long dequeue_at = now + _delayQ._delay; + _delayQ.add(event,dequeue_at); + } + // else we schedule the event + else if (event._state.compareAndSet(State.NEW,State.SCHEDULED)) + { + _timerQ.add(event); + if (interval<=MAX_SLEEP) + { + Thread th=_runner; + if (th!=null) + th.interrupt(); + } + } + else + throw new IllegalSelectorException(); + } + } + + @Override + public void run() + { + try + { + _runner=Thread.currentThread(); + while(isRunning()) + { + try + { + // Work out how long to sleep for and execute expired events + long now=System.currentTimeMillis(); + long sleep=MAX_SLEEP; + + // Process delay Q + QNode next=_delayQ._head.next(); + + while (next!=null && !next.isTail()) + { + long dequeue_at = next._dequeueAt; + if (dequeue_at<=now) + { + Event event=next.dequeue(); + if (event!=null) + _timerQ.add(event); + } + else + { + long interval=dequeue_at-now; + if (interval i=_timerQ.iterator();i.hasNext();) + { + Event event=i.next(); + + // Is the event still scheduled? + if (!event.isScheduled()) + i.remove(); + + // is it ready to execute + else if (event._executeAt<=now) + { + i.remove(); + if (event._state.compareAndSet(State.SCHEDULED,State.DONE)) + { + _executor.execute(event._task); + } + } + // else how long do we need to wait? + else + { + long interval=event._executeAt-now; + if (interval0) + { + Thread.sleep(sleep); + } + } + catch(InterruptedException i) + { + LOG.ignore(i); + } + } + } + finally + { + _runner=null; + } + } + + + enum State { NEW, DELAYED, SCHEDULED, CANCELLED, DONE }; + + + private class Event implements Scheduler.Task + { + final Runnable _task; + final long _executeAt; + final AtomicReference _state=new AtomicReference<>(State.NEW); + volatile QNode _node; + + public Event(Runnable task, long executeAt) + { + super(); + _task = task; + _executeAt = executeAt; + } + + public boolean isScheduled() + { + return _state.get()==State.SCHEDULED; + } + + @Override + public boolean cancel() + { + while(true) + { + switch(_state.get()) + { + case NEW: + throw new IllegalStateException(); + + case DONE: + case CANCELLED: + return false; + case DELAYED: + if (_state.compareAndSet(State.DELAYED,State.CANCELLED)) + { + _node.cancel(); + return true; + } + break; + case SCHEDULED: + if (_state.compareAndSet(State.SCHEDULED,State.CANCELLED)) + { + _timerQ.remove(this); + return true; + } + break; + } + } + } + + @Override + public String toString() + { + return String.format("Event@%x{%s,%d,%s}",hashCode(),_state,_executeAt,_task); + } + } + + + + + private static class Queue + { + final int _delay; + final QNode _head = new QNode(null,0,null,null); + final QNode _tail = new QNode(null,0,null,null); + + Queue(int delay) + { + _delay=delay; + _head._next.set(_tail); + _tail._prev=_head; + } + + void clear() + { + _head._next.set(_tail); + _tail._prev=_head; + } + + void add(Event event, long dequeue_at) + { + if (event._state.compareAndSet(State.NEW,State.DELAYED)) + { + while (true) + { + QNode prev = _tail.prev(); + + if (prev!=null) + { + QNode node = new QNode(event,dequeue_at,prev,_tail); + if (prev._next.compareAndSet(_tail,node)) + { + _tail._prev=node; + event._node=node; + return; + } + } + } + } + else + throw new IllegalStateException(); + } + + @Override + public String toString() + { + StringBuilder b = new StringBuilder(); + b.append(String.format("Q@%x{%d,",hashCode(),_delay)); + b.append(_head); + QNode next=_head.next(); + if (next!=null && !next.isTail()) + { + b.append("->"); + b.append(next); + + next=next.next(); + if (next!=null && !next.isTail()) + b.append("..."); + } + + b.append("->"); + b.append(_tail); + b.append("}"); + return b.toString(); + } + } + + + /* ------------------------------------------------------------ */ + /** An Event in a constant time queue. + * Roughly based on public domain lock free queue algorithm from: + * http://www.java2s.com/Code/Java/Collections-Data-Structure/ConcurrentDoublyLinkedList.htm + */ + private static class QNode + { + /* These are invarients + * + * (1) next references are the ground truth. + * + * (2) next references to dead nodes can be improved by + * swinging them further forward around the dead node. + * + * (2.1) next references are still correct when pointing to dead nodes + * and next references from dead nodes are left as they were when the node + * was deleted. + * + * (2.2) multiple dead nodes may point forward to the same node. + * + * (3) backward pointers were correct when they were installed. + * + * (3.1) backward pointers are correct when pointing to any node which + * next reference points to them, but since more than one next reference + * may point to them, the live one is best. + * + * (4) backward pointers that are out of date due to deletion + * point to a deleted node, and need to point further back until they point + * to the live node that points to their source. + * + * (5) backward pointers from a dead node cannot be "improved" since there may be no live node pointing + * forward to their origin. (However, it does no harm to try to improve them + * while racing with a deletion.) + * + */ + + final Event _event; + final long _dequeueAt; + final AtomicReference _next=new AtomicReference<>(); + volatile QNode _prev; + + QNode(Event event, long dequeue_at, QNode prev, QNode next) + { + _event=event; + _dequeueAt=dequeue_at; + _prev=prev; + _next.set(next); + } + + + /** + * Returns the previous non-deleted event, patching up pointers as needed. + */ + QNode prev() + { + QNode event = this; + while(true) + { + QNode prev = event._prev; + + // If the event has no previous + if (prev == null) + // event must be head, so scan forward from it + // to find ourselves to determine the previous. + return event.scanForPrevOf(this); + + // If the previous next is this (still linked normally) + QNode prev_next = prev._next.get(); + if (prev_next==this) + return prev; + + if (prev_next==null || prev_next.isDelayed()) + { + QNode p = prev.scanForPrevOf(this); + if (p!=null) + return p; + } + + event = prev; + } + } + + + /** + * Returns the apparent predecessor of target by searching forward for + * it starting at this node, patching up pointers while traversing. Used + * by predecessor(). + * + * @return target's previous, or null if not found + */ + private QNode scanForPrevOf(QNode target) + { + QNode scan = this; + while (true) + { + QNode next = scan.next(); + if (next == target) + return scan; + if (next == null) + return null; + scan = next; + } + } + + + /** + * Returns the next non-deleted event, swinging next pointer around any + * encountered deleted events, and also patching up previous''s prev + * link to point back to this. Returns null if this event is trailer so + * has no successor. + * + * @return successor, or null if no such + */ + QNode next() + { + QNode next = _next.get(); + while (true) + { + if (next == null) + return null; + if (next.isDelayed() || next.isTail()) + { + if (next._prev != this && isDelayed()) + next._prev=this; + return next; + } + QNode next_next = next._next.get(); + _next.compareAndSet(next, next_next); + next = next_next; + } + } + + public boolean cancel() + { + if (_event._state.compareAndSet(State.DELAYED,State.CANCELLED)) + { + QNode prev = _prev; + QNode next = _next.get(); + if (prev != null && next != null && next.isDelayed()) + { + if (prev._next.compareAndSet(this, next)) + next._prev=prev; + } + return true; + } + return false; + } + + public Event dequeue() + { + if (_event._state.compareAndSet(State.DELAYED,State.SCHEDULED)) + { + QNode prev = _prev; + QNode next = _next.get(); + if (prev != null && next != null && next.isDelayed()) + { + if (prev._next.compareAndSet(this, next)) + next._prev=prev; + } + return _event; + } + return null; + } + + public boolean isDelayed() + { + return _event!=null && _event._state.get()==State.DELAYED; + } + + public boolean isTail() + { + return _event==null && _next.get()==null; + } + + + @Override + public String toString() + { + QNode p=_prev; + QNode n=_next.get(); + return String.format("QNode@%x{%x<-%s->%x}",hashCode(),p==null?0:p.hashCode(),_event,n==null?0:n.hashCode()); + } + } + +} diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/Scheduler.java b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/Scheduler.java new file mode 100644 index 00000000000..1229012413e --- /dev/null +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/Scheduler.java @@ -0,0 +1,15 @@ +package org.eclipse.jetty.util.thread; + +import java.util.concurrent.TimeUnit; + +import org.eclipse.jetty.util.component.LifeCycle; + +public interface Scheduler extends LifeCycle +{ + interface Task + { + boolean cancel(); + } + + Task schedule(Runnable task, long delay, TimeUnit units); +} diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/SimpleScheduler.java b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/SimpleScheduler.java new file mode 100644 index 00000000000..b4b4e521cf6 --- /dev/null +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/SimpleScheduler.java @@ -0,0 +1,77 @@ +package org.eclipse.jetty.util.thread; + +import java.util.Timer; +import java.util.TimerTask; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +import org.eclipse.jetty.util.component.AbstractLifeCycle; + +public class SimpleScheduler extends AbstractLifeCycle implements Scheduler +{ + /* this class uses the Timer class rather than an ScheduledExecutionService because + * it uses the same algorithm internally and the signature is cheaper to use as there are no + * Futures involved (which we do not need). + * However, Timer is still locking and a concurrent queue would be better. + */ + Timer _timer; + final String _name; + + public SimpleScheduler() + { + this(null); + } + + public SimpleScheduler(String name) + { + _name=name; + } + + @Override + protected void doStart() throws Exception + { + _timer=_name==null?new Timer():new Timer(_name); + super.doStart(); + } + + @Override + protected void doStop() throws Exception + { + _timer.cancel(); + super.doStop(); + _timer=null; + } + + @Override + public Task schedule(final Runnable task, final long delay, final TimeUnit units) + { + Timer timer=_timer; + if (timer!=null) + { + SimpleTask t = new SimpleTask(task); + _timer.schedule(t,units.toMillis(delay)); + return t; + } + throw new IllegalStateException("STOPPED: "+this); + } + + private static class SimpleTask extends TimerTask implements Task + { + private final Runnable _task; + + SimpleTask(Runnable runnable) + { + _task=runnable; + } + + @Override + public void run() + { + _task.run(); + } + } + + +} diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/Timeout.java b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/Timeout.java index 321e4510062..66353e050ca 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/Timeout.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/Timeout.java @@ -31,6 +31,7 @@ import org.eclipse.jetty.util.log.Logger; * The nested class Task should be extended by users of this class to obtain call back notification of * expires. */ +@Deprecated public class Timeout { private static final Logger LOG = Log.getLogger(Timeout.class); diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/ArrayQueueTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/ArrayQueueTest.java index 7cbd9e1a002..782e9473c62 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/ArrayQueueTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/ArrayQueueTest.java @@ -18,12 +18,12 @@ package org.eclipse.jetty.util; -import org.junit.Test; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import org.junit.Test; + public class ArrayQueueTest { diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/BlockingArrayQueueTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/BlockingArrayQueueTest.java index ea634b72e80..5080583e523 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/BlockingArrayQueueTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/BlockingArrayQueueTest.java @@ -18,6 +18,9 @@ package org.eclipse.jetty.util; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.util.HashSet; import java.util.Random; import java.util.concurrent.ConcurrentLinkedQueue; @@ -29,9 +32,6 @@ import org.eclipse.jetty.toolchain.test.annotation.Slow; import org.junit.Test; import org.junit.runner.RunWith; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - @RunWith(AdvancedRunner.class) public class BlockingArrayQueueTest { diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/BufferUtilTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/BufferUtilTest.java index 78e47e97893..6b878725b4f 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/BufferUtilTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/BufferUtilTest.java @@ -19,15 +19,15 @@ package org.eclipse.jetty.util; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.nio.ByteBuffer; import java.util.Arrays; import org.junit.Assert; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - public class BufferUtilTest { @Test diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/DateCacheTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/DateCacheTest.java index 1c1771e3b0f..a355524cf0e 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/DateCacheTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/DateCacheTest.java @@ -24,6 +24,7 @@ import java.util.TimeZone; import java.util.concurrent.TimeUnit; import junit.framework.Assert; + import org.eclipse.jetty.toolchain.test.AdvancedRunner; import org.eclipse.jetty.toolchain.test.annotation.Slow; import org.junit.Test; diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/IPAddressMapTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/IPAddressMapTest.java index b9af773d447..cc1cf04a586 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/IPAddressMapTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/IPAddressMapTest.java @@ -18,12 +18,12 @@ package org.eclipse.jetty.util; -import org.junit.Test; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import org.junit.Test; + public class IPAddressMapTest { diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/LazyListTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/LazyListTest.java index f38ea76a28f..ab01b72ed26 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/LazyListTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/LazyListTest.java @@ -18,6 +18,12 @@ package org.eclipse.jetty.util; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + import java.net.URI; import java.util.ArrayList; import java.util.Arrays; @@ -30,12 +36,6 @@ import java.util.ListIterator; import org.junit.Assume; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - /** * Tests for LazyList utility class. */ diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/MultiExceptionTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/MultiExceptionTest.java index 1fa82c4d9fa..e42943f3879 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/MultiExceptionTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/MultiExceptionTest.java @@ -18,13 +18,13 @@ package org.eclipse.jetty.util; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - public class MultiExceptionTest { diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/MultiMapTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/MultiMapTest.java index 369d27a3add..aba87c61d43 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/MultiMapTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/MultiMapTest.java @@ -18,6 +18,8 @@ package org.eclipse.jetty.util; +import static org.hamcrest.Matchers.nullValue; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -26,8 +28,6 @@ import java.util.Map; import org.junit.Assert; import org.junit.Test; -import static org.hamcrest.Matchers.nullValue; - public class MultiMapTest { /** diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/MultiPartInputStreamTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/MultiPartInputStreamTest.java index bac19ae1549..656f591889d 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/MultiPartInputStreamTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/MultiPartInputStreamTest.java @@ -18,24 +18,26 @@ package org.eclipse.jetty.util; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertThat; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.Collection; + import javax.servlet.MultipartConfigElement; import javax.servlet.ServletException; import javax.servlet.http.Part; import junit.framework.TestCase; -import org.eclipse.jetty.util.MultiPartInputStream.MultiPart; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertThat; +import org.eclipse.jetty.util.MultiPartInputStream.MultiPart; /** * MultiPartInputStreamTest diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/QuotedStringTokenizerTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/QuotedStringTokenizerTest.java index 884101280f4..3429df9138a 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/QuotedStringTokenizerTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/QuotedStringTokenizerTest.java @@ -18,12 +18,12 @@ package org.eclipse.jetty.util; -import org.junit.Test; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import org.junit.Test; + /** * diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/StringMapTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/StringMapTest.java index 3e8032bd133..0712b89a46b 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/StringMapTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/StringMapTest.java @@ -18,15 +18,15 @@ package org.eclipse.jetty.util; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import java.util.Set; import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - /** * diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/StringUtilTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/StringUtilTest.java index 8b7f75e8352..1169306f733 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/StringUtilTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/StringUtilTest.java @@ -18,12 +18,12 @@ package org.eclipse.jetty.util; -import junit.framework.Assert; -import org.junit.Test; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import junit.framework.Assert; + +import org.junit.Test; /** diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/TestIntrospectionUtil.java b/jetty-util/src/test/java/org/eclipse/jetty/util/TestIntrospectionUtil.java index a032dd48fbc..1969faf8f45 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/TestIntrospectionUtil.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/TestIntrospectionUtil.java @@ -18,15 +18,15 @@ package org.eclipse.jetty.util; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + import java.lang.reflect.Field; import java.lang.reflect.Method; import org.junit.BeforeClass; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - /** * TestInjection diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/URITest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/URITest.java index bf457dca928..9e7479ff82f 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/URITest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/URITest.java @@ -18,10 +18,10 @@ package org.eclipse.jetty.util; -import org.junit.Test; - import static org.junit.Assert.assertEquals; +import org.junit.Test; + /* ------------------------------------------------------------ */ /** Util meta Tests. diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/URLEncodedTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/URLEncodedTest.java index 0f55c91a013..dbeeb5658a5 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/URLEncodedTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/URLEncodedTest.java @@ -18,14 +18,14 @@ package org.eclipse.jetty.util; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.io.ByteArrayInputStream; import org.junit.Assert; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - /* ------------------------------------------------------------ */ /** Util meta Tests. diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/Utf8LineParserTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/Utf8LineParserTest.java index a8c8afd83a3..da583b6500a 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/Utf8LineParserTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/Utf8LineParserTest.java @@ -18,6 +18,9 @@ package org.eclipse.jetty.util; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.lessThan; + import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; @@ -25,9 +28,6 @@ import java.util.List; import org.junit.Assert; import org.junit.Test; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.lessThan; - public class Utf8LineParserTest { private void appendUtf8(ByteBuffer buf, String line) diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/Utf8StringBufferTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/Utf8StringBufferTest.java index 3e6d2d52534..e39eaff09d9 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/Utf8StringBufferTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/Utf8StringBufferTest.java @@ -18,13 +18,13 @@ package org.eclipse.jetty.util; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.io.UnsupportedEncodingException; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - public class Utf8StringBufferTest { @Test diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/Utf8StringBuilderTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/Utf8StringBuilderTest.java index 293b4116d3e..7a0d1830579 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/Utf8StringBuilderTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/Utf8StringBuilderTest.java @@ -18,12 +18,12 @@ package org.eclipse.jetty.util; -import org.junit.Assert; -import org.junit.Test; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import org.junit.Assert; +import org.junit.Test; + public class Utf8StringBuilderTest { @Test diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/component/AggregateLifeCycleTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/component/AggregateLifeCycleTest.java index f8c1c63d55c..43d541fa619 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/component/AggregateLifeCycleTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/component/AggregateLifeCycleTest.java @@ -24,6 +24,7 @@ import java.io.StringReader; import java.util.concurrent.atomic.AtomicInteger; import junit.framework.Assert; + import org.eclipse.jetty.util.TypeUtil; import org.junit.Test; diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/component/LifeCycleListenerTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/component/LifeCycleListenerTest.java index 83337e28b95..e412fccb382 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/component/LifeCycleListenerTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/component/LifeCycleListenerTest.java @@ -18,14 +18,14 @@ package org.eclipse.jetty.util.component; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.StdErrLog; -import org.junit.Test; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.log.StdErrLog; +import org.junit.Test; + public class LifeCycleListenerTest { diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/log/CapturingJULHandler.java b/jetty-util/src/test/java/org/eclipse/jetty/util/log/CapturingJULHandler.java index 5bd2179c7cd..a3d4bf5429c 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/log/CapturingJULHandler.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/log/CapturingJULHandler.java @@ -18,6 +18,8 @@ package org.eclipse.jetty.util.log; +import static org.hamcrest.Matchers.containsString; + import java.io.PrintWriter; import java.io.StringWriter; import java.util.logging.Handler; @@ -26,8 +28,6 @@ import java.util.logging.LogRecord; import org.eclipse.jetty.util.IO; import org.junit.Assert; -import static org.hamcrest.Matchers.containsString; - public class CapturingJULHandler extends Handler { private static final String LN = System.getProperty("line.separator"); diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/log/JavaUtilLogTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/log/JavaUtilLogTest.java index 09753b4bccd..722cc411dfe 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/log/JavaUtilLogTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/log/JavaUtilLogTest.java @@ -18,6 +18,8 @@ package org.eclipse.jetty.util.log; +import static org.hamcrest.Matchers.is; + import java.io.PrintWriter; import java.io.StringWriter; import java.util.logging.Handler; @@ -29,8 +31,6 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import static org.hamcrest.Matchers.is; - public class JavaUtilLogTest { private static Handler[] originalHandlers; diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrCapture.java b/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrCapture.java index 295a95ddd84..4d29f8de276 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrCapture.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrCapture.java @@ -18,14 +18,14 @@ package org.eclipse.jetty.util.log; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.not; + import java.io.ByteArrayOutputStream; import java.io.PrintStream; import org.junit.Assert; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; - public class StdErrCapture { private ByteArrayOutputStream test; diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrLogTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrLogTest.java index d12daa0b718..aac159a0814 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrLogTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrLogTest.java @@ -18,6 +18,9 @@ package org.eclipse.jetty.util.log; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.is; + import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.io.PrintWriter; @@ -29,9 +32,6 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.is; - /** * Tests for StdErrLog */ diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceCollectionTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceCollectionTest.java index 4b70ff76ab8..757a0b9cb00 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceCollectionTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceCollectionTest.java @@ -18,6 +18,9 @@ package org.eclipse.jetty.util.resource; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.io.BufferedReader; import java.io.File; import java.io.InputStreamReader; @@ -25,9 +28,6 @@ import java.io.InputStreamReader; import org.eclipse.jetty.util.IO; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - public class ResourceCollectionTest { diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceTest.java index 81e457e02f0..840939c7689 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceTest.java @@ -18,6 +18,11 @@ package org.eclipse.jetty.util.resource; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeTrue; + import java.io.File; import java.io.FilePermission; import java.io.FilenameFilter; @@ -35,11 +40,6 @@ import org.eclipse.jetty.util.IO; import org.junit.BeforeClass; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; - public class ResourceTest { diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/ssl/SslContextFactoryTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/ssl/SslContextFactoryTest.java index 15de00f8bf4..ec62d4a660c 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/ssl/SslContextFactoryTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/ssl/SslContextFactoryTest.java @@ -18,6 +18,11 @@ package org.eclipse.jetty.util.ssl; +import static junit.framework.Assert.assertTrue; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + import java.io.IOException; import java.io.InputStream; import java.security.KeyStore; @@ -30,11 +35,6 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import static junit.framework.Assert.assertTrue; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - public class SslContextFactoryTest { diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/statistic/SampleStatisticTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/statistic/SampleStatisticTest.java index db5b33ae2c9..ba133acb60e 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/statistic/SampleStatisticTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/statistic/SampleStatisticTest.java @@ -18,12 +18,12 @@ package org.eclipse.jetty.util.statistic; +import static org.junit.Assert.assertEquals; + import org.hamcrest.Matchers; import org.junit.Assert; import org.junit.Test; -import static org.junit.Assert.assertEquals; - /* ------------------------------------------------------------ */ public class SampleStatisticTest diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/QueuedThreadPoolTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/QueuedThreadPoolTest.java index 5714e030f4b..ea889a8e77b 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/QueuedThreadPoolTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/QueuedThreadPoolTest.java @@ -18,18 +18,19 @@ package org.eclipse.jetty.util.thread; +import static org.junit.Assert.assertTrue; + import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import junit.framework.Assert; + import org.eclipse.jetty.toolchain.test.AdvancedRunner; import org.eclipse.jetty.toolchain.test.annotation.Slow; import org.junit.Test; import org.junit.runner.RunWith; -import static org.junit.Assert.assertTrue; - @RunWith(AdvancedRunner.class) public class QueuedThreadPoolTest { diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/SchedulerTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/SchedulerTest.java new file mode 100644 index 00000000000..acfca5243ee --- /dev/null +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/SchedulerTest.java @@ -0,0 +1,204 @@ +package org.eclipse.jetty.util.thread; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Random; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; + +import org.eclipse.jetty.toolchain.test.annotation.Slow; +import org.eclipse.jetty.util.statistic.SampleStatistic; +import org.hamcrest.Matchers; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + + +@RunWith(value = Parameterized.class) +public class SchedulerTest +{ + @Parameterized.Parameters + public static Collection data() + { + Object[][] data = new Object[][]{ + {new SimpleScheduler()}, + {new ConcurrentScheduler(Executors.newCachedThreadPool(),2000)} + }; + return Arrays.asList(data); + } + + // Scheduler _scheduler=new SimpleScheduler(); + Scheduler _scheduler; + + public SchedulerTest(Scheduler scheduler) + { + _scheduler=scheduler; + } + + @Before + public void before() throws Exception + { + _scheduler.start(); + } + + @After + public void after() throws Exception + { + _scheduler.stop(); + } + + @Test + public void testExecution() throws Exception + { + final AtomicLong executed = new AtomicLong(); + long expected=System.currentTimeMillis()+3000; + Scheduler.Task task=_scheduler.schedule(new Runnable() + { + @Override + public void run() + { + executed.set(System.currentTimeMillis()); + } + },3000,TimeUnit.MILLISECONDS); + + Thread.sleep(4000); + Assert.assertFalse(task.cancel()); + Assert.assertThat(executed.get(),Matchers.greaterThanOrEqualTo(expected)); + Assert.assertThat(expected-executed.get(),Matchers.lessThan(1000L)); + + } + + @Test + public void testQuickCancel() throws Exception + { + final AtomicLong executed = new AtomicLong(); + Scheduler.Task task=_scheduler.schedule(new Runnable() + { + @Override + public void run() + { + executed.set(System.currentTimeMillis()); + } + },3000,TimeUnit.MILLISECONDS); + + Thread.sleep(100); + Assert.assertTrue(task.cancel()); + Thread.sleep(3500); + Assert.assertEquals(0,executed.get()); + } + + @Test + public void testLongCancel() throws Exception + { + final AtomicLong executed = new AtomicLong(); + Scheduler.Task task=_scheduler.schedule(new Runnable() + { + @Override + public void run() + { + executed.set(System.currentTimeMillis()); + } + },3000,TimeUnit.MILLISECONDS); + + Thread.sleep(2100); + Assert.assertTrue(task.cancel()); + Thread.sleep(1500); + Assert.assertEquals(0,executed.get()); + } + + + @Test + @Slow + public void testManySchedulesAndCancels() throws Exception + { + final Random random = new Random(); + Thread[] test = new Thread[2000]; + + final AtomicInteger schedules = new AtomicInteger(); + final SampleStatistic executions = new SampleStatistic(); + final SampleStatistic cancellations = new SampleStatistic(); + + for (int i=test.length;i-->0;) + { + test[i]=new Thread() + { + @Override + public void run() + { + try + { + long now = System.currentTimeMillis(); + long start=now; + long end=start+5000; + + while (now clients = new ConcurrentLinkedQueue<>(); private final WebSocketClientSelectorManager selector; - public ConnectionManager(ByteBufferPool bufferPool, Executor executor, ScheduledExecutorService scheduler, SslContextFactory sslContextFactory, + public ConnectionManager(ByteBufferPool bufferPool, Executor executor, Scheduler scheduler, SslContextFactory sslContextFactory, WebSocketPolicy policy) { selector = new WebSocketClientSelectorManager(bufferPool,executor,scheduler,policy); diff --git a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/io/UpgradeConnection.java b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/io/UpgradeConnection.java index e67889e767b..48de40bccfd 100644 --- a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/io/UpgradeConnection.java +++ b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/io/UpgradeConnection.java @@ -26,7 +26,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.concurrent.Executor; -import java.util.concurrent.ScheduledExecutorService; + import org.eclipse.jetty.io.AbstractConnection; import org.eclipse.jetty.io.ByteBufferPool; @@ -37,6 +37,7 @@ import org.eclipse.jetty.util.QuotedStringTokenizer; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.util.thread.Scheduler; import org.eclipse.jetty.websocket.api.Extension; import org.eclipse.jetty.websocket.api.UpgradeException; import org.eclipse.jetty.websocket.api.UpgradeResponse; @@ -82,7 +83,7 @@ public class UpgradeConnection extends AbstractConnection private static final Logger LOG = Log.getLogger(UpgradeConnection.class); private final ByteBufferPool bufferPool; - private final ScheduledExecutorService scheduler; + private final Scheduler scheduler; private final IWebSocketClient client; private final HttpResponseHeaderParser parser; private ClientUpgradeRequest request; diff --git a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/io/WebSocketClientSelectorManager.java b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/io/WebSocketClientSelectorManager.java index eaa88831431..6a9aef76283 100644 --- a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/io/WebSocketClientSelectorManager.java +++ b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/io/WebSocketClientSelectorManager.java @@ -22,7 +22,7 @@ import java.io.IOException; import java.nio.channels.SelectionKey; import java.nio.channels.SocketChannel; import java.util.concurrent.Executor; -import java.util.concurrent.ScheduledExecutorService; + import javax.net.ssl.SSLEngine; import org.eclipse.jetty.io.ByteBufferPool; @@ -34,6 +34,7 @@ import org.eclipse.jetty.io.ssl.SslConnection; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.ssl.SslContextFactory; +import org.eclipse.jetty.util.thread.Scheduler; import org.eclipse.jetty.websocket.api.WebSocketPolicy; import org.eclipse.jetty.websocket.client.WebSocketClientFactory; import org.eclipse.jetty.websocket.client.internal.IWebSocketClient; @@ -42,12 +43,12 @@ public class WebSocketClientSelectorManager extends SelectorManager { private static final Logger LOG = Log.getLogger(WebSocketClientSelectorManager.class); private final Executor executor; - private final ScheduledExecutorService scheduler; + private final Scheduler scheduler; private final WebSocketPolicy policy; private final ByteBufferPool bufferPool; private SslContextFactory sslContextFactory; - public WebSocketClientSelectorManager(ByteBufferPool bufferPool, Executor executor, ScheduledExecutorService scheduler, WebSocketPolicy policy) + public WebSocketClientSelectorManager(ByteBufferPool bufferPool, Executor executor, Scheduler scheduler, WebSocketPolicy policy) { super(); this.bufferPool = bufferPool; diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/io/AbstractWebSocketConnection.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/io/AbstractWebSocketConnection.java index b4a4ad83466..c69017da638 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/io/AbstractWebSocketConnection.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/io/AbstractWebSocketConnection.java @@ -24,7 +24,6 @@ import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; import java.util.concurrent.Executor; -import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -37,6 +36,7 @@ import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.FutureCallback; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.util.thread.Scheduler; import org.eclipse.jetty.websocket.api.BaseConnection; import org.eclipse.jetty.websocket.api.CloseException; import org.eclipse.jetty.websocket.api.StatusCode; @@ -58,7 +58,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp private static final Logger LOG_FRAMES = Log.getLogger("org.eclipse.jetty.websocket.io.Frames"); private final ByteBufferPool bufferPool; - private final ScheduledExecutorService scheduler; + private final Scheduler scheduler; private final Generator generator; private final Parser parser; private final WebSocketPolicy policy; @@ -69,7 +69,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp private boolean flushing; private boolean isFilling; - public AbstractWebSocketConnection(EndPoint endp, Executor executor, ScheduledExecutorService scheduler, WebSocketPolicy policy, ByteBufferPool bufferPool) + public AbstractWebSocketConnection(EndPoint endp, Executor executor, Scheduler scheduler, WebSocketPolicy policy, ByteBufferPool bufferPool) { super(endp,executor); this.policy = policy; @@ -199,7 +199,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp return getEndPoint().getRemoteAddress(); } - public ScheduledExecutorService getScheduler() + public Scheduler getScheduler() { return scheduler; } diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/io/FrameBytes.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/io/FrameBytes.java index 08cfe4a9dcd..f57f8fd4086 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/io/FrameBytes.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/io/FrameBytes.java @@ -26,6 +26,7 @@ import org.eclipse.jetty.io.EofException; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.util.thread.Scheduler; import org.eclipse.jetty.websocket.protocol.WebSocketFrame; public abstract class FrameBytes implements Callback, Runnable @@ -36,7 +37,7 @@ public abstract class FrameBytes implements Callback, Runnable protected final C context; protected final WebSocketFrame frame; // Task used to timeout the bytes - protected volatile ScheduledFuture task; + protected volatile Scheduler.Task task; protected FrameBytes(AbstractWebSocketConnection connection, Callback callback, C context, WebSocketFrame frame) { @@ -48,11 +49,9 @@ public abstract class FrameBytes implements Callback, Runnable private void cancelTask() { - ScheduledFuture task = this.task; + Scheduler.Task task = this.task; if (task != null) - { - task.cancel(false); - } + task.cancel(); } @Override diff --git a/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketServerConnection.java b/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketServerConnection.java index ce8b5c9ee01..acfabd75ad0 100644 --- a/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketServerConnection.java +++ b/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketServerConnection.java @@ -19,10 +19,11 @@ package org.eclipse.jetty.websocket.server; import java.util.concurrent.Executor; -import java.util.concurrent.ScheduledExecutorService; + import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.EndPoint; +import org.eclipse.jetty.util.thread.Scheduler; import org.eclipse.jetty.websocket.api.WebSocketPolicy; import org.eclipse.jetty.websocket.io.AbstractWebSocketConnection; @@ -31,7 +32,7 @@ public class WebSocketServerConnection extends AbstractWebSocketConnection private final WebSocketServerFactory factory; private boolean connected; - public WebSocketServerConnection(EndPoint endp, Executor executor, ScheduledExecutorService scheduler, WebSocketPolicy policy, + public WebSocketServerConnection(EndPoint endp, Executor executor, Scheduler scheduler, WebSocketPolicy policy, ByteBufferPool bufferPool, WebSocketServerFactory factory) { super(endp,executor,scheduler,policy,bufferPool); diff --git a/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketServerFactory.java b/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketServerFactory.java index 1c2cec86261..4e28360bef6 100644 --- a/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketServerFactory.java +++ b/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketServerFactory.java @@ -29,7 +29,7 @@ import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.Executor; import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -39,8 +39,11 @@ import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.server.HttpConnection; import org.eclipse.jetty.util.component.AbstractLifeCycle; +import org.eclipse.jetty.util.component.AggregateLifeCycle; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.util.thread.Scheduler; +import org.eclipse.jetty.util.thread.SimpleScheduler; import org.eclipse.jetty.websocket.annotations.WebSocket; import org.eclipse.jetty.websocket.api.Extension; import org.eclipse.jetty.websocket.api.ExtensionRegistry; @@ -61,7 +64,7 @@ import org.eclipse.jetty.websocket.server.handshake.HandshakeRFC6455; /** * Factory to create WebSocket connections */ -public class WebSocketServerFactory extends AbstractLifeCycle implements WebSocketCreator +public class WebSocketServerFactory extends AggregateLifeCycle implements WebSocketCreator { private static final Logger LOG = Log.getLogger(WebSocketServerFactory.class); @@ -75,7 +78,7 @@ public class WebSocketServerFactory extends AbstractLifeCycle implements WebSock /** * Have the factory maintain 1 and only 1 scheduler. All connections share this scheduler. */ - private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); + private final Scheduler scheduler = new SimpleScheduler(); private final String supportedVersions; private final WebSocketPolicy basePolicy; private final EventMethodsCache methodsCache; @@ -91,6 +94,9 @@ public class WebSocketServerFactory extends AbstractLifeCycle implements WebSock public WebSocketServerFactory(WebSocketPolicy policy, ByteBufferPool bufferPool) { + addBean(scheduler); + addBean(bufferPool); + this.basePolicy = policy; this.methodsCache = new EventMethodsCache(); this.bufferPool = bufferPool;