camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [01/34] git commit: Initial commit
Date Wed, 30 Jul 2014 13:00:44 GMT
Repository: camel
Updated Branches:
  refs/heads/master d98a45e84 -> ca67967e0


Initial commit


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/375f13ee
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/375f13ee
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/375f13ee

Branch: refs/heads/master
Commit: 375f13eed7be48abb3f548209b87ba45501559a9
Parents: 
Author: Lauri Kimmel <lauri.kimmel@gmx.com>
Authored: Tue May 6 20:44:21 2014 +1000
Committer: Lauri Kimmel <lauri.kimmel@gmx.com>
Committed: Tue May 6 20:44:21 2014 +1000

----------------------------------------------------------------------
 .gitignore                                      |  8 ++
 pom.xml                                         | 95 ++++++++++++++++++++
 .../java/org/apache/camel/MetricsComponent.java | 18 ++++
 .../java/org/apache/camel/MetricsConsumer.java  | 39 ++++++++
 .../java/org/apache/camel/MetricsEndpoint.java  | 35 ++++++++
 .../java/org/apache/camel/MetricsProducer.java  | 24 +++++
 .../services/org/apache/camel/component/metrics |  1 +
 .../org/apache/camel/MetricsComponentTest.java  | 28 ++++++
 src/test/resources/log4j.properties             | 14 +++
 9 files changed, 262 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/375f13ee/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..9365f3c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,8 @@
+# Maven
+target
+
+# Eclipse
+
+.classpath
+.project
+.settings/
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/375f13ee/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..ae5ac4a
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.camel</groupId>
+  <artifactId>camel-metrics</artifactId>
+  <packaging>bundle</packaging>
+  <version>2.13.0</version>
+
+  <name>Camel Metrics Component</name>
+  <url>http://www.myorganization.org</url>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-core</artifactId>
+      <version>2.13.0</version>
+    </dependency>
+
+    <!-- logging -->
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <version>1.7.6</version>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+      <version>1.7.6</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>log4j</groupId>
+      <artifactId>log4j</artifactId>
+      <version>1.2.17</version>
+      <scope>test</scope>
+    </dependency>
+
+    <!-- testing -->
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-test</artifactId>
+      <version>2.13.0</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <defaultGoal>install</defaultGoal>
+
+    <plugins>
+      
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>2.5.1</version>
+        <configuration>
+          <source>1.6</source>
+          <target>1.6</target>
+        </configuration>
+      </plugin>
+      
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-resources-plugin</artifactId>
+        <version>2.6</version>
+        <configuration>
+          <encoding>UTF-8</encoding>
+        </configuration>
+      </plugin>
+
+      <!-- to generate the MANIFEST-FILE of the bundle -->
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <version>2.3.7</version>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Bundle-SymbolicName>org.apache.camel.camel-metrics</Bundle-SymbolicName>
+            <Export-Service>org.apache.camel.spi.ComponentResolver;component=metrics</Export-Service>
+          </instructions>
+        </configuration>
+      </plugin>
+
+    </plugins>
+  </build>
+
+</project>

