You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@mina.apache.org by Alexander Christian <al...@root1.de> on 2013/04/23 11:47:14 UTC

MINA's IoBuffer#getObject/putObject: DalvikVM<->JVM issues?

Hi there,

a few months ago, I asked this list if someone uses MINA for 
communication between Android (DalvikVM) + Java (Oracle JVM), especially 
with regard to built-in object serialization

This was the answer (forget to copy also the author's name ...):
----

Yes, MINA works on Android!

I have been using it to develop a publish/subscribe system that supports 
Android clients. I think you won't be able to use built-in 
serialization, though. Dalvik is not a standard JVM...

Other than that, I've had no issues.

My deployments include Android 2.3 and Android 4.1 using Nexus S 
smartphones and the latest version of MINA. In fact, I think they are a 
great combination...

----

Today I tested my application (which is a kind of RMI replacement, see 
http://dev.root1.de/projects/simon and makes heavy use of serialization 
via IoBuffers#getObject/putObject) with Android 4.2.2 (via Android SDK 
Emulator). Result: Serialization works... At least with simple classes like:

----
package de.root1.shared;

import java.io.Serializable;

public class MyClass implements Serializable {

     private long i = 0;

     public MyClass(long i) {
         this.i = i;
     }

     public long getI() {
         return i;
     }

     @Override
     public String toString() {
         return "MyClass{" + "i=" + i + "}@"+hashCode();
     }

}
----

For now, I did not test complex classes. But I assume that this will 
also work.

So: Great. Serialization works. But why? I read that it is not working? 
I found a lot of resources on the net talking about other ways of 
serialization and ways around this issue...

Is there someone on this list who can confirm that serialization between 
DalvikVM and JVM with help of MINAs IoBuffer#putObject/getObject is not 
an issue at all?
My gurrent guess is, that serialization between both platforms became 
compatible with Android Version XYZ ... Would be good to know which 
version this was...

Any comments/ideas?

br,
Alex


Re: MINA's IoBuffer#getObject/putObject: DalvikVM<->JVM issues?

Posted by Julien Vermillard <jv...@gmail.com>.
if json is too verbose for you, you can use :
https://github.com/SierraWireless/m3da-server/blob/master/codec/src/main/java/m3da/codec/impl/BysantEncoderImpl.java
It's an implementation of
http://wiki.eclipse.org/images/6/6a/M3DABysantSerializer.pdf in java


On Tue, Apr 23, 2013 at 10:29 PM, Leonardo K. Shikida <sh...@gmail.com>wrote:

> agreed
>
> you could have problems with java serialization even with different
> versions of the same JVM
>
> json is safer
>
> []
>
> Leo
>
>
> On Tue, Apr 23, 2013 at 1:08 PM, Julien Vermillard <jvermillard@gmail.com
> >wrote:
>
> > Yeah I think you should avoid java serialization.
> > You can try Json serialization wth something like jackson.
> > it's much safer
> >
> > Julien
> >
> >
> > On Tue, Apr 23, 2013 at 5:40 PM, Emmanuel Lécharny <elecharny@gmail.com
> > >wrote:
> >
> > > Le 4/23/13 4:39 PM, Alexander Christian a écrit :
> > > > Hmm, no answer yet. So I have to investigate myself :-(
> > > >
> > > > Here's what I found out so far:
> > > >
> > > > 1) Simple classes with primitive instance variables are not a problem
> > > > for MINA. Works just fine.
> > > > 2) Classes with objects don't work.
> > > You may have classloader issues.
> > >
> > > The pb when you transfer Objects over the wire, you have no way to know
> > > which version of the JVM you have on the other end (you may have
> various
> > > versions of dalvik on the remote phones).
> > >
> > > As the getObject() method heavily depend on the classLoader, it's
> likely
> > > to fail.
> > >
> > >
> > > --
> > > Regards,
> > > Cordialement,
> > > Emmanuel Lécharny
> > > www.iktek.com
> > >
> > >
> >
>

Re: MINA's IoBuffer#getObject/putObject: DalvikVM<->JVM issues?

Posted by "Leonardo K. Shikida" <sh...@gmail.com>.
agreed

you could have problems with java serialization even with different
versions of the same JVM

json is safer

[]

Leo


On Tue, Apr 23, 2013 at 1:08 PM, Julien Vermillard <jv...@gmail.com>wrote:

