4

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

skaffman
  • 398,947
  • 96
  • 818
  • 769
inj.rav
  • 41
  • 2
  • I answered something similar in the past, it's not easy, but can be done. But I'd rather changed the requirements if I were you:) http://stackoverflow.com/questions/15090069/sending-java-object-of-an-unknown-class/15090966#15090966 – MarianP Jun 17 '14 at 15:39

2 Answers2

1

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.

Faustas
  • 350
  • 1
  • 2
  • 10
0

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.

Rafael Winterhalter
  • 42,759
  • 13
  • 108
  • 192