[ 
https://issues.apache.org/jira/browse/IGNITE-4647?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Stanilovsky Evgeny updated IGNITE-4647:
---------------------------------------
    Attachment:     (was: repro-2813.tar.gz)

> ComputeTask with custom classLoader fail
> ----------------------------------------
>
>                 Key: IGNITE-4647
>                 URL: https://issues.apache.org/jira/browse/IGNITE-4647
>             Project: Ignite
>          Issue Type: Bug
>          Components: compute
>    Affects Versions: 2.0
>            Reporter: Stanilovsky Evgeny
>            Priority: Minor
>         Attachments: repro-2813.tar.gz
>
>
> In case, when we want to run ComputeTask with custom classLoader and custom 
> inherited IgniteCallable class initialized with instance from custom loader, 
> catch error *java.lang.ClassNotFoundException*. 
> for example we implementing something like :
> {code}
> public class MyCallable implements Callable<Integer> {
>     public Integer call() throws Exception {
>         System.out.println("I'm called. Working now!");
>     }
> }
> {code}
> {code}
> public class IgniteCallableWrapper implements IgniteCallable<Integer> {
>         private final Class<? extends Callable<Integer>> innerCallableClass;
>         public IgniteCallableWrapper(Class<? extends Callable<Integer>> 
> innerCallableClass) {
>             this.innerCallableClass = innerCallableClass;
>         }
>         public Integer call() throws Exception {
>             Callable<Integer> callableInstance = 
> innerCallableClass.newInstance();
>             return callableInstance.call();
>         }
> }
> {code}
> and start two nodes like :
> first
> {code}
>     public static void main(String[] args) throws MalformedURLException, 
> ClassNotFoundException {
>         IgniteConfiguration icfg = new IgniteConfiguration();
>         icfg.setGridName("grid");
>         icfg.setPeerClassLoadingEnabled(true);
>         Ignition.start(icfg);
>     }
> {code}
> and second :
> {code}
>     private final static File myCallableArtifact = new 
> File("./my-callable-artifact.jar");
>     private final static File igniteCallableArtifact = new 
> File("./ignite-callable.jar");
>     public static void main(String[] args) throws MalformedURLException, 
> ClassNotFoundException, NoSuchMethodException, IllegalAccessException, 
> InvocationTargetException, InstantiationException {
>         URLClassLoader myCallableLoader = new URLClassLoader(new URL[] {
>                 myCallableArtifact.toURI().toURL()});
>         URLClassLoader igniteWrapperLoader = new URLClassLoader(new URL[] {
>                 igniteCallableArtifact.toURI().toURL()},
>                 SecondNode.class.getClassLoader());
>         IgniteLoader igniteLoader = new 
> IgniteLoader(SecondNode.class.getClassLoader(), myCallableLoader, 
> igniteWrapperLoader);
>         // Start node
>         IgniteConfiguration icfg = new IgniteConfiguration();
>         icfg.setGridName("grid");
>         icfg.setPeerClassLoadingEnabled(true);
>         icfg.setClassLoader(igniteLoader);
>         Ignite ignite = Ignition.start(icfg);
>         CacheConfiguration<Long, Long> cacheConfiguration = new 
> CacheConfiguration<Long, Long>("cache");
>         IgniteCache<Long, Long> cache = 
> ignite.createCache(cacheConfiguration);
>         // Load callable
>         Class<?> myCallable = myCallableLoader.loadClass("MyCallable");
>         Class<? extends IgniteCallable> igniteCallableClass = (Class<? 
> extends IgniteCallable>) 
> igniteWrapperLoader.loadClass("IgniteCallableWrapper");
>         Constructor<? extends IgniteCallable> constructor = 
> igniteCallableClass.getConstructor(Class.class);
>         IgniteCallable igniteCallable = constructor.newInstance(myCallable);
>         // Send it everywhere!
>         for (int i = 0; i < 1024; i++) {
>             ignite.compute().affinityCall("cache", i, igniteCallable);
>         }
>     }
> {code}
> all detailed info, how to reproduce in attach.
> debug shows that function {code} processResourceRequest(UUID nodeId, 
> GridDeploymentRequest req) {code} return classLoader {code} ClassLoader ldr = 
> dep.classLoader(); {code} not that expected (that was setting throught 
> icfg.setClassLoader(igniteLoader);) but classLoader from {code} 
> ignite.compute().affinityCall("cache", i, igniteCallable); {code}    {code} 
> igniteCallable {code} object.
> All source for reproduce can be found in attach.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to