Hello!

You can see it here: https://github.com/apache/ignite/pull/2955/files

Without fix, testTaskWithServiceRemoteFirst() will fail but
testTaskWithServiceLocalFirst() will complete successfully, making it a
workaround.

But I guess your workaround is just as good as long as it works.

-- 
Ilya Kasnacheev

2017-11-01 23:59 GMT+03:00 daivanov <daiva...@gridfore.com>:

> Hi.
> I have found another work around.
> I change thread context classloader to parent classloader before proxy
> method invoke and swich it back after.
>
> So the code look like this:
>
> public class ServiceHelper {
>     public static <T> T serviceMethodInvoke(Object service, final String
> methodName, final Object... args) {
>         ClassLoader initClassloader =
> Thread.currentThread().getContextClassLoader();
>
> Thread.currentThread().setContextClassLoader(getCorrectClassloader(
> initClassloader));
>         try {
>             Method method = service.getClass().getMethod(methodName,
> Arrays.stream(args).map(Object::getClass).toArray(Class[]::new));
>             if (service instanceof GridServiceProxy) {
>                 return (T) ((GridServiceProxy)
> service).invokeMethod(method,
> args);
>             } else {
>                 return (T) method.invoke(service, args);
>             }
>         } catch (NoSuchMethodException | IllegalAccessException |
> InvocationTargetException e) {
>             throw new IllegalStateException("Error while method invoke: " +
> methodName, e);
>         } finally {
>             Thread.currentThread().setContextClassLoader(initClassloader);
>         }
>     }
>     private static ClassLoader getCorrectClassloader(ClassLoader
> initClassloader) {
>         ClassLoader correctClassloader = initClassloader;
>         while (correctClassloader.getParent() != null &&
> correctClassloader.getClass().getName().equals("org.apache.
> ignite.spi.deployment.uri.GridUriDeploymentClassLoader"))
> {
>             correctClassloader = correctClassloader.getParent();
>         }
>         return correctClassloader;
>     }
> }
>
>
> But I don't understand what do you mean by "locally-deployed job with same
> dependency"?
>
> Your sincerely, Dmitry.
>
>
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>

Reply via email to