开发者

transmit a java.lang.reflect.Proxy over a network

开发者 https://www.devze.com 2022-12-29 23:46 出处:网络
Is there a convenient way to transmit an object including its code (the class) over a network (not just the instance data)?

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开发者_如何学JAVA 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号