Serialization error when using DOSGi with Karaf Cellar (4.1.1)

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Serialization error when using DOSGi with Karaf Cellar (4.1.1)

jonathanknez
I am experienced with OSGi but new to distributed OSGi. Karaf provides Cellar for DOSGi so I am starting with that one, though at this point I am still open to any DOSGi implementation. I have followed the Karaf - Cellar - Greeter DOSGi example and it works correctly. I even read the Learning Karaf Cellar book to get more information on that specific example. I am now trying to write my own code that does something similar. I always end up with a Hazelcast ClassNotFoundException serialization error that makes no sense. I am hoping someone here can point me in the right direction.

I have three bundles, just like the Greeter example; API, Publisher, and Subscriber.
API
The API bundle defines the IPublisher interface. It also includes a concrete class called Sub that IPublisher takes as an argument on some functions.

Publisher
The Publisher bundle contains a Publisher class that implements IPublisher. For the sake of completeness, here is the majority of the Publisher class.
@Component(immediate = true, name = "IPublisher", property = { "service.exported.interfaces=*" })
public class Publisher implements IPublisher {
	private static final long serialVersionUID = 1L;
	private List<Sub> mSubs = new ArrayList<Sub>();
	private Timer mTimer = new Timer();

	public void registerSubscriber(Sub s) {
		System.out.println("registerSubscriber");
		synchronized (mSubs) {
			mSubs.add(s);
		}
	}

The publisher bundle also contains another class that is an OSGi component that gets a reference to IPublisher, and successfully registers a "Sub" instance.

Subscriber
This bundle has a class that is an OSGi component, gets a reference to IPublisher, and tries to register a "Sub" instance.

I have a cluster of two nodes.
1. I successfully install the API bundle into the cluster. It is local on both nodes.
2. I successfully install the Publisher bundle on the first node. That works. The Sub that is local inside the Publisher bundle is successfully registered.
3. I successfully install the Subscriber bundle on the second node. The bundle is successfully activated but there are issues. My class successfully gets a reference to IPublisher. It successfully creates an instance of Sub (from the API package). It then attempts to pass Sub to the IPublisher in the registerSubscriber() I created. That fails every time. It does not fail in the second node. It actually fails on the first node, the node that has the Publisher bundle loaded (and API).

The error message is as follows:
2017-07-27 16:46:26,005 | WARN  | pool-40-thread-1 | QueueConsumer                    | 63 - org.apache.karaf.cellar.hazelcast - 4.1.0 | CELLAR HAZELCAST: consumer task failed to poll the queue
com.hazelcast.nio.serialization.HazelcastSerializationException: java.lang.ClassNotFoundException: myCompany.Sub

To me this error means that "Sub" couldn't be deserialized on Node A, as if the class has not been loaded yet. That is bogus though because the Pub bundle already created an instance of Sub itself and it worked fine. Plus, Sub is defined in the API bundle that is loaded everywhere. I am baffled as to why I am getting a serialization error, yet the Greeter example works correctly.

If I take out Sub, and instead just invoke some methods on the IPublisher which take primitives, they work fine. I only run into problems when passing classes I have defined, regardless of whether they are in the API bundle or not.

I know this problem is wordy. I appreciate any help you can provide.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Serialization error when using DOSGi with Karaf Cellar (4.1.1)

jbonofre
Hi Jonathan,

Do you have a serialization exception (HazelcastSerializationException for
instance) ?

Can you share your code in order for me to investigate and reproduce ? I guess
that your classes/interfaces are Serializable, right ?

Regards
JB

On 07/28/2017 12:57 AM, jonathanknez wrote:

> I am experienced with OSGi but new to distributed OSGi. Karaf provides Cellar
> for DOSGi so I am starting with that one, though at this point I am still
> open to any DOSGi implementation. I have followed the  Karaf - Cellar -
> Greeter DOSGi example
> <https://github.com/apache/karaf-cellar/tree/master/samples/dosgi-greeter>
> and it works correctly. I even read the Learning Karaf Cellar book to get
> more information on that specific example. I am now trying to write my own
> code that does something similar. I always end up with a *Hazelcast
> ClassNotFoundException serialization error that makes no sense*. I am hoping
> someone here can point me in the right direction.
>
> I have three bundles, just like the Greeter example; API, Publisher, and
> Subscriber.
> *API*
> The API bundle defines the IPublisher interface. It also includes a concrete
> class called Sub that IPublisher takes as an argument on some functions.
>
> *Publisher*
> The Publisher bundle contains a Publisher class that implements IPublisher.
> For the sake of completeness, here is the majority of the Publisher class.
>
>
> The publisher bundle also contains another class that is an OSGi component
> that gets a reference to IPublisher, and successfully registers a "Sub"
> instance.
>
> *Subscriber*
> This bundle has a class that is an OSGi component, gets a reference to
> IPublisher, and tries to register a "Sub" instance.
>
> I have a cluster of two nodes.
> 1. I successfully install the *API *bundle into the cluster. It is local on
> both nodes.
> 2. I successfully install the *Publisher *bundle on the first node. That
> works. The Sub that is local inside the Publisher bundle is successfully
> registered.
> 3. I successfully install the *Subscriber *bundle on the second node. The
> bundle is successfully activated but there are issues. My class successfully
> gets a reference to IPublisher. It successfully creates an instance of Sub
> (from the API package). It then attempts to pass Sub to the IPublisher in
> the registerSubscriber() I created. That fails every time. It does not fail
> in the second node. It actually fails on the first node, the node that has
> the Publisher bundle loaded (and API).
>
> The error message is as follows:
>
>
> To me this error means that "Sub" couldn't be deserialized on Node A, as if
> the class has not been loaded yet. That is bogus though because the Pub
> bundle already created an instance of Sub itself and it worked fine. Plus,
> Sub is defined in the API bundle that is loaded everywhere. I am baffled as
> to why I am getting a serialization error, yet the Greeter example works
> correctly.
>
> If I take out Sub, and instead just invoke some methods on the IPublisher
> which take primitives, they work fine. I only run into problems when passing
> classes I have defined, regardless of whether they are in the API bundle or
> not.
>
> I know this problem is wordy. I appreciate any help you can provide.
>
>
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/Serialization-error-when-using-DOSGi-with-Karaf-Cellar-4-1-1-tp4051114.html
> Sent from the Karaf - User mailing list archive at Nabble.com.
>

--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Serialization error when using DOSGi with Karaf Cellar (4.1.1)

jonathanknez
Thank you Jean-Baptiste for your help. Yes the classes to be exchanged are serializable. I put all three projects into a zip file which is available here:
http://knez.org/jonathan_dosgi.zip

I do get a serialization error. It is raised on Node A that has the Publisher bundle installed locally and the API installed from the cluster.

2017-07-28 09:10:47,850 | WARN  | pool-46-thread-1 | QueueConsumer                    | 63 - org.apache.karaf.cellar.hazelcast - 4.1.0 | CELLAR HAZELCAST: consumer task failed to poll the queue
com.hazelcast.nio.serialization.HazelcastSerializationException: java.lang.ClassNotFoundException: myCompany.Sub
        at com.hazelcast.internal.serialization.impl.JavaDefaultSerializers$JavaSerializer.read(JavaDefaultSerializers.java:224) [57:com.hazelcast:3.8.1]
        at com.hazelcast.internal.serialization.impl.StreamSerializerAdapter.read(StreamSerializerAdapter.java:48) [57:com.hazelcast:3.8.1]
        at com.hazelcast.internal.serialization.impl.AbstractSerializationService.toObject(AbstractSerializationService.java:184) [57:com.hazelcast:3.8.1]
        at com.hazelcast.spi.impl.operationservice.impl.InvocationFuture.resolve(InvocationFuture.java:106) [57:com.hazelcast:3.8.1]
        at com.hazelcast.spi.impl.operationservice.impl.InvocationFuture.resolveAndThrowIfException(InvocationFuture.java:75) [57:com.hazelcast:3.8.1]
        at com.hazelcast.spi.impl.AbstractInvocationFuture.get(AbstractInvocationFuture.java:155) [57:com.hazelcast:3.8.1]
        at com.hazelcast.collection.impl.queue.QueueProxySupport.invokeAndGet(QueueProxySupport.java:177) [57:com.hazelcast:3.8.1]
        at com.hazelcast.collection.impl.queue.QueueProxySupport.pollInternal(QueueProxySupport.java:124) [57:com.hazelcast:3.8.1]
        at com.hazelcast.collection.impl.queue.QueueProxyImpl.poll(QueueProxyImpl.java:88) [57:com.hazelcast:3.8.1]
        at org.apache.karaf.cellar.hazelcast.QueueConsumer.run(QueueConsumer.java:93) [63:org.apache.karaf.cellar.hazelcast:4.1.0]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:?]
        at java.lang.Thread.run(Thread.java:748) [?:?]
