Pulling out _resolveMethod_ from NettyRemoteSupport and moving it into ReflectiveAccess

This commit is contained in:
Viktor Klang 2011-03-14 12:17:59 +01:00
parent b5b46aaff0
commit cce0fa8b8f
2 changed files with 24 additions and 1 deletions

View file

@ -166,4 +166,26 @@ object ReflectiveAccess {
case e: Exception =>
None
}
def resolveMethod(bottomType: Class[_], methodName: String, methodSignature: Array[Class[_]]): java.lang.reflect.Method = {
var typeToResolve = bottomType
var targetMethod: java.lang.reflect.Method = null
var firstException: NoSuchMethodException = null
while((typeToResolve ne null) && (targetMethod eq null)) {
try {
targetMethod = typeToResolve.getDeclaredMethod(methodName, methodSignature:_*)
targetMethod.setAccessible(true)
} catch {
case e: NoSuchMethodException =>
if (firstException eq null)
firstException = e
typeToResolve = typeToResolve.getSuperclass
}
}
if((targetMethod eq null) && (firstException ne null))
throw firstException
targetMethod
}
}

View file

@ -927,7 +927,8 @@ class RemoteServerHandler(
val (argClasses, args) = MessageSerializer.deserialize(request.getMessage).asInstanceOf[Tuple2[Array[Class[_]],Array[AnyRef]]]
try {
val messageReceiver = typedActor.getClass.getDeclaredMethod(typedActorInfo.getMethod, argClasses: _*)
val messageReceiver = ReflectiveAccess.resolveMethod(typedActor.getClass, typedActorInfo.getMethod, argClasses)
if (request.getOneWay) messageReceiver.invoke(typedActor, args: _*)
else {
//Sends the response