Better toString() methods for the unique ID of the client/server

This commit is contained in:
Robinson 2023-07-02 21:59:45 +02:00
parent e403e1d6e1
commit 6220ec617b
No known key found for this signature in database
GPG Key ID: 8E7DB78588BD6F5C
3 changed files with 13 additions and 6 deletions

View File

@ -205,6 +205,10 @@ open class Client<CONNECTION : Connection>(
@Volatile @Volatile
private var connection0: CONNECTION? = null private var connection0: CONNECTION? = null
private val string0: String by lazy {
"EndPoint [Client: $${storage.publicKey!!.toHexString()}]"
}
final override fun newException(message: String, cause: Throwable?): Throwable { final override fun newException(message: String, cause: Throwable?): Throwable {
// +2 because we do not want to see the stack for the abstract `newException` // +2 because we do not want to see the stack for the abstract `newException`
val clientException = ClientException(message, cause) val clientException = ClientException(message, cause)
@ -907,7 +911,7 @@ open class Client<CONNECTION : Connection>(
} }
override fun toString(): String { override fun toString(): String {
return "EndPoint [Client: $${storage.publicKey!!.toHexString()}]" return string0
} }
fun <R> use(block: (Client<CONNECTION>) -> R): R { fun <R> use(block: (Client<CONNECTION>) -> R): R {

View File

@ -15,6 +15,7 @@
*/ */
package dorkbox.network package dorkbox.network
import dorkbox.bytes.toHexString
import dorkbox.network.aeron.AeronDriver import dorkbox.network.aeron.AeronDriver
import dorkbox.network.aeron.AeronPoller import dorkbox.network.aeron.AeronPoller
import dorkbox.network.aeron.EventPoller import dorkbox.network.aeron.EventPoller
@ -180,6 +181,10 @@ open class Server<CONNECTION : Connection>(
var port: Int = 0 var port: Int = 0
private set private set
private val string0: String by lazy {
"EndPoint [Server: $${storage.publicKey!!.toHexString()}]"
}
final override fun newException(message: String, cause: Throwable?): Throwable { final override fun newException(message: String, cause: Throwable?): Throwable {
// +2 because we do not want to see the stack for the abstract `newException` // +2 because we do not want to see the stack for the abstract `newException`
val serverException = ServerException(message, cause) val serverException = ServerException(message, cause)
@ -392,7 +397,7 @@ open class Server<CONNECTION : Connection>(
} }
override fun toString(): String { override fun toString(): String {
return "EndPoint [Server]" return string0
} }
/** /**

View File

@ -74,10 +74,8 @@ internal class RmiClient(val isGlobal: Boolean,
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
private val EMPTY_ARRAY: Array<Any> = Collections.EMPTY_LIST.toTypedArray() as Array<Any> private val EMPTY_ARRAY: Array<Any> = Collections.EMPTY_LIST.toTypedArray() as Array<Any>
private val safeAsyncState = object: ThreadLocal<Boolean?>() { private val safeAsyncState: ThreadLocal<Boolean?> = ThreadLocal.withInitial {
override fun initialValue(): Boolean? { null
return null
}
} }
private const val charPrim = 0.toChar() private const val charPrim = 0.toChar()