Skip to content

Commit

Permalink
PlatformDependent: drop type aliases
Browse files Browse the repository at this point in the history
They were only necessary for the Kotlin multiplatform project back then, and Rd is no longer a multiplatform project.
  • Loading branch information
ForNeVeR committed Jul 31, 2024
1 parent 396da37 commit 4cf5608
Show file tree
Hide file tree
Showing 28 changed files with 90 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.jetbrains.rd.util.reactive.IScheduler
import com.jetbrains.rd.util.reactive.ISource
import java.time.Duration
import java.util.*
import java.util.EnumSet
import java.util.concurrent.atomic.AtomicReference
import kotlin.concurrent.schedule

private val timer by lazy { Timer("rd throttler", true) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.jetbrains.rd.util

import java.util.concurrent.atomic.AtomicInteger

open class BitSlice(val lowBit: Int, val bitCount: Int) {
init {
require(lowBit >= 0) { "[lowBit] must be >= 0, actual: '$lowBit'"}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,17 @@
package com.jetbrains.rd.util

import com.jetbrains.rd.util.threading.SpinWait
import java.io.Closeable
import java.io.PrintWriter
import java.io.StringWriter
import java.util.Date
import java.util.concurrent.CancellationException
import java.util.concurrent.ExecutionException
import java.util.concurrent.TimeoutException
import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.atomic.AtomicReference
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
import kotlin.io.use
import kotlin.reflect.KClass

typealias ExecutionException = ExecutionException

fun currentThreadName() : String = Thread.currentThread().run { "$id:$name"}

class AtomicReference<T> constructor(initial: T) {
private val impl = AtomicReference(initial)
fun get(): T = impl.get()
fun getAndUpdate(f: (T) -> T): T = impl.getAndUpdate(f)
fun getAndSet(newValue: T): T = impl.getAndSet(newValue)
fun compareAndSet(expectedValue: T, newValue: T): Boolean = impl.compareAndSet(expectedValue, newValue)
}

typealias CancellationException = CancellationException
typealias TimeoutException = TimeoutException

typealias ThreadLocal<T> = java.lang.ThreadLocal<T>

fun <T> threadLocalWithInitial(initial: () -> T) : ThreadLocal<T> = ThreadLocal.withInitial(initial)

val eol : String = System.lineSeparator()
Expand All @@ -47,14 +27,14 @@ object Sync {
return synchronized(obj, acton)
}
fun notifyAll(obj: Any) = (obj as Object).notifyAll()
fun notify(obj: Any) = (obj as Object).notify()
fun wait(obj: Any) = (obj as Object).wait()
fun wait(obj: Any, timeout: Long) = (obj as Object).wait(timeout)
}

fun<K,V> concurrentMapOf() : MutableMap<K,V> = ConcurrentHashMap()
// For the protocol generator to avoid imports from java.util:
typealias Date = java.util.Date
typealias EnumSet<T> = java.util.EnumSet<T>

typealias Closeable = java.io.Closeable
inline fun <T : Closeable?, R> T.use(block:(T) -> R) : R = use(block)

fun Throwable.getThrowableText(): String = StringWriter().apply { printStackTrace(PrintWriter(this)) }.toString()
Expand All @@ -63,18 +43,6 @@ fun qualifiedName(kclass: KClass<*>) : String = kclass.qualifiedName?:"<anonymou

fun measureTimeMillis(block: () -> Unit): Long = kotlin.system.measureTimeMillis(block)

//special jvm classes
typealias URI = java.net.URI

typealias Date = Date

typealias UUID = java.util.UUID

typealias AtomicInteger = AtomicInteger

typealias Queue<E> = java.util.concurrent.LinkedBlockingQueue<E>
typealias ConcurrentHashMap<K, V> = java.util.concurrent.ConcurrentHashMap<K, V>

fun printlnError(msg: String) = System.err.println(msg)

fun assert(value: Boolean) = kotlin.assert(value)
Expand All @@ -84,11 +52,5 @@ inline fun assert(value: Boolean, lazyMessage: () -> Any) = kotlin.assert(value
inline fun spinUntil(condition: () -> Boolean) = SpinWait.spinUntil(condition)
inline fun spinUntil(timeoutMs: Long, condition: () -> Boolean) = SpinWait.spinUntil(timeoutMs, condition)

typealias EnumSet<T> = java.util.EnumSet<T>
inline fun <reified T : Enum<T>> enumSetOf(values: Set<T> = emptySet()) : EnumSet<T> = EnumSet.noneOf(T::class.java).apply { addAll(values) }
fun <T: Enum<T>> EnumSet<T>.values() : Set<T> = this

typealias Runnable = java.lang.Runnable
typealias Callable<T> = java.util.concurrent.Callable<T>

typealias CopyOnWriteArrayList<T> = java.util.concurrent.CopyOnWriteArrayList<T>
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.jetbrains.rd.util

import java.io.Closeable
import java.util.concurrent.atomic.AtomicReference
import kotlin.reflect.KClass

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import com.jetbrains.rd.util.reactive.viewNotNull
import com.jetbrains.rd.util.threading.coroutines.RdCoroutineScope
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.cancel
import java.io.Closeable
import java.util.concurrent.CancellationException
import java.util.concurrent.atomic.AtomicInteger
import kotlin.math.min


Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.jetbrains.rd.util.lifetime

import com.jetbrains.rd.util.AtomicReference
import com.jetbrains.rd.util.Logger
import com.jetbrains.rd.util.error
import java.util.concurrent.atomic.AtomicReference

open class SequentialLifetimes(private val parentLifetime: Lifetime) {
private val currentDef = AtomicReference(LifetimeDefinition.Terminated)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.jetbrains.rd.util.reactive

import com.jetbrains.rd.util.ExecutionException
import com.jetbrains.rd.util.getThrowableText
import java.util.concurrent.ExecutionException


class RdFault constructor(val reasonTypeFqn: String, val reasonMessage: String, val reasonAsText: String, reason: Throwable? = null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.jetbrains.rd.util.reactive

import com.jetbrains.rd.util.TlsBoxed
import com.jetbrains.rd.util.*
import com.jetbrains.rd.util.lifetime.Lifetime
import com.jetbrains.rd.util.lifetime.isAlive
import com.jetbrains.rd.util.reflection.incrementCookie
import com.jetbrains.rd.util.reflection.usingValue
import java.util.concurrent.atomic.AtomicReference

open class Signal<T> : ISignal<T> {
companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.jetbrains.rd.util.reactive

import com.jetbrains.rd.util.*
import java.util.concurrent.CancellationException

sealed class TaskResult<out T> {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.jetbrains.rd.util.threading.coroutines

import com.jetbrains.rd.util.*
import com.jetbrains.rd.util.error
import com.jetbrains.rd.util.getLogger
import com.jetbrains.rd.util.lifetime.Lifetime
import com.jetbrains.rd.util.trace
import kotlinx.coroutines.*
import kotlinx.coroutines.CancellationException
import java.lang.IllegalStateException
import java.util.concurrent.atomic.AtomicReference
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package com.jetbrains.rd.util.test.cases

import com.jetbrains.rd.util.AtomicInteger
import com.jetbrains.rd.util.Closeable
import com.jetbrains.rd.util.ILoggerFactory
import com.jetbrains.rd.util.Statics
import com.jetbrains.rd.util.log.ErrorAccumulatorLoggerFactory
import com.jetbrains.rd.util.threading.TestSingleThreadScheduler
import org.junit.jupiter.api.*
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import java.io.Closeable
import java.util.concurrent.atomic.AtomicInteger


class BackgroundSchedulerTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.jetbrains.rd.util.test.framework

import com.jetbrains.rd.util.*
import com.jetbrains.rd.util.ILoggerFactory
import com.jetbrains.rd.util.Statics
import com.jetbrains.rd.util.error
import com.jetbrains.rd.util.getLogger
import com.jetbrains.rd.util.lifetime.Lifetime
import com.jetbrains.rd.util.lifetime.SequentialLifetimes
import com.jetbrains.rd.util.log.ErrorAccumulatorLoggerFactory
import com.jetbrains.rd.util.threading.Linearization
import java.io.Closeable
import kotlin.test.AfterTest
import kotlin.test.BeforeTest

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.jetbrains.rd.framework

import com.jetbrains.rd.framework.impl.RdSecureString
import com.jetbrains.rd.util.*
import kotlin.reflect.*
import com.jetbrains.rd.util.Date
import com.jetbrains.rd.util.EnumSet
import com.jetbrains.rd.util.PublicApi
import java.net.URI
import java.util.*
import kotlin.reflect.KClass
import kotlin.time.Duration

open class UniversalMarshaller<T : Any>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.jetbrains.rd.framework


import com.jetbrains.rd.util.AtomicInteger
import com.jetbrains.rd.util.hash.getPlatformIndependentHash
import com.jetbrains.rd.util.string.condstr
import java.util.concurrent.atomic.AtomicInteger

enum class IdKind {
Client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ import com.jetbrains.rd.framework.base.AllowBindingCookie
import com.jetbrains.rd.framework.base.IRdWireable
import com.jetbrains.rd.framework.base.IRdWireableDispatchHelper
import com.jetbrains.rd.framework.impl.ProtocolContexts
import com.jetbrains.rd.util.Queue
import com.jetbrains.rd.util.Sync
import com.jetbrains.rd.util.blockingPutUnique
import com.jetbrains.rd.util.lifetime.Lifetime
import com.jetbrains.rd.util.lifetime.intersect
import com.jetbrains.rd.util.lifetime.isAlive
import com.jetbrains.rd.util.lifetime.isNotAlive
import com.jetbrains.rd.util.reactive.IScheduler
import com.jetbrains.rd.util.string.IPrintable
import com.jetbrains.rd.util.string.PrettyPrinter
import com.jetbrains.rd.util.trace
import java.util.concurrent.LinkedBlockingQueue

class RdMessage (val id : RdId, val istream : AbstractBuffer)
class MessageBroker(queueMessages: Boolean = false) : IPrintable {
Expand All @@ -23,15 +22,15 @@ class MessageBroker(queueMessages: Boolean = false) : IPrintable {
val log = Protocol.sublogger("MQ")
}

private var unprocessedMessages: Queue<RdMessage>? = if (queueMessages) Queue() else null
private var unprocessedMessages: LinkedBlockingQueue<RdMessage>? = if (queueMessages) LinkedBlockingQueue() else null

private val lock = Any()

private val subscriptions = hashMapOf<RdId, Entry>()

fun startDeliveringMessages() {
while (true) {
val queue: Queue<RdMessage>
val queue: LinkedBlockingQueue<RdMessage>
Sync.lock (lock) {
queue = requireNotNull(unprocessedMessages) { "Already started delivering messages" }

Expand All @@ -41,7 +40,7 @@ class MessageBroker(queueMessages: Boolean = false) : IPrintable {
return
}

unprocessedMessages = Queue()
unprocessedMessages = LinkedBlockingQueue()
}

for (rdMessage in queue) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.jetbrains.rd.framework

import com.jetbrains.rd.util.ConcurrentHashMap
import com.jetbrains.rd.util.addUnique
import com.jetbrains.rd.util.lifetime.Lifetime
import java.util.concurrent.ConcurrentHashMap

class RdEntitiesRegistrar {
private val map = ConcurrentHashMap<RdId, IRdDynamic>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ package com.jetbrains.rd.framework
import com.jetbrains.rd.framework.base.ISerializersOwner
import com.jetbrains.rd.framework.impl.RdSecureString
import com.jetbrains.rd.util.*
import com.jetbrains.rd.util.Date
import com.jetbrains.rd.util.EnumSet
import com.jetbrains.rd.util.hash.getPlatformIndependentHash
import com.jetbrains.rd.util.lifetime.Lifetime
import java.net.URI
import java.util.*
import java.util.concurrent.ConcurrentHashMap
import kotlin.reflect.KClass
import kotlin.time.Duration
import kotlin.time.DurationUnit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ package com.jetbrains.rd.framework.base
import com.jetbrains.rd.framework.*
import com.jetbrains.rd.framework.impl.ProtocolContexts
import com.jetbrains.rd.framework.impl.RdPropertyBase
import com.jetbrains.rd.util.*
import com.jetbrains.rd.util.Logger
import com.jetbrains.rd.util.Sync
import com.jetbrains.rd.util.assert
import com.jetbrains.rd.util.lifetime.Lifetime
import com.jetbrains.rd.util.lifetime.isNotAlive
import com.jetbrains.rd.util.reactive.*
import com.jetbrains.rd.util.string.printToString
import com.jetbrains.rd.util.threading.asSequentialScheduler
import com.jetbrains.rd.util.trace
import java.util.concurrent.LinkedBlockingQueue
import java.util.concurrent.atomic.AtomicReference
import javax.management.openmbean.InvalidOpenTypeException

abstract class RdExtBase : RdReactiveBase() {
Expand Down Expand Up @@ -285,7 +290,7 @@ class ExtWire : IWire {
}


private val sendQ = Queue<QueueItem>()
private val sendQ = LinkedBlockingQueue<QueueItem>()

init {
connected.whenTrue(Lifetime.Eternal) { _ ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.jetbrains.rd.framework.impl

import com.jetbrains.rd.framework.*
import com.jetbrains.rd.util.*
import com.jetbrains.rd.util.lifetime.Lifetime
import com.jetbrains.rd.util.string.RName
import com.jetbrains.rd.framework.IInternRoot
import com.jetbrains.rd.framework.base.IRdBindable
import com.jetbrains.rd.framework.base.IRdWireableDispatchHelper
import com.jetbrains.rd.framework.base.RdReactiveBase
import com.jetbrains.rd.util.assert
import com.jetbrains.rd.util.lifetime.Lifetime
import com.jetbrains.rd.util.string.RName
import com.jetbrains.rd.util.trace
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.AtomicInteger
import kotlin.collections.set

class InternRoot<TBase: Any>(val serializer: ISerializer<TBase> = Polymorphic()): IInternRoot<TBase> {
override fun deepClone(): IRdBindable {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package com.jetbrains.rd.framework.impl

import com.jetbrains.rd.framework.*
import com.jetbrains.rd.framework.base.*
import com.jetbrains.rd.framework.AbstractBuffer
import com.jetbrains.rd.framework.IProtocol
import com.jetbrains.rd.framework.RdContext
import com.jetbrains.rd.framework.SerializationCtx
import com.jetbrains.rd.framework.base.IRdBindable
import com.jetbrains.rd.framework.base.IRdWireableDispatchHelper
import com.jetbrains.rd.framework.base.ISingleContextHandler
import com.jetbrains.rd.util.ConcurrentHashMap
import com.jetbrains.rd.util.CopyOnWriteArrayList
import com.jetbrains.rd.framework.base.RdReactiveBase
import com.jetbrains.rd.util.Sync
import com.jetbrains.rd.util.assert
import com.jetbrains.rd.util.lifetime.Lifetime
import com.jetbrains.rd.util.reactive.IAppendOnlyViewableConcurrentSet
import com.jetbrains.rd.util.reactive.IMutableViewableSet
import com.jetbrains.rd.util.reactive.IScheduler
import com.jetbrains.rd.util.reactive.ViewableList
import com.jetbrains.rd.util.reflection.threadLocal
import com.jetbrains.rd.util.reflection.usingValue
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.CopyOnWriteArrayList

/**
* This class handles RdContext on protocol level. It tracks existing contexts and allows access to their value sets (when present)
Expand Down
Loading

0 comments on commit 4cf5608

Please sign in to comment.