peholmst / vaadin4spring

Vaadin integration for Spring and Spring Boot
Apache License 2.0
266 stars 131 forks source link

ScopedEventBus serializable problem #324

Open Emmenemoi opened 4 years ago

Emmenemoi commented 4 years ago

ListenerCollection implements Serializable but not WeakHashMap. As a consequence ListenerCollection is NOT Serializable because of weakListeners property.

Emmenemoi commented 4 years ago

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()));
+
+    }
 }
knoobie commented 4 years ago

@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).

Emmenemoi commented 4 years ago

I'll add a pull request, the idea is here but it needs testing