/** * Creates a WebSocketServer that will attempt to bind/listen on the given <var>address</var>, and * comply with <tt>Draft</tt> version <var>draft</var>. * * @param address The address (host:port) this server should listen on. * @param decodercount The number of {@link WebSocketWorker}s that will be used to process the * incoming network data. By default this will be <code> * Runtime.getRuntime().availableProcessors()</code> * @param drafts The versions of the WebSocket protocol that this server instance should comply * to. Clients that use an other protocol version will be rejected. * @param connectionscontainer Allows to specify a collection that will be used to store the * websockets in. <br> * If you plan to often iterate through the currently connected websockets you may want to use * a collection that does not require synchronization like a {@link CopyOnWriteArraySet}. In * that case make sure that you overload {@link #removeConnection(WebSocket)} and {@link * #addConnection(WebSocket)}.<br> * By default a {@link HashSet} will be used. * @see #removeConnection(WebSocket) for more control over syncronized operation * @see <a href="https://github.com/TooTallNate/Java-WebSocket/wiki/Drafts" > more about drafts */ public WebSocketServer( InetSocketAddress address, int decodercount, List<Draft> drafts, Collection<WebSocket> connectionscontainer) { if (address == null || decodercount < 1 || connectionscontainer == null) { throw new IllegalArgumentException( "address and connectionscontainer must not be null and you need at least 1 decoder"); } if (drafts == null) this.drafts = Collections.emptyList(); else this.drafts = drafts; this.address = address; this.connections = connectionscontainer; oqueue = new LinkedBlockingQueue<WebSocketImpl>(); iqueue = new LinkedList<WebSocketImpl>(); decoders = new ArrayList<WebSocketWorker>(decodercount); buffers = new LinkedBlockingQueue<ByteBuffer>(); for (int i = 0; i < decodercount; i++) { WebSocketWorker ex = new WebSocketWorker(); decoders.add(ex); ex.start(); } }
public WebSocketServer(InetSocketAddress address, int decodercount, List<Draft> drafts) { if (drafts == null) this.drafts = Collections.emptyList(); else this.drafts = drafts; setAddress(address); oqueue = new LinkedBlockingQueue<WebSocketImpl>(); decoders = new ArrayList<WebSocketWorker>(decodercount); buffers = new LinkedBlockingQueue<ByteBuffer>(); for (int i = 0; i < decodercount; i++) { WebSocketWorker ex = new WebSocketWorker(); decoders.add(ex); ex.start(); } }