Merging callback services into single facade - phase 1 - rearranging interfaces and implementations into target files

This commit is contained in:
Ilya Chernikov
2015-10-01 14:30:10 +02:00
parent be66c24467
commit 0f33633cc5
13 changed files with 205 additions and 254 deletions
@@ -0,0 +1,106 @@
/*
* Copyright 2010-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.kotlin.rmi.kotlinr
import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.incremental.components.ScopeKind
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents
import org.jetbrains.kotlin.load.kotlin.incremental.components.JvmPackagePartProto
import org.jetbrains.kotlin.modules.TargetId
import org.jetbrains.kotlin.progress.CompilationCanceledStatus
import org.jetbrains.kotlin.rmi.*
import java.rmi.server.UnicastRemoteObject
public class RemoteIncrementalCompilationComponentsServer(val base: IncrementalCompilationComponents, val port: Int = SOCKET_ANY_FREE_PORT) : RemoteIncrementalCompilationComponents {
init {
UnicastRemoteObject.exportObject(this, port, LoopbackNetworkInterface.clientLoopbackSocketFactory, LoopbackNetworkInterface.serverLoopbackSocketFactory)
}
private val cacheServers = hashMapOf<TargetId, RemoteIncrementalCacheServer>()
private val lookupTrackerServer by lazy { RemoteLookupTrackerServer(base.getLookupTracker()) }
override fun getIncrementalCache(target: TargetId): RemoteIncrementalCache =
cacheServers.get(target) ?: {
val newServer = RemoteIncrementalCacheServer(base.getIncrementalCache(target), port)
cacheServers.put(target, newServer)
newServer
}()
override fun getLookupTracker(): RemoteLookupTracker = lookupTrackerServer
}
public class RemoteIncrementalCacheServer(val cache: IncrementalCache, port: Int = SOCKET_ANY_FREE_PORT) : RemoteIncrementalCache {
init {
UnicastRemoteObject.exportObject(this, port, LoopbackNetworkInterface.clientLoopbackSocketFactory, LoopbackNetworkInterface.serverLoopbackSocketFactory)
}
override fun getObsoletePackageParts(): Collection<String> = cache.getObsoletePackageParts()
override fun getObsoleteMultifileClassFacades(): Collection<String> = cache.getObsoleteMultifileClasses()
override fun getMultifileFacadeParts(internalName: String): Collection<String>? = cache.getStableMultifileFacadeParts(internalName)
override fun getMultifileFacade(partInternalName: String): String? = cache.getMultifileFacade(partInternalName)
override fun getPackagePartData(fqName: String): JvmPackagePartProto? = cache.getPackagePartData(fqName)
override fun getModuleMappingData(): ByteArray? = cache.getModuleMappingData()
override fun registerInline(fromPath: String, jvmSignature: String, toPath: String) {
cache.registerInline(fromPath, jvmSignature, toPath)
}
override fun getClassFilePath(internalClassName: String): String = cache.getClassFilePath(internalClassName)
override fun close() {
cache.close()
}
public fun disconnect() {
UnicastRemoteObject.unexportObject(this, true)
}
}
public class RemoteLookupTrackerServer(val base: LookupTracker, port: Int = SOCKET_ANY_FREE_PORT) : RemoteLookupTracker {
init {
UnicastRemoteObject.exportObject(this, port, LoopbackNetworkInterface.clientLoopbackSocketFactory, LoopbackNetworkInterface.serverLoopbackSocketFactory)
}
override fun record(lookupContainingFile: String, lookupLine: Int?, lookupColumn: Int?, scopeFqName: String, scopeKind: ScopeKind, name: String) {
base.record(lookupContainingFile, lookupLine, lookupColumn, scopeFqName, scopeKind, name)
}
private val _isDoNothing: Boolean = base == LookupTracker.DO_NOTHING
override fun isDoNothing(): Boolean = _isDoNothing
}
public class RemoteCompilationCanceledStatusServer(val base: CompilationCanceledStatus, port: Int = SOCKET_ANY_FREE_PORT) : RemoteCompilationCanceledStatus {
init {
UnicastRemoteObject.exportObject(this, port, LoopbackNetworkInterface.clientLoopbackSocketFactory, LoopbackNetworkInterface.serverLoopbackSocketFactory)
}
override fun checkCanceled() {
base.checkCanceled()
}
}
@@ -139,8 +139,8 @@ public object KotlinCompilerClient {
}
fun makeRemoteServices(services: CompilationServices): CompileService.RemoteCompilationServices =
CompileService.RemoteCompilationServices(
fun makeRemoteServices(services: CompilationServices): RemoteCompilationServices =
RemoteCompilationServices(
incrementalCompilationComponents = if (services.incrementalCompilationComponents == null) null else RemoteIncrementalCompilationComponentsServer(services.incrementalCompilationComponents),
compilationCanceledStatus = if (services.compilationCanceledStatus == null) null else RemoteCompilationCanceledStatusServer(services.compilationCanceledStatus)
)
@@ -1,35 +0,0 @@
/*
* Copyright 2010-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.kotlin.rmi.kotlinr
import org.jetbrains.kotlin.progress.CompilationCanceledStatus
import org.jetbrains.kotlin.rmi.CompileService
import org.jetbrains.kotlin.rmi.LoopbackNetworkInterface
import org.jetbrains.kotlin.rmi.SOCKET_ANY_FREE_PORT
import java.rmi.server.UnicastRemoteObject
public class RemoteCompilationCanceledStatusServer(val base: CompilationCanceledStatus, port: Int = SOCKET_ANY_FREE_PORT) : CompileService.RemoteCompilationCanceledStatus {
init {
UnicastRemoteObject.exportObject(this, port, LoopbackNetworkInterface.clientLoopbackSocketFactory, LoopbackNetworkInterface.serverLoopbackSocketFactory)
}
override fun checkCanceled() {
base.checkCanceled()
}
}
@@ -1,57 +0,0 @@
/*
* Copyright 2010-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.kotlin.rmi.kotlinr
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache
import org.jetbrains.kotlin.load.kotlin.incremental.components.JvmPackagePartProto
import org.jetbrains.kotlin.rmi.CompileService
import org.jetbrains.kotlin.rmi.LoopbackNetworkInterface
import org.jetbrains.kotlin.rmi.SOCKET_ANY_FREE_PORT
import java.rmi.server.UnicastRemoteObject
public class RemoteIncrementalCacheServer(val cache: IncrementalCache, port: Int = SOCKET_ANY_FREE_PORT) : CompileService.RemoteIncrementalCache {
init {
UnicastRemoteObject.exportObject(this, port, LoopbackNetworkInterface.clientLoopbackSocketFactory, LoopbackNetworkInterface.serverLoopbackSocketFactory)
}
override fun getObsoletePackageParts(): Collection<String> = cache.getObsoletePackageParts()
override fun getObsoleteMultifileClassFacades(): Collection<String> = cache.getObsoleteMultifileClasses()
override fun getMultifileFacadeParts(internalName: String): Collection<String>? = cache.getStableMultifileFacadeParts(internalName)
override fun getMultifileFacade(partInternalName: String): String? = cache.getMultifileFacade(partInternalName)
override fun getPackagePartData(fqName: String): JvmPackagePartProto? = cache.getPackagePartData(fqName)
override fun getModuleMappingData(): ByteArray? = cache.getModuleMappingData()
override fun registerInline(fromPath: String, jvmSignature: String, toPath: String) {
cache.registerInline(fromPath, jvmSignature, toPath)
}
override fun getClassFilePath(internalClassName: String): String = cache.getClassFilePath(internalClassName)
override fun close() {
cache.close()
}
public fun disconnect() {
UnicastRemoteObject.unexportObject(this, true)
}
}
@@ -1,44 +0,0 @@
/*
* Copyright 2010-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.kotlin.rmi.kotlinr
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents
import org.jetbrains.kotlin.modules.TargetId
import org.jetbrains.kotlin.rmi.CompileService
import org.jetbrains.kotlin.rmi.LoopbackNetworkInterface
import org.jetbrains.kotlin.rmi.SOCKET_ANY_FREE_PORT
import java.rmi.server.UnicastRemoteObject
public class RemoteIncrementalCompilationComponentsServer(val base: IncrementalCompilationComponents, val port: Int = SOCKET_ANY_FREE_PORT) : CompileService.RemoteIncrementalCompilationComponents {
init {
UnicastRemoteObject.exportObject(this, port, LoopbackNetworkInterface.clientLoopbackSocketFactory, LoopbackNetworkInterface.serverLoopbackSocketFactory)
}
private val cacheServers = hashMapOf<TargetId, RemoteIncrementalCacheServer>()
private val lookupTrackerServer by lazy { RemoteLookupTrackerServer(base.getLookupTracker()) }
override fun getIncrementalCache(target: TargetId): CompileService.RemoteIncrementalCache =
cacheServers.get(target) ?: {
val newServer = RemoteIncrementalCacheServer(base.getIncrementalCache(target), port)
cacheServers.put(target, newServer)
newServer
}()
override fun getLookupTracker(): CompileService.RemoteLookupTracker = lookupTrackerServer
}
@@ -1,40 +0,0 @@
/*
* Copyright 2010-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.kotlin.rmi.kotlinr
import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.incremental.components.ScopeKind
import org.jetbrains.kotlin.rmi.CompileService
import org.jetbrains.kotlin.rmi.LoopbackNetworkInterface
import org.jetbrains.kotlin.rmi.SOCKET_ANY_FREE_PORT
import java.rmi.server.UnicastRemoteObject
public class RemoteLookupTrackerServer(val base: LookupTracker, port: Int = SOCKET_ANY_FREE_PORT) : CompileService.RemoteLookupTracker {
init {
UnicastRemoteObject.exportObject(this, port, LoopbackNetworkInterface.clientLoopbackSocketFactory, LoopbackNetworkInterface.serverLoopbackSocketFactory)
}
override fun record(lookupContainingFile: String, lookupLine: Int?, lookupColumn: Int?, scopeFqName: String, scopeKind: ScopeKind, name: String) {
base.record(lookupContainingFile, lookupLine, lookupColumn, scopeFqName, scopeKind, name)
}
private val _isDoNothing: Boolean = base == LookupTracker.DO_NOTHING
override fun isDoNothing(): Boolean = _isDoNothing
}
@@ -16,10 +16,6 @@
package org.jetbrains.kotlin.rmi
import org.jetbrains.kotlin.incremental.components.ScopeKind
import org.jetbrains.kotlin.load.kotlin.incremental.components.JvmPackagePartProto
import org.jetbrains.kotlin.modules.TargetId
import java.io.Serializable
import java.rmi.Remote
import java.rmi.RemoteException
@@ -30,67 +26,6 @@ public interface CompileService : Remote {
XML
}
public interface RemoteIncrementalCache : Remote {
@Throws(RemoteException::class)
public fun getObsoletePackageParts(): Collection<String>
@Throws(RemoteException::class)
public fun getObsoleteMultifileClassFacades(): Collection<String>
@Throws(RemoteException::class)
public fun getMultifileFacade(partInternalName: String): String?
@Throws(RemoteException::class)
public fun getPackagePartData(fqName: String): JvmPackagePartProto?
@Throws(RemoteException::class)
public fun getModuleMappingData(): ByteArray?
@Throws(RemoteException::class)
public fun registerInline(fromPath: String, jvmSignature: String, toPath: String)
@Throws(RemoteException::class)
fun getClassFilePath(internalClassName: String): String
@Throws(RemoteException::class)
public fun close()
@Throws(RemoteException::class)
public fun getMultifileFacadeParts(internalName: String): Collection<String>?
}
public interface RemoteLookupTracker : Remote {
@Throws(RemoteException::class)
fun record(
lookupContainingFile: String,
lookupLine: Int?,
lookupColumn: Int?,
scopeFqName: String,
scopeKind: ScopeKind,
name: String
)
@Throws(RemoteException::class)
fun isDoNothing(): Boolean
}
public interface RemoteIncrementalCompilationComponents : Remote {
@Throws(RemoteException::class)
public fun getIncrementalCache(target: TargetId): RemoteIncrementalCache
@Throws(RemoteException::class)
public fun getLookupTracker(): RemoteLookupTracker
}
public interface RemoteCompilationCanceledStatus : Remote {
@Throws(RemoteException::class)
fun checkCanceled(): Unit
}
public data class RemoteCompilationServices(
public val incrementalCompilationComponents: RemoteIncrementalCompilationComponents? = null,
public val compilationCanceledStatus: RemoteCompilationCanceledStatus? = null
) : Serializable
@Throws(RemoteException::class)
public fun getCompilerId(): CompilerId
@@ -0,0 +1,86 @@
/*
* Copyright 2010-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.kotlin.rmi
import org.jetbrains.kotlin.incremental.components.ScopeKind
import org.jetbrains.kotlin.load.kotlin.incremental.components.JvmPackagePartProto
import org.jetbrains.kotlin.modules.TargetId
import java.io.Serializable
import java.rmi.Remote
import java.rmi.RemoteException
public interface RemoteIncrementalCache : Remote {
@Throws(RemoteException::class)
public fun getObsoletePackageParts(): Collection<String>
@Throws(RemoteException::class)
public fun getObsoleteMultifileClassFacades(): Collection<String>
@Throws(RemoteException::class)
public fun getMultifileFacade(partInternalName: String): String?
@Throws(RemoteException::class)
public fun getPackagePartData(fqName: String): JvmPackagePartProto?
@Throws(RemoteException::class)
public fun getModuleMappingData(): ByteArray?
@Throws(RemoteException::class)
public fun registerInline(fromPath: String, jvmSignature: String, toPath: String)
@Throws(RemoteException::class)
fun getClassFilePath(internalClassName: String): String
@Throws(RemoteException::class)
public fun close()
@Throws(RemoteException::class)
public fun getMultifileFacadeParts(internalName: String): Collection<String>?
}
public interface RemoteLookupTracker : Remote {
@Throws(RemoteException::class)
fun record(
lookupContainingFile: String,
lookupLine: Int?,
lookupColumn: Int?,
scopeFqName: String,
scopeKind: ScopeKind,
name: String
)
@Throws(RemoteException::class)
fun isDoNothing(): Boolean
}
public interface RemoteIncrementalCompilationComponents : Remote {
@Throws(RemoteException::class)
public fun getIncrementalCache(target: TargetId): RemoteIncrementalCache
@Throws(RemoteException::class)
public fun getLookupTracker(): RemoteLookupTracker
}
public interface RemoteCompilationCanceledStatus : Remote {
@Throws(RemoteException::class)
fun checkCanceled(): Unit
}
public data class RemoteCompilationServices(
public val incrementalCompilationComponents: RemoteIncrementalCompilationComponents? = null,
public val compilationCanceledStatus: RemoteCompilationCanceledStatus? = null
) : Serializable
@@ -59,7 +59,7 @@ class CompileServiceImpl<Compiler: CLICompiler<*>>(
}
override fun remoteCompile(args: Array<out String>,
services: CompileService.RemoteCompilationServices,
services: RemoteCompilationServices,
compilerOutputStream: RemoteOutputStream,
outputFormat: CompileService.OutputFormat,
serviceOutputStream: RemoteOutputStream
@@ -72,7 +72,7 @@ class CompileServiceImpl<Compiler: CLICompiler<*>>(
}
override fun remoteIncrementalCompile(args: Array<out String>,
services: CompileService.RemoteCompilationServices,
services: RemoteCompilationServices,
compilerOutputStream: RemoteOutputStream,
compilerOutputFormat: CompileService.OutputFormat,
serviceOutputStream: RemoteOutputStream
@@ -134,7 +134,7 @@ class CompileServiceImpl<Compiler: CLICompiler<*>>(
}
}
private fun createCompileServices(services: CompileService.RemoteCompilationServices, rpcProfiler: Profiler): Services {
private fun createCompileServices(services: RemoteCompilationServices, rpcProfiler: Profiler): Services {
val builder = Services.Builder()
services.incrementalCompilationComponents?.let { builder.register(IncrementalCompilationComponents::class.java, RemoteIncrementalCompilationComponentsClient(it, rpcProfiler)) }
services.compilationCanceledStatus?.let { builder.register(CompilationCanceledStatus::class.java, RemoteCompilationCanceledStatusClient(it, rpcProfiler)) }
@@ -17,12 +17,12 @@
package org.jetbrains.kotlin.rmi.service
import org.jetbrains.kotlin.progress.CompilationCanceledStatus
import org.jetbrains.kotlin.rmi.CompileService
import org.jetbrains.kotlin.rmi.DummyProfiler
import org.jetbrains.kotlin.rmi.Profiler
import org.jetbrains.kotlin.rmi.RemoteCompilationCanceledStatus
class RemoteCompilationCanceledStatusClient(val proxy: CompileService.RemoteCompilationCanceledStatus, val profiler: Profiler = DummyProfiler()): CompilationCanceledStatus {
class RemoteCompilationCanceledStatusClient(val proxy: RemoteCompilationCanceledStatus, val profiler: Profiler = DummyProfiler()): CompilationCanceledStatus {
override fun checkCanceled() {
profiler.withMeasure(this) { proxy.checkCanceled() }
}
@@ -18,11 +18,11 @@ package org.jetbrains.kotlin.rmi.service
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache
import org.jetbrains.kotlin.load.kotlin.incremental.components.JvmPackagePartProto
import org.jetbrains.kotlin.rmi.CompileService
import org.jetbrains.kotlin.rmi.DummyProfiler
import org.jetbrains.kotlin.rmi.Profiler
import org.jetbrains.kotlin.rmi.RemoteIncrementalCache
public class RemoteIncrementalCacheClient(val cache: CompileService.RemoteIncrementalCache, val profiler: Profiler = DummyProfiler()): IncrementalCache {
public class RemoteIncrementalCacheClient(val cache: RemoteIncrementalCache, val profiler: Profiler = DummyProfiler()): IncrementalCache {
override fun getObsoletePackageParts(): Collection<String> = profiler.withMeasure(this) { cache.getObsoletePackageParts() }
@@ -20,12 +20,12 @@ import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents
import org.jetbrains.kotlin.modules.TargetId
import org.jetbrains.kotlin.rmi.CompileService
import org.jetbrains.kotlin.rmi.DummyProfiler
import org.jetbrains.kotlin.rmi.Profiler
import org.jetbrains.kotlin.rmi.RemoteIncrementalCompilationComponents
class RemoteIncrementalCompilationComponentsClient(val proxy: CompileService.RemoteIncrementalCompilationComponents, val profiler: Profiler = DummyProfiler()) : IncrementalCompilationComponents {
class RemoteIncrementalCompilationComponentsClient(val proxy: RemoteIncrementalCompilationComponents, val profiler: Profiler = DummyProfiler()) : IncrementalCompilationComponents {
override fun getIncrementalCache(target: TargetId): IncrementalCache = RemoteIncrementalCacheClient(profiler.withMeasure(this) { proxy.getIncrementalCache(target) }, profiler)
@@ -18,12 +18,12 @@ package org.jetbrains.kotlin.rmi.service
import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.incremental.components.ScopeKind
import org.jetbrains.kotlin.rmi.CompileService
import org.jetbrains.kotlin.rmi.DummyProfiler
import org.jetbrains.kotlin.rmi.Profiler
import org.jetbrains.kotlin.rmi.RemoteLookupTracker
class RemoteLookupTrackerClient(val proxy: CompileService.RemoteLookupTracker, val profiler: Profiler = DummyProfiler()) : LookupTracker {
class RemoteLookupTrackerClient(val proxy: RemoteLookupTracker, val profiler: Profiler = DummyProfiler()) : LookupTracker {
private val isDoNothing = profiler.withMeasure(this) { proxy.isDoNothing() }