You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Creates a WebSocketServer that will attempt to bind/listen on the given <var>address</var>,
129
+
* and comply with <tt>Draft</tt> version <var>draft</var>.
130
+
*
131
+
* @param address
132
+
* The address (host:port) this server should listen on.
133
+
* @param decodercount
134
+
* 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>
135
+
* @param drafts
136
+
* The versions of the WebSocket protocol that this server
137
+
* instance should comply to. Clients that use an other protocol version will be rejected.
138
+
*
139
+
* @param connectionscontainer
140
+
* Allows to specify a collection that will be used to store the websockets in. <br>
141
+
* 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.
142
+
*
143
+
* @see #removeConnection(WebSocket) for more control over syncronized operation
144
+
* @see <a href="https://github.com/TooTallNate/Java-WebSocket/wiki/Drafts" > more about drafts
@@ -462,10 +480,8 @@ public final void onWebsocketClose( WebSocket conn, int code, String reason, boo
462
480
oqueue.add( (WebSocketImpl) conn );// because the ostream will close the channel
463
481
selector.wakeup();
464
482
try {
465
-
synchronized ( connections ) {
466
-
if( this.connections.remove( conn ) ) {
467
-
onClose( conn, code, reason, remote );
468
-
}
483
+
if( removeConnection( conn ) ) {
484
+
onClose( conn, code, reason, remote );
469
485
}
470
486
} finally {
471
487
try {
@@ -477,6 +493,25 @@ public final void onWebsocketClose( WebSocket conn, int code, String reason, boo
477
493
478
494
}
479
495
496
+
/**
497
+
* This method performs remove operations on the connection and therefore also gives control over whether the operation shall be synchronized
498
+
* <p>
499
+
* {@link #WebSocketServer(InetSocketAddress, int, List, Collection)} allows to specify a collection which will be used to store current connections in.<br>
500
+
* Depending on the type on the connection, modifications of that collection may have to be synchronized.
501
+
**/
502
+
protectedbooleanremoveConnection( WebSocketws ) {
503
+
synchronized ( connections ) {
504
+
returnthis.connections.remove( ws );
505
+
}
506
+
}
507
+
508
+
/** @see #removeConnection(WebSocket) */
509
+
protectedbooleanaddConnection( WebSocketws ) {
510
+
synchronized ( connections ) {
511
+
returnthis.connections.add( ws );
512
+
}
513
+
}
514
+
480
515
/**
481
516
* @param conn
482
517
* may be null if the error does not belong to a single connection
0 commit comments