You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2006/08/10 00:06:57 UTC

svn commit: r430153 - in /incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa: instrument/CayenneAgent.java instrument/InstrumentingUnit.java spi/JpaProviderContext.java

Author: aadamchik
Date: Wed Aug  9 15:06:56 2006
New Revision: 430153

URL: http://svn.apache.org/viewvc?rev=430153&view=rev
Log:
simplifying the agent to defer class loading in premain

Removed:
    incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/spi/JpaProviderContext.java
Modified:
    incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/instrument/CayenneAgent.java
    incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/instrument/InstrumentingUnit.java

Modified: incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/instrument/CayenneAgent.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/instrument/CayenneAgent.java?rev=430153&r1=430152&r2=430153&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/instrument/CayenneAgent.java (original)
+++ incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/instrument/CayenneAgent.java Wed Aug  9 15:06:56 2006
@@ -17,13 +17,10 @@
  *  under the License.
  ****************************************************************/
 
-
 package org.apache.cayenne.jpa.instrument;
 
 import java.lang.instrument.Instrumentation;
 
-import org.apache.cayenne.jpa.spi.JpaPersistenceProvider;
-
 /**
  * An instrumentation agent that configures a
  * {@link org.apache.cayenne.jpa.spi.JpaUnitFactory} that will load JPA class enhancers in
@@ -33,7 +30,7 @@
  * the JVM with the "-javaagent:" option. E.g.:
  * 
  * <pre>
- *         java -javaagent:/path/to/cayenne-jpa-3.0.jar org.example.Main
+ *          java -javaagent:/path/to/cayenne-jpa-3.0.jar org.example.Main
  * </pre>
  * 
  * @author Andrus Adamchik
@@ -44,12 +41,18 @@
     // using a unit test to ensure that the factory name is valid.
     static final String FACTORY_CLASS = "org.apache.cayenne.jpa.instrument.InstrumentingUnitFactory";
 
+    // duplicating JpaPersistenceProvider property constant to avoid premature loading of
+    // JPA classes.
+    static final String UNIT_FACTORY_PROPERTY = "org.apache.cayenne.jpa.jpaUnitFactory";
+
+    static Instrumentation instrumentation;
+
     public static void premain(String agentArgs, Instrumentation instrumentation) {
         System.out.println("*** CayenneAgent starting...");
-        InstrumentingUnit.setInstrumentation(instrumentation);
+        CayenneAgent.instrumentation = instrumentation;
 
         // TODO: andrus, 5/1/2006 - add explicit debugging option to the agent
-        
+
         // This can be used to debug enhancer:
         // instrumentation.addTransformer(new ClassFileTransformer() {
         //
@@ -70,6 +73,14 @@
         // }
         // });
 
-        System.setProperty(JpaPersistenceProvider.UNIT_FACTORY_PROPERTY, FACTORY_CLASS);
+        System.setProperty(UNIT_FACTORY_PROPERTY, FACTORY_CLASS);
+    }
+
+    static Instrumentation getInstrumentation() {
+        return instrumentation;
+    }
+
+    static void setInstrumentation(Instrumentation instrumentation) {
+        CayenneAgent.instrumentation = instrumentation;
     }
 }

Modified: incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/instrument/InstrumentingUnit.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/instrument/InstrumentingUnit.java?rev=430153&r1=430152&r2=430153&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/instrument/InstrumentingUnit.java (original)
+++ incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/instrument/InstrumentingUnit.java Wed Aug  9 15:06:56 2006
@@ -22,12 +22,10 @@
 
 import java.lang.instrument.ClassFileTransformer;
 import java.lang.instrument.IllegalClassFormatException;
-import java.lang.instrument.Instrumentation;
 import java.security.ProtectionDomain;
 
 import javax.persistence.spi.ClassTransformer;
 
-import org.apache.cayenne.jpa.spi.JpaProviderContext;
 import org.apache.cayenne.jpa.spi.JpaUnit;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -40,23 +38,13 @@
  */
 public class InstrumentingUnit extends JpaUnit {
 
-    static final String INSTRUMENTATION_KEY = "cayenne.jpa.instrumentation";
-
-    public static Instrumentation getInstrumentation() {
-        return (Instrumentation) JpaProviderContext.getObject(INSTRUMENTATION_KEY);
-    }
-
-    public static void setInstrumentation(Instrumentation instance) {
-        JpaProviderContext.setObject(INSTRUMENTATION_KEY, instance);
-    }
-
     protected Log logger;
 
     @Override
     public void addTransformer(final ClassTransformer transformer) {
 
         // sanity check
-        if (getInstrumentation() == null) {
+        if (CayenneAgent.getInstrumentation() == null) {
             getLogger().warn(
                     "*** No instrumentation instance present. "
                             + "Check the -javaagent: option");
@@ -82,7 +70,7 @@
             }
         };
 
-        getInstrumentation().addTransformer(transformerWrapper);
+        CayenneAgent.getInstrumentation().addTransformer(transformerWrapper);
     }
 
     protected Log getLogger() {