Skip to content
This repository has been archived by the owner on Aug 10, 2024. It is now read-only.

Commit

Permalink
* Asynchronicity was breaking outbound message order, remove it.
Browse files Browse the repository at this point in the history
* ktor was including logback-classic, which is bad practice for a library, will file a bug
  • Loading branch information
sanity committed Mar 15, 2017
1 parent 723415d commit 30253d1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 13 deletions.
14 changes: 10 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'com.github.sanity'
version '0.0.36'
version '0.0.37'

buildscript {
ext.kotlin_version = '1.1.1'
Expand Down Expand Up @@ -70,9 +70,15 @@ dependencies {
compile 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.12'
compile 'org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:0.12'

compile 'org.jetbrains.ktor:ktor-core:0.3.0'
compile 'org.jetbrains.ktor:ktor-netty:0.3.0'
compile 'org.jetbrains.ktor:ktor-websockets:0.3.0'
compile ('org.jetbrains.ktor:ktor-core:0.3.0') {
exclude group : 'ch.qos.logback', module : 'logback-classic'
}
compile ('org.jetbrains.ktor:ktor-netty:0.3.0') {
exclude group : 'ch.qos.logback', module : 'logback-classic'
}
compile('org.jetbrains.ktor:ktor-websockets:0.3.0') {
exclude group : 'ch.qos.logback', module : 'logback-classic'
}

compile 'io.github.microutils:kotlin-logging:1.4.2'

Expand Down
5 changes: 4 additions & 1 deletion src/main/kotlin/com/github/sanity/kweb/Kweb.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,13 @@ class Kweb(val port: Int,
thread.stackTrace.pruneAndDumpStackTo(logStatementBuilder)
val logStatement = logStatementBuilder.toString()
logger.warn { logStatement }
}) {buildPage(RootReceiver(newClientId, httpRequestInfo,this@Kweb))
}) {
buildPage(RootReceiver(newClientId, httpRequestInfo,this@Kweb))
logger.debug { "Outbound message queue size after buildPage is ${outboundBuffer.queueSize()}"}
}
} else {
buildPage(RootReceiver(newClientId, httpRequestInfo, this@Kweb))
logger.debug { "Outbound message queue size after buildPage is ${outboundBuffer.queueSize()}"}
}
for (plugin in plugins) {
execute(newClientId, plugin.executeAfterPageCreation())
Expand Down
8 changes: 3 additions & 5 deletions src/main/kotlin/com/github/sanity/kweb/RootReceiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package com.github.sanity.kweb

import com.github.sanity.kweb.dom.Document
import com.github.sanity.kweb.plugins.KWebPlugin
import kotlinx.coroutines.experimental.CommonPool
import kotlinx.coroutines.experimental.async
import org.jetbrains.ktor.util.ValuesMap
import java.util.concurrent.CompletableFuture
import kotlin.reflect.KClass
Expand All @@ -29,11 +27,11 @@ class RootReceiver(private val clientId: String, val httpRequestInfo: HttpReques
}
}

fun execute(js: String) = async(CommonPool){
fun execute(js: String) {
cc.execute(clientId, js)
}

fun executeWithCallback(js: String, callbackId: Int, callback: (String) -> Unit) = async(CommonPool){
fun executeWithCallback(js: String, callbackId: Int, callback: (String) -> Unit) {
cc.executeWithCallback(clientId, js, callbackId, callback)
}

Expand All @@ -47,7 +45,7 @@ class RootReceiver(private val clientId: String, val httpRequestInfo: HttpReques
}


fun evaluateWithCallback(js: String, rh: RootReceiver.() -> Boolean) = async(CommonPool){
fun evaluateWithCallback(js: String, rh: RootReceiver.() -> Boolean) {
cc.evaluate(clientId, js, { rh.invoke(RootReceiver(clientId, httpRequestInfo, cc, it)) })
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.github.sanity.kweb.browserConnection

import io.netty.channel.Channel
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame
import org.jetbrains.ktor.websocket.Frame
import org.jetbrains.ktor.websocket.WebSocket
import java.util.concurrent.ConcurrentLinkedQueue
Expand All @@ -28,5 +26,7 @@ sealed class OutboundChannel {
queue = null
return r
}

fun queueSize() = queue?.size
}
}
5 changes: 4 additions & 1 deletion src/main/kotlin/com/github/sanity/kweb/demos/async/async.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ package com.github.sanity.kweb.demos.async

import com.github.sanity.kweb.Kweb
import com.github.sanity.kweb.dom.element.creation.createElement
import com.github.sanity.kweb.dom.element.modification.setAttribute
import com.github.sanity.kweb.dom.element.modification.addText
import com.github.sanity.kweb.dom.element.modification.setAttribute
import com.github.sanity.kweb.dom.element.read.read
import kotlinx.coroutines.experimental.future.await
import kotlinx.coroutines.experimental.future.future
import mu.KotlinLogging

/**
* Created by ian on 1/11/17.
*/

private val logger = KotlinLogging.logger {}
fun main(args: Array<String>) {
println("Visit http://127.0.0.1:8091/ in your browser...")
Kweb(8091) {
Expand Down

0 comments on commit 30253d1

Please sign in to comment.