> Yeah I think you should avoid java serialization.
> You can try Json serialization wth something like jackson.
> it's much safer
>
> Julien
>
>
> On Tue, Apr 23, 2013 at 5:40 PM, Emmanuel Lécharny <elecharny@gmail.com
> >wrote:
>
> > Le 4/23/13 4:39 PM, Alexander Christian a écrit :
> > > Hmm, no answer yet. So I have to investigate myself :-(
> > >
> > > Here's what I found out so far:
> > >
> > > 1) Simple classes with primitive instance variables are not a problem
> > > for MINA. Works just fine.
> > > 2) Classes with objects don't work.
> > You may have classloader issues.
> >
> > The pb when you transfer Objects over the wire, you have no way to know
> > which version of the JVM you have on the other end (you may have various
> > versions of dalvik on the remote phones).
> >
> > As the getObject() method heavily depend on the classLoader, it's likely
> > to fail.
> >
> >
> > --
> > Regards,
> > Cordialement,
> > Emmanuel Lécharny
> > www.iktek.com
> >
> >
>

Re: MINA's IoBuffer#getObject/putObject: DalvikVM<->JVM issues?

Posted by Julien Vermillard <jv...@gmail.com>.
Yeah I think you should avoid java serialization.
You can try Json serialization wth something like jackson.
it's much safer

Julien


On Tue, Apr 23, 2013 at 5:40 PM, Emmanuel Lécharny <el...@gmail.com>wrote:

> Le 4/23/13 4:39 PM, Alexander Christian a écrit :
> > Hmm, no answer yet. So I have to investigate myself :-(
> >
> > Here's what I found out so far:
> >
> > 1) Simple classes with primitive instance variables are not a problem
> > for MINA. Works just fine.
> > 2) Classes with objects don't work.
> You may have classloader issues.
>
> The pb when you transfer Objects over the wire, you have no way to know
> which version of the JVM you have on the other end (you may have various
> versions of dalvik on the remote phones).
>
> As the getObject() method heavily depend on the classLoader, it's likely
> to fail.
>
>
> --
> Regards,
> Cordialement,
> Emmanuel Lécharny
> www.iktek.com
>
>

Re: MINA's IoBuffer#getObject/putObject: DalvikVM<->JVM issues?

Posted by Emmanuel Lécharny <el...@gmail.com>.
Le 4/23/13 4:39 PM, Alexander Christian a écrit :
> Hmm, no answer yet. So I have to investigate myself :-(
>
> Here's what I found out so far:
>
> 1) Simple classes with primitive instance variables are not a problem
> for MINA. Works just fine.
> 2) Classes with objects don't work.
You may have classloader issues.

The pb when you transfer Objects over the wire, you have no way to know
which version of the JVM you have on the other end (you may have various
versions of dalvik on the remote phones).

As the getObject() method heavily depend on the classLoader, it's likely
to fail.


-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com 


Re: MINA's IoBuffer#getObject/putObject: DalvikVM<->JVM issues?

Posted by Alexander Christian <al...@root1.de>.
Hmm, no answer yet. So I have to investigate myself :-(

Here's what I found out so far:

1) Simple classes with primitive instance variables are not a problem 
for MINA. Works just fine.
2) Classes with objects don't work.


To test 2), I did the following:

I created this Test-Class which will be serialized later:

----
package de.root1.shared;

import java.io.Serializable;
import java.math.BigInteger;

public class MyClass implements Serializable {

     private static final long serialVersionUID = 123L;

     private long i = 0;
     private BigInteger bigInt;
     private final String string;

     public MyClass(long i, String bigint, String string) {
         this.i = i;
         this.bigInt = new BigInteger(bigint);
         this.string = string;
     }

     public long getI() {
         return i;
     }

     @Override
     public String toString() {
         return "MyClass{" + "i=" + i + ", bigInt=" + bigInt.longValue() 
+ ", string=" + string + '}';
     }

}
----

... and executed the following code to serialize an object of this class 
once on Android 4.2.2 and once on JVM:

----
             Long l = 26495472873L;
             MyClass mc = new MyClass(l, "1234567890", "Hello World:" + l);
             IoBuffer ioBuffer = IoBuffer.allocate(1024 * 10);

             ioBuffer.putObject(mc);
             ioBuffer.flip();

             StringBuilder sb = new StringBuilder();
             while (ioBuffer.position() < ioBuffer.limit()) {
                 sb.append(ioBuffer.get()).append("|");
             }
             System.out.println("buffer: " + sb.toString());
