Projects
home:jvle:branches:openEuler:24.03:Extra
libreoffice
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 71
View file
_service:tar_scm:Java-WebSocket-1.5.4.tar.gz/CHANGELOG.md -> _service:tar_scm:Java-WebSocket-1.5.6.tar.gz/CHANGELOG.md
Changed
@@ -1,6 +1,33 @@ # Change log ############################################################################### +## Version Release 1.5.6 (2024/02/06) + +#### Bugs Fixed + +* Issue 1382(https://github.com/TooTallNate/Java-WebSocket/issues/1382) - WebSocketClient.upgradeSocketToSSL is enforcing TLS 1.2 (PR 1387(https://github.com/TooTallNate/Java-WebSocket/pull/1387)) +* PR 1387(https://github.com/TooTallNate/Java-WebSocket/pull/1387) - Retrieve default SSL socket factory + +#### New Features + +* Issue 1390(https://github.com/TooTallNate/Java-WebSocket/issues/1390) - Thread created by NamedThreadFactory should be a daemon (PR 1391(https://github.com/TooTallNate/Java-WebSocket/pull/1391)) +* PR 1391(https://github.com/TooTallNate/Java-WebSocket/pull/1391) - Provide way to start the client/server as daemons + +In this release 2 issues and 2 pull requests were closed. + +############################################################################### + +## Version Release 1.5.5 (2023/12/18) + +#### Bugs Fixed + +* Issue 1365(https://github.com/TooTallNate/Java-WebSocket/issues/1365) - Hang on reconnectBlocking +* Issue 1364(https://github.com/TooTallNate/Java-WebSocket/issues/1364) - NPE during reconnect (PR 1367(https://github.com/TooTallNate/Java-WebSocket/pull/1367)) +* PR 1367(https://github.com/TooTallNate/Java-WebSocket/pull/1367) - Fix multiple issues related to reconnect + +In this release 2 issues and 1 pull request were closed. + +############################################################################### ## Version Release 1.5.4 (2023/07/20)
View file
_service:tar_scm:Java-WebSocket-1.5.4.tar.gz/README.markdown -> _service:tar_scm:Java-WebSocket-1.5.6.tar.gz/README.markdown
Changed
@@ -30,7 +30,7 @@ <dependency> <groupId>org.java-websocket</groupId> <artifactId>Java-WebSocket</artifactId> - <version>1.5.3</version> + <version>1.5.6</version> </dependency> ``` @@ -41,11 +41,11 @@ ``` Then you can just add the latest version to your build. ```xml -compile "org.java-websocket:Java-WebSocket:1.5.3" +compile "org.java-websocket:Java-WebSocket:1.5.6" ``` Or this option if you use gradle 7.0 and above. ```xml -implementation 'org.java-websocket:Java-WebSocket:1.5.3' +implementation 'org.java-websocket:Java-WebSocket:1.5.6' ``` #### Logging
View file
_service:tar_scm:Java-WebSocket-1.5.4.tar.gz/build.gradle -> _service:tar_scm:Java-WebSocket-1.5.6.tar.gz/build.gradle
Changed
@@ -10,7 +10,7 @@ } group = 'org.java-websocket' -version = '1.5.4-SNAPSHOT' +version = '1.5.6' sourceCompatibility = 1.7 targetCompatibility = 1.7 @@ -35,8 +35,8 @@ } dependencies { - implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25' - testImplementation group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25' + implementation group: 'org.slf4j', name: 'slf4j-api', version: '2.0.6' + testImplementation group: 'org.slf4j', name: 'slf4j-simple', version: '2.0.6' testImplementation group: 'junit', name: 'junit', version: '4.12' testImplementation group: 'org.json', name: 'json', version: '20180813' }
View file
_service:tar_scm:Java-WebSocket-1.5.4.tar.gz/pom.xml -> _service:tar_scm:Java-WebSocket-1.5.6.tar.gz/pom.xml
Changed
@@ -5,7 +5,7 @@ <groupId>org.java-websocket</groupId> <artifactId>Java-WebSocket</artifactId> <packaging>jar</packaging> - <version>1.5.4-SNAPSHOT</version> + <version>1.5.6</version> <name>Java-WebSocket</name> <description>A barebones WebSocket client and server implementation written 100% in Java</description> <url>https://github.com/TooTallNate/Java-WebSocket</url> @@ -26,7 +26,7 @@ <maven.javadoc.plugin.version>3.5.0</maven.javadoc.plugin.version> <maven.shade.plugin.version>3.4.1</maven.shade.plugin.version> <maven.source.plugin.version>3.2.1</maven.source.plugin.version> - <nexus.staging.maven.plugin.version>1.6.8</nexus.staging.maven.plugin.version> + <nexus.staging.maven.plugin.version>1.6.13</nexus.staging.maven.plugin.version> <sonar.projectKey>org.java-websocket:Java-WebSocket</sonar.projectKey> <sonar.organization>marci4-github</sonar.organization> <sonar.host.url>https://sonarcloud.io</sonar.host.url> @@ -156,6 +156,10 @@ <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version>${maven.javadoc.plugin.version}</version> + <configuration> + <sourcepath>src/main/java</sourcepath> + <additionalOptions>-Xdoclint:none</additionalOptions> + </configuration> <executions> <execution> <id>attach-javadocs</id> @@ -182,6 +186,7 @@ </goals> </execution> </executions> + </plugin> <plugin> <groupId>org.sonatype.plugins</groupId> @@ -250,7 +255,7 @@ <extensions>true</extensions> <configuration> <serverId>ossrh</serverId> - <autoReleaseAfterClose>true</autoReleaseAfterClose> + <autoReleaseAfterClose>false</autoReleaseAfterClose> <nexusUrl>https://oss.sonatype.org/</nexusUrl> </configuration> </plugin> @@ -261,72 +266,9 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> - </plugin> - </plugins> - </build> - </profile> - <profile> - <id>full</id> - <activation> - <activeByDefault>false</activeByDefault> - </activation> - <dependencies> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-simple</artifactId> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>biz.aQute.bnd</groupId> - <artifactId>bnd-maven-plugin</artifactId> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-shade-plugin</artifactId> - <executions> - <execution> - <phase>package</phase> - <goals> - <goal>shade</goal> - </goals> - <configuration> - <shadedArtifactAttached>true</shadedArtifactAttached> - <shadedClassifierName>with-dependencies</shadedClassifierName> - <transformers> - <transformer - implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer"> - <resource>simplelogger.properties</resource> - <file>src\main\example\simplelogger.properties</file> - </transformer> - </transformers> - </configuration> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-source-plugin</artifactId> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - <executions> - <execution> - <goals> - <goal>test-jar</goal> - </goals> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-javadoc-plugin</artifactId> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-gpg-plugin</artifactId> + <configuration> + <additionalOptions>-Xdoclint:none</additionalOptions> + </configuration> </plugin> </plugins> </build>
View file
_service:tar_scm:Java-WebSocket-1.5.4.tar.gz/src/main/java/org/java_websocket/AbstractWebSocket.java -> _service:tar_scm:Java-WebSocket-1.5.6.tar.gz/src/main/java/org/java_websocket/AbstractWebSocket.java
Changed
@@ -91,6 +91,13 @@ private boolean websocketRunning = false; /** + * Attribute to start internal threads as daemon + * + * @since 1.5.6 + */ + private boolean daemon = false; + + /** * Attribute to sync on */ private final Object syncConnectionLost = new Object(); @@ -182,7 +189,7 @@ private void restartConnectionLostTimer() { cancelConnectionLostTimer(); connectionLostCheckerService = Executors - .newSingleThreadScheduledExecutor(new NamedThreadFactory("connectionLostChecker")); + .newSingleThreadScheduledExecutor(new NamedThreadFactory("connectionLostChecker", daemon)); Runnable connectionLostChecker = new Runnable() { /** @@ -308,4 +315,25 @@ this.reuseAddr = reuseAddr; } + + /** + * Getter for daemon + * + * @return whether internal threads are spawned in daemon mode + * @since 1.5.6 + */ + public boolean isDaemon() { + return daemon; + } + + /** + * Setter for daemon + * <p> + * Controls whether or not internal threads are spawned in daemon mode + * + * @since 1.5.6 + */ + public void setDaemon(boolean daemon) { + this.daemon = daemon; + } }
View file
_service:tar_scm:Java-WebSocket-1.5.4.tar.gz/src/main/java/org/java_websocket/WebSocketAdapter.java -> _service:tar_scm:Java-WebSocket-1.5.6.tar.gz/src/main/java/org/java_websocket/WebSocketAdapter.java
Changed
@@ -99,7 +99,7 @@ * Default implementation for onPreparePing, returns a (cached) PingFrame that has no application * data. * - * @param conn The <tt>WebSocket</tt> connection from which the ping frame will be sent. + * @param conn The <code>WebSocket</code> connection from which the ping frame will be sent. * @return PingFrame to be sent. * @see org.java_websocket.WebSocketListener#onPreparePing(WebSocket) */
View file
_service:tar_scm:Java-WebSocket-1.5.4.tar.gz/src/main/java/org/java_websocket/WebSocketListener.java -> _service:tar_scm:Java-WebSocket-1.5.6.tar.gz/src/main/java/org/java_websocket/WebSocketListener.java
Changed
@@ -38,8 +38,8 @@ import org.java_websocket.handshake.ServerHandshakeBuilder; /** - * Implemented by <tt>WebSocketClient</tt> and <tt>WebSocketServer</tt>. The methods within are - * called by <tt>WebSocket</tt>. Almost every method takes a first parameter conn which represents + * Implemented by <code>WebSocketClient</code> and <code>WebSocketServer</code>. The methods within are + * called by <code>WebSocket</code>. Almost every method takes a first parameter conn which represents * the source of the respective event. */ public interface WebSocketListener { @@ -86,7 +86,7 @@ /** * Called when an entire text frame has been received. Do whatever you want here... * - * @param conn The <tt>WebSocket</tt> instance this event is occurring on. + * @param conn The <code>WebSocket</code> instance this event is occurring on. * @param message The UTF-8 decoded message that was received. */ void onWebsocketMessage(WebSocket conn, String message); @@ -94,7 +94,7 @@ /** * Called when an entire binary frame has been received. Do whatever you want here... * - * @param conn The <tt>WebSocket</tt> instance this event is occurring on. + * @param conn The <code>WebSocket</code> instance this event is occurring on. * @param blob The binary message that was received. */ void onWebsocketMessage(WebSocket conn, ByteBuffer blob); @@ -103,16 +103,16 @@ * Called after <var>onHandshakeReceived</var> returns <var>true</var>. Indicates that a complete * WebSocket connection has been established, and we are ready to send/receive data. * - * @param conn The <tt>WebSocket</tt> instance this event is occurring on. + * @param conn The <code>WebSocket</code> instance this event is occurring on. * @param d The handshake of the websocket instance */ void onWebsocketOpen(WebSocket conn, Handshakedata d); /** - * Called after <tt>WebSocket#close</tt> is explicity called, or when the other end of the + * Called after <code>WebSocket#close</code> is explicity called, or when the other end of the * WebSocket connection is closed. * - * @param ws The <tt>WebSocket</tt> instance this event is occurring on. + * @param ws The <code>WebSocket</code> instance this event is occurring on. * @param code The codes can be looked up here: {@link CloseFrame} * @param reason Additional information string * @param remote Returns whether or not the closing of the connection was initiated by the remote @@ -123,7 +123,7 @@ /** * Called as soon as no further frames are accepted * - * @param ws The <tt>WebSocket</tt> instance this event is occurring on. + * @param ws The <code>WebSocket</code> instance this event is occurring on. * @param code The codes can be looked up here: {@link CloseFrame} * @param reason Additional information string * @param remote Returns whether or not the closing of the connection was initiated by the remote @@ -134,7 +134,7 @@ /** * send when this peer sends a close handshake * - * @param ws The <tt>WebSocket</tt> instance this event is occurring on. + * @param ws The <code>WebSocket</code> instance this event is occurring on. * @param code The codes can be looked up here: {@link CloseFrame} * @param reason Additional information string */ @@ -144,7 +144,7 @@ * Called if an exception worth noting occurred. If an error causes the connection to fail onClose * will be called additionally afterwards. * - * @param conn The <tt>WebSocket</tt> instance this event is occurring on. + * @param conn The <code>WebSocket</code> instance this event is occurring on. * @param ex The exception that occurred. <br> Might be null if the exception is not related to * any specific connection. For example if the server port could not be bound. */ @@ -153,7 +153,7 @@ /** * Called a ping frame has been received. This method must send a corresponding pong by itself. * - * @param conn The <tt>WebSocket</tt> instance this event is occurring on. + * @param conn The <code>WebSocket</code> instance this event is occurring on. * @param f The ping frame. Control frames may contain payload. */ void onWebsocketPing(WebSocket conn, Framedata f); @@ -162,7 +162,7 @@ * Called just before a ping frame is sent, in order to allow users to customize their ping frame * data. * - * @param conn The <tt>WebSocket</tt> connection from which the ping frame will be sent. + * @param conn The <code>WebSocket</code> connection from which the ping frame will be sent. * @return PingFrame to be sent. */ PingFrame onPreparePing(WebSocket conn); @@ -170,7 +170,7 @@ /** * Called when a pong frame is received. * - * @param conn The <tt>WebSocket</tt> instance this event is occurring on. + * @param conn The <code>WebSocket</code> instance this event is occurring on. * @param f The pong frame. Control frames may contain payload. **/ void onWebsocketPong(WebSocket conn, Framedata f); @@ -179,19 +179,19 @@ * This method is used to inform the selector thread that there is data queued to be written to * the socket. * - * @param conn The <tt>WebSocket</tt> instance this event is occurring on. + * @param conn The <code>WebSocket</code> instance this event is occurring on. */ void onWriteDemand(WebSocket conn); /** - * @param conn The <tt>WebSocket</tt> instance this event is occurring on. + * @param conn The <code>WebSocket</code> instance this event is occurring on. * @return Returns the address of the endpoint this socket is bound to. * @see WebSocket#getLocalSocketAddress() */ InetSocketAddress getLocalSocketAddress(WebSocket conn); /** - * @param conn The <tt>WebSocket</tt> instance this event is occurring on. + * @param conn The <code>WebSocket</code> instance this event is occurring on. * @return Returns the address of the endpoint this socket is connected to, or{@code null} if it * is unconnected. * @see WebSocket#getRemoteSocketAddress()
View file
_service:tar_scm:Java-WebSocket-1.5.4.tar.gz/src/main/java/org/java_websocket/client/WebSocketClient.java -> _service:tar_scm:Java-WebSocket-1.5.6.tar.gz/src/main/java/org/java_websocket/client/WebSocketClient.java
Changed
@@ -45,7 +45,6 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import javax.net.SocketFactory; -import javax.net.ssl.SSLContext; import javax.net.ssl.SSLException; import javax.net.ssl.SSLParameters; import javax.net.ssl.SSLSession; @@ -343,10 +342,12 @@ closeBlocking(); if (writeThread != null) { this.writeThread.interrupt(); + this.writeThread.join(); this.writeThread = null; } if (connectReadThread != null) { this.connectReadThread.interrupt(); + this.connectReadThread.join(); this.connectReadThread = null; } this.draft.reset(); @@ -372,6 +373,7 @@ throw new IllegalStateException("WebSocketClient objects are not reuseable"); } connectReadThread = new Thread(this); + connectReadThread.setDaemon(isDaemon()); connectReadThread.setName("WebSocketConnectReadThread-" + connectReadThread.getId()); connectReadThread.start(); } @@ -505,7 +507,16 @@ throw e; } + if (writeThread != null) { + writeThread.interrupt(); + try { + writeThread.join(); + } catch (InterruptedException e) { + /* ignore */ + } + } writeThread = new Thread(new WebsocketWriteThread(this)); + writeThread.setDaemon(isDaemon()); writeThread.start(); byte rawbuffer = new byteWebSocketImpl.RCVBUF; @@ -523,7 +534,6 @@ onError(e); engine.closeConnection(CloseFrame.ABNORMAL_CLOSE, e.getMessage()); } - connectReadThread = null; } private void upgradeSocketToSSL() @@ -534,9 +544,7 @@ if (socketFactory instanceof SSLSocketFactory) { factory = (SSLSocketFactory) socketFactory; } else { - SSLContext sslContext = SSLContext.getInstance("TLSv1.2"); - sslContext.init(null, null, null); - factory = sslContext.getSocketFactory(); + factory = (SSLSocketFactory) SSLSocketFactory.getDefault(); } socket = factory.createSocket(socket, uri.getHost(), getPort(), true); } @@ -801,7 +809,6 @@ handleIOException(e); } finally { closeSocket(); - writeThread = null; } }
View file
_service:tar_scm:Java-WebSocket-1.5.4.tar.gz/src/main/java/org/java_websocket/server/WebSocketServer.java -> _service:tar_scm:Java-WebSocket-1.5.6.tar.gz/src/main/java/org/java_websocket/server/WebSocketServer.java
Changed
@@ -71,7 +71,7 @@ import org.slf4j.LoggerFactory; /** - * <tt>WebSocketServer</tt> is an abstract class that only takes care of the + * <code>WebSocketServer</code> is an abstract class that only takes care of the * HTTP handshake portion of WebSockets. It's up to a subclass to add functionality/purpose to the * server. */ @@ -183,7 +183,7 @@ /** * 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>. + * comply with <code>Draft</code> 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 @@ -245,7 +245,9 @@ if (selectorthread != null) { throw new IllegalStateException(getClass().getName() + " can only be started once."); } - new Thread(this).start(); + Thread t = new Thread(this); + t.setDaemon(isDaemon()); + t.start(); } public void stop(int timeout) throws InterruptedException { @@ -326,6 +328,20 @@ return port; } + @Override + public void setDaemon(boolean daemon) { + // pass it to the AbstractWebSocket too, to use it on the connectionLostChecker thread factory + super.setDaemon(daemon); + // we need to apply this to the decoders as well since they were created during the constructor + for (WebSocketWorker w : decoders) { + if (w.isAlive()) { + throw new IllegalStateException("Cannot call setDaemon after server is already started!"); + } else { + w.setDaemon(daemon); + } + } + } + /** * Get the list of active drafts * @@ -872,7 +888,7 @@ * Called after an opening handshake has been performed and the given websocket is ready to be * written on. * - * @param conn The <tt>WebSocket</tt> instance this event is occurring on. + * @param conn The <code>WebSocket</code> instance this event is occurring on. * @param handshake The handshake of the websocket instance */ public abstract void onOpen(WebSocket conn, ClientHandshake handshake); @@ -880,7 +896,7 @@ /** * Called after the websocket connection has been closed. * - * @param conn The <tt>WebSocket</tt> instance this event is occurring on. + * @param conn The <code>WebSocket</code> instance this event is occurring on. * @param code The codes can be looked up here: {@link CloseFrame} * @param reason Additional information string * @param remote Returns whether or not the closing of the connection was initiated by the remote @@ -891,7 +907,7 @@ /** * Callback for string messages received from the remote host * - * @param conn The <tt>WebSocket</tt> instance this event is occurring on. + * @param conn The <code>WebSocket</code> instance this event is occurring on. * @param message The UTF-8 decoded message that was received. * @see #onMessage(WebSocket, ByteBuffer) **/ @@ -919,7 +935,7 @@ /** * Callback for binary messages received from the remote host * - * @param conn The <tt>WebSocket</tt> instance this event is occurring on. + * @param conn The <code>WebSocket</code> instance this event is occurring on. * @param message The binary message that was received. * @see #onMessage(WebSocket, ByteBuffer) **/
View file
_service:tar_scm:Java-WebSocket-1.5.4.tar.gz/src/main/java/org/java_websocket/util/Base64.java -> _service:tar_scm:Java-WebSocket-1.5.6.tar.gz/src/main/java/org/java_websocket/util/Base64.java
Changed
@@ -35,7 +35,7 @@ * <br> * <code>byte myByteArray = Base64.decode( encoded );</code> * - * <p>The <tt>options</tt> parameter, which appears in a few places, is used to pass + * <p>The <code>options</code> parameter, which appears in a few places, is used to pass * several pieces of information to the encoder. In the "higher level" methods such as encodeBytes( * bytes, options ) the options parameter can be used to indicate such things as first gzipping the * bytes before encoding them, not inserting linefeeds, and encoding using the URL-safe and Ordered @@ -140,9 +140,9 @@ * when data that's being decoded is gzip-compressed and will decompress it * automatically. Generally things are cleaner. You'll probably have to * change some method calls that you were making to support the new - * options format (<tt>int</tt>s that you "OR" together).</li> + * options format (<code>int</code>s that you "OR" together).</li> * <li>v1.5.1 - Fixed bug when decompressing and decoding to a - * byte using <tt>decode( String s, boolean gzipCompressed )</tt>. + * byte using <code>decode( String s, boolean gzipCompressed )</code>. * Added the ability to "suspend" encoding in the Output Stream so * you can turn on and off the encoding if you need to embed base64 * data in an otherwise "normal" stream (like an XML file).</li> @@ -873,7 +873,7 @@ /** * A {@link Base64.OutputStream} will write data to another - * <tt>java.io.OutputStream</tt>, given in the constructor, + * <code>java.io.OutputStream</code>, given in the constructor, * and encode/decode to/from Base64 notation on the fly. * * @see Base64 @@ -895,7 +895,7 @@ /** * Constructs a {@link Base64.OutputStream} in ENCODE mode. * - * @param out the <tt>java.io.OutputStream</tt> to which data will be written. + * @param out the <code>java.io.OutputStream</code> to which data will be written. * @since 1.3 */ public OutputStream(java.io.OutputStream out) { @@ -914,7 +914,7 @@ * <p> * Example: <code>new Base64.OutputStream( out, Base64.ENCODE )</code> * - * @param out the <tt>java.io.OutputStream</tt> to which data will be written. + * @param out the <code>java.io.OutputStream</code> to which data will be written. * @param options Specified options. * @see Base64#ENCODE * @see Base64#DO_BREAK_LINES
View file
_service:tar_scm:Java-WebSocket-1.5.4.tar.gz/src/main/java/org/java_websocket/util/NamedThreadFactory.java -> _service:tar_scm:Java-WebSocket-1.5.6.tar.gz/src/main/java/org/java_websocket/util/NamedThreadFactory.java
Changed
@@ -34,14 +34,22 @@ private final ThreadFactory defaultThreadFactory = Executors.defaultThreadFactory(); private final AtomicInteger threadNumber = new AtomicInteger(1); private final String threadPrefix; + private final boolean daemon; public NamedThreadFactory(String threadPrefix) { this.threadPrefix = threadPrefix; + this.daemon = false; + } + + public NamedThreadFactory(String threadPrefix, boolean daemon) { + this.threadPrefix = threadPrefix; + this.daemon = daemon; } @Override public Thread newThread(Runnable runnable) { Thread thread = defaultThreadFactory.newThread(runnable); + thread.setDaemon(daemon); thread.setName(threadPrefix + "-" + threadNumber); return thread; }
View file
_service:tar_scm:Java-WebSocket-1.5.6.tar.gz/src/test/java/org/java_websocket/server/DaemonThreadTest.java
Added
@@ -0,0 +1,75 @@ +package org.java_websocket.server; + +import java.io.IOException; +import java.net.*; +import java.util.Set; +import java.util.concurrent.CountDownLatch; +import org.java_websocket.WebSocket; +import org.java_websocket.handshake.*; +import org.java_websocket.client.*; +import org.java_websocket.server.WebSocketServer; +import org.java_websocket.util.SocketUtil; +import org.junit.Test; +import static org.junit.Assert.assertTrue; + +public class DaemonThreadTest { + + @Test(timeout = 1000) + public void test_AllCreatedThreadsAreDaemon() throws Throwable { + + Set<Thread> threadSet1 = Thread.getAllStackTraces().keySet(); + final CountDownLatch ready = new CountDownLatch(1); + + WebSocketServer server = new WebSocketServer(new InetSocketAddress(SocketUtil.getAvailablePort())) { + @Override + public void onOpen(WebSocket conn, ClientHandshake handshake) {} + @Override + public void onClose(WebSocket conn, int code, String reason, boolean remote) {} + @Override + public void onMessage(WebSocket conn, String message) {} + @Override + public void onError(WebSocket conn, Exception ex) {} + @Override + public void onStart() {} + }; + server.setDaemon(true); + server.setDaemon(false); + server.setDaemon(true); + server.start(); + + WebSocketClient client = new WebSocketClient(URI.create("ws://localhost:" + server.getPort())) { + @Override + public void onOpen(ServerHandshake handshake) { + ready.countDown(); + } + @Override + public void onClose(int code, String reason, boolean remote) {} + @Override + public void onMessage(String message) {} + @Override + public void onError(Exception ex) {} + }; + client.setDaemon(false); + client.setDaemon(true); + client.connect(); + + ready.await(); + Set<Thread> threadSet2 = Thread.getAllStackTraces().keySet(); + threadSet2.removeAll(threadSet1); + + assertTrue("new threads created (no new threads indicates issue in test)", !threadSet2.isEmpty()); + + for (Thread t : threadSet2) + assertTrue(t.getName(), t.isDaemon()); + + boolean exception = false; + try { + server.setDaemon(false); + } catch(IllegalStateException e) { + exception = true; + } + assertTrue("exception was thrown when calling setDaemon on a running server", exception); + + server.stop(); + } +}
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2