diff --git a/.ci/doc/test-snippet.sh b/.ci/doc/test-snippet.sh index f1785793..d259fceb 100755 --- a/.ci/doc/test-snippet.sh +++ b/.ci/doc/test-snippet.sh @@ -4,7 +4,7 @@ set -e if [ ${1: -3} == ".kt" ] then - cp /mnt/build/libs/sdk-jvm-[0-9+].[0-9+].[0-9+]-without-dependencies.jar /mnt/.ci/doc/kotlin-project/libs/ && cp $1 /mnt/.ci/doc/kotlin-project/src/main/java/SnippetTest.kt && cd /mnt/.ci/doc/kotlin-project/ && ./gradlew build && java -classpath 'libs/sdk-jvm-1.2.0-without-dependencies.jar:' -jar build/libs/project-1.jar + cp /mnt/build/libs/sdk-jvm-[0-9+].[0-9+].[0-9+]-without-dependencies.jar /mnt/.ci/doc/kotlin-project/libs/ && cp $1 /mnt/.ci/doc/kotlin-project/src/main/java/SnippetTest.kt && cd /mnt/.ci/doc/kotlin-project/ && ./gradlew build && java -classpath 'libs/sdk-jvm-1.2.1-without-dependencies.jar:' -jar build/libs/project-1.jar else - cp /mnt/build/libs/sdk-jvm-[0-9+].[0-9+].[0-9+]-without-dependencies.jar /mnt/.ci/doc/java-project/libs/ && cp $1 /mnt/.ci/doc/java-project/src/main/java/SnippetTest.java && cd /mnt/.ci/doc/java-project/ && ./gradlew build && java -classpath 'libs/jvm-1.2.0-without-dependencies.jar:' -jar build/libs/project-1.jar + cp /mnt/build/libs/sdk-jvm-[0-9+].[0-9+].[0-9+]-without-dependencies.jar /mnt/.ci/doc/java-project/libs/ && cp $1 /mnt/.ci/doc/java-project/src/main/java/SnippetTest.java && cd /mnt/.ci/doc/java-project/ && ./gradlew build && java -classpath 'libs/jvm-1.2.1-without-dependencies.jar:' -jar build/libs/project-1.jar fi diff --git a/README.md b/README.md index 99638f01..2d69f948 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ https://bintray.com/kuzzle/maven io.kuzzle sdk-jvm - 1.2.0 + 1.2.1 pom ``` @@ -54,19 +54,19 @@ https://bintray.com/kuzzle/maven ### Gradle ```groovy -compile 'io.kuzzle:sdk-jvm:1.2.0' +compile 'io.kuzzle:sdk-jvm:1.2.1' ``` For amd64: ```groovy -compile 'io.kuzzle:sdk-jvm:1.2.0' +compile 'io.kuzzle:sdk-jvm:1.2.1' ``` ### Ivy ```html - + ``` diff --git a/build.gradle.kts b/build.gradle.kts index 39822e9a..682dcb81 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -17,7 +17,7 @@ plugins { val artifactName = "sdk-jvm" val artifactGroup = "io.kuzzle" -val artifactVersion = "1.2.0" +val artifactVersion = "1.2.1" val pomUrl = "https://github.com/kuzzleio/sdk-jvm" val pomScmUrl = "https://github.com/kuzzleio/sdk-jvm" @@ -35,7 +35,7 @@ val pomDeveloperId = "kuzzleio" val pomDeveloperName = "kuzzle" group = "io.kuzzle.sdk" -version = "1.2.0" +version = "1.2.1" val ktorVersion = "1.5.2" repositories { @@ -90,12 +90,12 @@ application { } tasks.withType { - archiveFileName.set("sdk-jvm-1.2.0-without-dependencies.jar") + archiveFileName.set("sdk-jvm-1.2.1-without-dependencies.jar") } tasks { register("fatJar", Jar::class.java) { - archiveFileName.set("sdk-jvm-1.2.0.jar") + archiveFileName.set("sdk-jvm-1.2.1.jar") duplicatesStrategy = DuplicatesStrategy.EXCLUDE manifest { attributes("Main-Class" to application.mainClassName) diff --git a/doc/1/controllers/document/upsert/index.md b/doc/1/controllers/document/upsert/index.md index 9be13286..7e364481 100644 --- a/doc/1/controllers/document/upsert/index.md +++ b/doc/1/controllers/document/upsert/index.md @@ -8,7 +8,7 @@ description: Applies partial changes to a document. If the document doesn't alre # upsert - + Applies partial changes to a document. If the document doesn't already exist, a new document is created. diff --git a/doc/1/getting-started/java/index.md b/doc/1/getting-started/java/index.md index 519f172a..975fd5db 100644 --- a/doc/1/getting-started/java/index.md +++ b/doc/1/getting-started/java/index.md @@ -61,7 +61,7 @@ To build the project, add the following lines: io.kuzzle sdk-jvm - 1.2.0 + 1.2.1 pom ``` @@ -75,14 +75,14 @@ repositories { } } dependencies { - compile 'io.kuzzle:sdk-jvm:1.2.0' + compile 'io.kuzzle:sdk-jvm:1.2.1' } ``` ### Ivy ```html - + ``` diff --git a/doc/1/getting-started/kotlin/index.md b/doc/1/getting-started/kotlin/index.md index 65a9e339..398123bd 100644 --- a/doc/1/getting-started/kotlin/index.md +++ b/doc/1/getting-started/kotlin/index.md @@ -73,7 +73,7 @@ To build the project, add the following lines: io.kuzzle sdk-jvm - 1.2.0 + 1.2.1 pom ``` @@ -87,14 +87,14 @@ repositories { } } dependencies { - compile 'io.kuzzle:sdk-jvm:1.2.0' + compile 'io.kuzzle:sdk-jvm:1.2.1' } ``` ### Ivy ```html - + ``` diff --git a/src/main/kotlin/io/kuzzle/sdk/protocol/WebSocket.kt b/src/main/kotlin/io/kuzzle/sdk/protocol/WebSocket.kt index a8ed63a2..b3ebedae 100644 --- a/src/main/kotlin/io/kuzzle/sdk/protocol/WebSocket.kt +++ b/src/main/kotlin/io/kuzzle/sdk/protocol/WebSocket.kt @@ -61,16 +61,24 @@ open class WebSocket : AbstractProtocol { this.reconnectionRetries = reconnectionRetries } - private fun tryToReconnect() { - if (retryCount < reconnectionRetries) { + private fun tryToReconnect(): Boolean { + if (!autoReconnect) + return false + + state = ProtocolState.RECONNECTING + trigger("networkStateChange", state.toString()) + + while (retryCount < reconnectionRetries) { retryCount++ - state = ProtocolState.RECONNECTING - trigger("networkStateChange", state.toString()) Thread.sleep(reconnectionDelay) - thread(start = true) { + try { connect() + return true + } catch (e: Exception) { + // Nothing to do, just retry } } + return false } @KtorExperimentalAPI @@ -81,6 +89,7 @@ open class WebSocket : AbstractProtocol { // @TODO Create enums for events state = ProtocolState.OPEN trigger("networkStateChange", ProtocolState.OPEN.toString()) + retryCount = 0 thread(start = true) { while (ws != null) { val payload = queue.poll() @@ -92,6 +101,7 @@ open class WebSocket : AbstractProtocol { } } wait.complete(null) + var reconnected = false try { for (frame in incoming) { when (frame) { @@ -102,11 +112,13 @@ open class WebSocket : AbstractProtocol { } } } catch (e: Exception) { - tryToReconnect() + reconnected = tryToReconnect() + } + if (!reconnected) { + state = ProtocolState.CLOSE + trigger("networkStateChange", ProtocolState.CLOSE.toString()) + ws = null } - state = ProtocolState.CLOSE - trigger("networkStateChange", ProtocolState.CLOSE.toString()) - ws = null } GlobalScope.launch { try { @@ -135,8 +147,15 @@ open class WebSocket : AbstractProtocol { is ConnectException, is SocketException, is IOException -> { - tryToReconnect() - wait.complete(null) + if (state != ProtocolState.RECONNECTING) { + if (!tryToReconnect()) { + wait.completeExceptionally(e) + } else { + wait.complete(null) + } + } else { + wait.completeExceptionally(e) + } } else -> throw e } }