Track instance attribute changes

We are working on several processes that use RMI for RPC.

The problem we are facing is that the main object that needs to be passed between the processes is very large (during serialization), and this drastically reduced the performance of the code.

Since none of the processes changes the entire object or changes only small parts of it, we decided to simply pass the “modifications” through RMI.

but I did not find a suitable way to implement such a concept. The first idea was to track all changes to the primary instance. But it does not look easy according to this .

I need a way we can:

  • developing fast
  • performs fast

any suggestion?

+4
source share
4 answers

Just make this “main object” a remote object that implements the remote interface, and export it, rather than serializing it back and forth.

0
source

I think the best way is to set up serialization so that you can only post changes. you can do this using the private private void writeObject method (java.io.ObjectOutputStream stream) and, of course, readObject on the other hand. ok what should you do in these functions? I suggest that you manage the bitmap of all members that have been changed and send them only to serialization, just change the unchanged members to zero by sending the object to serialization and returning the values ​​there. on the other hand, read the bitmap and you will know how

0
source

The first time you need to pass the whole object.

Use the PropertyChangeListener property for the object, this will lead to the creation of a PropertyChangeEvent.

You can pass PropertyChangeEvent. It has getSource (), with which you can identify the object. If this is not enough, if you need an IOR or some other link, create a wrapper and send it via.

-Maddy

-1
source

Take a look at http://docs.oracle.com/javase/tutorial/uiswing/events/propertychangelistener.html

public class Test { PropertyChangeSupport pcs = new PropertyChangeSupport(this); private String name; private int age; public String getName() { return name; } public void setName(String name) { String oldName = this.name; this.name = name; pcs.firePropertyChange("name", oldName, name); } public int getAge() { return age; } public void setAge(int age) { int oldAge = this.age; this.age = age; pcs.firePropertyChange("age", oldAge, age); } public void addPropertyChangeListener(PropertyChangeListener listener) { pcs.addPropertyChangeListener(listener); } public void removePropertyChangeListener(PropertyChangeListener listener) { pcs.removePropertyChangeListener(listener); } public Test(){ } public static void main (String[] args){ Test myTestObject = new Test(); myTestObject.addPropertyChangeListener(new MyPropertyChangeListener()); myTestObject.setAge(12); myTestObject.setName("Rick"); myTestObject.setName("Andrew"); } private static class MyPropertyChangeListener implements PropertyChangeListener { @Override public void propertyChange(PropertyChangeEvent event) { String clazz = event.getSource().getClass().getName(); System.out.println(clazz+"::"+event.getPropertyName()+" changed from "+event.getOldValue()+" to "+event.getNewValue()); } } } 

This is a simple example, but using this approach, you can create different PropertyChangeListeners and provide different logic inside your propertyChange method. You can also run only changes on a small set of attributes, and not on all of them (without saving the oldValue and without starting the firePropertyChange PropertyChangeSupport method).

Of course, you can use AOP, but maybe you are looking for a solution similar to the one presented above. Hope this helps.

-1
source

Source: https://habr.com/ru/post/1440218/


All Articles