You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2014/12/27 17:25:51 UTC

jena git commit: JENA-557 : Deprecate object field 'graph' in SimpleEventManager

Repository: jena
Updated Branches:
  refs/heads/master 03342b1aa -> 6c4eecd84


JENA-557 : Deprecate object field 'graph' in SimpleEventManager


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/6c4eecd8
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/6c4eecd8
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/6c4eecd8

Branch: refs/heads/master
Commit: 6c4eecd84bddc5d51d29fb96323b3383f383cf5b
Parents: 03342b1
Author: Andy Seaborne <an...@apache.org>
Authored: Sat Dec 27 16:25:37 2014 +0000
Committer: Andy Seaborne <an...@apache.org>
Committed: Sat Dec 27 16:25:37 2014 +0000

----------------------------------------------------------------------
 .../com/hp/hpl/jena/graph/impl/GraphBase.java   |   2 +-
 .../hpl/jena/graph/impl/SimpleEventManager.java | 243 +++++++++----------
 .../hp/hpl/jena/graph/impl/WrappedGraph.java    |   2 +-
 .../hp/hpl/jena/sdb/graph/EventManagerSDB.java  |  19 +-
 .../com/hp/hpl/jena/sdb/graph/GraphSDB.java     |   2 +-
 5 files changed, 135 insertions(+), 133 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/6c4eecd8/jena-core/src/main/java/com/hp/hpl/jena/graph/impl/GraphBase.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/com/hp/hpl/jena/graph/impl/GraphBase.java b/jena-core/src/main/java/com/hp/hpl/jena/graph/impl/GraphBase.java
index e85e98a..0ac6c5f 100644
--- a/jena-core/src/main/java/com/hp/hpl/jena/graph/impl/GraphBase.java
+++ b/jena-core/src/main/java/com/hp/hpl/jena/graph/impl/GraphBase.java
@@ -106,7 +106,7 @@ public abstract class GraphBase implements GraphWithPerform
     @Override
     public GraphEventManager getEventManager()
         { 
-        if (gem == null) gem = new SimpleEventManager( this ); 
+        if (gem == null) gem = new SimpleEventManager( ); 
         return gem;
         }
     

http://git-wip-us.apache.org/repos/asf/jena/blob/6c4eecd8/jena-core/src/main/java/com/hp/hpl/jena/graph/impl/SimpleEventManager.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/com/hp/hpl/jena/graph/impl/SimpleEventManager.java b/jena-core/src/main/java/com/hp/hpl/jena/graph/impl/SimpleEventManager.java
index e708dc5..481d605 100644
--- a/jena-core/src/main/java/com/hp/hpl/jena/graph/impl/SimpleEventManager.java
+++ b/jena-core/src/main/java/com/hp/hpl/jena/graph/impl/SimpleEventManager.java
@@ -30,161 +30,158 @@ import com.hp.hpl.jena.util.iterator.ExtendedIterator;
     Simple implementation of GraphEventManager for GraphBase to use.
     The listeners are held as an [Array]List.
 <p>
-    The code duplication is a right pain. The most natural removal tactic, a
-    meta-method that took the notification method as an argument, is not
-    available in Java, and I can't off-hand think of a clean alternative.
-<p>
     This class also holds the utility method notifyingRemove, which wraps 
     iterators so that their .remove() operation notifies the specified graph of
     the removal.    
 */
 
 public class SimpleEventManager implements GraphEventManager
