ExecutorService remote task execution doesn't work

598 views
Skip to first unread message

mayo...@gmail.com

unread,
Feb 19, 2014, 3:49:21 AM2/19/14
to haze...@googlegroups.com
When using Hazelcast ExecutorService  to send a task (via native client in my test as below) to a dedicated note (version 3.1.5) that was started by simply executing com.hazelcast.examples.StartServer, the dedicated Hz node received the task, but it threw ClassNotFoundException (stack trace as below). So we have to have the same Echo class in the dedicated node JVM? How to get the remote task execution work? If the remote task is to shut down the dedicated note, how will the shutdown task look like? I would appreciate it if you could provide code sample. Thanks a lot!

SEVERE: [127.0.0.1]:5701 [dev] java.lang.ClassNotFoundException: com.test.demo.hazelcast.Echo
com.hazelcast.nio.serialization.HazelcastSerializationException: java.lang.ClassNotFoundException: com.test.demo.hazelcast.Echo
        at com.hazelcast.nio.serialization.DefaultSerializers$ObjectSerializer.read(DefaultSerializers.java:190)
        at com.hazelcast.nio.serialization.StreamSerializerAdapter.read(StreamSerializerAdapter.java:40)
        at com.hazelcast.nio.serialization.SerializationServiceImpl.readObject(SerializationServiceImpl.java:276)
        at com.hazelcast.nio.serialization.ByteArrayObjectDataInput.readObject(ByteArrayObjectDataInput.java:431)
        at com.hazelcast.executor.client.TargetCallableRequest.readData(TargetCallableRequest.java:84)
        at com.hazelcast.nio.serialization.DataSerializer.read(DataSerializer.java:105)
        at com.hazelcast.nio.serialization.DataSerializer.read(DataSerializer.java:36)
        at com.hazelcast.nio.serialization.StreamSerializerAdapter.read(StreamSerializerAdapter.java:59)
        at com.hazelcast.nio.serialization.SerializationServiceImpl.toObject(SerializationServiceImpl.java:218)
        at com.hazelcast.client.ClientEngineImpl$ClientPacketProcessor.run(ClientEngineImpl.java:346)
        at com.hazelcast.util.executor.ManagedExecutorService$Worker.run(ManagedExecutorService.java:166)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
        at com.hazelcast.util.executor.PoolExecutorThreadFactory$ManagedThread.run(PoolExecutorThreadFactory.java:59)
Caused by: java.lang.ClassNotFoundException: com.test.demo.hazelcast.Echo
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at com.hazelcast.nio.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:83)
        at com.hazelcast.nio.IOUtil$1.resolveClass(IOUtil.java:77)
        at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
        at java.io.ObjectInputStream.readClassDesc(Unknown Source)
        at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
        at java.io.ObjectInputStream.readObject0(Unknown Source)
        at java.io.ObjectInputStream.readObject(Unknown Source)
        at com.hazelcast.nio.serialization.DefaultSerializers$ObjectSerializer.read(DefaultSerializers.java:185)



//Test method:

public static void echoOnTheMember(String input) throws Exception {

Callable<String> task = new Echo("Sample input");


ClientConfig clientConfig = new ClientConfig();

        clientConfig.addAddress("127.0.0.1:5701");

HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);

Set<Member> ms = client.getCluster().getMembers();

IExecutorService executorService = client.getExecutorService("default");

for(Member m : ms) {

System.out.println(m.getUuid() + ":" + m.toString());

Future<String> future = executorService.submitToMember(task, m);

Thread.sleep(5000);

String echoResult = future.get();

System.out.println("####EchoResult:" + echoResult);

}

executorService.shutdownNow();

client.shutdown();

}

/**
 * Callalbe task
 */

import java.io.Serializable;
import java.util.concurrent.Callable;
import com.hazelcast.core.Member;
public class Echo implements Callable<String>, Serializable {
    String input = null;
    public Echo() {
    }
    public Echo(String input) {
        this.input = input;
    }
    @Override
    public String call() {
        System.out.println("######Echoed:" + input);
        return "######Echoed:" + input;
    }


Erdem ASLAN

unread,
Feb 19, 2014, 4:22:11 AM2/19/14
to haze...@googlegroups.com
"So we have to have the same Echo class in the dedicated node JVM?"

Yes, your Echo class has to be "loadable" by that remote server's ClassLoader in order to be de-serializable via Hazelcast's or some other serialisation method.

Cheers

Peter Veentjer

unread,
Feb 19, 2014, 4:45:01 AM2/19/14
to haze...@googlegroups.com
The Echo class needs to be available on the sender and the receiver. Hazelcast doesn't support remote classloading. 


--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+...@googlegroups.com.
To post to this group, send email to haze...@googlegroups.com.
Visit this group at http://groups.google.com/group/hazelcast.
To view this discussion on the web visit https://groups.google.com/d/msgid/hazelcast/39af9f4c-d788-4c4f-bb9b-7865ce3f3dbf%40googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages