labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simo...@apache.org
Subject svn commit: r763465 - in /labs/magma/trunk/foundation-basics/src/main/java/org/apache/magma/basics/startup: Cycle.java CycleThreadLocal.java
Date Thu, 09 Apr 2009 00:08:20 GMT
Author: simoneg
Date: Thu Apr  9 00:08:19 2009
New Revision: 763465

URL: http://svn.apache.org/viewvc?rev=763465&view=rev
Log:
LABS-338 : Fix Cycle memory leak

Modified:
    labs/magma/trunk/foundation-basics/src/main/java/org/apache/magma/basics/startup/Cycle.java
    labs/magma/trunk/foundation-basics/src/main/java/org/apache/magma/basics/startup/CycleThreadLocal.java

Modified: labs/magma/trunk/foundation-basics/src/main/java/org/apache/magma/basics/startup/Cycle.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-basics/src/main/java/org/apache/magma/basics/startup/Cycle.java?rev=763465&r1=763464&r2=763465&view=diff
==============================================================================
--- labs/magma/trunk/foundation-basics/src/main/java/org/apache/magma/basics/startup/Cycle.java
(original)
+++ labs/magma/trunk/foundation-basics/src/main/java/org/apache/magma/basics/startup/Cycle.java
Thu Apr  9 00:08:19 2009
@@ -2,7 +2,9 @@
 
 import java.lang.reflect.Method;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
@@ -38,14 +40,29 @@
 		};
 	};
 
-	{
-		scan();
-	}
-	
 	private volatile static boolean inited = false; 
 	private static AtomicBoolean initing = new AtomicBoolean(false); 
 	private static List<Method> setups = new ArrayList<Method>(); 
 	private static List<Method> teardowns = new ArrayList<Method>(); 
+
+	static {
+		scan();
+	}
+		
+	
+	private Map<Object, Object> localVars = new HashMap<Object, Object>();
+	
+	public Object getLocalVar(Object key) {
+		return localVars.get(key);
+	}
+	
+	public void setLocalVar(Object key, Object value) {
+		localVars.put(key, value);
+	}
+	
+	public void removeLocalVar(Object key) {
+		localVars.remove(key);
+	}
 	
 	/**
 	 * Components that manage cycles calls this method to start a new cycle.

Modified: labs/magma/trunk/foundation-basics/src/main/java/org/apache/magma/basics/startup/CycleThreadLocal.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-basics/src/main/java/org/apache/magma/basics/startup/CycleThreadLocal.java?rev=763465&r1=763464&r2=763465&view=diff
==============================================================================
--- labs/magma/trunk/foundation-basics/src/main/java/org/apache/magma/basics/startup/CycleThreadLocal.java
(original)
+++ labs/magma/trunk/foundation-basics/src/main/java/org/apache/magma/basics/startup/CycleThreadLocal.java
Thu Apr  9 00:08:19 2009
@@ -1,15 +1,24 @@
 package org.apache.magma.basics.startup;
 
 /**
- * Implements the {@link ThreadLocal} interface, saving con {@link Cycle}.
+ * Implements the {@link ThreadLocal} interface, saving on {@link Cycle}.
  *
  * @author Simone Gianni <simoneg@apache.org>
  * @param <T> The class this instance will hold.
  */
-public class CycleThreadLocal<T> extends ThreadLocal<T> implements CycleCleanable
{
+public class CycleThreadLocal<T> {
+	
+	public void remove() {
+		Cycle.get().removeLocalVar(this);
+	}
+
+	@SuppressWarnings("unchecked")
+	public T get() {
+		return (T)Cycle.get().getLocalVar(this);
+	}
 
-	public CycleThreadLocal() {
-		Cycle.get().register(this);
+	public void set(T value) {
+		Cycle.get().setLocalVar(this, value);
 	}
 	
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org


Mime
View raw message