]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Made DB ListenerAdapter abstract to force isDisposed implementation 51/1151/4
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 27 Oct 2017 22:14:27 +0000 (01:14 +0300)
committerJani Simomaa <jani.simomaa@semantum.fi>
Mon, 30 Oct 2017 05:28:03 +0000 (07:28 +0200)
This forces the user of the adapter to still handle the life-cycle of
the listener, which should never be neglected.

refs #7581

Change-Id: I1a54b3f130dfe5f82fcdf01eb799ac96b31e7636

12 files changed:
bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/adapter/AsyncListenerAdapter.java
bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/adapter/ListenerAdapter.java
bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/adapter/SyncListenerAdapter.java
bundles/org.simantics.scenegraph.loader/src/org/simantics/scenegraph/loader/ScenegraphLoaderUtils.java
tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/exception/RecoveryFromExceptedState.java
tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/listening/ObjectsListeningTest.java
tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/RequestProcessorTest1.java
tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/thread/ThreadingTest1.java
tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/thread/ThreadingTest2.java
tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/CachedDirectPredicatesWithNoCluster.java
tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/ObjectsWithNoClusterWithCachedRelationInfo.java
tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/ReadHierarchicalNames.java

index 3f4d95a0e3307f8d4dbf37051fadfa17c06549bf..0046e413d75e3173116ebbeb0b5ebaf3ae94f21c 100644 (file)
@@ -14,7 +14,7 @@ package org.simantics.db.common.procedure.adapter;
 import org.simantics.db.AsyncReadGraph;
 import org.simantics.db.procedure.AsyncListener;
 
