]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/EventSupportImpl.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.db.procore / src / fi / vtt / simantics / procore / internal / EventSupportImpl.java
1 /*******************************************************************************
2  * Copyright (c) 2019 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     Semantum Oy - initial API and implementation
11  *******************************************************************************/
12 package fi.vtt.simantics.procore.internal;
13
14 import java.util.concurrent.CopyOnWriteArrayList;
15
16 import org.simantics.db.service.EventSupport;
17
18 /**
19  * Simple implementation for Event Support.
20  * 
21  * Note: for more extended / complicated scenarios, we could use org.simantics.utils.threads.SyncListenerList.
22  * 
23  * @author luukkainen
24  *
25  */
26 public class EventSupportImpl implements EventSupport {
27     
28     private CopyOnWriteArrayList<EventListener> listeners = new CopyOnWriteArrayList<>();
29     
30     @Override
31     public synchronized void addListener(EventListener l) {
32         listeners.add(l);
33     }
34     
35     @Override
36     public synchronized void removeListener(EventListener l) {
37         listeners.remove(l);
38     }
39     
40     public void fireEvent(String type, Object data) {
41         for (EventListener l : listeners) {
42             l.event(type, data);
43         }
44     }
45
46 }