Thursday, January 12, 2006

Serializing a Stream


We start by declaring _actualDocument to be transient. transient is a Java keyword that
tells the serialization mechanism not to serialize the variable's value out. We then implement
writeObject( ), which does two things:

· Calls out.defaultWriteObject( ). This invokes the generic serialization
mechanism (which is the default) to write out all nontransient objects. That is, when
out.defaultWriteObject( ) is called, everything but _actualDocument has been
encoded in the stream.

· Copies _actualDocument to the stream, exactly as we did for the socket-based version
of the program.
Similarly, in readObject( ), we first call defaultReadObject( ), which retrieves all the
nontransient values, including _length, from the stream. We then read _actualDocument
from the stream.

RMI Headaches part 2

Well some things have been figured out since yesterday they are:

- rmic takes package arguments as: rmic the.package.it.is.in.ClassName (so '.'s not '/')
- RMI treats classes that implements Serialazable as objects that are passed by value, so if you pass one of those objects to a server, dont expect local changes (i think?)
- RMI treas classes that extend Remote as objects to be passed by ref
- There is an Oreilly book on Java RMI that is good.

Wednesday, January 11, 2006

Java RMI Headaches

Things one needs to do to get RMI working:

- Everything on the server must be interfaced where where interface extends Remote
- Everything that is passed between server and client must implement Serializable
- Every remote method must throw RemoteException

- You must run rmiregistry.exe on the server
- you cant use LocateRegistry on remote, must use Naming
- If you get a ClassNotFoundException on server it means you havent set your codebase properly.
- Since i havent figured out how to do SecurityManager stuff properly, i can override 2 checkPermission methods in SecurityManager with empty method bodies, thats a quick and dirty fix.
- Alternativly, you can set your policy file located in /lib/security/java.policy to: http://java.sun.com/docs/books/tutorial/rmi/example-1dot2/java.policy

RMI codebase crap:
Apperantly this needs to be set to something all clients can access, so a url on the www must be what this needs.

1. first you must compile your classes into stubs and skelletons with rmic.
- add rmic to your PATH variable in windows so you can use it. reopen all shells!
- or if windows decides to be gay and STILL NOT WORK, move the file to C:\windows
- at this point you should run rmic on your classes, so:
>rmic package/subpackage/ClassName

i get this error:
java.lang.NoClassDefFoundError

Google recomends:
Sometimes the rmic compiler has problems when the runtime libraries aren't
specified in the classpath. You shouldn't have to do this, but for some
reason it works. Try the following:

rmic -classpath ;\jre\lib\rt.jar

ex: rmic -classpath C:\MyClasses;C:\java\jre\lib\rt.jar MyRMIObject

----
did that, still no go. Found this tho:
- eclipse RMI plugin that supports automatic stub/skel generation
http://www.genady.net/rmi/
example:

Monday, January 09, 2006