-public class AsyncListenerAdapter<T> implements AsyncListener<T> {
+public abstract class AsyncListenerAdapter<T> implements AsyncListener<T> {
 
     @Override
     public void exception(AsyncReadGraph graph, Throwable t) {
@@ -25,8 +25,6 @@ public class AsyncListenerAdapter<T> implements AsyncListener<T> {
     }
 
     @Override
-    public boolean isDisposed() {
-        return false;
-    }
+    public abstract boolean isDisposed();
 
 }
index 6959236d6c03e78c5da2afc36adf25e13b6f0ec0..ab681f8ef8168be1794dccda90e56fc80db5a446 100644 (file)
@@ -13,7 +13,7 @@ package org.simantics.db.common.procedure.adapter;
 
 import org.simantics.db.procedure.Listener;
 
-public class ListenerAdapter<T> implements Listener<T> {
+public abstract class ListenerAdapter<T> implements Listener<T> {
 
     @Override
     public void exception(Throwable t) {
@@ -24,8 +24,6 @@ public class ListenerAdapter<T> implements Listener<T> {
     }
 
     @Override
-    public boolean isDisposed() {
-        return false;
-    }
+    public abstract boolean isDisposed();
 
 }
index 0b8b99208366b074634332d0e079c66606d697f0..b5bdb5bca8005f89941655e68aa9d2636cc775aa 100644 (file)
@@ -14,7 +14,7 @@ package org.simantics.db.common.procedure.adapter;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.procedure.SyncListener;
 
-public class SyncListenerAdapter<T> implements SyncListener<T> {
+public abstract class SyncListenerAdapter<T> implements SyncListener<T> {
 
     @Override
     public void exception(ReadGraph graph, Throwable t) {
@@ -25,8 +25,6 @@ public class SyncListenerAdapter<T> implements SyncListener<T> {
     }
 
     @Override
-    public boolean isDisposed() {
-        return false;
-    }
+    public abstract boolean isDisposed();
 
 }
index acf585dcc91ccb131cb111afeb42d074ffee9e29..e40773002ebfb68fb5bab610b5896c1e0f699001 100644 (file)
@@ -15,7 +15,7 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.RequestProcessor;
 import org.simantics.db.Resource;
 import org.simantics.db.common.NamedResource;
-import org.simantics.db.common.procedure.adapter.ListenerAdapter;
+import org.simantics.db.common.procedure.adapter.ProcedureAdapter;
 import org.simantics.db.common.request.BinaryRead;
 import org.simantics.db.common.request.ParametrizedPrimitiveRead;
 import org.simantics.db.common.request.ResourceRead;
@@ -29,6 +29,7 @@ import org.simantics.db.layer0.variable.Variable;
 import org.simantics.db.layer0.variable.VariableBuilder;
 import org.simantics.db.layer0.variable.Variables;
 import org.simantics.db.procedure.Listener;
+import org.simantics.db.procedure.Procedure;
 import org.simantics.layer0.Layer0;
 import org.simantics.scenegraph.INode;
 import org.simantics.scenegraph.LoaderNode;
@@ -44,7 +45,7 @@ import org.simantics.utils.threads.ThreadUtils;
 
 public class ScenegraphLoaderUtils {
        
-       static Map<Pair<Variable, String>, Collection<Listener<Object>>> externalMap = new HashMap<Pair<Variable, String>, Collection<Listener<Object>>>(); 
+       static Map<Pair<Variable, String>, Collection<Procedure<Object>>> externalMap = new HashMap<Pair<Variable, String>, Collection<Procedure<Object>>>(); 
        static Map<Pair<Variable, String>, Object> externalValueMap = new HashMap<Pair<Variable, String>, Object>(); 
 
        final public static class ScenegraphPropertyReference<T> {
@@ -59,12 +60,12 @@ public class ScenegraphLoaderUtils {
                        public void register(ReadGraph graph, final Listener<T> procedure) {
                                Object value = externalValueMap.get(parameter);
                                procedure.execute((T)value);
-                               Collection<Listener<Object>> listeners = externalMap.get(parameter);
+                               Collection<Procedure<Object>> listeners = externalMap.get(parameter);
                                if(listeners == null) {
-                                       listeners = new ArrayList<Listener<Object>>();
+                                       listeners = new ArrayList<Procedure<Object>>();
                                        externalMap.put(parameter, listeners);
                                }
-                               listeners.add(new ListenerAdapter<Object>() {
+                               listeners.add(new ProcedureAdapter<Object>() {
                                        
                                        @Override
                                        public void execute(Object result) {
@@ -353,9 +354,9 @@ public class ScenegraphLoaderUtils {
                public Boolean apply(String property, Object value) {
                        Pair<Variable, String> key = Pair.make(reference.first, reference.second + "#" + property);
                        externalValueMap.put(key, value);
-                       Collection<Listener<Object>> listeners = externalMap.get(key);
+                       Collection<Procedure<Object>> listeners = externalMap.get(key);
                        if(listeners != null) {
-                               for(Listener<Object> listener : listeners) listener.execute(value);
+                               for(Procedure<Object> listener : listeners) listener.execute(value);
                        }
                        return true;
                }
index 9a18036d8628b317c5657afba160082895a8d1c9..31e995f1ed7ed138f39be930e8c1562bca03c47f 100644 (file)
@@ -63,7 +63,12 @@ public class RecoveryFromExceptedState extends ExistingDatabaseTest {
                                        return graph.getResource("http://A");
                                }
                                
-                       }, new ListenerAdapter<Resource>());
+                       }, new ListenerAdapter<Resource>() {
+                               @Override
+                               public boolean isDisposed() {
+                                       return false;
+                               }
+                       });
 
                        /*
                         * Invalidates the request. Request is updated (is has a listener) and enters 'Excepted' state. 
index 6811ce5f481ef7f7f6ff424e378375d5107f643a..998eb94e23896eaf9e6a60db314cda16555de70d 100644 (file)
@@ -65,6 +65,11 @@ public class ObjectsListeningTest extends ExistingDatabaseTest {
                        executions.incrementAndGet();
                }
                
+               @Override
+               public boolean isDisposed() {
+                       return false;
+               }
+               
         });
         
         session.syncRequest(new WriteRequest() {
index be32a81fb98078d81661aaa8f94bc24ff0f6ffed..2c89c1ecc11bed2f654ca575cb9d1d7701536f5f 100644 (file)
@@ -104,6 +104,11 @@ public class RequestProcessorTest1 extends WriteReadTest {
                                listeners.add(result);
                        }
                        
+                       @Override
+                       public boolean isDisposed() {
+                               return false;
+                       }
+                       
                };
                
                assertEquals(Layer0.URIs.ConsistsOf, graph.sync(new R1(L0.ConsistsOf)));
index cac163968b21ed5ebfaafe9a57cdc7a4fc1a272b..e96ea1cbbd45c859859b8005bfbb93f47fedf184 100644 (file)
@@ -61,7 +61,12 @@ public class ThreadingTest1 extends ExistingDatabaseTest {
                return 0;
             }
                    
-               }, new ListenerAdapter<Integer>());
+               }, new ListenerAdapter<Integer>() {
+                       @Override
+                       public boolean isDisposed() {
+                               return false;
+                       }
+               });
                
                assert(result == 1);
                
index f3e1cd14a4a49fe9f5da489b961b0f7cac91d165..6bd67790fb2d1ee6a72869e629b16a62dabd6b14 100644 (file)
@@ -61,7 +61,12 @@ public class ThreadingTest2 extends ExistingDatabaseTest {
                return 0;
             }
                    
-               }, new ListenerAdapter<Integer>());
+               }, new ListenerAdapter<Integer>() {
+                       @Override
+                       public boolean isDisposed() {
+                               return false;
+                       }
+               });
                
                assert(result == 1);
                
index 19091b51862b5dcc552d70f80d8516d86aed8271..a9698e744f946a3a14daa61fd92bb43d3d61ab2a 100644 (file)
@@ -31,7 +31,12 @@ public class CachedDirectPredicatesWithNoCluster extends ExistingDatabaseTest {
                 return graph.hasStatement(L0.Entity);
             }
             
-        }, new ListenerAdapter<Boolean>());
+        }, new ListenerAdapter<Boolean>() {
+            @Override
+            public boolean isDisposed() {
+                return false;
+            }
+        });
         
         ClusterControl support = getSession().getService(ClusterControl.class);
         support.collectClusters(Integer.MAX_VALUE);
index 0596f765873630e4bfda2f322385b91aa94ec272..75985072186dce8864132e3b603518a2d0810ab8 100644 (file)
@@ -36,7 +36,12 @@ public class ObjectsWithNoClusterWithCachedRelationInfo extends ExistingDatabase
         });
        
         // Cache RelationInfo for HasName
-        session.syncRequest(new PossibleObject(L0.Entity, L0.HasName), new ListenerAdapter<Resource>());
+        session.syncRequest(new PossibleObject(L0.Entity, L0.HasName), new ListenerAdapter<Resource>() {
+            @Override
+            public boolean isDisposed() {
+                return false;
+            }
+        });
 
         // Flush clusters
                ClusterControl support = getSession().getService(ClusterControl.class);
index 974cc71049f92e0da38b3ead19ef3dee5fa4198c..66e3842e0df12305071307a8891875f27605d588 100644 (file)
@@ -94,7 +94,12 @@ public class ReadHierarchicalNames extends ExistingDatabaseTest {
        private void listenTime(String label, Read<Object> request) throws DatabaseException {
 
                long start = System.nanoTime();
-               getSession().syncRequest(request, new ListenerAdapter<Object>());
+               getSession().syncRequest(request, new ListenerAdapter<Object>() {
+                       @Override
+                       public boolean isDisposed() {
+                               return false;
+                       }
+               });
                long duration = System.nanoTime() - start;
                System.out.println(label + " = " + 1e-9*duration);