What I have currently:
2 JVMs, and on 1 JVM I have an interchangeable array of objects (constantly re-ordering). For the ease of reading, I'm gonna refer to the first JVM which doesn't contain the array with JVM 1, and the second JVM with the interchangeable array with JVM2.
What I want : To reach an Object pulled out of the array at JVM2 on JVM1, by sending the object to shared memory (is it called native?) then JVM1 would grab the object from shared memory.
Why? JVM2 needs its garbage collection frequency unchanged and needs to stay light, therefore JVM1 has all the logic and load.
Problems/Constraints:
-
JVM2 array objects are Unserializable, and there is no way to serialize them due to them being not controlled by me (Fetched by Reflection).
-
JVM2 array is interchangeable and re-orders every Garbage Collection and gets added to all the time.
-
I need the object to have its direct reference intact, so it can't be copied or turned into XML for an example. so no XStream, No GSON.. etc..
-
I need to keep JVM2's garbage collection frequency the same, so I cannot increase load by much. (So basically, I can't just wrap the objects and store them in a map so that I can interact with the object's fields from JVM1)
-
JVM2's array and its contents are fetched by reflection as an "Object" type, so I can't physically just grab the array like this: "
ClassContainingArray.getArray()
". -
Object sent by JVM2 to shared memory needs to be removed from memory once the same object at the array is garbage collected.
Example of what I want to do in code:
JVM2 (the one interchangeable array) class:
public class Main**JVM2** {
public void getObjectFromArray() {
Field field = classLoader.loadClass("ClassContainingArray").getDeclaredFields("array");
Object[] arrayObject = (Object[]) field.get(null); //Static
//... logic to get the wanted object from the array
Object obFromArray = arrayObject[index_Fetched_from_logic_above];
sendObjectToJVM1(obFromArray);
}
public void sendObjectTo**JVM1**(Object ob) {
//Here I want to put the object into shared memory. But at the same time
//I want it to be removed from shared memory once the same object from the array
//has been garbage collected/removed.
}
}
JVM1 class:
public class Main**JVM1** {
public void receiveObject() {
//Get the object from shared memory
//Use reflection to get objects within (Primitive and Non-primitive)
//If Getting objects-within isn't possible, it's alright at least I'll have a
//reference to the object which I can use to ask **JVM2** for the objects within.
}
}
Note 1: The objects that will sent from JVM2 to JVM1 will be a lot (as there are lots of arrays and lots of objects (over-time of course).
Note 2: After sending the object to shared memory (it has to be removed once the same object in the array is removed/garbage collected)
Note 3: The object also have a connection by RMI for other stuff.
Questions you might have: (Will add more here, once asked in comments)
1) Where is the ClassContainingArray to the point you're getting it via Reflection? It's on another ClassLoader, as I'm attached to it (Java Attach API/Instrumentation).
-- Maybe there's something I can do with like ByteBuffer? Unsafe? I'm honestly lost in those 2.
Aucun commentaire:
Enregistrer un commentaire