----

I expected that both platforms would create the same output. But it's 
different:

JVM 1.7u21 64bit
buffer: 
0|0|0|-102|-84|-19|0|5|115|114|1|0|23|100|101|46|114|111|111|116|49|46|115|104|97|114|101|100|46|77|121|67|108|97|115|115|120|112|0|0|0|6|43|64|-44|-23|115|114|1|0|20|106|97|118|97|46|109|97|116|104|46|66|105|103|73|110|116|101|103|101|114|120|114|1|0|16|106|97|118|97|46|108|97|110|103|46|78|117|109|98|101|114|120|112|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-2|-1|-1|-1|-2|0|0|0|1|117|114|1|0|2|91|66|120|112|0|0|0|4|73|-106|2|-46|120|116|0|23|72|101|108|108|111|32|87|111|114|108|100|58|50|54|52|57|53|52|55|50|56|55|51|

ANDROID 4.2.2 on Android-SDK-Emulator
buffer: 
0|0|0|-118|-84|-19|0|5|115|114|1|0|23|100|101|46|114|111|111|116|49|46|115|104|97|114|101|100|46|77|121|67|108|97|115|115|120|112|0|0|0|6|43|64|-44|-23|115|114|1|0|20|106|97|118|97|46|109|97|116|104|46|66|105|103|73|110|116|101|103|101|114|120|114|1|0|16|106|97|118|97|46|108|97|110|103|46|78|117|109|98|101|114|120|112|0|0|0|1|117|114|1|0|2|91|66|120|112|0|0|0|4|73|-106|2|-46|120|116|0|23|72|101|108|108|111|32|87|111|114|108|100|58|50|54|52|57|53|52|55|50|56|55|51|

A lot of bytes are equal, but after a lot of bytes, there's a point 
where the JVM uses the following additional bytes: 
"-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-2|-1|-1|-1|-2|".

So the part before this substring, and the part after this substring is 
equal to the Android output...

On both systems, I don't get any exception.

Any ideas what goes wrong?

br,
Alex






Am 23.04.2013 11:47, schrieb Alexander Christian:
> Hi there,
>
> a few months ago, I asked this list if someone uses MINA for 
> communication between Android (DalvikVM) + Java (Oracle JVM), 
> especially with regard to built-in object serialization
>
> This was the answer (forget to copy also the author's name ...):
> ----
>
> Yes, MINA works on Android!
>
> I have been using it to develop a publish/subscribe system that 
> supports Android clients. I think you won't be able to use built-in 
> serialization, though. Dalvik is not a standard JVM...
>
> Other than that, I've had no issues.
>
> My deployments include Android 2.3 and Android 4.1 using Nexus S 
> smartphones and the latest version of MINA. In fact, I think they are 
> a great combination...
>
> ----
>
> Today I tested my application (which is a kind of RMI replacement, see 
> http://dev.root1.de/projects/simon and makes heavy use of 
> serialization via IoBuffers#getObject/putObject) with Android 4.2.2 
> (via Android SDK Emulator). Result: Serialization works... At least 
> with simple classes like:
>
> ----
> package de.root1.shared;
>
> import java.io.Serializable;
>
> public class MyClass implements Serializable {
>
>     private long i = 0;
>
>     public MyClass(long i) {
>         this.i = i;
>     }
>
>     public long getI() {
>         return i;
>     }
>
>     @Override
>     public String toString() {
>         return "MyClass{" + "i=" + i + "}@"+hashCode();
>     }
>
> }
> ----
>
> For now, I did not test complex classes. But I assume that this will 
> also work.
>
> So: Great. Serialization works. But why? I read that it is not 
> working? I found a lot of resources on the net talking about other 
> ways of serialization and ways around this issue...
>
> Is there someone on this list who can confirm that serialization 
> between DalvikVM and JVM with help of MINAs 
> IoBuffer#putObject/getObject is not an issue at all?
> My gurrent guess is, that serialization between both platforms became 
> compatible with Android Version XYZ ... Would be good to know which 
> version this was...
>
> Any comments/ideas?
>
> br,
> Alex
>