Author: aadamchik
Date: Tue Oct 10 07:36:08 2006
New Revision: 454754

URL: http://svn.apache.org/viewvc?view=rev&rev=454754
Log:
CAY-684 - added a sniffer that checks the agent presence in the environment;
moved the agent to cayenne.instrument package

Added:
    
incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/main/java/org/apache/cayenne/instrument/
    
incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/main/java/org/apache/cayenne/instrument/InstrumentUtil.java

Added: 
incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/main/java/org/apache/cayenne/instrument/InstrumentUtil.java
URL: 
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/main/java/org/apache/cayenne/instrument/InstrumentUtil.java?view=auto&rev=454754
==============================================================================
--- 
incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/main/java/org/apache/cayenne/instrument/InstrumentUtil.java
 (added)
+++ 
incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/main/java/org/apache/cayenne/instrument/InstrumentUtil.java
 Tue Oct 10 07:36:08 2006
@@ -0,0 +1,50 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.instrument;
+
+import java.lang.reflect.Method;
+
+/**
+ * Instrumentation utilities.
+ * 
+ * @since 3.0
+ * @author Andrus Adamchik
+ */
+public class InstrumentUtil {
+
+    /**
+     * Checks whether the JVM was started with CayenneAgent.
+     */
+    public static boolean isAgentLoaded() {
+
+        // check whether CayenneAgent class is initialized and instrumentation 
is set.
+        try {
+            Class agent = Class.forName(
+                    "org.apache.cayenne.instrument.CayenneAgent",
+                    false,
+                    Thread.currentThread().getContextClassLoader());
+
+            Method getInstrumentation = 
agent.getDeclaredMethod("getInstrumentation");
+            return getInstrumentation.invoke(null) != null;
+        }
+        catch (Throwable th) {
+            return false;
+        }
+    }
+}


Reply via email to