http://git-wip-us.apache.org/repos/asf/camel/blob/375f13ee/src/main/java/org/apache/camel/MetricsComponent.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/MetricsComponent.java b/src/main/java/org/apache/camel/MetricsComponent.java
new file mode 100644
index 0000000..2690fdb
--- /dev/null
+++ b/src/main/java/org/apache/camel/MetricsComponent.java
@@ -0,0 +1,18 @@
+package org.apache.camel;
+
+import java.util.Map;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.DefaultComponent;
+
+/**
+ * Represents the component that manages {@link MetricsEndpoint}.
+ */
+public class MetricsComponent extends DefaultComponent {
+
+    protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object>
parameters) throws Exception {
+        Endpoint endpoint = new MetricsEndpoint(uri, this);
+        setProperties(endpoint, parameters);
+        return endpoint;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/375f13ee/src/main/java/org/apache/camel/MetricsConsumer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/MetricsConsumer.java b/src/main/java/org/apache/camel/MetricsConsumer.java
new file mode 100644
index 0000000..26199ea
--- /dev/null
+++ b/src/main/java/org/apache/camel/MetricsConsumer.java
@@ -0,0 +1,39 @@
+package org.apache.camel;
+
+import java.util.Date;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.impl.ScheduledPollConsumer;
+
+/**
+ * The Metrics consumer.
+ */
+public class MetricsConsumer extends ScheduledPollConsumer {
+    private final MetricsEndpoint endpoint;
+
+    public MetricsConsumer(MetricsEndpoint endpoint, Processor processor) {
+        super(endpoint, processor);
+        this.endpoint = endpoint;
+    }
+
+    @Override
+    protected int poll() throws Exception {
+        Exchange exchange = endpoint.createExchange();
+
+        // create a message body
+        Date now = new Date();
+        exchange.getIn().setBody("Hello World! The time is " + now);
+
+        try {
+            // send message to next processor in the route
+            getProcessor().process(exchange);
+            return 1; // number of messages polled
+        } finally {
+            // log exception if an exception occurred and was not handled
+            if (exchange.getException() != null) {
+                getExceptionHandler().handleException("Error processing exchange", exchange,
exchange.getException());
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/375f13ee/src/main/java/org/apache/camel/MetricsEndpoint.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/MetricsEndpoint.java b/src/main/java/org/apache/camel/MetricsEndpoint.java
new file mode 100644
index 0000000..4327a03
--- /dev/null
+++ b/src/main/java/org/apache/camel/MetricsEndpoint.java
@@ -0,0 +1,35 @@
+package org.apache.camel;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.impl.DefaultEndpoint;
+
+/**
+ * Represents a Metrics endpoint.
+ */
+public class MetricsEndpoint extends DefaultEndpoint {
+
+    public MetricsEndpoint() {
+    }
+
+    public MetricsEndpoint(String uri, MetricsComponent component) {
+        super(uri, component);
+    }
+
+    public MetricsEndpoint(String endpointUri) {
+        super(endpointUri);
+    }
+
+    public Producer createProducer() throws Exception {
+        return new MetricsProducer(this);
+    }
+
+    public Consumer createConsumer(Processor processor) throws Exception {
+        return new MetricsConsumer(this, processor);
+    }
+
+    public boolean isSingleton() {
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/375f13ee/src/main/java/org/apache/camel/MetricsProducer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/MetricsProducer.java b/src/main/java/org/apache/camel/MetricsProducer.java
new file mode 100644
index 0000000..4d6a1cd
--- /dev/null
+++ b/src/main/java/org/apache/camel/MetricsProducer.java
@@ -0,0 +1,24 @@
+package org.apache.camel;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultProducer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The Metrics producer.
+ */
+public class MetricsProducer extends DefaultProducer {
+    private static final Logger LOG = LoggerFactory.getLogger(MetricsProducer.class);
+    private MetricsEndpoint endpoint;
+
+    public MetricsProducer(MetricsEndpoint endpoint) {
+        super(endpoint);
+        this.endpoint = endpoint;
+    }
+
+    public void process(Exchange exchange) throws Exception {
+        System.out.println(exchange.getIn().getBody());    
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/375f13ee/src/main/resources/META-INF/services/org/apache/camel/component/metrics
----------------------------------------------------------------------
diff --git a/src/main/resources/META-INF/services/org/apache/camel/component/metrics b/src/main/resources/META-INF/services/org/apache/camel/component/metrics
new file mode 100644
index 0000000..e7239ec
--- /dev/null
+++ b/src/main/resources/META-INF/services/org/apache/camel/component/metrics
@@ -0,0 +1 @@
+class=org.apache.camel.MetricsComponent

http://git-wip-us.apache.org/repos/asf/camel/blob/375f13ee/src/test/java/org/apache/camel/MetricsComponentTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/camel/MetricsComponentTest.java b/src/test/java/org/apache/camel/MetricsComponentTest.java
new file mode 100644
index 0000000..2fb5926
--- /dev/null
+++ b/src/test/java/org/apache/camel/MetricsComponentTest.java
@@ -0,0 +1,28 @@
+package org.apache.camel;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class MetricsComponentTest extends CamelTestSupport {
+
+    @Test
+    public void testMetrics() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMinimumMessageCount(1);       
+        
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() {
+                from("metrics://foo")
+                  .to("metrics://bar")
+                  .to("mock:result");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/375f13ee/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/src/test/resources/log4j.properties b/src/test/resources/log4j.properties
new file mode 100644
index 0000000..3b1bd38
--- /dev/null
+++ b/src/test/resources/log4j.properties
@@ -0,0 +1,14 @@
+#
+# The logging properties used
+#
+log4j.rootLogger=INFO, out
+
+# uncomment the following line to turn on Camel debugging
+#log4j.logger.org.apache.camel=DEBUG
+
+# CONSOLE appender not used by default
+log4j.appender.out=org.apache.log4j.ConsoleAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n
+#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+


Mime
View raw message