Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScopedEventBus serializable problem #324

Open
Emmenemoi opened this issue Jan 15, 2020 · 3 comments
Open

ScopedEventBus serializable problem #324

Emmenemoi opened this issue Jan 15, 2020 · 3 comments

Comments

@Emmenemoi
Copy link

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

@Emmenemoi Emmenemoi changed the title EventBus serializable EventBus (ScopedEventBus) serializable Jan 15, 2020
@Emmenemoi Emmenemoi changed the title EventBus (ScopedEventBus) serializable ScopedEventBus serializable problem Jan 15, 2020
@Emmenemoi
Copy link
Author

Emmenemoi commented Jan 20, 2020

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
Copy link

knoobie commented Feb 7, 2020

@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
Copy link
Author

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

@Emmenemoi Emmenemoi mentioned this issue Feb 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants