labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From psm...@apache.org
Subject svn commit: r567967 - in /labs/pinpoint/trunk: ./ pinpoint-cli/ pinpoint-core/ pinpoint-core/src/main/java/org/apache/logging/pinpoint/converter/ pinpoint-loadgenerator/ pinpoint-metric/src/main/java/org/apache/logging/pinpoint/metric/ pinpoint-search/...
Date Tue, 21 Aug 2007 05:55:41 GMT
Author: psmith
Date: Mon Aug 20 22:55:40 2007
New Revision: 567967

URL: http://svn.apache.org/viewvc?rev=567967&view=rev
Log:
Added command-line option to pinpoint-service to allow user to specify SocketHubReceivers
to connect to remote systems. 
By default, only a SocketReceiver is configured, which relies on remote applications knowing
where Pinpoint might be.
This allows users to decide between a central Event Clearhousing model, or a "Service knows
where stuff is" approach.

Changed graph produced to simply show # events the indexer is behind, which is vastly easier
to understand than
my lame attempt at rate conversion and comparision (thanks to Alison Winters for pointing
me at an obvious solution).

Added QA/DEBUG JMX attribute so that one can slow the indexing rate to the point of observing
an event backlog; obviously
this option is not on by default... :)

Created an assembly that bundles up the service into a standalone project.  At this point
both the -service
and -cli modules are seperate, but I'm thinking that a combined module that ships a combined
artifact
with both the -service and -cli shell scripts might be easier to download and install.


Added:
    labs/pinpoint/trunk/pinpoint-loadgenerator/
    labs/pinpoint/trunk/pinpoint-service/src/assembly/
    labs/pinpoint/trunk/pinpoint-service/src/assembly/service.xml
Removed:
    labs/pinpoint/trunk/pinpoint-cli/.classpath
    labs/pinpoint/trunk/pinpoint-core/.project
Modified:
    labs/pinpoint/trunk/pinpoint-cli/.project
    labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/converter/PinpointEventWriterHandler.java
    labs/pinpoint/trunk/pinpoint-metric/src/main/java/org/apache/logging/pinpoint/metric/MetricChartUtils.java
    labs/pinpoint/trunk/pinpoint-search/.project
    labs/pinpoint/trunk/pinpoint-service/   (props changed)
    labs/pinpoint/trunk/pinpoint-service/.project
    labs/pinpoint/trunk/pinpoint-service/pom.xml
    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
    labs/pinpoint/trunk/pom.xml

Modified: labs/pinpoint/trunk/pinpoint-cli/.project
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-cli/.project?rev=567967&r1=567966&r2=567967&view=diff
==============================================================================
--- labs/pinpoint/trunk/pinpoint-cli/.project (original)
+++ labs/pinpoint/trunk/pinpoint-cli/.project Mon Aug 20 22:55:40 2007
@@ -1,21 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
 <projectDescription>
-  <name>pinpoint-cli</name>
-  <comment>Index and search infrastructure for log4j</comment>
-  <projects>
-    <project>pinpoint-core</project>
-    <project>pinpoint-metric</project>
-    <project>pinpoint-search</project>
-  </projects>
-  <buildSpec>
-    <buildCommand>
-      <name>org.eclipse.jdt.core.javabuilder</name>
-    </buildCommand>
-    <buildCommand>
-      <name>org.maven.ide.eclipse.maven2Builder</name>
-    </buildCommand>
-  </buildSpec>
-  <natures>
-    <nature>org.eclipse.jdt.core.javanature</nature>
-    <nature>org.maven.ide.eclipse.maven2Nature</nature>
-  </natures>
-</projectDescription>
\ No newline at end of file
+	<name>pinpoint-cli</name>
+	<comment>Index and search infrastructure for log4j</comment>
+	<projects>
+		<project>pinpoint-core</project>
+		<project>pinpoint-metric</project>
+		<project>pinpoint-search</project>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.maven.ide.eclipse.maven2Builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.maven.ide.eclipse.maven2Nature</nature>
+	</natures>
+</projectDescription>

Modified: labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/converter/PinpointEventWriterHandler.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/converter/PinpointEventWriterHandler.java?rev=567967&r1=567966&r2=567967&view=diff
==============================================================================
--- labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/converter/PinpointEventWriterHandler.java
(original)
+++ labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/converter/PinpointEventWriterHandler.java
Mon Aug 20 22:55:40 2007
@@ -20,18 +20,20 @@
 import org.apache.logging.pinpoint.selector.PinpointContextSelector;
 import org.apache.logging.pinpoint.store.EventStore;
 import org.apache.logging.pinpoint.store.SimpleEventStore;
