Added continuation serializer for when serializing methods that are suspend
This commit is contained in:
parent
6f8a9c9d05
commit
98c77488b5
38
src/dorkbox/network/rmi/messages/ContinuationSerializer.kt
Normal file
38
src/dorkbox/network/rmi/messages/ContinuationSerializer.kt
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2016 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
|
||||||
|
*
|
||||||
|
* 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 dorkbox.network.rmi.messages
|
||||||
|
|
||||||
|
import com.esotericsoftware.kryo.Kryo
|
||||||
|
import com.esotericsoftware.kryo.Serializer
|
||||||
|
import com.esotericsoftware.kryo.io.Input
|
||||||
|
import com.esotericsoftware.kryo.io.Output
|
||||||
|
import kotlin.coroutines.Continuation
|
||||||
|
|
||||||
|
class ContinuationSerializer() : Serializer<Continuation<*>>() {
|
||||||
|
init {
|
||||||
|
isImmutable = true
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
override fun write(kryo: Kryo, output: Output, response: Continuation<*>) {
|
||||||
|
// nothing to write, because we DO NOT transfer the continuation object. The remote side (side where the object lives)
|
||||||
|
// uses it's continuation object from the call stack
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun read(kryo: Kryo, input: Input, type: Class<out Continuation<*>>): Continuation<*>? {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,6 +29,7 @@ import dorkbox.network.rmi.CachedMethod
|
||||||
import dorkbox.network.rmi.RmiUtils
|
import dorkbox.network.rmi.RmiUtils
|
||||||
import dorkbox.network.rmi.messages.ConnectionObjectCreateRequest
|
import dorkbox.network.rmi.messages.ConnectionObjectCreateRequest
|
||||||
import dorkbox.network.rmi.messages.ConnectionObjectCreateResponse
|
import dorkbox.network.rmi.messages.ConnectionObjectCreateResponse
|
||||||
|
import dorkbox.network.rmi.messages.ContinuationSerializer
|
||||||
import dorkbox.network.rmi.messages.GlobalObjectCreateRequest
|
import dorkbox.network.rmi.messages.GlobalObjectCreateRequest
|
||||||
import dorkbox.network.rmi.messages.GlobalObjectCreateResponse
|
import dorkbox.network.rmi.messages.GlobalObjectCreateResponse
|
||||||
import dorkbox.network.rmi.messages.MethodRequest
|
import dorkbox.network.rmi.messages.MethodRequest
|
||||||
|
@ -51,6 +52,7 @@ import org.objenesis.strategy.StdInstantiatorStrategy
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.lang.reflect.Constructor
|
import java.lang.reflect.Constructor
|
||||||
import java.lang.reflect.InvocationHandler
|
import java.lang.reflect.InvocationHandler
|
||||||
|
import kotlin.coroutines.Continuation
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Threads reading/writing at the same time a single instance of kryo. it is possible to use a single kryo with the use of
|
* Threads reading/writing at the same time a single instance of kryo. it is possible to use a single kryo with the use of
|
||||||
|
@ -132,6 +134,7 @@ class Serialization(private val references: Boolean,
|
||||||
private val methodResponseSerializer = MethodResponseSerializer()
|
private val methodResponseSerializer = MethodResponseSerializer()
|
||||||
private val objectRequestSerializer = RmiClientRequestSerializer()
|
private val objectRequestSerializer = RmiClientRequestSerializer()
|
||||||
private val objectResponseSerializer = ObjectResponseSerializer(rmiImplToIface)
|
private val objectResponseSerializer = ObjectResponseSerializer(rmiImplToIface)
|
||||||
|
private val continuationRequestSerializer = ContinuationSerializer()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -172,6 +175,8 @@ class Serialization(private val references: Boolean,
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
kryo.register(InvocationHandler::class.java as Class<Any>, objectRequestSerializer)
|
kryo.register(InvocationHandler::class.java as Class<Any>, objectRequestSerializer)
|
||||||
|
|
||||||
|
kryo.register(Continuation::class.java, continuationRequestSerializer)
|
||||||
|
|
||||||
// check to see which interfaces are mapped to RMI (otherwise, the interface requires a serializer)
|
// check to see which interfaces are mapped to RMI (otherwise, the interface requires a serializer)
|
||||||
classesToRegister.forEach { registration ->
|
classesToRegister.forEach { registration ->
|
||||||
registration.register(kryo)
|
registration.register(kryo)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user