views:

44

answers:

2

Is there a convenient way to transmit an object including its code (the class) over a network (not just the instance data)?

Don't ask me why I want to do this. It's in an assignment. I asked several times if that is really what they meant and the didn't rephrase their answer so I guess they really want us to transmit code (not just the field data) over a network. To be honest I have no clue why we need a Proxy in this assignment anyway, just writing a simple class would do IMO. The assignment says that we should instantiate the proxy on the server and transmit it to the client (and yes, they talk about a java.lang.reflect.Proxy, they name this class). Because there is no class file for a proxy I can't deploy that. I guess I would have to somehow read out the bytecode of the generated Proxy, transmit it to the client and then load it. Which makes absolutely no sense at all, but this seems what they want us to do. I don't get why.

+1  A: 

This is the core value proposition of the Apache River project (formerly known as Jini when it was run by Sun).

You put the code you need to run remotely in a jar on a "codebase" http server and publish your proxy to a lookup server. River annotates that proxy (which is a serialized instance) with the codebase URL(s). When a client fetches that proxy from the lookup server and instantiates it, the codebase jars are used in a sandboxed classloader. It's common to create "smart proxies" which load a bunch of code to run on the client to manage communication back to the source service, or you can use a simpler proxy to just make RMI calls.

The technology encapsulated by River is complicated, but profound.

Chris Dolan
This indeed sounds like what is intended to do here. (Still, speaking of our assignment I don't see why we should do such a thing. It's much to complicated for the pretty static setup of the assignment and the focus of the exercise is a totally different one.)
panzi
A: 

Proxy is Serializable ...

EJP