1

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.

panzi
  • 7,517
  • 5
  • 42
  • 54
  • Are you sure they don't want you to call the code remotely? That is a call to the proxy on the client actually executes the code on the server and returns the result to the client? – Yishai May 06 '10 at 21:39
  • Yishai is probably correct here - proxy objects are often used to allow for transmission of requests across the wire. I would recommend reading the java.lang.reflect.Proxy java docs, located here: http://java.sun.com/javase/6/docs/api/java/lang/reflect/Proxy.html – aperkins May 06 '10 at 21:41
  • I know what the Proxy class is good for. The exercise to another lecture was to write a RMI like middleware, which I really enjoyed. I wrote my own serialization framework, network transport, very basic naming, used annotations and reflection a lot in order to generate nice proxies etc. In this exercise the main focus is to write a transparently replicated system and we have to hide the fact that the servers are replicated with a proxy. And the assignment really states that we have to instantiate the proxy on the server and then the proxy shall be used by the client. – panzi May 07 '10 at 02:47

1 Answers1

1

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
  • 8,905
  • 2
  • 35
  • 73
  • 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 May 08 '10 at 12:10