Network/test/dorkboxTest/network/rmi/cows/TestCowImpl.kt

120 lines
3.3 KiB
Kotlin
Raw Normal View History

/*
2023-09-13 13:49:13 +02:00
* Copyright 2023 dorkbox, llc
*
* 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
2020-08-19 15:29:35 +02:00
*
* 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.
*/
2020-08-31 14:52:42 +02:00
package dorkboxTest.network.rmi.cows
import dorkbox.network.connection.Connection
2020-08-18 23:18:27 +02:00
import kotlinx.coroutines.delay
open class TestCowImpl(val id: Int) : TestCowBaseImpl(), TestCow {
private var moos = 0
override fun moo() {
throw RuntimeException("Should never be executed!")
}
fun moo(connection: Connection) {
moos++
connection.logger.error("Moo! $moos")
}
override fun moo(value: String) {
throw RuntimeException("Should never be executed!")
}
2023-02-16 23:23:47 +01:00
override fun mooTwo(value: String): String {
2023-02-27 11:28:24 +01:00
// println(value)
2023-02-24 16:35:00 +01:00
return "moo-two: $value"
2023-02-16 23:23:47 +01:00
}
fun moo(connection: Connection, value: String) {
moos += 2
connection.logger.error("Moo! $moos: $value")
}
2023-09-13 13:49:13 +02:00
override fun moo(value: String, delay: Long) {
throw RuntimeException("Should never be executed!")
}
2023-09-13 13:49:13 +02:00
fun moo(connection: Connection, value: String, delay: Long) {
moos += 4
connection.logger.error("Moo! $moos: $value ($delay)")
Thread.sleep(delay)
}
override suspend fun mooSuspend(value: String, delay: Long) {
throw RuntimeException("Should never be executed!")
}
suspend fun mooSuspend(connection: Connection, value: String, delay: Long) {
moos += 4
connection.logger.error("Moo! $moos: $value ($delay)")
delay(delay)
}
override fun id(): Int {
return id
}
override suspend fun slow(): Float {
throw RuntimeException("Should never be executed!")
}
suspend fun slow(connection: Connection): Float {
connection.logger.error("Slowdown!!")
delay(2000)
return 123.0f
}
2020-08-18 23:18:27 +02:00
override suspend fun withSuspend(value: String, v2: Int) {
2021-07-02 11:40:20 +02:00
throw RuntimeException("'$value : $v2' should never be executed!")
}
suspend fun withSuspend(connection: Connection, value: String, v2: Int) {
2021-07-02 11:40:20 +02:00
connection.logger.error("Suspending '$value : $v2'!")
2020-08-18 23:18:27 +02:00
delay(2000)
}
override suspend fun withSuspendAndReturn(value: String, v2: Int): Int {
2021-07-02 11:40:20 +02:00
throw RuntimeException("'$value : $v2' should never be executed!")
}
suspend fun withSuspendAndReturn(connection: Connection, value: String, v2: Int): Int {
2021-07-02 11:40:20 +02:00
connection.logger.error("Suspending '$value' with return!")
2020-08-18 23:18:27 +02:00
delay(2000)
return v2
}
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
}
if (other == null || javaClass != other.javaClass) {
return false
}
val that = other as TestCowImpl
return id == that.id
}
override fun hashCode(): Int {
return id
}
override fun toString(): String {
return "Tada! This is a remote object!"
}
}