labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From psm...@apache.org
Subject svn commit: r566023 - in /labs/pinpoint/trunk: ./ pinpoint-core/src/main/java/org/apache/logging/pinpoint/ pinpoint-core/src/main/java/org/apache/logging/pinpoint/converter/ pinpoint-core/src/main/java/org/apache/logging/pinpoint/jmx/ pinpoint-core/src...
Date Wed, 15 Aug 2007 04:36:02 GMT
Author: psmith
Date: Tue Aug 14 21:36:00 2007
New Revision: 566023

URL: http://svn.apache.org/viewvc?view=rev&rev=566023
Log:
Basic JMX infrastructure now setup so that Spring beans can be easily annotated to appear
nicely in the local MBeanServer.  Only one JMX MBean being exposed at the moment, and it's
hardly 
useful, but more will come.

Default IndexWriter factory now uses MMapDirectory by default and uses the Native file locking
implementation.
This gets around the stupid 'write.lock' file that _could_ be left around if the Service does
not get
shut down cleanly.  Unfortunately what that meant was that starting it back up again prevented
inedxing 
from happening.  Using the NativeFSLockFactory uses NIO to do the file lock, and does get
properly
cleaned up by the JVM/OS regardless of how hard one kills the process.

Use a proper log4j.properties for the Service layer for nice logging.

Added:
    labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/jmx/
    labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/jmx/AttributeOperationHidingMBeanExporter.java
    labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/jmx/BeanMetaAttributeNamingStrategy.java
    labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/service/
    labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/service/jmx/
    labs/pinpoint/trunk/pinpoint-service/src/main/resources/log4j.properties
    labs/pinpoint/trunk/pinpoint-service/src/main/resources/org/apache/logging/pinpoint/service/jmx.xml
Modified:
    labs/pinpoint/trunk/   (props changed)
    labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/PinpointHome.java
    labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/converter/DefaultIndexWriterFactory.java
    labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/service/Service.java
    labs/pinpoint/trunk/pinpoint-service/src/main/resources/org/apache/logging/pinpoint/service/pinpoint-context.xml

Propchange: labs/pinpoint/trunk/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Tue Aug 14 21:36:00 2007
@@ -1,2 +1,3 @@
 target
 .settings
+activemq-data

Modified: labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/PinpointHome.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/PinpointHome.java?view=diff&rev=566023&r1=566022&r2=566023
==============================================================================
--- labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/PinpointHome.java
(original)
+++ labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/PinpointHome.java
Tue Aug 14 21:36:00 2007
@@ -20,26 +20,31 @@
 import org.apache.commons.lang.SystemUtils;
 import org.apache.log4j.Logger;
 import org.apache.logging.pinpoint.utils.PinpointUtils;
+import org.springframework.jmx.export.annotation.ManagedAttribute;
+import org.springframework.jmx.export.annotation.ManagedResource;
 
