Discussion:
Help needed on returning serviceregistrar by hand
Alex Co
2009-06-25 15:00:32 UTC
Permalink
Hi all,

Jini serialization is not the same as writeObject/readObject serialization, right?

Suppose I have a compiled class file called MyServiceRegistrarProxy that
implements ServiceRegistrar, Serializable.

MyServiceRegistrarProxy x= new MyServiceRegistrarProxy();

Now I want to store the x object into a file but following the same serialization
protocol that reggie follows when it returns its serviceregistrar to clients by
sockets.

I want that the file contents be compliant with the future use of:
ServiceRegistrar registrar = lookup.getRegistrar();

e.g on future i want to have a second thread or something reading the file and
sending file data to clients and clients building ServiceRegistrar objects from
my MyServiceRegistrarProxy type.


To serialize the object to file using standard serialization i do this:

String filename = "myserviceregistrar.svr";

FileOutputStream fos = null;
ObjectOutputStream out = null;

MyServiceRegistrarProxy p = new MyServiceRegistrarProxy();
try
{
fos = new FileOutputStream(filename);
out = new ObjectOutputStream(fos);
out.writeObject(p);
out.close();
}
catch(IOException ex)
{
ex.printStackTrace();
}


whichs classes can i use to serialize it to file in a Jini compliant way?
An example would be very appreciated.

Thanks a lot

Alex

--------------------------------------------------------------------------
Getting Started: http://www.jini.org/wiki/Category:Getting_Started
Community Web Site: http://jini.org
jini-users Archive: http://archives.java.sun.com/archives/jini-users.html
Unsubscribing: email "signoff JINI-USERS" to ***@java.sun.com
Gregg Wonderly
2009-06-25 18:04:01 UTC
Permalink
Serialization is "Serialization". The issue is which object is serialized
across the wire. For Reggie, you need to look at the implementation of lookup()
in the RegistrarProxy class. The MarshalledWrapper class is what the server
returns to the client.

Gregg Wonderly
Post by Alex Co
Hi all,
Jini serialization is not the same as writeObject/readObject serialization, right?
Suppose I have a compiled class file called MyServiceRegistrarProxy that
implements ServiceRegistrar, Serializable.
MyServiceRegistrarProxy x= new MyServiceRegistrarProxy();
Now I want to store the x object into a file but following the same serialization
protocol that reggie follows when it returns its serviceregistrar to clients by
sockets.
ServiceRegistrar registrar = lookup.getRegistrar();
e.g on future i want to have a second thread or something reading the file and
sending file data to clients and clients building ServiceRegistrar objects from
my MyServiceRegistrarProxy type.
String filename = "myserviceregistrar.svr";
FileOutputStream fos = null;
ObjectOutputStream out = null;
MyServiceRegistrarProxy p = new MyServiceRegistrarProxy();
try
{
fos = new FileOutputStream(filename);
out = new ObjectOutputStream(fos);
out.writeObject(p);
out.close();
}
catch(IOException ex)
{
ex.printStackTrace();
}
whichs classes can i use to serialize it to file in a Jini compliant way?
An example would be very appreciated.
Thanks a lot
Alex
--------------------------------------------------------------------------
Getting Started: http://www.jini.org/wiki/Category:Getting_Started
Community Web Site: http://jini.org
jini-users Archive: http://archives.java.sun.com/archives/jini-users.html
--------------------------------------------------------------------------
Getting Started: http://www.jini.org/wiki/Category:Getting_Started
Community Web Site: http://jini.org
jini-users Archive: http://archives.java.sun.com/archives/jini-users.html
Unsubscribing: email "signoff JINI-USERS" to ***@java.sun.com
Alex Co
2009-06-25 18:45:52 UTC
Permalink
I am trying this on MyLUS

MyRegistrarProxy p = new MyRegistrarProxy();


out.writeObject(new
MarshalledInstance(p,Collections.EMPTY_LIST).convertToMarshalledObject());

Then another thread reads the file (out) and sends byte by byte to receiver.

but on receiver (client) when the line

ServiceRegistrar registrar = lookup.getRegistrar();

is executed JVM says:

Exception in thread "main" java.io.StreamCorruptedException: invalid type
code:00

Alex

--------------------------------------------------------------------------
Getting Started: http://www.jini.org/wiki/Category:Getting_Started
Community Web Site: http://jini.org
jini-users Archive: http://archives.java.sun.com/archives/jini-users.html
Unsubscribing: email "signoff JINI-USERS" to ***@java.sun.com
Gregg Wonderly
2009-06-25 19:34:36 UTC
Permalink
Post by Alex Co
I am trying this on MyLUS
MyRegistrarProxy p = new MyRegistrarProxy();
out.writeObject(new
MarshalledInstance(p,Collections.EMPTY_LIST).convertToMarshalledObject());
Just from my perspective:

The purpose of MarshalledInstance is to provide some separation from
MarshalledObject. In your case, you can just use MarshalledObject to wrap the
proxy object with the codebase that the associated classloader is advertising
via the RMIClassLoaderSPI.

To your problem, look at how you are doing the writeObject() and readObject().
I suspect that you have corrupted the stream by intermingly I/O with the
Object(Input/Output)Stream and the underlying InputStream/OutputStream and not
flushing at the appropriate times to make sure the bytes that go out the
OutputStream or come in the InputStream are properly ordered.

Gregg Wonderly

--------------------------------------------------------------------------
Getting Started: http://www.jini.org/wiki/Category:Getting_Started
Community Web Site: http://jini.org
jini-users Archive: http://archives.java.sun.com/archives/jini-users.html
Unsubscribing: email "signoff JINI-USERS" to ***@java.sun.com
Alex Co
2009-06-25 19:38:56 UTC
Permalink
By the way, the file is written using the writeObject method (Java) but then
the file is read using Windows C API and sent to client via winsock api.
Hence, at client side there is a typical Jini Java client application.

I will try your advices.

Thank you very much

Alex

--------------------------------------------------------------------------
Getting Started: http://www.jini.org/wiki/Category:Getting_Started
Community Web Site: http://jini.org
jini-users Archive: http://archives.java.sun.com/archives/jini-users.html
Unsubscribing: email "signoff JINI-USERS" to ***@java.sun.com
Loading...