Re: Cellar And Hazelcast Questions
Hi Gareth, I think that it doesn't matter who initializes the instance. It matters though who creates the Hazelcast collection (Set,List,Map etc). So I think that the best approach is to reuse cellar's hazelcast instance which is exported as a service. I really don't understand why these scenarios fail for you. I reused the code you posted in your previous example and it worked fine (that was scenario 1). I've created a sample of a hazelcast application that reuses the cellar hazelcast instance (imports it as an OSGi service). You can have a look of that sample at: https://svn.apache.org/repos/asf/karaf/cellar/trunk/samples/hazelcast-app/. I wonder if the reason that makes this sample work is the fact that cellar-hazelcast has a dynamic-import on org.apache.karaf.cellar.* packages. I will try changing the package name and see if it still works. -- *Ioannis Canellos* * http://iocanel.blogspot.com Apache Karaf http://karaf.apache.org/ Committer PMC Apache ServiceMix http://servicemix.apache.org/ Committer Apache Gora http://incubator.apache.org/gora/ Committer *
Re: Cellar And Hazelcast Questions
Ok, I managed to reproduced it. I couldn't reproduce it so far because my sample bundle was dynamically imported by cellar-hazelcast bundle. I created a jira issue for that: https://issues.apache.org/jira/browse/KARAF-842 and I will start working on it. Till then you can either use a fragment or your own Hazelcast instance. Thanks Gareth for bringing this up and having the patience to try different scenarios/combinations. -- *Ioannis Canellos* * http://iocanel.blogspot.com Apache Karaf http://karaf.apache.org/ Committer PMC Apache ServiceMix http://servicemix.apache.org/ Committer Apache Gora http://incubator.apache.org/gora/ Committer *
Re: Cellar And Hazelcast Questions
Hello Ioannis, Thank you very much for all your responses. It has been very helpful. Please bear with me. I must be missing something fundamental here. I realize there are two variables in play here rather than one (i.e. who initializes the Hazelcast instance, whether the TCCL is used). I don't believe Hazelcast can inherit my TCCL if my bundle only uses Hazelcast as a service, can it? When you ran your test, was the Hazelcast instance initialized as part of the same bundle? I did run through a few scenarios to confirm my understanding: (1) Use existing Karaf Hazelcast instance, use TCCL - FAILED (2) Create my own Hazelcast instance, don't use TCCL - FAILED (3) Create my own Hazelcast instance, use TCCL - SUCCESS! So it appears that unless I create my own Hazelcast instance, Hazelcast cannot see my classes (unless I use fragments, of course). Have I missed something obvious here? Would it be an idea to get cellar to use my hazelcast instance? Thus in my bundle which starts hazelcast, I could make sure I import both cellar and my own packages. Thus hazelcast can load both cellar and my classes via the TCCL. Would that make sense? Thank you very much again for all your help. regards, Gareth -- View this message in context: http://karaf.922171.n3.nabble.com/Cellar-And-Hazelcast-Questions-tp3184320p3294046.html Sent from the Karaf - User mailing list archive at Nabble.com.
Re: Cellar And Hazelcast Questions
Hi Gareth, I created a sample project based on the code you pasted in your previous email and it works fine for me. The only modification I did was was to create the default constructor on the PredTester class, but this is something that I don't think thats directly related to the problem you encountered. As I mentioned in my previous post as long as you set the thread context class loader everything should work fine. Now regardin your question about fragments. I think that using fragments would also work, but they have the drawback that you have to install the prior to hazelcast or refresh the hazelcast bundle afterwards. -- *Ioannis Canellos* * http://iocanel.blogspot.com Apache Karaf http://karaf.apache.org/ Committer PMC Apache ServiceMix http://servicemix.apache.org/ Committer Apache Gora http://incubator.apache.org/gora/ Committer *
Re: Cellar And Hazelcast Questions
Hello Ioannis, I was wondering. Would using fragments be a reasonable way to solve Hazelcast classloading issues (i.e. any class which may need to be serialized/deserialized by Hazelcast, I should include in a fragment which is attached to the Hazelcast bundle)? thanks in advance, Gareth -- View this message in context: http://karaf.922171.n3.nabble.com/Cellar-And-Hazelcast-Questions-tp3184320p3276278.html Sent from the Karaf - User mailing list archive at Nabble.com.
Re: Cellar And Hazelcast Questions
Hello Ioannis, I found where the issue occurs. It occurs when I try and execute a predicate on a class I defined. Here is the sample code I used to reproduce the problem: My custom class: public class PredTester implements DataSerializable { private static final long serialVersionUID = -1359492685240522455L; private String myvalue; public PredTester(String value) { this.myvalue = value; } @Override public void writeData(DataOutput out) throws IOException { out.writeUTF(myvalue); } public String getMyvalue() { return this.myvalue; } @Override public void readData(DataInput in) throws IOException { this.myvalue = in.readUTF(); } } My activator: public class Activator implements BundleActivator { private volatile HazelcastInstance instance = null; private volatile Thread myThread = null; private volatile IMaplt;String,PredTestergt; myMap = null; @Override public void start(BundleContext context) throws Exception { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); ServiceReference reference = context.getServiceReference(com.hazelcast.core.HazelcastInstance); instance = (HazelcastInstance) context.getService(reference); context.ungetService(reference); try { myMap = instance.getMap(fred-osgi); myMap.addIndex(myvalue, true); myMap.put(test1, new PredTester(belt)); EntryObject e = new PredicateBuilder().getEntryObject(); @SuppressWarnings(unchecked) Predicatelt;String,PredTestergt; predicate = e.get(myvalue).equal(belt); Setlt;Map.Entrylt;String,PredTestergt; entrySet = myMap.entrySet(predicate); logger.info(Entries returned = {},entrySet.size()); I believe it fails here } catch (Exception ex) { ex.printStackTrace(); } Thread.currentThread().setContextClassLoader(classLoader); } The following exception is thrown, whether I use an index or not (I thought using an index may stop Hazelcast needing to deserialize to check for a match): 21:01:16,037 | ERROR | .cached.thread-1 | AbstractSerializer | dardLoggerFactory$StandardLogger 58 | - - | Problem reading DataSerializable class : PredTester, exception: java.lang.ClassNotFoundException: PredTester not found from bundle [org.apache.karaf.cellar.hazelcast] java.io.IOException: Problem reading DataSerializable class : com.antennasoftware.hazelcasttest.PredTester, exception: java.lang.ClassNotFoundException: com.antennasoftware.hazelcasttest.PredTester not found from bundle [org.apache.karaf.cellar.hazelcast] at com.hazelcast.nio.Serializer$DataSerializer.read(Serializer.java:98)[135:hazelcast:1.9.3] at com.hazelcast.nio.Serializer$DataSerializer.read(Serializer.java:69)[135:hazelcast:1.9.3] at com.hazelcast.nio.AbstractSerializer.toObject(AbstractSerializer.java:105)[135:hazelcast:1.9.3] at com.hazelcast.nio.AbstractSerializer.toObject(AbstractSerializer.java:135)[135:hazelcast:1.9.3] at com.hazelcast.nio.Serializer.readObject(Serializer.java:62)[135:hazelcast:1.9.3] at com.hazelcast.impl.ThreadContext.toObject(ThreadContext.java:113)[135:hazelcast:1.9.3] at com.hazelcast.nio.IOUtil.toObject(IOUtil.java:149)[135:hazelcast:1.9.3] at com.hazelcast.impl.Record.getValue(Record.java:143)[135:hazelcast:1.9.3] at com.hazelcast.query.Predicates$GetExpressionImpl.doGetValue(Predicates.java:842)[135:hazelcast:1.9.3] at com.hazelcast.query.Predicates$GetExpressionImpl.getValue(Predicates.java:836)[135:hazelcast:1.9.3] at com.hazelcast.query.Predicates$EqualPredicate.apply(Predicates.java:450)[135:hazelcast:1.9.3] at com.hazelcast.query.PredicateBuilder.apply(PredicateBuilder.java:32)[135:hazelcast:1.9.3] at com.hazelcast.impl.ConcurrentMapManager$QueryOperationHandler.createResultPairs(ConcurrentMapManager.java:2658)[135:hazelcast:1.9.3] at com.hazelcast.impl.ConcurrentMapManager$QueryOperationHandler$QueryTask.run(ConcurrentMapManager.java:2627)[135:hazelcast:1.9.3] at com.hazelcast.impl.executor.ParallelExecutorService$ParallelExecutorImpl$ExecutionSegment.run(ParallelExecutorService.java:179)[135:hazelcast:1.9.3] at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)[:1.6.0_26] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)[:1.6.0_26] at java.lang.Thread.run(Thread.java:680)[:1.6.0_26] I guess this makes it difficult to use Hazelcast predicates in OSGi (for now). thanks again, Gareth --
Re: Cellar And Hazelcast Questions
Could you sent me a small sample? -- *Ioannis Canellos* * http://iocanel.blogspot.com Apache Karaf http://karaf.apache.org/ Committer PMC Apache ServiceMix http://servicemix.apache.org/ Committer *
Re: Cellar And Hazelcast Questions
Hello JB, Thank you very much for responding so quickly! I am just using the default cluster group (only one machine currently as I am testing on my Mac): karaf@root cluster:group-list Node Group * 192.168.190.1:5701 default I am getting the HazelcastInstance via the service cellar creates (directly now as I am still exploring OSGi, probably using blueprint in the future): ServiceReference reference = bundleContext.getServiceReference(com.hazelcast.core.HazelcastInstance); HazelcastInstance instance = (HazelcastInstance) bundleContext.getService(reference); bundleContext.ungetService(reference); Then I am looking up/creating two maps (MyKeyType and MyValueType are defined in the same bundle - the exception thrown below is for MyKeyType): IMaplt;String,Longgt; myMap1 = hazelcastInstance.getMap(myMap1); IMaplt;MyKeyType,MyValueTypegt; myMap2 = hazelcastInstance.getMap(myMap2); Is that enough information? Am I doing anything I shouldn't be doing? thanks in advance, Gareth -- View this message in context: http://karaf.922171.n3.nabble.com/Cellar-And-Hazelcast-Questions-tp3184320p3185631.html Sent from the Karaf - User mailing list archive at Nabble.com.
Re: Cellar And Hazelcast Questions
Hi Gareth, Hazelcast is using Thread.getCurrentThread().getContextClassLoader() in order to read object it exchanges over the cluster. You may have to to change the context class loader before you create the Map. For example: ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); //Do stuff here. } finally { Thread.currentThread().setContextClassLoader(originalClassLoader); } I know its not the most elegant thing to do, but it will get things working. -- *Ioannis Canellos* * http://iocanel.blogspot.com Apache Karaf http://karaf.apache.org/ Committer PMC Apache ServiceMix http://servicemix.apache.org/ Committer *
Re: Cellar And Hazelcast Questions
Hi Gareth, thanks for your interest in Karaf and Cellar. It seems that you found a bug. I'm gonna raise a Jira and reproduce your issue with a test case. Could you provide some information about your bundle ? Do you have create Cellar group ? Thanks Regards JB On 07/20/2011 04:36 AM, Gareth wrote: Hello, I would like to use Karaf as well as Cellar. I also would like to use Hazelcast for my program (since it is now getting a lot of Apache integration vs. other open-source clustering software). So I have some questions: (1) Is there an issue if I piggyback on the Cellar Hazelcast cluster, or should I make a completely separate one? Just as a note, I am seeing some exceptions when I uninstall my bundles after using Hazelcast: java.lang.ClassNotFoundException:my class not found from bundle [org.apache.karaf.cellar.hazelcast] at org.springframework.osgi.util.BundleDelegatingClassLoader.findClass(BundleDelegatingClassLoader.java:103) at org.springframework.osgi.util.BundleDelegatingClassLoader.loadClass(BundleDelegatingClassLoader.java:156) at java.lang.ClassLoader.loadClass(ClassLoader.java:247) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:247) . . Caused by: java.lang.ClassNotFoundException:My class not found by org.apache.karaf.cellar.hazelcast [141] at org.apache.felix.framework.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:787) at org.apache.felix.framework.ModuleImpl.access$400(ModuleImpl.java:71) at org.apache.felix.framework.ModuleImpl$ModuleClassLoader.loadClass(ModuleImpl.java:1768) at java.lang.ClassLoader.loadClass(ClassLoader.java:247) at org.apache.felix.framework.ModuleImpl.getClassByDelegation(ModuleImpl.java:645) (2) I see there is an OSGi classloader problem with the Hazelcast Cluster Monitor. If you use any custom classes in an IMap it cannot find them. e.g.: Caused by: java.lang.ClassNotFoundException: org.apache.karaf.cellar.core.Group not found by com.hazelcast.monitor [143] at org.apache.felix.framework.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:787) at org.apache.felix.framework.ModuleImpl.access$400(ModuleImpl.java:71) at org.apache.felix.framework.ModuleImpl$ModuleClassLoader.loadClass(ModuleImpl.java:1768) at java.lang.ClassLoader.loadClass(ClassLoader.java:247)[:1.6.0_26] Is there any way around this? Is using the Hazelcast cluster monitor to be avoided for OSGi/Keraf Cellar? thanks in advance, Gareth -- View this message in context: http://karaf.922171.n3.nabble.com/Cellar-And-Hazelcast-Questions-tp3184320p3184320.html Sent from the Karaf - User mailing list archive at Nabble.com. -- Jean-Baptiste Onofré jbono...@apache.org http://blog.nanthrax.net Talend - http://www.talend.com