vaadin4spring
vaadin4spring copied to clipboard
ScopedEventBus serializable problem
ListenerCollection implements Serializable but not WeakHashMap. As a consequence ListenerCollection is NOT Serializable because of weakListeners property.
Would it be a solution ?
@@ -188,4 +191,24 @@ class ListenerCollection implements Serializable {
}
}
}
+
+ private void readObject(ObjectInputStream ois)
+ throws IOException, ClassNotFoundException {
+
+ this.listeners = (Set<Listener>) ois.readObject();
+ this.weakListeners = Collections.newSetFromMap(new WeakHashMap<Listener, Boolean>());
+ this.weakListeners.addAll( (Set<Listener>) ois.readObject() ) ;
+ this.logger = LoggerFactory.getLogger(getClass());
+ logger.debug("after readObject weakListeners = {}", Arrays.deepToString(weakListeners.toArray()));
+ }
+
+ private void writeObject(ObjectOutputStream oos)
+ throws IOException {
+
+ oos.writeObject(listeners);
+ oos.writeObject(new HashSet<>(weakListeners));
+ logger.debug("writeObject weakListeners = {}", Arrays.deepToString(weakListeners.toArray()));
+
+ }
}
@peholmst Hey Petter, is your side project applicable for BFP? We currently ran into the same issue using your eventbus addon in one of our applications (V8 + addon 2-0-0).
I'll add a pull request, the idea is here but it needs testing