+@ManagedResource(description = "The root of the Pinpoint system.  All PinpointContexts are
created under this.")
 public class PinpointHome {
 
-    private static final Logger LOG = PinpointUtils.getLogger(PinpointHome.class);
+    private static final Logger LOG = PinpointUtils
+            .getLogger(PinpointHome.class);
 
     private final File pinpointHome;
 
     public PinpointHome(File pinpointHome) {
         if (pinpointHome.exists() && !pinpointHome.isDirectory()) {
-            throw new IllegalStateException(pinpointHome.getAbsolutePath()
-                    + " exists, but is not a directory");
+            throw new IllegalStateException(pinpointHome.getAbsolutePath() +
+                    " exists, but is not a directory");
         }
         this.pinpointHome = pinpointHome;
 
         if (!pinpointHome.exists()) {
-            LOG.info("Pinpoint Home '" + pinpointHome.getAbsolutePath()
-                    + "' does not exist, creating...");
+            LOG.info("Pinpoint Home '" + pinpointHome.getAbsolutePath() +
+                    "' does not exist, creating...");
             if (!pinpointHome.mkdirs()) {
-                throw new IllegalStateException("Failed to create Pinpoint home @ '"
-                        + pinpointHome.getAbsolutePath() + "'");
+                throw new IllegalStateException(
+                        "Failed to create Pinpoint home @ '" +
+                                pinpointHome.getAbsolutePath() + "'");
             }
         }
     }
@@ -53,16 +58,20 @@
     }
 
     public List<PinpointContext> listContexts() {
-        Collection<File> listFiles = FileUtils.listFiles(pinpointHome, FileFilterUtils
-                .trueFileFilter(), FileFilterUtils.andFileFilter(FileFilterUtils
-                .prefixFileFilter("ctx."), FileFilterUtils.directoryFileFilter()));
-        List<PinpointContext> ctxs = new ArrayList<PinpointContext>(listFiles.size());
+        Collection<File> listFiles = FileUtils.listFiles(pinpointHome,
+                FileFilterUtils.trueFileFilter(), FileFilterUtils
+                        .andFileFilter(
+                                FileFilterUtils.prefixFileFilter("ctx."),
+                                FileFilterUtils.directoryFileFilter()));
+        List<PinpointContext> ctxs = new ArrayList<PinpointContext>(listFiles
+                .size());
         for (File file : listFiles) {
             ctxs.add(PinpointContext.create(this, file.getName()));
         }
         return ctxs;
     }
 
+    @ManagedAttribute(description = "Physical filesystem space where this PinpointHome is
located")
     public File getHomeDirectory() {
         return this.pinpointHome;
     }

Modified: labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/converter/DefaultIndexWriterFactory.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/converter/DefaultIndexWriterFactory.java?view=diff&rev=566023&r1=566022&r2=566023
==============================================================================
--- labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/converter/DefaultIndexWriterFactory.java
(original)
+++ labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/converter/DefaultIndexWriterFactory.java
Tue Aug 14 21:36:00 2007
@@ -14,7 +14,7 @@
  See the License for the specific language governing permissions and
  limitations under the License.
 
-**/
+ **/
 package org.apache.logging.pinpoint.converter;
 
 import java.io.File;
@@ -22,11 +22,18 @@
 
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.FSDirectory;
+import org.apache.lucene.store.NativeFSLockFactory;
 
-public class DefaultIndexWriterFactory implements IndexWriterFactory{
+public class DefaultIndexWriterFactory implements IndexWriterFactory {
+
+    public IndexWriter create(File indexDirectory, Analyzer analyzer,
+            boolean createIndex) throws IOException {
+
+        Directory dir = FSDirectory.getDirectory(indexDirectory);
+        dir.setLockFactory(new NativeFSLockFactory(FSDirectory.LOCK_DIR));
 
-    public IndexWriter create(File indexDirectory, Analyzer analyzer, boolean createIndex)
throws IOException {
-        
         return new IndexWriter(indexDirectory, analyzer, createIndex);
     }
 

Added: labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/jmx/AttributeOperationHidingMBeanExporter.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/jmx/AttributeOperationHidingMBeanExporter.java?view=auto&rev=566023
==============================================================================
--- labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/jmx/AttributeOperationHidingMBeanExporter.java
(added)
+++ labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/jmx/AttributeOperationHidingMBeanExporter.java
Tue Aug 14 21:36:00 2007
@@ -0,0 +1,86 @@
+package org.apache.logging.pinpoint.jmx;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.management.MBeanException;
+import javax.management.MBeanInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.modelmbean.ModelMBean;
+import javax.management.modelmbean.ModelMBeanAttributeInfo;
+import javax.management.modelmbean.ModelMBeanConstructorInfo;
+import javax.management.modelmbean.ModelMBeanInfoSupport;
+import javax.management.modelmbean.ModelMBeanNotificationInfo;
+import javax.management.modelmbean.ModelMBeanOperationInfo;
+import javax.management.modelmbean.RequiredModelMBean;
+
+import org.apache.commons.lang.ObjectUtils;
+import org.springframework.jmx.export.MBeanExporter;
+
+/**
+ * An extension to the MBeanExporter class so that it does NOT export Attributes
+ * as Operations.
+ * 
+ * Honestly, I'm not sure why we need to do this, the default behaviour is
+ * completely stupid in my opinion.
+ * 
+ * I'm very grateful to Oliver Hutchison for teaching me this trick a while back
+ * at Aconex.
+ * 
+ * @author psmith
+ * 
+ */
+public class AttributeOperationHidingMBeanExporter extends MBeanExporter {
+
+    private static final String FIELD_VISIBILITY = "visibility";
+
+    private static final Integer ATTRIBUTE_OPERATION_VISIBILITY = Integer
+            .valueOf(4);
+
+    @Override
+    protected ModelMBean createModelMBean() throws MBeanException {
+
+        return new RequiredModelMBean() {
+
+            @Override
+            public MBeanInfo getMBeanInfo() {
+                ModelMBeanInfoSupport modelMBeanInfo = (ModelMBeanInfoSupport) super
+                        .getMBeanInfo();
+                List<MBeanOperationInfo> operations = new ArrayList<MBeanOperationInfo>(
+                        Arrays.asList(modelMBeanInfo.getOperations()));
+                for (Iterator<MBeanOperationInfo> i = operations.iterator(); i
+                        .hasNext();) {
+                    ModelMBeanOperationInfo info = (ModelMBeanOperationInfo) i
+                            .next();
+                    if (ObjectUtils.equals(info.getDescriptor().getFieldValue(
+                            FIELD_VISIBILITY), ATTRIBUTE_OPERATION_VISIBILITY)) {
+                        i.remove();
+                    }
+                }
+
+                ModelMBeanInfoSupport mBeanInfoCopy = new ModelMBeanInfoSupport(
+                        modelMBeanInfo.getClassName(), modelMBeanInfo
+                                .getDescription(),
+                        (ModelMBeanAttributeInfo[]) modelMBeanInfo
+                                .getAttributes(),
+                        (ModelMBeanConstructorInfo[]) modelMBeanInfo
+                                .getConstructors(), operations
+                                .toArray(new ModelMBeanOperationInfo[operations
+                                        .size()]),
+                        (ModelMBeanNotificationInfo[]) modelMBeanInfo
+                                .getNotifications());
+
+                try {
+                    mBeanInfoCopy.setMBeanDescriptor(modelMBeanInfo
+                            .getMBeanDescriptor());
+                } catch (Exception e) {
+                    throw new RuntimeException(e);
+                }
+                return mBeanInfoCopy;
+            }
+        };
+    }
+
+}

Added: labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/jmx/BeanMetaAttributeNamingStrategy.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/jmx/BeanMetaAttributeNamingStrategy.java?view=auto&rev=566023
==============================================================================
--- labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/jmx/BeanMetaAttributeNamingStrategy.java
(added)
+++ labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/jmx/BeanMetaAttributeNamingStrategy.java
Tue Aug 14 21:36:00 2007
@@ -0,0 +1,51 @@
+package org.apache.logging.pinpoint.jmx;
+
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.apache.commons.lang.StringUtils;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.BeanFactoryAware;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.jmx.export.naming.ObjectNamingStrategy;
+
+/**
+ * A naming strategy that inspects the 'jmxObjectName' meta value in the Spring
+ * context and uses that as the basis for the JMX name.
+ * 
+ * I'm very grateful to Oliver Hutchison for teaching me this trick a while back
+ * at Aconex.
+ * 
+ * @author psmith
+ * 
+ */
+public class BeanMetaAttributeNamingStrategy implements ObjectNamingStrategy,
+        BeanFactoryAware {
+
+    public static final String OBJECT_NAME_ATTRIBUTE = "jmxObjectName";
+
+    private ConfigurableListableBeanFactory beanFactory;
+
+    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
+        this.beanFactory = (ConfigurableListableBeanFactory) beanFactory;
+    }
+
+    public ObjectName getObjectName(Object managedBean, String beanKey)
+            throws MalformedObjectNameException {
+
+        String objectName = (String) beanFactory.getBeanDefinition(beanKey)
+                .getAttribute(OBJECT_NAME_ATTRIBUTE);
+        ObjectName objName = null;
+        if (StringUtils.isNotBlank(objectName)) {
+            objName = new ObjectName(objectName);
+        } else {
+            throw new MalformedObjectNameException(
+                    "Object name must be specified for bean [" + beanKey +
+                            "] using the meta attribute \"jmxObjectName\".");
+        }
+
+        return objName;
+    }
+
+}

Modified: labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/service/Service.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/service/Service.java?view=diff&rev=566023&r1=566022&r2=566023
==============================================================================
--- labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/service/Service.java
(original)
+++ labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/service/Service.java
Tue Aug 14 21:36:00 2007
@@ -10,7 +10,6 @@
 
 import org.apache.commons.daemon.Daemon;
 import org.apache.commons.daemon.DaemonContext;
-import org.apache.log4j.BasicConfigurator;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 public class Service implements Daemon {
@@ -34,15 +33,21 @@
     }
 
     private void configure(String[] args) {
+
+        // TODO configure this? Needs to be done before anything else. Not the
+        // best design in Lucene.
+
+        System.setProperty("org.apache.lucene.FSDirectory.class",
+                "org.apache.lucene.store.MMapDirectory");
+
         String basePackage = Service.class.getPackage().getName().replace('.',
                 '/');
         String config = "default-receiver-config.xml";
 
         System.setProperty("log4j.debug", "true");
-        BasicConfigurator.resetConfiguration();
-        BasicConfigurator.configure();
+
         this.configs = new String[] { "logger-repository.xml", "amq.xml",
-                "pinpoint-context.xml", config };
+                "jmx.xml", "pinpoint-context.xml", config };
 
         for (int i = 0; i < configs.length; i++) {
             configs[i] = basePackage + "/" + configs[i];

Added: labs/pinpoint/trunk/pinpoint-service/src/main/resources/log4j.properties
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-service/src/main/resources/log4j.properties?view=auto&rev=566023
==============================================================================
--- labs/pinpoint/trunk/pinpoint-service/src/main/resources/log4j.properties (added)
+++ labs/pinpoint/trunk/pinpoint-service/src/main/resources/log4j.properties Tue Aug 14 21:36:00
2007
@@ -0,0 +1,4 @@
+log4j.rootCategory=INFO, console
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+log4j.appender.console.layout.ConversionPattern=[%d{ISO8601} %-5p][%20.20c][%t] %m%n
\ No newline at end of file

Added: labs/pinpoint/trunk/pinpoint-service/src/main/resources/org/apache/logging/pinpoint/service/jmx.xml
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-service/src/main/resources/org/apache/logging/pinpoint/service/jmx.xml?view=auto&rev=566023
==============================================================================
--- labs/pinpoint/trunk/pinpoint-service/src/main/resources/org/apache/logging/pinpoint/service/jmx.xml
(added)
+++ labs/pinpoint/trunk/pinpoint-service/src/main/resources/org/apache/logging/pinpoint/service/jmx.xml
Tue Aug 14 21:36:00 2007
@@ -0,0 +1,27 @@
+<beans 
+  xmlns="http://www.springframework.org/schema/beans" 
+  xmlns:amq="http://activemq.org/config/1.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+	<bean name="jmxExporter"
+		class="org.apache.logging.pinpoint.jmx.AttributeOperationHidingMBeanExporter">
+		<property name="autodetectModeName"
+			value="AUTODETECT_ASSEMBLER" />
+		<property name="assembler">
+			<bean
+				class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler">
+				<property name="attributeSource">
+					<bean id="jmxAttributeSource"
+						class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource" />
+				</property>
+			</bean>
+		</property>
+		<property name="namingStrategy">
+			<bean class="org.apache.logging.pinpoint.jmx.BeanMetaAttributeNamingStrategy" />
+		</property>
+		
+	</bean>
+	
+	
+</beans>
\ No newline at end of file

Modified: labs/pinpoint/trunk/pinpoint-service/src/main/resources/org/apache/logging/pinpoint/service/pinpoint-context.xml
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-service/src/main/resources/org/apache/logging/pinpoint/service/pinpoint-context.xml?view=diff&rev=566023&r1=566022&r2=566023
==============================================================================
--- labs/pinpoint/trunk/pinpoint-service/src/main/resources/org/apache/logging/pinpoint/service/pinpoint-context.xml
(original)
+++ labs/pinpoint/trunk/pinpoint-service/src/main/resources/org/apache/logging/pinpoint/service/pinpoint-context.xml
Tue Aug 14 21:36:00 2007
@@ -23,7 +23,7 @@
   http://activemq.org/config/1.0 http://people.apache.org/repository/org.apache.activemq/xsds/activemq-core-4.1-SNAPSHOT.xsd">
 
   <bean id="pinpointHome" class="org.apache.logging.pinpoint.PinpointHome">
-  
+  		<meta key="jmxObjectName" value="Pinpoint:name=PinpointHome" />
   </bean>
   
   <bean id="contextSelector" class="org.apache.logging.pinpoint.selector.StandardPinpointContextSelector">



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


Mime
View raw message