diff --git a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketClient.java b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketClient.java index 0f9b61cfdb4..e3fb77a4b60 100644 --- a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketClient.java +++ b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketClient.java @@ -301,7 +301,7 @@ public class WebSocketClient /* ------------------------------------------------------------ */ /** The Future Websocket Connection. */ - private static class WebSocketFuture implements Future + static class WebSocketFuture implements Future { final WebSocket _websocket; final URI _uri; diff --git a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketClientFactory.java b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketClientFactory.java index 040c1be99ab..45d6d1d0ffd 100644 --- a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketClientFactory.java +++ b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketClientFactory.java @@ -2,22 +2,10 @@ package org.eclipse.jetty.websocket; import java.io.EOFException; import java.io.IOException; -import java.net.InetSocketAddress; import java.net.ProtocolException; -import java.net.URI; -import java.nio.channels.ByteChannel; import java.nio.channels.SelectionKey; import java.nio.channels.SocketChannel; -import java.util.List; -import java.util.Map; import java.util.Random; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; import org.eclipse.jetty.http.HttpFields; import org.eclipse.jetty.http.HttpParser; @@ -39,9 +27,11 @@ import org.eclipse.jetty.util.thread.ThreadPool; /* ------------------------------------------------------------ */ -/** WebSocket Client Factory. - * The WebSocketClientFactory contains the common mechanisms for multiple WebSocketClient instances (eg threadpool, NIO selector). - * WebSocketClients with different configurations should share the same factory to avoid wasted resources. +/** + *

WebSocketClientFactory contains the common components needed by multiple {@link WebSocketClient} instances + * (for example, a {@link ThreadPool}, a {@link SelectorManager NIO selector}, etc).

+ *

WebSocketClients with different configurations should share the same factory to avoid to waste resources.

+ * * @see WebSocketClient */ public class WebSocketClientFactory extends AggregateLifeCycle @@ -52,20 +42,22 @@ public class WebSocketClientFactory extends AggregateLifeCycle private final ThreadPool _threadPool; private final WebSocketClientSelector _selector; - private MaskGen _maskGen; private WebSocketBuffers _buffers; /* ------------------------------------------------------------ */ - /** Create a WebSocket Client with default configuration. + /** + *

Creates a WebSocketClientFactory with the default configuration.

*/ public WebSocketClientFactory() { - this(new QueuedThreadPool(),new RandomMaskGen(),16*1024); + this(new QueuedThreadPool()); } - + /* ------------------------------------------------------------ */ - /** Create a WebSocket Client with ThreadPool . + /** + *

Creates a WebSocketClientFactory with the given ThreadPool and the default configuration.

+ * @param threadPool the ThreadPool instance to use */ public WebSocketClientFactory(ThreadPool threadPool) { @@ -73,12 +65,15 @@ public class WebSocketClientFactory extends AggregateLifeCycle } /* ------------------------------------------------------------ */ - /** Create a WebSocket Client with shared threadpool. - * @param threadpool + /** + *

Creates a WebSocketClientFactory with the specified configuration.

+ * @param threadPool the ThreadPool instance to use + * @param maskGen the mask generator to use + * @param bufferSize the read buffer size */ - public WebSocketClientFactory(ThreadPool threadpool,MaskGen maskGen,int bufferSize) + public WebSocketClientFactory(ThreadPool threadPool,MaskGen maskGen,int bufferSize) { - _threadPool=threadpool; + _threadPool=threadPool; _selector=new WebSocketClientSelector(); _buffers=new WebSocketBuffers(bufferSize); _maskGen=maskGen; @@ -98,7 +93,7 @@ public class WebSocketClientFactory extends AggregateLifeCycle /* ------------------------------------------------------------ */ /** Get the ThreadPool. - *

Used to set/query the thread pool configuration. + * Used to set/query the thread pool configuration. * @return The {@link ThreadPool} */ public ThreadPool getThreadPool() @@ -107,39 +102,60 @@ public class WebSocketClientFactory extends AggregateLifeCycle } /* ------------------------------------------------------------ */ + /** + * @return the shared mask generator, or null if no shared mask generator is used + * @see {@link WebSocketClient#getMaskGen()} + */ public MaskGen getMaskGen() { return _maskGen; } - + /* ------------------------------------------------------------ */ + /** + * @param maskGen the shared mask generator, or null if no shared mask generator is used + * @see {@link WebSocketClient#setMaskGen(MaskGen)} + */ public void setMaskGen(MaskGen maskGen) { if (isRunning()) throw new IllegalStateException(getState()); _maskGen=maskGen; } - + /* ------------------------------------------------------------ */ + /** + * @param bufferSize the read buffer size + * @see #getBufferSize() + */ public void setBufferSize(int bufferSize) { if (isRunning()) throw new IllegalStateException(getState()); _buffers=new WebSocketBuffers(bufferSize); } - + /* ------------------------------------------------------------ */ + /** + * @return the read buffer size + */ public int getBufferSize() { return _buffers.getBufferSize(); } - + /* ------------------------------------------------------------ */ + /** + *

Creates and returns a new instance of a {@link WebSocketClient}, configured with this + * WebSocketClientFactory instance.

+ * + * @return a new {@link WebSocketClient} instance + */ public WebSocketClient newWebSocketClient() { return new WebSocketClient(this); } - + /* ------------------------------------------------------------ */ @Override protected void doStart() throws Exception @@ -303,7 +319,7 @@ public class WebSocketClientFactory extends AggregateLifeCycle path="/"; String origin = future.getOrigin(); - + String request= "GET "+path+" HTTP/1.1\r\n"+ "Host: "+future.getURI().getHost()+":"+_holder.getURI().getPort()+"\r\n"+ @@ -402,8 +418,4 @@ public class WebSocketClientFactory extends AggregateLifeCycle _holder.handshakeFailed(new EOFException()); } } - - - - }