[archstudio-commits] svn commit: r7083 - in /bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4: BNAModelEvent.java DefaultBNAModel.java ThingTree.java

archstudio-commits-owner at uci.edu archstudio-commits-owner at uci.edu
Mon May 5 08:22:55 PDT 2008


Author: shendric
Date: Mon May  5 08:22:55 2008
New Revision: 7083

Log:
Removed possible deadlock
Added THING_RESTACKED event, fired when a thing is moved above/below other =
things

Modified:
    bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/BNAModelEvent.java
    bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/DefaultBNAModel.java
    bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/ThingTree.java

Modified: bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/BNAModelEvent.ja=
va
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/BNAModelEvent.java (or=
iginal)
+++ bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/BNAModelEvent.java Mon=
 May  5 08:22:55 2008
@@ -3,7 +3,7 @@
 public class BNAModelEvent{
 =

 	public enum EventType{
-		THING_ADDED, THING_REMOVING, THING_REMOVED, THING_CHANGED, BULK_CHANGE_B=
EGIN, BULK_CHANGE_END, STREAM_NOTIFICATION_EVENT
+		THING_ADDED, THING_REMOVING, THING_REMOVED, THING_CHANGED, THING_RESTACK=
ED, BULK_CHANGE_BEGIN, BULK_CHANGE_END, STREAM_NOTIFICATION_EVENT
 	};
 =

 	protected IBNAModel source;

Modified: bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/DefaultBNAModel.=
java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/DefaultBNAModel.java (=
original)
+++ bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/DefaultBNAModel.java M=
on May  5 08:22:55 2008
@@ -138,6 +138,7 @@
 =

 	protected void fireBNAModelEvent(BNAModelEvent evt){
 		assert modelEventLock.isHeldByCurrentThread();
+
 		for(IBNASynchronousLockModelListener l: syncLockListeners.getListeners()=
){
 			try{
 				long lTime;
@@ -211,7 +212,9 @@
 		try{
 			t.addThingListener(this);
 			t.setPropertyLock(modelEventLock);
-			thingTree.add(t);
+			synchronized(thingTree){
+				thingTree.add(t);
+			}
 			fireBNAModelEvent(BNAModelEvent.EventType.THING_ADDED, t);
 		}
 		finally{
@@ -224,7 +227,9 @@
 		try{
 			t.addThingListener(this);
 			t.setPropertyLock(modelEventLock);
-			thingTree.add(t, parentThing);
+			synchronized(thingTree){
+				thingTree.add(t, parentThing);
+			}
 			fireBNAModelEvent(BNAModelEvent.EventType.THING_ADDED, t);
 		}
 		finally{
@@ -237,9 +242,12 @@
 		try{
 			IThing t =3D getThing(id);
 			if(t !=3D null){
-				if(thingTree.contains(t)){
-					fireBNAModelEvent(BNAModelEvent.EventType.THING_REMOVING, t);
+				synchronized(thingTree){
+					if(!thingTree.contains(t)){
+						return;
+					}
 				}
+				fireBNAModelEvent(BNAModelEvent.EventType.THING_REMOVING, t);
 			}
 		}
 		finally{
@@ -250,9 +258,12 @@
 	public void removeThing(IThing t){
 		modelEventLock.lock();
 		try{
-			if(thingTree.contains(t)){
-				fireBNAModelEvent(BNAModelEvent.EventType.THING_REMOVING, t);
+			synchronized(thingTree){
+				if(!thingTree.contains(t)){
+					return;
+				}
 			}
+			fireBNAModelEvent(BNAModelEvent.EventType.THING_REMOVING, t);
 		}
 		finally{
 			modelEventLock.unlock();
@@ -274,7 +285,9 @@
 		try{
 			t.removeThingListener(this);
 			t.setPropertyLock(null);
-			thingTree.remove(t);
+			synchronized(thingTree){
+				thingTree.remove(t);
+			}
 			fireBNAModelEvent(BNAModelEvent.EventType.THING_REMOVED, t);
 		}
 		finally{
@@ -298,79 +311,59 @@
 	}
 =

 	public Iterator<IThing> getThingIterator(){
-		modelEventLock.lock();
-		try{
+		synchronized(thingTree){
 			return Arrays.asList(thingTree.getAllThings()).iterator();
 		}
-		finally{
-			modelEventLock.unlock();
-		}
 	}
 =

 	public ListIterator<IThing> getThingListIterator(int index){
-		modelEventLock.lock();
-		try{
+		synchronized(thingTree){
 			return Arrays.asList(thingTree.getAllThings()).listIterator(index);
 		}
-		finally{
-			modelEventLock.unlock();
-		}
 	}
 =

 	public int getNumThings(){
-		modelEventLock.lock();
-		try{
+		synchronized(thingTree){
 			return thingTree.size();
 		}
-		finally{
-			modelEventLock.unlock();
-		}
 	}
 =

 	public IThing[] getAllThings(){
-		modelEventLock.lock();
-		try{
+		synchronized(thingTree){
 			return thingTree.getAllThings();
 		}
-		finally{
-			modelEventLock.unlock();
-		}
 	}
 =

 	public IThing[] getChildThings(IThing t){
-		modelEventLock.lock();
-		try{
+		synchronized(thingTree){
 			return thingTree.getChildren(t);
 		}
-		finally{
-			modelEventLock.unlock();
-		}
 	}
 =

 	public IThing getParentThing(IThing t){
-		modelEventLock.lock();
-		try{
+		synchronized(thingTree){
 			return thingTree.getParent(t);
 		}
-		finally{
-			modelEventLock.unlock();
-		}
 	}
 =

 	public IThing[] getAncestorThings(IThing t){
-		modelEventLock.lock();
-		try{
+		synchronized(thingTree){
 			return thingTree.getAncestors(t);
 		}
-		finally{
-			modelEventLock.unlock();
-		}
 	}
-
+	=

 	public void stackAbove(IThing upperThing, IThing lowerThing){
 		modelEventLock.lock();
 		try{
-			thingTree.moveAfter(lowerThing, upperThing);
+			IThing[] movedThings;
+			synchronized(thingTree){
+				thingTree.moveAfter(lowerThing, upperThing);
+				movedThings =3D thingTree.getAllChildren(lowerThing);
+			}
+			fireBNAModelEvent(BNAModelEvent.EventType.THING_RESTACKED, lowerThing);
+			for(IThing mt: movedThings){
+				fireBNAModelEvent(BNAModelEvent.EventType.THING_RESTACKED, mt);
+			}
 		}
 		finally{
 			modelEventLock.unlock();
@@ -380,7 +373,15 @@
 	public void bringToFront(IThing thing){
 		modelEventLock.lock();
 		try{
-			thingTree.bringToFront(thing);
+			IThing[] movedThings;
+			synchronized(thingTree){
+				thingTree.bringToFront(thing);
+				movedThings =3D thingTree.getAllChildren(thing);
+			}
+			fireBNAModelEvent(BNAModelEvent.EventType.THING_RESTACKED, thing);
+			for(IThing mt: movedThings){
+				fireBNAModelEvent(BNAModelEvent.EventType.THING_RESTACKED, mt);
+			}
 		}
 		finally{
 			modelEventLock.unlock();
@@ -390,7 +391,15 @@
 	public void sendToBack(IThing thing){
 		modelEventLock.lock();
 		try{
-			thingTree.sendToBack(thing);
+			IThing[] movedThings;
+			synchronized(thingTree){
+				thingTree.sendToBack(thing);
+				movedThings =3D thingTree.getAllChildren(thing);
+			}
+			fireBNAModelEvent(BNAModelEvent.EventType.THING_RESTACKED, thing);
+			for(IThing mt: movedThings){
+				fireBNAModelEvent(BNAModelEvent.EventType.THING_RESTACKED, mt);
+			}
 		}
 		finally{
 			modelEventLock.unlock();

Modified: bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/ThingTree.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/ThingTree.java (origin=
al)
+++ bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/ThingTree.java Mon May=
  5 08:22:55 2008
@@ -17,7 +17,6 @@
 		List<Node> children =3D new ArrayList<Node>();
 =

 		public Node(IThing t){
-			super();
 			this.t =3D t;
 		}
 	}
@@ -145,6 +144,16 @@
 		return EMPTY_ARRAY;
 	}
 =

+	public IThing[] getAllChildren(IThing t){
+		Node parentNode =3D getNode(t, false);
+		if(parentNode !=3D null){
+			List<IThing> allChildren =3D new ArrayList<IThing>();
+			appendChildren(allChildren, parentNode);
+			return allChildren.toArray(new IThing[allChildren.size()]);
+		}
+		return EMPTY_ARRAY;
+	}
+
 	public IThing[] getAncestors(IThing t){
 		List<IThing> ancestors =3D new ArrayList<IThing>();
 		if(t !=3D null){




More information about the archstudio-commits mailing list