You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by da...@apache.org on 2007/01/09 04:50:04 UTC

svn commit: r494312 - in /incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb: core/ core/ivm/ proxy/ resource/ ri/sp/ timer/ util/

Author: dain
Date: Mon Jan  8 19:50:03 2007
New Revision: 494312

URL: http://svn.apache.org/viewvc?view=rev&rev=494312
Log:
Removed FastThreadLocal and clean up ThreadLocal usage

Removed:
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/FastThreadLocal.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/HashThreadLocal.java
Modified:
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ServerFederation.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/IntraVmArtifact.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/IntraVmCopyMonitor.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/proxy/ImmutableArtifact.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/SharedLocalConnectionManager.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/ri/sp/PseudoSecurityService.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/timer/TimerState.java

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ServerFederation.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ServerFederation.java?view=diff&rev=494312&r1=494311&r2=494312
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ServerFederation.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ServerFederation.java Mon Jan  8 19:50:03 2007
@@ -17,7 +17,6 @@
 package org.apache.openejb.core;
 
 import org.apache.openejb.ProxyInfo;
-import org.apache.openejb.util.FastThreadLocal;
 
 import org.apache.openejb.core.ivm.IntraVmServer;
 import org.apache.openejb.spi.ApplicationServer;
@@ -29,8 +28,9 @@
 import javax.ejb.EJBHome;
 
 public class ServerFederation implements ApplicationServer {
+    private static final IntraVmServer localServer = new IntraVmServer();
 
-    private static FastThreadLocal threadStorage = new FastThreadLocal();
+    private static final ThreadLocal<ApplicationServer> applicationServer = new ThreadLocal<ApplicationServer>();
 
     public Handle getHandle(ProxyInfo proxyInfo) {
         return getApplicationServer().getHandle(proxyInfo);
@@ -53,17 +53,20 @@
     }
 
     public static void setApplicationServer(ApplicationServer server) {
+        // todo why do we restrict null?  This makes call to setApplicationServer non symetrical. Throw an exception?
         if (server != null) {
-            threadStorage.set(server);
+            applicationServer.set(server);
         }
     }
 
     public static ApplicationServer getApplicationServer() {
-        ApplicationServer server = (ApplicationServer) threadStorage.get();
-
-        return (server == null) ? localServer : server;
+        ApplicationServer server = applicationServer.get();
+        if (server == null) {
+            // todo: consider making this the thread local intialValue
+            return localServer;
+        }
+        return server;
     }
 
-    private static final IntraVmServer localServer = new IntraVmServer();
 }
 

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/IntraVmArtifact.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/IntraVmArtifact.java?view=diff&rev=494312&r1=494311&r2=494312
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/IntraVmArtifact.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/IntraVmArtifact.java Mon Jan  8 19:50:03 2007
@@ -25,25 +25,20 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.openejb.util.FastThreadLocal;
-
 public class IntraVmArtifact implements Externalizable {
+    private static final ThreadLocal<List<Object>> handles = new ThreadLocal<List<Object>>() {
+        protected List<Object> initialValue() {
+            return new ArrayList<Object>();
+        }
+    };
 
-    private int instanceHandle;
-
-    private static FastThreadLocal thread = new FastThreadLocal();
-
-    private static final String NO_MAP_ERROR = "There is no HashMap stored in the thread.  This object may have been moved outside the Virtual Machine.";
-
+    // todo why not put in message catalog?
     private static final String NO_ARTIFACT_ERROR = "The artifact this object represents could not be found.";
 
-    public IntraVmArtifact(Object obj) {
+    private int instanceHandle;
 
-        List list = (List) thread.get();
-        if (list == null) {
-            list = new ArrayList();
-            thread.set(list);
-        }
+    public IntraVmArtifact(Object obj) {
+        List<Object> list = handles.get();
         instanceHandle = list.size();
         list.add(obj);
     }
@@ -59,11 +54,11 @@
         instanceHandle = in.read();
     }
 
-    private Object readResolve() throws ObjectStreamException {
-        List list = (List) thread.get();
-        if (list == null) throw new InvalidObjectException(NO_MAP_ERROR);
+    protected Object readResolve() throws ObjectStreamException {
+        List<Object> list = handles.get();
         Object artifact = list.get(instanceHandle);
         if (artifact == null) throw new InvalidObjectException(NO_ARTIFACT_ERROR + instanceHandle);
+        // todo WHY?
         if (list.size() == instanceHandle + 1) {
             list.clear();
         }

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/IntraVmCopyMonitor.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/IntraVmCopyMonitor.java?view=diff&rev=494312&r1=494311&r2=494312
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/IntraVmCopyMonitor.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/IntraVmCopyMonitor.java Mon Jan  8 19:50:03 2007
@@ -16,32 +16,29 @@
  */
 package org.apache.openejb.core.ivm;
 
-import org.apache.openejb.util.FastThreadLocal;
-
 public class IntraVmCopyMonitor {
+    private static final ThreadLocal<IntraVmCopyMonitor> threadMonitor = new ThreadLocal<IntraVmCopyMonitor>();
 
-    private static FastThreadLocal threadStorage = new FastThreadLocal();
-
-    boolean intraVmCopyOperation = false;
+    private boolean intraVmCopyOperation = false;
 
-    boolean statefulPassivationOperation = false;
+    private boolean statefulPassivationOperation = false;
 
-    IntraVmCopyMonitor() {
+    private IntraVmCopyMonitor() {
     }
 
     public static boolean exists() {
-        return (threadStorage.get() != null);
+        return (threadMonitor.get() != null);
     }
 
     public static void release() {
-        threadStorage.set(null);
+        threadMonitor.set(null);
     }
 
-    static IntraVmCopyMonitor getMonitor() {
-        IntraVmCopyMonitor monitor = (IntraVmCopyMonitor) threadStorage.get();
+    private static IntraVmCopyMonitor getMonitor() {
+        IntraVmCopyMonitor monitor = threadMonitor.get();
         if (monitor == null) {
             monitor = new IntraVmCopyMonitor();
-            threadStorage.set(monitor);
+            threadMonitor.set(monitor);
         }
         return monitor;
     }
@@ -68,17 +65,11 @@
 
     public static boolean isIntraVmCopyOperation() {
         IntraVmCopyMonitor monitor = getMonitor();
-        if (monitor.intraVmCopyOperation)
-            return true;
-        else
-            return false;
+        return monitor.intraVmCopyOperation;
     }
 
     public static boolean isStatefulPassivationOperation() {
         IntraVmCopyMonitor monitor = getMonitor();
-        if (monitor.statefulPassivationOperation)
-            return true;
-        else
-            return false;
+        return monitor.statefulPassivationOperation;
     }
 }

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/proxy/ImmutableArtifact.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/proxy/ImmutableArtifact.java?view=diff&rev=494312&r1=494311&r2=494312
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/proxy/ImmutableArtifact.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/proxy/ImmutableArtifact.java Mon Jan  8 19:50:03 2007
@@ -25,59 +25,50 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.openejb.util.FastThreadLocal;
-
 public class ImmutableArtifact implements Externalizable {
-
     /**
-     * A handle created using information about the object
-     * instance for which this IntraVMArtifact was created.
+     * Error detailing that the object instance can not be found in the thread's List.
      */
-    private int instanceHandle;
-    
+    // TODO: move text to Message.properties
+    private static final String NO_ARTIFACT_ERROR = "The artifact this object represents could not be found.";
+
     /**
-     * Holds a list of threads.  Each thread gets a HashMap to store 
+     * Holds a list of threads.  Each thread gets a HashMap to store
      * instances artifacts of the intra-vm.  The instances are not serialized,
      * instead, a key for the object is serialized to the stream.
-     * 
+     * <p/>
      * At deserialization, the key is used to get the original object
      * instance from the List
      */
-    private static FastThreadLocal thread = new FastThreadLocal();
-    
-    /**
-     * Error detailing that the List for this Thread can not be found.
-     */
-    // TODO: move text to Message.properties
-    private static final String NO_MAP_ERROR = "There is no HashMap stored in the thread.  This object may have been moved outside the Virtual Machine.";
-    
+    private static ThreadLocal<List<Object>> handles = new ThreadLocal<List<Object>>() {
+        protected List<Object> initialValue() {
+            return new ArrayList<Object>();
+        }
+    };
+
     /**
-     * Error detailing that the object instance can not be found in the thread's List.
+     * A handle created using information about the object
+     * instance for which this IntraVMArtifact was created.
      */
-    // TODO: move text to Message.properties
-    private static final String NO_ARTIFACT_ERROR = "The artifact this object represents could not be found.";
+    private int instanceHandle;
 
     /**
      * Used to creat an ImmutableArtifact object that can represent
      * the true intra-vm artifact in a stream.
-     * 
-     * @param obj    The object instance this class should represent in the stream.
+     *
+     * @param obj The object instance this class should represent in the stream.
      */
     public ImmutableArtifact(Object obj) {
         // the prev implementation used a hash map and removed the handle in the readResolve method
         // which would prevent marshaling of objects with the same hashcode in one request.
-        List list = (List)thread.get();
-        if (list == null) {
-            list = new ArrayList();
-            thread.set(list);
-        }
+        List<Object> list = handles.get();
         instanceHandle = list.size();
         list.add(obj);
-            }
+    }
 
     /**
      * This class is Externalizable and this public, no-arg, constructor is required.
-     * 
+     * <p/>
      * This constructor should only be used by the deserializing stream.
      */
     public ImmutableArtifact() {
@@ -85,21 +76,21 @@
 
     /**
      * Writes the instanceHandle to the stream.
-     * 
+     *
      * @param out
-     * @exception IOException
+     * @throws IOException
      */
-    public void writeExternal(ObjectOutput out) throws IOException{
-        out.write(instanceHandle);                                            
+    public void writeExternal(ObjectOutput out) throws IOException {
+        out.write(instanceHandle);
     }
 
     /**
      * Reads the instanceHandle from the stream
-     * 
+     *
      * @param in
-     * @exception IOException
+     * @throws IOException
      */
-    public void readExternal(ObjectInput in) throws IOException{
+    public void readExternal(ObjectInput in) throws IOException {
         instanceHandle = in.read();
     }
 
@@ -108,16 +99,16 @@
      * This class implements the readResolve method of the serialization API.
      * In the readResolve method, the original object instance is retrieved
      * from the List and returned instead.
-     * 
-     * @return 
-     * @exception ObjectStreamException
-     */
-    private Object readResolve() throws ObjectStreamException{
-        List list = (List) thread.get();
-        if (list == null) throw new InvalidObjectException(NO_MAP_ERROR);
+     *
+     * @return
+     * @throws ObjectStreamException
+     */
+    protected Object readResolve() throws ObjectStreamException {
+        List list = handles.get();
         Object artifact = list.get(instanceHandle);
-        if (artifact == null) throw new InvalidObjectException(NO_ARTIFACT_ERROR+instanceHandle);
-        if(list.size()==instanceHandle+1) {
+        if (artifact == null) throw new InvalidObjectException(NO_ARTIFACT_ERROR + instanceHandle);
+        // todo WHY?
+        if (list.size() == instanceHandle + 1) {
             list.clear();
         }
         return artifact;

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/SharedLocalConnectionManager.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/SharedLocalConnectionManager.java?view=diff&rev=494312&r1=494311&r2=494312
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/SharedLocalConnectionManager.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/SharedLocalConnectionManager.java Mon Jan  8 19:50:03 2007
@@ -19,40 +19,46 @@
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Set;
+import java.util.Map;
+import java.util.Collections;
+import java.util.Properties;
+import java.io.Serializable;
 
 import javax.resource.spi.ConnectionEvent;
 import javax.resource.spi.ConnectionRequestInfo;
 import javax.resource.spi.LocalTransaction;
 import javax.resource.spi.ManagedConnection;
 import javax.resource.spi.ManagedConnectionFactory;
+import javax.resource.spi.ConnectionManager;
+import javax.resource.spi.ConnectionEventListener;
+import javax.resource.spi.ApplicationServerInternalException;
+import javax.resource.ResourceException;
 import javax.transaction.Transaction;
 import javax.transaction.TransactionManager;
+import javax.transaction.SystemException;
+import javax.transaction.RollbackException;
 
 /**
  * @org.apache.xbean.XBean element="sharedLocalConnectionManager"
  */
-public class SharedLocalConnectionManager implements javax.resource.spi.ConnectionManager,
-        javax.resource.spi.ConnectionEventListener,
-        java.io.Serializable {
-
-    private Set connSet;
-    private SpecialHashThreadLocal threadLocal = new SpecialHashThreadLocal();
-    private HashMap factoryMap = new HashMap();
+public class SharedLocalConnectionManager implements ConnectionManager, ConnectionEventListener, Serializable {
+    private static final long serialVersionUID = -276853822988761008L;
+
+    private final ThreadLocal<ConnectionCache> threadConnectionCache = new ThreadLocal<ConnectionCache>() {
+        protected ConnectionCache initialValue() {
+            return new ConnectionCache();
+        }
+    };
+    private final Set<ManagedConnection> connSet = Collections.synchronizedSet(new HashSet<ManagedConnection>());
     private TransactionManager transactionManager;
 
-    public void init(java.util.Properties props) {
+    public void init(Properties props) {
         transactionManager = (TransactionManager) props.get(TransactionManager.class.getName());
     }
 
-    public SharedLocalConnectionManager() throws javax.resource.spi.ApplicationServerInternalException {
-        connSet = java.util.Collections.synchronizedSet(new HashSet());
-    }
-
-    public java.lang.Object allocateConnection(ManagedConnectionFactory factory,
-                                               ConnectionRequestInfo cxRequestInfo)
-            throws javax.resource.ResourceException {
-
-        ManagedConnection conn = (ManagedConnection) threadLocal.get(factory);
+    public Object allocateConnection(ManagedConnectionFactory factory, ConnectionRequestInfo cxRequestInfo) throws ResourceException {
+        ConnectionCache connectionCache = threadConnectionCache.get();
+        ManagedConnection conn = connectionCache.getConnection(factory);
         if (conn == null) {
             conn = factory.matchManagedConnections(connSet, null, cxRequestInfo);
             if (conn != null) {
@@ -75,13 +81,13 @@
                 if (tx != null) {
                     tx.registerSynchronization(new Synchronizer(conn.getLocalTransaction()));
                 }
-            } catch (javax.transaction.SystemException se) {
-                throw new javax.resource.spi.ApplicationServerInternalException("Can not obtain a Transaction object from TransactionManager. " + se.getMessage());
-            } catch (javax.transaction.RollbackException re) {
-                throw new javax.resource.spi.ApplicationServerInternalException("Can not register org.apache.openejb.resource.LocalTransacton with transaciton manager. Transaction has already been rolled back" + re.getMessage());
+            } catch (SystemException se) {
+                throw new ApplicationServerInternalException("Can not obtain a Transaction object from TransactionManager. " + se.getMessage());
+            } catch (RollbackException re) {
+                throw new ApplicationServerInternalException("Can not register org.apache.openejb.resource.LocalTransacton with transaciton manager. Transaction has already been rolled back" + re.getMessage());
             }
 
-            threadLocal.put(factory, conn);
+            connectionCache.putConnection(factory, conn);
         }
 
         Object handle = conn.getConnection(null, cxRequestInfo);
@@ -113,12 +119,10 @@
     public void connectionErrorOccurred(ConnectionEvent event) {
         ManagedConnection conn = (ManagedConnection) event.getSource();
 
-        ManagedConnectionFactory mcf = (ManagedConnectionFactory) threadLocal.getKey(conn);
         try {
             conn.destroy();
-            if (threadLocal.get(mcf) == conn) {
-                threadLocal.put(mcf, null);
-            }
+
+            threadConnectionCache.get().removeConnection(conn);
         } catch (javax.resource.ResourceException re) {
 
         }
@@ -134,26 +138,21 @@
 
     private void cleanup(ManagedConnection conn) {
         if (conn != null) {
-
-            ManagedConnectionFactory mcf = (ManagedConnectionFactory) threadLocal.getKey(conn);
             try {
                 conn.cleanup();
                 connSet.add(conn);
-
-            } catch (javax.resource.ResourceException re) {
+            } catch (ResourceException re) {
                 try {
-
                     conn.destroy();
-                } catch (javax.resource.ResourceException re2) {
-
+                } catch (ResourceException re2) {
                 }
             }
-            threadLocal.put(mcf, null);
+
+            threadConnectionCache.get().removeConnection(conn);
         }
     }
 
     public void localTransactionStarted(ConnectionEvent event) {
-
     }
 
     static class Synchronizer implements javax.transaction.Synchronization {
@@ -183,25 +182,29 @@
         }
     }
 
-    /*
-    * This class allows the ConnectionManager to determine the key used for
-    * any object stored in this type of HashThreadLocal.  Its needed when handling
-    * ConnectionListner events because the key (ManagedConnectionFactory) used to
-    * store values (ManagedConnecitons) is not available.
-    */
-    static class SpecialHashThreadLocal extends org.apache.openejb.util.HashThreadLocal {
-        HashMap keyMap = new HashMap();
-
-        public synchronized void put(Object key, Object value) {
-            if (!keyMap.containsKey(key)) {
-                keyMap.put(value, key);
+    /**
+     * Thread scoped cache of connections.
+     */
+    private static class ConnectionCache {
+        private final Map<ManagedConnectionFactory,ManagedConnection> connectionByFactory =
+                new HashMap<ManagedConnectionFactory,ManagedConnection>();
+        private final Map<ManagedConnection,ManagedConnectionFactory> factoriesByConnection = new
+                HashMap<ManagedConnection,ManagedConnectionFactory>();
+
+        public ManagedConnection getConnection(ManagedConnectionFactory factory) {
+            return connectionByFactory.get(factory);
+        }
+
+        public void putConnection(ManagedConnectionFactory factory, ManagedConnection connection) {
+            connectionByFactory.put(factory, connection);
+            factoriesByConnection.put(connection, factory);
+        }
+
+        public void removeConnection(ManagedConnection connection) {
+            ManagedConnectionFactory factory = factoriesByConnection.remove(connection);
+            if (factory != null) {
+                connectionByFactory.remove(factory);
             }
-            super.put(key, value);
-        }
-
-        public synchronized Object getKey(Object value) {
-            return keyMap.get(value);
         }
     }
-
 }

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/ri/sp/PseudoSecurityService.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/ri/sp/PseudoSecurityService.java?view=diff&rev=494312&r1=494311&r2=494312
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/ri/sp/PseudoSecurityService.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/ri/sp/PseudoSecurityService.java Mon Jan  8 19:50:03 2007
@@ -24,17 +24,17 @@
  * @org.apache.xbean.XBean element="pseudoSecurityService"
  */
 public class PseudoSecurityService implements SecurityService {
-    private final ThreadLocal<Object> threadStorage = new ThreadLocal<Object>();
+    private final ThreadLocal<Object> securityIdentity = new ThreadLocal<Object>();
 
     public void init(java.util.Properties props) {
     }
 
     public Object getSecurityIdentity() {
-        return threadStorage.get();
+        return securityIdentity.get();
     }
 
     public void setSecurityIdentity(Object securityIdentity) {
-        threadStorage.set(securityIdentity);
+        this.securityIdentity.set(securityIdentity);
     }
 
     public boolean isCallerAuthorized(Object securityIdentity, Collection<String> roleNames) {

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/timer/TimerState.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/timer/TimerState.java?view=diff&rev=494312&r1=494311&r2=494312
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/timer/TimerState.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/timer/TimerState.java Mon Jan  8 19:50:03 2007
@@ -21,19 +21,18 @@
  * @version $Rev$ $Date$
  */
 public class TimerState {
-
-    private static final ThreadLocal timerState = new ThreadLocal() {
-        protected Object initialValue() {
+    private static final ThreadLocal<Boolean> timerState = new ThreadLocal<Boolean>() {
+        protected Boolean initialValue() {
             return Boolean.FALSE;
         }
     };
 
-    public static final boolean getTimerState() {
-        return ((Boolean)timerState.get()).booleanValue();
+    public static boolean getTimerState() {
+        return timerState.get();
     }
 
-    public static final void setTimerState(boolean state) {
-        timerState.set(Boolean.valueOf(state));
+    public static void setTimerState(boolean state) {
+        timerState.set(state);
     }
 
 }



Re: Removed FastThreadLocal

Posted by David Blevins <da...@visi.com>.
On Jan 8, 2007, at 7:59 PM, Dain Sundstrom wrote:

> I removed the FastThreadLocal class which was cruft from way back  
> in the day when ThreadLocals were very slow.  In the process I  
> generified and clean up all uses of ThreadLocal, but have a few  
> questions about some of the code. Hopefully someone who can  
> remember back to early 2000 can help.
>
> On Jan 8, 2007, at 7:50 PM, dain@apache.org wrote:
>
>> ===================================================================== 
>> =========
>> --- incubator/openejb/trunk/openejb3/container/openejb-core/src/ 
>> main/java/org/apache/openejb/core/ServerFederation.java (original)
>> +++ incubator/openejb/trunk/openejb3/container/openejb-core/src/ 
>> main/java/org/apache/openejb/core/ServerFederation.java Mon Jan  8  
>> 19:50:03 2007
>> @@ -53,17 +53,20 @@
>>      }
>>
>>      public static void setApplicationServer(ApplicationServer  
>> server) {
>> +        // todo why do we restrict null?  This makes call to  
>> setApplicationServer non symetrical. Throw an exception?
>>          if (server != null) {
>> -            threadStorage.set(server);
>> +            applicationServer.set(server);
>>          }
>>      }
>
> Any idea why we don't allow null to be set into the application  
> server?  If the thread local holds, null we return localServer.
>
> I think the proper implementation is to make localServer the  
> initValue for the thread local, and if someone attempts to set the  
> application server to null, we throw an exception.

The "if null return the localServer" thing is a situation that's  
potentially non-existent.  The only situation where I can think it'd  
actually occur is if a bean attempted to serialize a Handle or  
HomeHandle to disk, but even then I'm not certain.  In that  
situation, the local server is the one asking for the app server and  
could very well do it's own null check and opt to apply it's own  
logic if no app server is found.

The other place I imagined it being used, and is definitely not but  
should be, is if an app server wanted to swap it's proxies coming off  
the wire with local proxies for better performance should those  
proxies be used.  Even then we just make the private static final a  
public static final or better move the static final right into the  
IntraVmServer class.

>
>
>> Modified: incubator/openejb/trunk/openejb3/container/openejb-core/ 
>> src/main/java/org/apache/openejb/core/ivm/IntraVmArtifact.java
>> URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/ 
>> container/openejb-core/src/main/java/org/apache/openejb/core/ivm/ 
>> IntraVmArtifact.java?view=diff&rev=494312&r1=494311&r2=494312
>> ===================================================================== 
>> =========
>> +    // todo why not put in message catalog?
>>      private static final String NO_ARTIFACT_ERROR = "The artifact  
>> this object represents could not be found.";
>
> Is there a primer on how to use the message catalog somewhere?

Nowhere.  But, ideally each package would have it's own  
Messages.properties file.  You would then be able to grab your  
messages by referencing your package name.  Better, we could let  
classes  pass in MyClass.class and we could figure out their package  
name for them... or someday implement a class based strategy and not  
have to update any code.

>
>> @@ -59,11 +54,11 @@
>>          instanceHandle = in.read();
>>      }
>>
>> -    private Object readResolve() throws ObjectStreamException {
>> -        List list = (List) thread.get();
>> -        if (list == null) throw new InvalidObjectException 
>> (NO_MAP_ERROR);
>> +    protected Object readResolve() throws ObjectStreamException {
>> +        List<Object> list = handles.get();
>>          Object artifact = list.get(instanceHandle);
>>          if (artifact == null) throw new InvalidObjectException 
>> (NO_ARTIFACT_ERROR + instanceHandle);
>> +        // todo WHY?
>>          if (list.size() == instanceHandle + 1) {
>>              list.clear();
>>          }
>
> Does anyone know why we clear the list here? This same code exists  
> in org.apache.openejb.proxy.ImmutableArtifact.  Is this a duplicate  
> class?

org.apache.openejb.proxy is all duplicate code.  It'll get the boot  
eventually.

-David


Removed FastThreadLocal

Posted by Dain Sundstrom <da...@iq80.com>.
I removed the FastThreadLocal class which was cruft from way back in  
the day when ThreadLocals were very slow.  In the process I  
generified and clean up all uses of ThreadLocal, but have a few  
questions about some of the code. Hopefully someone who can remember  
back to early 2000 can help.

On Jan 8, 2007, at 7:50 PM, dain@apache.org wrote:

> ====================================================================== 
> ========
> --- incubator/openejb/trunk/openejb3/container/openejb-core/src/ 
> main/java/org/apache/openejb/core/ServerFederation.java (original)
> +++ incubator/openejb/trunk/openejb3/container/openejb-core/src/ 
> main/java/org/apache/openejb/core/ServerFederation.java Mon Jan  8  
> 19:50:03 2007
> @@ -53,17 +53,20 @@
>      }
>
>      public static void setApplicationServer(ApplicationServer  
> server) {
> +        // todo why do we restrict null?  This makes call to  
> setApplicationServer non symetrical. Throw an exception?
>          if (server != null) {
> -            threadStorage.set(server);
> +            applicationServer.set(server);
>          }
>      }

Any idea why we don't allow null to be set into the application  
server?  If the thread local holds, null we return localServer.

I think the proper implementation is to make localServer the  
initValue for the thread local, and if someone attempts to set the  
application server to null, we throw an exception.


> Modified: incubator/openejb/trunk/openejb3/container/openejb-core/ 
> src/main/java/org/apache/openejb/core/ivm/IntraVmArtifact.java
> URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/ 
> container/openejb-core/src/main/java/org/apache/openejb/core/ivm/ 
> IntraVmArtifact.java?view=diff&rev=494312&r1=494311&r2=494312
> ====================================================================== 
> ========
> +    // todo why not put in message catalog?
>      private static final String NO_ARTIFACT_ERROR = "The artifact  
> this object represents could not be found.";

Is there a primer on how to use the message catalog somewhere?

> @@ -59,11 +54,11 @@
>          instanceHandle = in.read();
>      }
>
> -    private Object readResolve() throws ObjectStreamException {
> -        List list = (List) thread.get();
> -        if (list == null) throw new InvalidObjectException 
> (NO_MAP_ERROR);
> +    protected Object readResolve() throws ObjectStreamException {
> +        List<Object> list = handles.get();
>          Object artifact = list.get(instanceHandle);
>          if (artifact == null) throw new InvalidObjectException 
> (NO_ARTIFACT_ERROR + instanceHandle);
> +        // todo WHY?
>          if (list.size() == instanceHandle + 1) {
>              list.clear();
>          }

Does anyone know why we clear the list here? This same code exists in  
org.apache.openejb.proxy.ImmutableArtifact.  Is this a duplicate class?


Thanks,

-dain