Fix remote repl state facade
This commit is contained in:
+2
-2
@@ -68,8 +68,8 @@ open class KotlinRemoteReplCompilerClient(
|
|||||||
RemoteReplCompilerState(compileService.replCreateState(sessionId).get(), lock)
|
RemoteReplCompilerState(compileService.replCreateState(sessionId).get(), lock)
|
||||||
|
|
||||||
override fun check(state: IReplStageState<*>, codeLine: ReplCodeLine): ReplCheckResult =
|
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 =
|
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()
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -25,7 +25,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock
|
|||||||
// TODO: verify that locla lock doesn't lead to any synch problems
|
// TODO: verify that locla lock doesn't lead to any synch problems
|
||||||
class RemoteReplCompilerStateHistory(private val state: RemoteReplCompilerState) : IReplStageHistory<Unit>, AbstractList<ReplHistoryRecord<Unit>>() {
|
class RemoteReplCompilerStateHistory(private val state: RemoteReplCompilerState) : IReplStageHistory<Unit>, AbstractList<ReplHistoryRecord<Unit>>() {
|
||||||
override val size: Int
|
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)
|
override fun get(index: Int): ReplHistoryRecord<Unit> = ReplHistoryRecord(state.replStateFacade.historyGet(index), Unit)
|
||||||
|
|
||||||
|
|||||||
+8
-2
@@ -18,13 +18,19 @@ package org.jetbrains.kotlin.daemon.common
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.cli.common.repl.ILineId
|
import org.jetbrains.kotlin.cli.common.repl.ILineId
|
||||||
import java.rmi.Remote
|
import java.rmi.Remote
|
||||||
|
import java.rmi.RemoteException
|
||||||
|
|
||||||
interface ReplStateFacade : Remote {
|
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
|
fun historyGet(index: Int): ILineId
|
||||||
|
|
||||||
|
@Throws(RemoteException::class)
|
||||||
fun historyResetTo(id: ILineId): List<ILineId>
|
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 compileAndEval(codeLine: ReplCodeLine, verifyHistory: List<ReplCodeLine>?): ReplEvalResult = ReplEvalResult.Error.Runtime("Eval is not supported on daemon")
|
||||||
|
|
||||||
fun createRemoteState(port: Int = portForServers): RemoteReplStateFacadeServer = statesLock.write {
|
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)
|
val stateFacade = RemoteReplStateFacadeServer(id, createState().asState(GenericReplCompilerState::class.java), port)
|
||||||
states.put(stateFacade, true)
|
states.put(stateFacade, true)
|
||||||
stateFacade
|
stateFacade
|
||||||
}
|
}
|
||||||
|
|
||||||
fun<R> withValidReplState(stateId: Int, body: (IReplStageState<*>) -> R): CompileService.CallResult<R> = statesLock.read {
|
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.Good(body(it.state))
|
||||||
}
|
}
|
||||||
?: CompileService.CallResult.Error("No REPL state with id $stateId found")
|
?: 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 org.jetbrains.kotlin.daemon.common.SOCKET_ANY_FREE_PORT
|
||||||
import java.rmi.server.UnicastRemoteObject
|
import java.rmi.server.UnicastRemoteObject
|
||||||
|
|
||||||
class RemoteReplStateFacadeServer(override val id: Int,
|
class RemoteReplStateFacadeServer(val _id: Int,
|
||||||
val state: GenericReplCompilerState,
|
val state: GenericReplCompilerState,
|
||||||
port: Int = SOCKET_ANY_FREE_PORT
|
port: Int = SOCKET_ANY_FREE_PORT
|
||||||
) : ReplStateFacade,
|
) : ReplStateFacade,
|
||||||
UnicastRemoteObject(port, LoopbackNetworkInterface.clientLoopbackSocketFactory, LoopbackNetworkInterface.serverLoopbackSocketFactory)
|
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
|
override fun historyGet(index: Int): ILineId = state.history[index].id
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user