Fix remote repl state facade

This commit is contained in:
Ilya Chernikov
2017-02-07 12:50:39 +01:00
parent b23911fd59
commit 75234701c7
5 changed files with 17 additions and 9 deletions
@@ -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()
}
@@ -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<Unit>, AbstractList<ReplHistoryRecord<Unit>>() {
override val size: Int
get() = state.replStateFacade.historySize
get() = state.replStateFacade.getHistorySize()
override fun get(index: Int): ReplHistoryRecord<Unit> = ReplHistoryRecord(state.replStateFacade.historyGet(index), Unit)
@@ -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<ILineId>
}
@@ -150,14 +150,14 @@ open class KotlinJvmReplService(
fun compileAndEval(codeLine: ReplCodeLine, verifyHistory: List<ReplCodeLine>?): 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<R> withValidReplState(stateId: Int, body: (IReplStageState<*>) -> R): CompileService.CallResult<R> = 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")
@@ -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