From 75234701c78143d35d0579105761850dc9f89ff4 Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Tue, 7 Feb 2017 12:50:39 +0100 Subject: [PATCH] Fix remote repl state facade --- .../daemon/client/KotlinRemoteReplCompilerClient.kt | 4 ++-- .../kotlin/daemon/client/RemoteReplCompilerState.kt | 2 +- .../jetbrains/kotlin/daemon/common/ReplStateFacade.kt | 10 ++++++++-- .../jetbrains/kotlin/daemon/KotlinRemoteReplService.kt | 4 ++-- .../kotlin/daemon/RemoteReplStateFacadeImpl.kt | 6 ++++-- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinRemoteReplCompilerClient.kt b/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinRemoteReplCompilerClient.kt index b0f1c8bdbc5..a68b61797aa 100644 --- a/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinRemoteReplCompilerClient.kt +++ b/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinRemoteReplCompilerClient.kt @@ -68,8 +68,8 @@ open class KotlinRemoteReplCompilerClient( RemoteReplCompilerState(compileService.replCreateState(sessionId).get(), lock) override fun check(state: IReplStageState<*>, codeLine: ReplCodeLine): ReplCheckResult = - compileService.replCheck(sessionId, state.asState(RemoteReplCompilerState::class.java).replStateFacade.id, codeLine).get() + compileService.replCheck(sessionId, state.asState(RemoteReplCompilerState::class.java).replStateFacade.getId(), codeLine).get() override fun compile(state: IReplStageState<*>, codeLine: ReplCodeLine): ReplCompileResult = - compileService.replCompile(sessionId, state.asState(RemoteReplCompilerState::class.java).replStateFacade.id, codeLine).get() + compileService.replCompile(sessionId, state.asState(RemoteReplCompilerState::class.java).replStateFacade.getId(), codeLine).get() } diff --git a/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/RemoteReplCompilerState.kt b/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/RemoteReplCompilerState.kt index 7c60d6da4e2..e16f050cfb2 100644 --- a/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/RemoteReplCompilerState.kt +++ b/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/RemoteReplCompilerState.kt @@ -25,7 +25,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock // TODO: verify that locla lock doesn't lead to any synch problems class RemoteReplCompilerStateHistory(private val state: RemoteReplCompilerState) : IReplStageHistory, AbstractList>() { override val size: Int - get() = state.replStateFacade.historySize + get() = state.replStateFacade.getHistorySize() override fun get(index: Int): ReplHistoryRecord = ReplHistoryRecord(state.replStateFacade.historyGet(index), Unit) diff --git a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/ReplStateFacade.kt b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/ReplStateFacade.kt index c4509bfc315..f9482a92fa4 100644 --- a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/ReplStateFacade.kt +++ b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/ReplStateFacade.kt @@ -18,13 +18,19 @@ package org.jetbrains.kotlin.daemon.common import org.jetbrains.kotlin.cli.common.repl.ILineId import java.rmi.Remote +import java.rmi.RemoteException interface ReplStateFacade : Remote { - val id: Int - val historySize: Int + @Throws(RemoteException::class) + fun getId(): Int + @Throws(RemoteException::class) + fun getHistorySize(): Int + + @Throws(RemoteException::class) fun historyGet(index: Int): ILineId + @Throws(RemoteException::class) fun historyResetTo(id: ILineId): List } \ No newline at end of file diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/KotlinRemoteReplService.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/KotlinRemoteReplService.kt index 26bc0e37d82..86450f02d4c 100644 --- a/compiler/daemon/src/org/jetbrains/kotlin/daemon/KotlinRemoteReplService.kt +++ b/compiler/daemon/src/org/jetbrains/kotlin/daemon/KotlinRemoteReplService.kt @@ -150,14 +150,14 @@ open class KotlinJvmReplService( fun compileAndEval(codeLine: ReplCodeLine, verifyHistory: List?): ReplEvalResult = ReplEvalResult.Error.Runtime("Eval is not supported on daemon") fun createRemoteState(port: Int = portForServers): RemoteReplStateFacadeServer = statesLock.write { - val id = getValidId(stateIdCounter) { id -> states.none { it.key.id == id} } + val id = getValidId(stateIdCounter) { id -> states.none { it.key.getId() == id} } val stateFacade = RemoteReplStateFacadeServer(id, createState().asState(GenericReplCompilerState::class.java), port) states.put(stateFacade, true) stateFacade } fun withValidReplState(stateId: Int, body: (IReplStageState<*>) -> R): CompileService.CallResult = statesLock.read { - states.keys.firstOrNull { it.id == stateId }?.let { + states.keys.firstOrNull { it.getId() == stateId }?.let { CompileService.CallResult.Good(body(it.state)) } ?: CompileService.CallResult.Error("No REPL state with id $stateId found") diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/RemoteReplStateFacadeImpl.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/RemoteReplStateFacadeImpl.kt index 3ae04737d88..5692042ca6b 100644 --- a/compiler/daemon/src/org/jetbrains/kotlin/daemon/RemoteReplStateFacadeImpl.kt +++ b/compiler/daemon/src/org/jetbrains/kotlin/daemon/RemoteReplStateFacadeImpl.kt @@ -23,13 +23,15 @@ import org.jetbrains.kotlin.daemon.common.ReplStateFacade import org.jetbrains.kotlin.daemon.common.SOCKET_ANY_FREE_PORT import java.rmi.server.UnicastRemoteObject -class RemoteReplStateFacadeServer(override val id: Int, +class RemoteReplStateFacadeServer(val _id: Int, val state: GenericReplCompilerState, port: Int = SOCKET_ANY_FREE_PORT ) : ReplStateFacade, UnicastRemoteObject(port, LoopbackNetworkInterface.clientLoopbackSocketFactory, LoopbackNetworkInterface.serverLoopbackSocketFactory) { - override val historySize: Int = state.history.size + override fun getId(): Int = _id + + override fun getHistorySize(): Int = state.history.size override fun historyGet(index: Int): ILineId = state.history[index].id