Caused by: java.lang.ClassNotFoundException: myCompany.Sub
        at org.apache.karaf.cellar.core.utils.CombinedClassLoader.findClass(CombinedClassLoader.java:79) ~[62:org.apache.karaf.cellar.core:4.1.0]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[?:?]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:?]
        at com.hazelcast.nio.ClassLoaderUtil.tryLoadClass(ClassLoaderUtil.java:149) ~[?:?]
        at com.hazelcast.nio.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:123) ~[?:?]
        at com.hazelcast.nio.IOUtil$ClassLoaderAwareObjectInputStream.resolveClass(IOUtil.java:522) ~[?:?]
        at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1826) ~[?:?]
        at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1713) ~[?:?]
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2000) ~[?:?]
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[?:?]
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:422) ~[?:?]
        at java.util.LinkedList.readObject(LinkedList.java:1149) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]
        at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1058) ~[?:?]
        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2136) ~[?:?]
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[?:?]
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[?:?]
        at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2245) ~[?:?]
        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2169) ~[?:?]
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) ~[?:?]
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) ~[?:?]
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:422) ~[?:?]
        at com.hazelcast.internal.serialization.impl.JavaDefaultSerializers$JavaSerializer.read(JavaDefaultSerializers.java:219) ~[?:?]
        ... 12 more
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Serialization error when using DOSGi with Karaf Cellar (4.1.1)