+import org.springframework.jmx.export.annotation.ManagedAttribute;
+import org.springframework.jmx.export.annotation.ManagedResource;
 
 /**
- * Handles events by writing to a {@link PinpointContext}, which is chosen by
- * the provide {@link PinpointContextSelector}.
+ * Handles events by writing to a {@link PinpointContext}, which is chosen by the provide
+ * {@link PinpointContextSelector}.
  * 
  * @author psmith
- * 
  */
+@ManagedResource
 public class PinpointEventWriterHandler implements LoggingEventHandler {
     private final PinpointContextSelector selector;
 
-    private Map<PinpointContext, PinpointContextContainer> contextMap = new HashMap<PinpointContext,
PinpointContextContainer>();
+    private Map<PinpointContext, EventWriter> contextMap = new HashMap<PinpointContext,
EventWriter>();
 
     private final IndexWriterFactory indexWriterFactor;
 
@@ -39,9 +41,10 @@
 
     private final Counter eventsWrittenCounter;
 
+    private boolean useExceptionallySlowIndexing = false;
+
     public PinpointEventWriterHandler(PinpointContextSelector selector,
-            IndexWriterFactory indexWriterFactory,
-            AnalyzerFactory analyzerFactory, Counter counter) {
+            IndexWriterFactory indexWriterFactory, AnalyzerFactory analyzerFactory, Counter
counter) {
         this.selector = selector;
         this.indexWriterFactor = indexWriterFactory;
         this.analyserFactory = analyzerFactory;
@@ -68,36 +71,46 @@
         // threading/JMS to process these
         PinpointContext ctx = this.selector.selectFor(event);
         try {
-            PinpointContextContainer container = contextMap.get(ctx);
+            EventWriter writer = contextMap.get(ctx);
+
+            if (writer == null) {
 
-            if (container == null) {
-                container = new PinpointContextContainer();
                 EventStore store = new SimpleEventStore(ctx);
 
-                container.eventWriter = new EventWriter(store, ctx
-                        .getIndexDirectory(), indexWriterFactor,
+                writer = new EventWriter(store, ctx.getIndexDirectory(), indexWriterFactor,
                         analyserFactory);
-                contextMap.put(ctx, container);
+                contextMap.put(ctx, writer);
             }
-            container.eventWriter.writeEvent(event);
+            writer.writeEvent(event);
             this.eventsWrittenCounter.inc();
         } catch (IOException e) {
             // TODO Handle failure
             e.printStackTrace();
+        } finally {
+            if (isUseExceptionallySlowIndexing()) {
+                try {
+                    Thread.sleep(1000); // TODO constant
+                } catch (Exception e) {
+                }
+            }
         }
     }
 
     public void close() {
-        for (Map.Entry<PinpointContext, PinpointContextContainer> entry : contextMap
-                .entrySet()) {
-            entry.getValue().eventWriter.close();
+        for (Map.Entry<PinpointContext, EventWriter> entry : contextMap.entrySet())
{
+            entry.getValue().close();
         }
 
     }
 
-    // TODO is this container really needed?
-    private static class PinpointContextContainer {
-        private EventWriter eventWriter;
+    @ManagedAttribute
+    public final boolean isUseExceptionallySlowIndexing() {
+        return useExceptionallySlowIndexing;
+    }
+
+    @ManagedAttribute(description = "Set to true if you would like to throttle this writer
to a point where you can observe events being backlogged/buffered.  QA/DEBUG ONLY!")
+    public final void setUseExceptionallySlowIndexing(boolean useExceptionallySlowIndexing)
{
+        this.useExceptionallySlowIndexing = useExceptionallySlowIndexing;
     }
 
 }

Modified: labs/pinpoint/trunk/pinpoint-metric/src/main/java/org/apache/logging/pinpoint/metric/MetricChartUtils.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-metric/src/main/java/org/apache/logging/pinpoint/metric/MetricChartUtils.java?rev=567967&r1=567966&r2=567967&view=diff
==============================================================================
--- labs/pinpoint/trunk/pinpoint-metric/src/main/java/org/apache/logging/pinpoint/metric/MetricChartUtils.java
(original)
+++ labs/pinpoint/trunk/pinpoint-metric/src/main/java/org/apache/logging/pinpoint/metric/MetricChartUtils.java
Mon Aug 20 22:55:40 2007
@@ -1,11 +1,19 @@
 package org.apache.logging.pinpoint.metric;
 
-import java.util.Collection;
 import java.util.List;
 
 import org.apache.log4j.Logger;
-import org.jfree.chart.ChartFactory;
 import org.jfree.chart.JFreeChart;
+import org.jfree.chart.axis.DateAxis;
+import org.jfree.chart.axis.NumberAxis;
+import org.jfree.chart.axis.ValueAxis;
+import org.jfree.chart.labels.StandardXYToolTipGenerator;
+import org.jfree.chart.labels.XYToolTipGenerator;
+import org.jfree.chart.plot.PlotOrientation;
+import org.jfree.chart.plot.XYPlot;
+import org.jfree.chart.renderer.xy.XYAreaRenderer;
+import org.jfree.chart.urls.StandardXYURLGenerator;
+import org.jfree.chart.urls.XYURLGenerator;
 import org.jfree.data.time.FixedMillisecond;
 import org.jfree.data.time.TimeSeries;
 import org.jfree.data.time.TimeSeriesCollection;
@@ -15,42 +23,47 @@
 
     private static final Logger LOG = Logger.getLogger(MetricChartUtils.class);
 
-    public static JFreeChart createChart(Collection<Counter> counters,
-            String title) {
+    public static JFreeChart createBacklogChart(Counter receivedCounter, Counter indexedCounter)
{
         TimeSeriesCollection collection = new TimeSeriesCollection();
 
-        for (Counter counter : counters) {
-            TimeSeries series = new TimeSeries(counter.getMetricName(),
-                    FixedMillisecond.class);
-            List<ObservedValue> observations = counter.getObservations();
-            ObservedValue lastValue = null;
-            for (ObservedValue observedValue : observations) {
-                if (lastValue != null) {
-                    long difference = observedValue.getObservedValue() -
-                            lastValue.getObservedValue();
-                    double rate = ((double) difference) /
-                            ((observedValue.getTimestamp() - lastValue
-                                    .getTimestamp()) / 1000);
-                    if (LOG.isDebugEnabled()) {
-                        LOG.debug(counter.getMetricName() + ": rate=" + rate);
-                    }
-                    series.add(new TimeSeriesDataItem(new FixedMillisecond(
-                            observedValue.getTimestamp()), rate));
-                }
-                lastValue = observedValue;
-            }
-
-            collection.addSeries(series);
+        TimeSeries series = new TimeSeries("Event Backlog", FixedMillisecond.class);
+        List<ObservedValue> receivedObservations = receivedCounter.getObservations();
+        List<ObservedValue> indexedObservations = indexedCounter.getObservations();
+        for (int i = 0; i < receivedObservations.size(); i++) {
+            double difference = receivedObservations.get(i).getObservedValue()
+                    - indexedObservations.get(i).getObservedValue();
+            series.add(new TimeSeriesDataItem(new FixedMillisecond(receivedObservations.get(i)
+                    .getTimestamp()), difference));
         }
+
+        collection.addSeries(series);
         boolean urls = false;
         boolean tooltips = true;
         boolean legend = true;
-        String valueAxisLabel = "Rate/second";
+        String valueAxisLabel = "# Received Events not yet indexed";
         String timeAxisLabel = "";
-        JFreeChart chart = ChartFactory.createTimeSeriesChart(title,
-                timeAxisLabel, valueAxisLabel, collection, legend, tooltips,
-                urls);
 
+        ValueAxis timeAxis = new DateAxis(timeAxisLabel);
+        timeAxis.setLowerMargin(0.02); // reduce the default margins
+        timeAxis.setUpperMargin(0.02);
+        NumberAxis yAxis = new NumberAxis(valueAxisLabel);
+        XYPlot plot = new XYPlot(collection, timeAxis, yAxis, null);
+        plot.setOrientation(PlotOrientation.VERTICAL);
+
+        XYToolTipGenerator tipGenerator = null;
+        if (tooltips) {
+            tipGenerator = new StandardXYToolTipGenerator();
+        }
+
+        XYURLGenerator urlGenerator = null;
+        if (urls) {
+            urlGenerator = new StandardXYURLGenerator();
+        }
+
+        plot.setRenderer(new XYAreaRenderer(XYAreaRenderer.AREA, tipGenerator, urlGenerator));
+
+        JFreeChart chart = new JFreeChart("Event Backlog", JFreeChart.DEFAULT_TITLE_FONT,
plot,
+                legend);
         return chart;
 
     }

Modified: labs/pinpoint/trunk/pinpoint-search/.project
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-search/.project?rev=567967&r1=567966&r2=567967&view=diff
==============================================================================
--- labs/pinpoint/trunk/pinpoint-search/.project (original)
+++ labs/pinpoint/trunk/pinpoint-search/.project Mon Aug 20 22:55:40 2007
@@ -1,20 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
 <projectDescription>
-  <name>pinpoint-search</name>
-  <comment>Index and search infrastructure for log4j</comment>
-  <projects>
-    <project>pinpoint-metric</project>
-    <project>pinpoint-core</project>
-  </projects>
-  <buildSpec>
-    <buildCommand>
-      <name>org.eclipse.jdt.core.javabuilder</name>
-    </buildCommand>
-    <buildCommand>
-      <name>org.maven.ide.eclipse.maven2Builder</name>
-    </buildCommand>
-  </buildSpec>
-  <natures>
-    <nature>org.eclipse.jdt.core.javanature</nature>
-    <nature>org.maven.ide.eclipse.maven2Nature</nature>
-  </natures>
-</projectDescription>
\ No newline at end of file
+	<name>pinpoint-search</name>
+	<comment>Index and search infrastructure for log4j</comment>
+	<projects>
+		<project>pinpoint-metric</project>
+		<project>pinpoint-core</project>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.maven.ide.eclipse.maven2Builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.maven.ide.eclipse.maven2Nature</nature>
+	</natures>
+</projectDescription>

Propchange: labs/pinpoint/trunk/pinpoint-service/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Mon Aug 20 22:55:40 2007
@@ -2,3 +2,5 @@
 .settings
 .classpath
 .project
+activem*
+metricGraph.jpg

Modified: labs/pinpoint/trunk/pinpoint-service/.project
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-service/.project?rev=567967&r1=567966&r2=567967&view=diff
==============================================================================
--- labs/pinpoint/trunk/pinpoint-service/.project (original)
+++ labs/pinpoint/trunk/pinpoint-service/.project Mon Aug 20 22:55:40 2007
@@ -1,21 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
 <projectDescription>
-  <name>pinpoint-service</name>
-  <comment>Index and search infrastructure for log4j</comment>
-  <projects>
-    <project>pinpoint-metric</project>
-    <project>pinpoint-core</project>
-    <project>pinpoint-search</project>
-  </projects>
-  <buildSpec>
-    <buildCommand>
-      <name>org.eclipse.jdt.core.javabuilder</name>
-    </buildCommand>
-    <buildCommand>
-      <name>org.maven.ide.eclipse.maven2Builder</name>
-    </buildCommand>
-  </buildSpec>
-  <natures>
-    <nature>org.eclipse.jdt.core.javanature</nature>
-    <nature>org.maven.ide.eclipse.maven2Nature</nature>
-  </natures>
-</projectDescription>
\ No newline at end of file
+	<name>pinpoint-service</name>
+	<comment>Index and search infrastructure for log4j</comment>
+	<projects>
+		<project>pinpoint-metric</project>
+		<project>pinpoint-core</project>
+		<project>pinpoint-search</project>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.maven.ide.eclipse.maven2Builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.maven.ide.eclipse.maven2Nature</nature>
+	</natures>
+</projectDescription>

Modified: labs/pinpoint/trunk/pinpoint-service/pom.xml
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-service/pom.xml?rev=567967&r1=567966&r2=567967&view=diff
==============================================================================
--- labs/pinpoint/trunk/pinpoint-service/pom.xml (original)
+++ labs/pinpoint/trunk/pinpoint-service/pom.xml Mon Aug 20 22:55:40 2007
@@ -31,7 +31,7 @@
           </execution>
         </executions>
         <configuration>
-          <extraJvmArguments>-Xmx256m -Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.port=5678 -Dcom.sun.management.jmxremote.ssl=false</extraJvmArguments>
+          <extraJvmArguments>-Xmx256m -Djava.awt.headless=true -Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.port=5678 -Dcom.sun.management.jmxremote.ssl=false</extraJvmArguments>
           <programs>
             <program>
               <mainClass>org.apache.logging.pinpoint.service.Service</mainClass>
@@ -39,6 +39,24 @@
             </program>
           </programs>
         </configuration>
+      </plugin>
+      <plugin>
+        <artifactId>maven-assembly-plugin</artifactId>
+        <configuration>
+          <descriptors>
+            <descriptor>src/assembly/service.xml</descriptor>
+          </descriptors>
+          <appendAssemblyId>false</appendAssemblyId>
+        </configuration>
+        <executions>
+          <execution>
+            <id>make-assembly</id>
+            <phase>package</phase>
+            <goals>
+              <goal>attached</goal>
+            </goals>
+          </execution>
+        </executions>
       </plugin>
     </plugins>
   </build>

Added: labs/pinpoint/trunk/pinpoint-service/src/assembly/service.xml
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-service/src/assembly/service.xml?rev=567967&view=auto
==============================================================================
--- labs/pinpoint/trunk/pinpoint-service/src/assembly/service.xml (added)
+++ labs/pinpoint/trunk/pinpoint-service/src/assembly/service.xml Mon Aug 20 22:55:40 2007
@@ -0,0 +1,21 @@
+<?xml version="1.0"?>
+<assembly>
+  <id>service</id>
+  <formats>
+    <format>zip</format>
+    <format>tar.gz</format>
+  </formats>
+  <fileSets>
+    <fileSet>
+      <includes>
+        <include>README*</include>
+        <include>LICENSE*</include>
+        <include>NOTICE*</include>
+      </includes>
+    </fileSet>
+    <fileSet>
+      <directory>target/appassembler</directory>
+      <outputDirectory/>
+    </fileSet>
+  </fileSets>
+</assembly>

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?rev=567967&r1=567966&r2=567967&view=diff
==============================================================================
--- 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
Mon Aug 20 22:55:40 2007
@@ -9,22 +9,33 @@
 package org.apache.logging.pinpoint.service;
 
 import java.io.File;
-import java.util.concurrent.CopyOnWriteArrayList;
 
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.GnuParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.Options;
 import org.apache.commons.daemon.Daemon;
 import org.apache.commons.daemon.DaemonContext;
+import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.SystemUtils;
+import org.apache.log4j.net.SocketHubReceiver;
+import org.apache.log4j.spi.LoggerRepository;
 import org.apache.logging.pinpoint.metric.Counter;
 import org.apache.logging.pinpoint.metric.MetricChartUtils;
 import org.apache.logging.pinpoint.metric.MetricRegistry;
 import org.jfree.chart.ChartUtilities;
 import org.jfree.chart.JFreeChart;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 public class Service implements Daemon {
 
     private String[] configs = null;
     private ClassPathXmlApplicationContext ctx;
+    private String[] socketHubReceivers;
 
     /**
      * @param args
@@ -35,16 +46,15 @@
 
         service.start();
 
-        MetricRegistry registry = (MetricRegistry) service.ctx
-                .getBean("metricRegistry");
+        MetricRegistry registry = (MetricRegistry) service.ctx.getBean("metricRegistry");
 
         File graphLocation = new File(SystemUtils.USER_DIR, "metricGraph.jpg");
         while (true) {
 
             Thread.sleep(1000);
-            JFreeChart chart = MetricChartUtils.createChart(
-                    new CopyOnWriteArrayList<Counter>(registry.getCounters()),
-                    "Event Rates");
+            JFreeChart chart = MetricChartUtils.createBacklogChart((Counter) service.ctx
+                    .getBean("receivedEventsCounter"), (Counter) service.ctx
+                    .getBean("eventsWrittenCounter"));
             ChartUtilities.saveChartAsJPEG(graphLocation, chart, 640, 480);
         }
 
@@ -52,26 +62,92 @@
 
     private void configure(String[] args) {
 
+        Options options = getOptions();
+        GnuParser parser = new GnuParser();
+
+        try {
+            CommandLine cmdLine = parser.parse(options, args);
+            /*
+             * Extract the requested SocketHubReceivers from the command line
+             */
+            if (cmdLine.hasOption('s')) {
+                this.socketHubReceivers = cmdLine.getOptionValues('s');
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            showHelp(options);
+            throw new IllegalArgumentException("Problematic arguments");
+        }
+
         // 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 basePackage = Service.class.getPackage().getName().replace('.', '/');
         String config = "default-receiver-config.xml";
 
         System.setProperty("log4j.debug", "true");
 
-        this.configs = new String[] { "logger-repository.xml", "amq.xml",
-                "jmx.xml", "pinpoint-context.xml", config };
+        this.configs = new String[] { "logger-repository.xml", "amq.xml", "jmx.xml",
+                "pinpoint-context.xml", config };
 
         for (int i = 0; i < configs.length; i++) {
             configs[i] = basePackage + "/" + configs[i];
         }
     }
 
+    private static void showHelp(Options options) {
+        HelpFormatter formatter = new HelpFormatter();
+        formatter.printHelp("pinpoint-service", options);
+    }
+
+    private Options getOptions() {
+        Options options = new Options();
+        options
+                .addOption(OptionBuilder
+                        .withLongOpt("socketHub")
+                        .withDescription(
+                                "Comma-separated list of SocketHubReceivers to create to
connect to remote Apps using SocketHubAppenders")
+                        .hasArgs().withArgName("[host]:[port]").withValueSeparator(',').create('s'));
+        return options;
+    }
+
+    /**
+     * Adds SocketHubReceivers according to the provided command line arguments
+     */
+    private class ExtraSocketHubReceiverPostProcesser implements BeanFactoryPostProcessor
{
+
+        public void postProcessBeanFactory(ConfigurableListableBeanFactory factory)
+                throws BeansException {
+            LoggerRepository loggerRepository = (LoggerRepository) ctx.getBean("loggerRepository");
+            for (String socketHubReceiver : socketHubReceivers) {
+                int port = 4560; // TODO constant
+                String host = "";
+                if (StringUtils.contains(socketHubReceiver, ":")) {
+                    String[] split = StringUtils.split(socketHubReceiver, ":");
+                    host = split[0];
+                    port = Integer.valueOf(split[1]);
+                    SocketHubReceiver receiver = (SocketHubReceiver) factory.createBean(
+                            SocketHubReceiver.class, ConfigurableListableBeanFactory.AUTOWIRE_NO,
+                            false);
+                    receiver.setLoggerRepository(loggerRepository);
+                    receiver.setHost(host);
+                    receiver.setPort(port);
+                    receiver.setReconnectionDelay(5000); // TODO constant?
+                    receiver.activateOptions();
+                    // TODO register in ctx?
+                } else {
+                    throw new UnsupportedOperationException(
+                            "TODO Currently do not support default port.  Please specify
in '<host>:<port>' format");
+                }
+            }
+
+        }
+
+    }
+
     public void destroy() {
         ctx.destroy();
 
@@ -84,6 +160,12 @@
 
     public void start() throws Exception {
         ctx = new ClassPathXmlApplicationContext(configs);
+        if (this.configs != null) {
+            new ExtraSocketHubReceiverPostProcesser().postProcessBeanFactory(this.ctx
+                    .getBeanFactory());
+        }
+
+        ctx.registerShutdownHook();
     }
 
     public void stop() throws Exception {

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?rev=567967&r1=567966&r2=567967&view=diff
==============================================================================
--- 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
Mon Aug 20 22:55:40 2007
@@ -46,6 +46,7 @@
   </bean>
   
   <bean id="eventWriterloggingEventHandler" class="org.apache.logging.pinpoint.converter.PinpointEventWriterHandler">
+  	<meta key="jmxObjectName" value="Pinpoint:name=eventWriterLoggingEventHandler" />
   	<constructor-arg ref="contextSelector" />
   	<constructor-arg ref="indexWriterFactory" />
   	<constructor-arg ref="analyserFactory" />

Modified: labs/pinpoint/trunk/pom.xml
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pom.xml?rev=567967&r1=567966&r2=567967&view=diff
==============================================================================
--- labs/pinpoint/trunk/pom.xml (original)
+++ labs/pinpoint/trunk/pom.xml Mon Aug 20 22:55:40 2007
@@ -27,7 +27,7 @@
     <lucene.version>2.2.0</lucene.version>
     <log4j.version>1.2.15-SNAPSHOT</log4j.version>
     <log4j.companion.version>1.0-SNAPSHOT</log4j.companion.version>
-    <commonscli.version>1.0</commonscli.version>
+    <commonscli.version>1.1</commonscli.version>
     <jline.version>0.9.91</jline.version>
   </properties>
   <modules>
@@ -38,6 +38,7 @@
     <module>pinpoint-web</module>
     <module>pinpoint-service</module>
     <module>pinpoint-metric</module>
+    <module>pinpoint-loadgenerator</module>
   </modules>
   <build>
     <plugins>



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


Mime
View raw message