-    {
+{
+    /* Implementation note:
+     * 
+     * Use of CopyOnWriteArray is unnecessarily inefficient, in that
+     * a copy is only needed when the register or unregister
+     * is concurrent with an iteration over the list.
+     * Since this list is not public we can either make it private
+     * or provide methods for iterating, so that we know when
+     * it is necessary to copy the array of listeners and when it 
+     * isn't.
+     * This is a fair bit of code, and would need either a lock or
+     * an atomic integer or something from the concurrent package.
+     * Until and unless the high cost of registering and unregistering
+     * is an issue I think the current code is elegant and clean.
+     * In practice, most graphs have no more than 10 listeners
+     * so the 10 registrations take 55 word copy operations - nothing
+     * to get upset about.
+     */
+    
+    /** @deprecated Use the graph passed in in notify operations. */
+    @Deprecated
     protected Graph graph;
     protected List<GraphListener>  listeners;
     
-    public SimpleEventManager( Graph graph ) 
-        { 
+    /** The graph object for the notification is passed
+     *  @deprecated Use the no argument constructor.    
+     */
+    @Deprecated
+    public SimpleEventManager( Graph graph )
+    { 
+        this();
         this.graph = graph;
+    }
+    
+    public SimpleEventManager() {
+        this.graph = null ;
         this.listeners = new CopyOnWriteArrayList<>();
-/* Implementation note: Jeremy Carroll
- * 
- * Use of CopyOnWriteArray is unnecessarily inefficient, in that
- * a copy is only needed when the register or unregister
- * is concurrent with an iteration over the list.
- * Since this list is not public we can either make it private
- * or provide methods for iterating, so that we know when
- * it is necessary to copy the array of listeners and when it 
- * isn't.
- * This is a fair bit of code, and would need either a lock or
- * an atomic integer or something from the concurrent package.
- * Until and unless the high cost of registering and unregistering
- * is an issue I think the current code is elegant and clean.
- * In practice, most graphs have no more than 10 listeners
- * so the 10 registrations take 55 word copy operations - nothing
- * to get upset about.
- */
-        }
+    }
     
     @Override
-    public GraphEventManager register( GraphListener listener ) 
-        { 
+    public GraphEventManager register( GraphListener listener ) { 
         listeners.add( listener );
         return this; 
         }
-        
+
     @Override
-    public GraphEventManager unregister( GraphListener listener ) 
-        { 
-        listeners.remove( listener ); 
-        return this;
-        }
-    
+    public GraphEventManager unregister(GraphListener listener) {
+        listeners.remove(listener) ;
+        return this ;
+    }
+
     @Override
-    public boolean listening()
-        { return listeners.size() > 0; }
-        
+    public boolean listening() {
+        return listeners.size() > 0 ;
+    }
+
     @Override
-    public void notifyAddTriple( Graph g, Triple t ) 
-        {
-        for (GraphListener l:listeners) 
-            l.notifyAddTriple( g, t ); 
-        }
-    
+    public void notifyAddTriple(Graph g, Triple t) {
+        for ( GraphListener l : listeners )
+            l.notifyAddTriple(g, t) ;
+    }
+
     @Override
-    public void notifyAddArray( Graph g, Triple [] ts )
-        {
-        for (GraphListener l:listeners) 
-            l.notifyAddArray( g, ts ); 
-        }
-        
+    public void notifyAddArray(Graph g, Triple[] ts) {
+        for ( GraphListener l : listeners )
+            l.notifyAddArray(g, ts) ;
+    }
+
     @Override
-    public void notifyAddList( Graph g, List<Triple> L )
-        {
-        for (GraphListener l:listeners) 
-            l.notifyAddList( g, L);      
-        }
-        
+    public void notifyAddList(Graph g, List<Triple> L) {
+        for ( GraphListener l : listeners )
+            l.notifyAddList(g, L) ;
+    }
+
     @Override
-    public void notifyAddIterator( Graph g, List<Triple> it )
-        {
-        for (GraphListener l:listeners) 
-            l.notifyAddIterator( g, it.iterator() ); 
-        }
-        
+    public void notifyAddIterator(Graph g, List<Triple> it) {
+        for ( GraphListener l : listeners )
+            l.notifyAddIterator(g, it.iterator()) ;
+    }
+
     @Override
-    public void notifyAddIterator( Graph g, Iterator<Triple> it )
-        { notifyAddIterator( g, IteratorCollection.iteratorToList( it ) ); }
-        
+    public void notifyAddIterator(Graph g, Iterator<Triple> it) {
+        notifyAddIterator(g, IteratorCollection.iteratorToList(it)) ;
+    }
+
     @Override
-    public void notifyAddGraph( Graph g, Graph added )
-        {
-        for (GraphListener l:listeners) 
-            l.notifyAddGraph( g, added ); 
-        }
-        
+    public void notifyAddGraph(Graph g, Graph added) {
+        for ( GraphListener l : listeners )
+            l.notifyAddGraph(g, added) ;
+    }
+
     @Override
-    public void notifyDeleteTriple( Graph g, Triple t ) 
-        { 
-        for (GraphListener l:listeners) 
-            l.notifyDeleteTriple( g, t ); 
-        }
-        
+    public void notifyDeleteTriple(Graph g, Triple t) {
+        for ( GraphListener l : listeners )
+            l.notifyDeleteTriple(g, t) ;
+    }
+
     @Override
-    public void notifyDeleteArray( Graph g, Triple [] ts )
-        {
-        for (GraphListener l:listeners) 
-            l.notifyDeleteArray( g, ts ); 
-        }
-        
+    public void notifyDeleteArray(Graph g, Triple[] ts) {
+        for ( GraphListener l : listeners )
+            l.notifyDeleteArray(g, ts) ;
+    }
+
     @Override
-    public void notifyDeleteList( Graph g, List<Triple> L )
-        {
-        for (GraphListener l:listeners) 
-            l.notifyDeleteList( g, L );      
-        }
-        
+    public void notifyDeleteList(Graph g, List<Triple> L) {
+        for ( GraphListener l : listeners )
+            l.notifyDeleteList(g, L) ;
+    }
+
     @Override
-    public void notifyDeleteIterator( Graph g, List<Triple> L )
-        {
-        for (GraphListener l:listeners) 
-            l.notifyDeleteIterator( g, L.iterator() ); 
-        }
-        
+    public void notifyDeleteIterator(Graph g, List<Triple> L) {
+        for ( GraphListener l : listeners )
+            l.notifyDeleteIterator(g, L.iterator()) ;
+    }
+
     @Override
-    public void notifyDeleteIterator( Graph g, Iterator<Triple> it )
-        { notifyDeleteIterator( g, IteratorCollection.iteratorToList( it ) ); }    
-            
+    public void notifyDeleteIterator(Graph g, Iterator<Triple> it) {
+        notifyDeleteIterator(g, IteratorCollection.iteratorToList(it)) ;
+    }
+
     @Override
-    public void notifyDeleteGraph( Graph g, Graph removed )
-        {
-        for (GraphListener l:listeners) 
-            l.notifyDeleteGraph( g, removed ); 
-        }
-    
+    public void notifyDeleteGraph(Graph g, Graph removed) {
+        for ( GraphListener l : listeners )
+            l.notifyDeleteGraph(g, removed) ;
+    }
+
     @Override
-    public void notifyEvent( Graph source, Object event )
-        {
-        for (GraphListener l:listeners) 
-            l.notifyEvent( source, event ); }
+    public void notifyEvent(Graph source, Object event) {
+        for ( GraphListener l : listeners )
+            l.notifyEvent(source, event) ;
+    }
 
     /**
-     * Answer an iterator which wraps <code>i</code> to ensure that if a .remove()
-     * is executed on it, the graph <code>g</code> will be notified.
-    */
-    public static ExtendedIterator<Triple> notifyingRemove( final Graph g, Iterator<Triple> i )
-        {
-        return new TrackingTripleIterator( i )
-            {            
-            protected final GraphEventManager gem = g.getEventManager();
+     * Answer an iterator which wraps <code>i</code> to ensure that if a
+     * .remove() is executed on it, the graph <code>g</code> will be notified.
+     */
+    public static ExtendedIterator<Triple> notifyingRemove(final Graph g, Iterator<Triple> i) {
+        return new TrackingTripleIterator(i) {
+            protected final GraphEventManager gem = g.getEventManager() ;
+
             @Override
-            public void remove()
-                {
-                super.remove();
-                gem.notifyDeleteTriple( g, current );
-                }
-            };
-        }
-    
+            public void remove() {
+                super.remove() ;
+                gem.notifyDeleteTriple(g, current) ;
+            }
+        } ;
     }
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/6c4eecd8/jena-core/src/main/java/com/hp/hpl/jena/graph/impl/WrappedGraph.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/com/hp/hpl/jena/graph/impl/WrappedGraph.java b/jena-core/src/main/java/com/hp/hpl/jena/graph/impl/WrappedGraph.java
index 29e7f01..1854374 100644
--- a/jena-core/src/main/java/com/hp/hpl/jena/graph/impl/WrappedGraph.java
+++ b/jena-core/src/main/java/com/hp/hpl/jena/graph/impl/WrappedGraph.java
@@ -61,7 +61,7 @@ public class WrappedGraph implements GraphWithPerform
     @Override
     public GraphEventManager getEventManager()
     {
-        if (gem == null) gem = new SimpleEventManager( this ); 
+        if (gem == null) gem = new SimpleEventManager( ); 
         return gem;
     }
 

http://git-wip-us.apache.org/repos/asf/jena/blob/6c4eecd8/jena-sdb/src/main/java/com/hp/hpl/jena/sdb/graph/EventManagerSDB.java
----------------------------------------------------------------------
diff --git a/jena-sdb/src/main/java/com/hp/hpl/jena/sdb/graph/EventManagerSDB.java b/jena-sdb/src/main/java/com/hp/hpl/jena/sdb/graph/EventManagerSDB.java
index aaa9e0e..a136ab6 100644
--- a/jena-sdb/src/main/java/com/hp/hpl/jena/sdb/graph/EventManagerSDB.java
+++ b/jena-sdb/src/main/java/com/hp/hpl/jena/sdb/graph/EventManagerSDB.java
@@ -18,15 +18,16 @@
 
 package com.hp.hpl.jena.sdb.graph;
 
+import org.apache.jena.atlas.logging.Log ;
+
 import com.hp.hpl.jena.graph.Graph;
 import com.hp.hpl.jena.graph.GraphEvents;
 import com.hp.hpl.jena.graph.impl.SimpleEventManager;
 
 public class EventManagerSDB extends SimpleEventManager {
 	
-	public EventManagerSDB(GraphSDB graph)
-	{
-		super(graph);
+	public EventManagerSDB() {
+		super();
 	}
 	
 	/*
@@ -35,10 +36,14 @@ public class EventManagerSDB extends SimpleEventManager {
 	@Override
 	public void notifyEvent(Graph arg0, Object arg1)
     {
-		if (arg1.equals(GraphEvents.startRead) )
-			((GraphSDB) graph).startBulkUpdate() ;
-		if (arg1.equals(GraphEvents.finishRead) )
-            ((GraphSDB) graph).finishBulkUpdate() ;
+	    if ( arg0 instanceof GraphSDB) {
+    		if (arg1.equals(GraphEvents.startRead) )
+    			((GraphSDB) arg0).startBulkUpdate() ;
+    		if (arg1.equals(GraphEvents.finishRead) )
+                ((GraphSDB) arg0).finishBulkUpdate() ;
+	    } else
+	        Log.warn(this, "Non GraphSDB passed to EventManagerSDB.notifyEvent");
+	    
 		super.notifyEvent(arg0, arg1) ;
 	}
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/6c4eecd8/jena-sdb/src/main/java/com/hp/hpl/jena/sdb/graph/GraphSDB.java
----------------------------------------------------------------------
diff --git a/jena-sdb/src/main/java/com/hp/hpl/jena/sdb/graph/GraphSDB.java b/jena-sdb/src/main/java/com/hp/hpl/jena/sdb/graph/GraphSDB.java
index a1c915c..a51b58a 100644
--- a/jena-sdb/src/main/java/com/hp/hpl/jena/sdb/graph/GraphSDB.java
+++ b/jena-sdb/src/main/java/com/hp/hpl/jena/sdb/graph/GraphSDB.java
@@ -263,7 +263,7 @@ public class GraphSDB extends GraphBase implements Graph
     @Override
     public GraphEventManager getEventManager()
     {
-    	if (gem == null) gem = new EventManagerSDB( this );
+    	if (gem == null) gem = new EventManagerSDB( );
         return gem;
     }