jbonofre
Yeah, it's what I thought. I have to check the dynamic import.

Let me take a look.

Regards
JB

On 07/28/2017 05:13 PM, jonathanknez wrote:

> Thank you Jean-Baptiste for your help. Yes the classes to be exchanged are
> serializable. I put all three projects into a zip file which is available
> here:
> http://knez.org/jonathan_dosgi.zip <http://knez.org/jonathan_dosgi.zip>
>
> I do get a serialization error. It is raised on Node A that has the
> Publisher bundle installed locally and the API installed from the cluster.
>
> 2017-07-28 09:10:47,850 | WARN  | pool-46-thread-1 | QueueConsumer
> | 63 - org.apache.karaf.cellar.hazelcast - 4.1.0 | CELLAR HAZELCAST:
> consumer task failed to poll the queue
> com.hazelcast.nio.serialization.HazelcastSerializationException:
> java.lang.ClassNotFoundException: myCompany.Sub
> at
> com.hazelcast.internal.serialization.impl.JavaDefaultSerializers$JavaSerializer.read(JavaDefaultSerializers.java:224)
> [57:com.hazelcast:3.8.1]
> at
> com.hazelcast.internal.serialization.impl.StreamSerializerAdapter.read(StreamSerializerAdapter.java:48)
> [57:com.hazelcast:3.8.1]
> at
> com.hazelcast.internal.serialization.impl.AbstractSerializationService.toObject(AbstractSerializationService.java:184)
> [57:com.hazelcast:3.8.1]
> at
> com.hazelcast.spi.impl.operationservice.impl.InvocationFuture.resolve(InvocationFuture.java:106)
> [57:com.hazelcast:3.8.1]
> at
> com.hazelcast.spi.impl.operationservice.impl.InvocationFuture.resolveAndThrowIfException(InvocationFuture.java:75)
> [57:com.hazelcast:3.8.1]
> at
> com.hazelcast.spi.impl.AbstractInvocationFuture.get(AbstractInvocationFuture.java:155)
> [57:com.hazelcast:3.8.1]
> at
> com.hazelcast.collection.impl.queue.QueueProxySupport.invokeAndGet(QueueProxySupport.java:177)
> [57:com.hazelcast:3.8.1]
> at
> com.hazelcast.collection.impl.queue.QueueProxySupport.pollInternal(QueueProxySupport.java:124)
> [57:com.hazelcast:3.8.1]
> at
> com.hazelcast.collection.impl.queue.QueueProxyImpl.poll(QueueProxyImpl.java:88)
> [57:com.hazelcast:3.8.1]
> at
> org.apache.karaf.cellar.hazelcast.QueueConsumer.run(QueueConsumer.java:93)
> [63:org.apache.karaf.cellar.hazelcast:4.1.0]
> at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
> [?:?]
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
> [?:?]
> at java.lang.Thread.run(Thread.java:748) [?:?]
> Caused by: java.lang.ClassNotFoundException: myCompany.Sub
> at
> org.apache.karaf.cellar.core.utils.CombinedClassLoader.findClass(CombinedClassLoader.java:79)
> ~[62:org.apache.karaf.cellar.core:4.1.0]
> at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[?:?]
> at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:?]
> at com.hazelcast.nio.ClassLoaderUtil.tryLoadClass(ClassLoaderUtil.java:149)
> ~[?:?]
> at com.hazelcast.nio.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:123)
> ~[?:?]
> at
> com.hazelcast.nio.IOUtil$ClassLoaderAwareObjectInputStream.resolveClass(IOUtil.java:522)
> ~[?:?]
> at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1826)
> ~[?:?]
> at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1713)
> ~[?:?]
> at
> java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2000)
> ~[?:?]
> at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535)
> ~[?:?]
> at java.io.ObjectInputStream.readObject(ObjectInputStream.java:422) ~[?:?]
> at java.util.LinkedList.readObject(LinkedList.java:1149) ~[?:?]
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> ~[?:?]
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> ~[?:?]
> at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]
> at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1058)
> ~[?:?]
> at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2136)
> ~[?:?]
> at
> java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027)
> ~[?:?]
> at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535)
> ~[?:?]
> at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2245)
> ~[?:?]
> at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2169)
> ~[?:?]
> at
> java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027)
> ~[?:?]
> at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535)
> ~[?:?]
> at java.io.ObjectInputStream.readObject(ObjectInputStream.java:422) ~[?:?]
> at
> com.hazelcast.internal.serialization.impl.JavaDefaultSerializers$JavaSerializer.read(JavaDefaultSerializers.java:219)
> ~[?:?]
> ... 12 more
>
>
>
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/Serialization-error-when-using-DOSGi-with-Karaf-Cellar-4-1-1-tp4051114p4051131.html
> Sent from the Karaf - User mailing list archive at Nabble.com.
>

--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Serialization error when using DOSGi with Karaf Cellar (4.1.1)

jonathanknez
Any thoughts on what might be going wrong?

Jonathan
Loading...