java类动态创建并使其可以通过网络不同的jvm访问,即可序列化
我需要动态创建java类并使其可以通过网络访问不同的jvm。我尝试使用反射和 javassist 工具,但没有任何效果。让我解释一下场景 我们正在使用 Coherence 分布式缓存。它具有跨集群并行进行聚合/过滤的能力。例如,如果一个类具有[动态类],则该类具有 amount 变量和 getAmount/setAmount 方法。然后,如果我们执行 COHERENCE 查询,它将在集群中并行启动处理。
我尝试使用 javassist 和反射在运行时创建类。我可以从单个 JVM 访问它,但是当我尝试从其他 JVM [通过一致性集群]访问同一个类时。我收到找不到类的异常[因为远程jvm不知道这个类]。我可以通过在远程jvm上动态创建相同的类并访问这些方法来解决这个问题。但内置方法/函数的一致性无法找到该类。 有人可以帮我解决这个问题吗
I have a requirement of creating java classes dynamically and make it accessible different jvms across the network. I tried to use reflection and javassist tool,but nothing worked. Let me explain the scenario
we are using Coherence distributed cache. It has a power of doing aggregation/filtering in parallel across the cluster. For example if a class has [dynamic class] has amount variable and getAmount/setAmount methods. Then if we execute COHERENCE queries, it will start process in parallel across the cluster.
I tried to create classes at run time by using javassist and reflection. I am able to access it from single JVM, but when I tried to access the same class from other jvm [through coherence cluster]. I am getting exception of class not found [as remote jvm is not having idea of this class].I can over come this by creating same class dynamically on remote jvm also and access the methods. But coherence in built methods/functions are not able to find the class.
could some one help me on this matter
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建的新类必须可供集群的所有节点使用。这意味着新创建的字节码必须到达每个节点 JVM 的类路径/类加载器。我认为最简单的方法是将生成的类放在共享网络驱动器上,并让所有 JVM 在其类路径中指向该共享网络位置。每次 JVM 找到对新类的引用时,它都应该从网络共享动态加载它。
A new class that gets created must be available to all nodes of the cluster. It means that the newly created bytecode must get on each node JVM's classpath/classloader. The simplest approach in my mind would be to put the generated classes on a shared network drive and have all JVMs point to that shared network location in their classpaths. Each time a JVM finds a reference to the new class it should load it dynamically from the network share.
您可以复制 javassist 创建的字节数组,并通过线路发送该字节数组,并通过自定义
ClassLoader
加载该字节数组。这样,该类将在所有 JVM 上呈现。You could copy the byte array that was created by javassist and send this byte array over the wire and load this byte array by a custom
ClassLoader
. This way, the class will be represented on all JVMs.