JB V8 debugger protocol — speedup scriptParsed event (part 1)

This commit is contained in:
Vladimir Krivosheev
2015-11-20 13:13:50 +01:00
parent 33117e2ffa
commit 22fa3cc16f
5 changed files with 19 additions and 30 deletions
@@ -17,6 +17,7 @@ package org.jetbrains.rpc
import com.intellij.openapi.diagnostic.Logger
import io.netty.buffer.ByteBuf
import org.jetbrains.concurrency.Promise
import org.jetbrains.jsonProtocol.Request
import java.util.concurrent.atomic.AtomicInteger
@@ -55,4 +56,12 @@ fun requestToByteBuf(message: Request<*>, isDebugEnabled: Boolean = LOG.isDebugE
interface ResultReader<RESPONSE> {
fun <RESULT> readResult(readMethodName: String, successResponse: RESPONSE): RESULT?
}
interface RequestCallback<SUCCESS_RESPONSE> {
fun onSuccess(response: SUCCESS_RESPONSE?, resultReader: ResultReader<SUCCESS_RESPONSE>?)
fun onError(error: Throwable)
fun onError(error: String) = onError(Promise.createError(error))
}
@@ -40,7 +40,9 @@ class MessageManager<REQUEST, INCOMING, INCOMING_WITH_SEQ : Any, SUCCESS>(privat
fun readIfHasSequence(incoming: INCOMING): INCOMING_WITH_SEQ?
fun getSequence(incomingWithSeq: INCOMING_WITH_SEQ): Int
fun getSequence(incomingWithSeq: INCOMING_WITH_SEQ): Int = throw AbstractMethodError()
fun getSequence(incomingWithSeq: INCOMING_WITH_SEQ, incoming: INCOMING) = getSequence(incomingWithSeq)
fun acceptNonSequence(incoming: INCOMING)
@@ -91,7 +93,7 @@ class MessageManager<REQUEST, INCOMING, INCOMING_WITH_SEQ : Any, SUCCESS>(privat
return
}
val callback = getCallbackAndRemove(handler.getSequence(commandResponse))
val callback = getCallbackAndRemove(handler.getSequence(commandResponse, incomingParsed))
if (rejectIfClosed(callback)) {
return
}
@@ -1,26 +0,0 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.rpc
import org.jetbrains.concurrency.Promise
interface RequestCallback<SUCCESS_RESPONSE> {
fun onSuccess(response: SUCCESS_RESPONSE?, resultReader: ResultReader<SUCCESS_RESPONSE>?)
fun onError(error: Throwable)
fun onError(error: String) = onError(Promise.createError(error))
}
@@ -243,7 +243,11 @@ internal class DomainGenerator(val generator: Generator, val domain: ProtocolMet
generateJsonProtocolInterface(className, event.description(), event.parameters(), object : TextOutConsumer {
override fun append(out: TextOutput) {
out.newLine().append("companion object TYPE : org.jetbrains.jsonProtocol.EventType<").append(fullName).append(", ").append(generator.naming.inputPackage).append('.').append(READER_INTERFACE_NAME).append('>')
out.append("(\"").append(domainName).append('.').append(event.name()).append("\")").block() {
out.append("(\"")
if (!domainName.isNullOrEmpty()) {
out.append(domainName).append('.')
}
out.append(event.name()).append("\")").block() {
out.append("override fun read(protocolReader: ")
out.append(generator.naming.inputPackage).append('.').append(READER_INTERFACE_NAME).append(", ").append(JSON_READER_PARAMETER_DEF).append(")")
out.append(" = protocolReader.").append(generator.naming.eventData.getParseMethodName(domainName, event.name())).append("(reader)")
@@ -82,7 +82,7 @@ private fun generate(configuration: GenerateConfiguration<*>, stringBuilder: Str
out.newLine().append("import org.jetbrains.io.JsonReaderEx")
out.newLine().newLine().append("import org.jetbrains.jsonProtocol.JsonReaders.*")
out.newLine().newLine().append("class ").append(configuration.className).space()
out.newLine().newLine().append("internal class ").append(configuration.className).space()
out.append(':').space().append(configuration.root.type.canonicalName).append(if (configuration.root.type.isInterface) "" else "()").openBlock(false)
val rootClassScope = fileScope.newClassScope()