camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [4/8] camel git commit: CAMEL-9157: JMX - Add dataformat as mbean category
Date Thu, 24 Sep 2015 11:36:17 GMT
CAMEL-9157: JMX - Add dataformat as mbean category


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

Branch: refs/heads/master
Commit: 0a991eabf139a9946d017649b5aae4d4637ff76a
Parents: ca7fd9a
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Thu Sep 24 11:52:43 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Sep 24 11:54:41 2015 +0200

----------------------------------------------------------------------
 .../org/apache/camel/impl/GzipDataFormat.java   | 12 ++++-
 .../camel/impl/SerializationDataFormat.java     | 12 ++++-
 .../org/apache/camel/impl/StringDataFormat.java | 13 ++++-
 .../org/apache/camel/impl/ZipDataFormat.java    | 11 +++-
 .../camel/processor/MarshalProcessor.java       |  5 +-
 .../camel/processor/UnmarshalProcessor.java     |  5 +-
 .../java/org/apache/camel/spi/DataFormat.java   |  5 +-
 .../camel/impl/DataFormatContextAwareTest.java  | 13 ++++-
 .../apache/camel/impl/RefDataFormatTest.java    | 12 ++++-
 .../camel/management/ManagedDataFormatTest.java | 55 ++++++++++++++++++++
 ...DeadLetterChannelUnmarshalSetHeaderTest.java | 13 ++++-
 .../camel/processor/UnmarshalProcessorTest.java | 13 ++++-
 12 files changed, 157 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/0a991eab/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java b/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java
index 236bd91..d89460a 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java
@@ -24,12 +24,13 @@ import java.util.zip.GZIPOutputStream;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.spi.DataFormat;
+import org.apache.camel.support.*;
 import org.apache.camel.util.IOHelper;
 
 /**
  * GZip {@link org.apache.camel.spi.DataFormat} for reading/writing data using gzip.
  */
-public class GzipDataFormat implements DataFormat {
+public class GzipDataFormat extends org.apache.camel.support.ServiceSupport implements DataFormat
{
 
     public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception
{
         InputStream is = exchange.getContext().getTypeConverter().mandatoryConvertTo(InputStream.class,
exchange, graph);
@@ -59,4 +60,13 @@ public class GzipDataFormat implements DataFormat {
         }
     }
 
+    @Override
+    protected void doStart() throws Exception {
+        // noop
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        // noop
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/0a991eab/camel-core/src/main/java/org/apache/camel/impl/SerializationDataFormat.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/SerializationDataFormat.java b/camel-core/src/main/java/org/apache/camel/impl/SerializationDataFormat.java
index 8d33d62..eb2fe24 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/SerializationDataFormat.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/SerializationDataFormat.java
@@ -32,7 +32,7 @@ import org.apache.camel.util.ExchangeHelper;
  *
  * @version 
  */
-public class SerializationDataFormat implements DataFormat {
+public class SerializationDataFormat extends org.apache.camel.support.ServiceSupport implements
DataFormat {
 
     public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception
{
         ObjectOutput out = ExchangeHelper.convertToMandatoryType(exchange, ObjectOutput.class,
stream);
@@ -60,4 +60,14 @@ public class SerializationDataFormat implements DataFormat {
             }
         }
     }
+
+    @Override
+    protected void doStart() throws Exception {
+        // noop
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        // noop
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/0a991eab/camel-core/src/main/java/org/apache/camel/impl/StringDataFormat.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/StringDataFormat.java b/camel-core/src/main/java/org/apache/camel/impl/StringDataFormat.java
index 7b115ac..545c482 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/StringDataFormat.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/StringDataFormat.java
@@ -30,7 +30,7 @@ import org.apache.camel.util.ExchangeHelper;
  *
  * @version 
  */
-public class StringDataFormat implements DataFormat {
+public class StringDataFormat extends org.apache.camel.support.ServiceSupport implements
DataFormat {
 
     private String charset;
 
@@ -73,5 +73,14 @@ public class StringDataFormat implements DataFormat {
 
         return answer;
     }
-    
+
+    @Override
+    protected void doStart() throws Exception {
+        // noop
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        // noop
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/0a991eab/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java b/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java
index c496714..daa9062 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java
@@ -31,7 +31,7 @@ import org.apache.camel.util.IOHelper;
  * "Deflate" compression data format.
  * See {@link org.apache.camel.model.dataformat.ZipFileDataFormat} for Zip file compression.
  */
-public class ZipDataFormat implements DataFormat {
+public class ZipDataFormat extends org.apache.camel.support.ServiceSupport implements DataFormat
{
 
     private int compressionLevel;
 
@@ -78,4 +78,13 @@ public class ZipDataFormat implements DataFormat {
         }
     }
 
+    @Override
+    protected void doStart() throws Exception {
+        // noop
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        // noop
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/0a991eab/camel-core/src/main/java/org/apache/camel/processor/MarshalProcessor.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/MarshalProcessor.java b/camel-core/src/main/java/org/apache/camel/processor/MarshalProcessor.java
index 1b78d86..d16205f 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/MarshalProcessor.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/MarshalProcessor.java
@@ -125,11 +125,14 @@ public class MarshalProcessor extends ServiceSupport implements AsyncProcessor,
         if (dataFormat instanceof CamelContextAware) {
             ((CamelContextAware) dataFormat).setCamelContext(camelContext);
         }
-        ServiceHelper.startService(dataFormat);
+        // add dataFormat as service which will also start the service
+        // (false => we and handling the lifecycle of the dataFormat)
+        getCamelContext().addService(dataFormat, false);
     }
 
     @Override
     protected void doStop() throws Exception {
         ServiceHelper.stopService(dataFormat);
+        getCamelContext().removeService(dataFormat);
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/0a991eab/camel-core/src/main/java/org/apache/camel/processor/UnmarshalProcessor.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/UnmarshalProcessor.java b/camel-core/src/main/java/org/apache/camel/processor/UnmarshalProcessor.java
index 60883c0..3c5183c 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/UnmarshalProcessor.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/UnmarshalProcessor.java
@@ -122,12 +122,15 @@ public class UnmarshalProcessor extends ServiceSupport implements AsyncProcessor
         if (dataFormat instanceof CamelContextAware) {
             ((CamelContextAware) dataFormat).setCamelContext(camelContext);
         }
-        ServiceHelper.startService(dataFormat);
+        // add dataFormat as service which will also start the service
+        // (false => we and handling the lifecycle of the dataFormat)
+        getCamelContext().addService(dataFormat, false);
     }
 
     @Override
     protected void doStop() throws Exception {
         ServiceHelper.stopService(dataFormat);
+        getCamelContext().removeService(dataFormat);
     }
 
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/0a991eab/camel-core/src/main/java/org/apache/camel/spi/DataFormat.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/DataFormat.java b/camel-core/src/main/java/org/apache/camel/spi/DataFormat.java
index 0d59ca0..86ed336 100644
--- a/camel-core/src/main/java/org/apache/camel/spi/DataFormat.java
+++ b/camel-core/src/main/java/org/apache/camel/spi/DataFormat.java
@@ -21,6 +21,7 @@ import java.io.OutputStream;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
+import org.apache.camel.Service;
 
 /**
  * Represents a
@@ -31,7 +32,9 @@ import org.apache.camel.Message;
  *
  * @version 
  */
-public interface DataFormat {
+public interface DataFormat extends Service {
+
+    // TODO: DataFormats should extends Service like the others
 
     /**
      * Marshals the object to the given Stream.

http://git-wip-us.apache.org/repos/asf/camel/blob/0a991eab/camel-core/src/test/java/org/apache/camel/impl/DataFormatContextAwareTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/impl/DataFormatContextAwareTest.java
b/camel-core/src/test/java/org/apache/camel/impl/DataFormatContextAwareTest.java
index 24b55d6..db451b3 100644
--- a/camel-core/src/test/java/org/apache/camel/impl/DataFormatContextAwareTest.java
+++ b/camel-core/src/test/java/org/apache/camel/impl/DataFormatContextAwareTest.java
@@ -24,6 +24,7 @@ import org.apache.camel.CamelContextAware;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.spi.DataFormat;
+import org.apache.camel.support.*;
 
 /**
  *
@@ -47,7 +48,7 @@ public class DataFormatContextAwareTest extends ContextTestSupport {
         assertNotNull(me.getCamelContext());
     }
 
-    private static class MyDataFormat implements DataFormat, CamelContextAware {
+    private static class MyDataFormat extends org.apache.camel.support.ServiceSupport implements
DataFormat, CamelContextAware {
 
         private CamelContext camelContext;
 
@@ -67,5 +68,15 @@ public class DataFormatContextAwareTest extends ContextTestSupport {
         public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {
             return null;
         }
+
+        @Override
+        protected void doStart() throws Exception {
+            // noop
+        }
+
+        @Override
+        protected void doStop() throws Exception {
+            // noop
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/0a991eab/camel-core/src/test/java/org/apache/camel/impl/RefDataFormatTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/impl/RefDataFormatTest.java b/camel-core/src/test/java/org/apache/camel/impl/RefDataFormatTest.java
index 0908bb0..a947561 100644
--- a/camel-core/src/test/java/org/apache/camel/impl/RefDataFormatTest.java
+++ b/camel-core/src/test/java/org/apache/camel/impl/RefDataFormatTest.java
@@ -71,7 +71,7 @@ public class RefDataFormatTest extends ContextTestSupport {
     }
 
     // START SNIPPET: e2
-    public static final class MyReverseDataFormat implements DataFormat {
+    public static final class MyReverseDataFormat extends ServiceSupport implements DataFormat
{
 
         public void marshal(Exchange exchange, Object graph, OutputStream stream) throws
Exception {
             byte[] bytes = exchange.getContext().getTypeConverter().mandatoryConvertTo(byte[].class,
graph);
@@ -93,6 +93,16 @@ public class RefDataFormatTest extends ContextTestSupport {
             }
             return sb.toString();
         }
+
+        @Override
+        protected void doStart() throws Exception {
+            // noop
+        }
+
+        @Override
+        protected void doStop() throws Exception {
+            // noop
+        }
     }
     // END SNIPPET: e2
 

http://git-wip-us.apache.org/repos/asf/camel/blob/0a991eab/camel-core/src/test/java/org/apache/camel/management/ManagedDataFormatTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedDataFormatTest.java
b/camel-core/src/test/java/org/apache/camel/management/ManagedDataFormatTest.java
new file mode 100644
index 0000000..fe5a58e
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedDataFormatTest.java
@@ -0,0 +1,55 @@
+/**
+ * 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.camel.management;
+
+import java.util.Set;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version 
+ */
+public class ManagedDataFormatTest extends ManagementTestSupport {
+
+    public void testManageDataFormat() throws Exception {
+        // JMX tests dont work well on AIX CI servers (hangs them)
+        if (isPlatform("aix")) {
+            return;
+        }
+
+        MBeanServer mbeanServer = getMBeanServer();
+
+        // there should be 1 data format
+        Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=dataformats,*"),
null);
+        assertEquals(1, set.size());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("seda:test")
+                    .unmarshal().string("iso-8859-1")
+                        .to("mock:result");
+            }
+        };
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/0a991eab/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelUnmarshalSetHeaderTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelUnmarshalSetHeaderTest.java
b/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelUnmarshalSetHeaderTest.java
index 5f6851f..41760d4 100644
--- a/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelUnmarshalSetHeaderTest.java
+++ b/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelUnmarshalSetHeaderTest.java
@@ -24,6 +24,7 @@ import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.spi.DataFormat;
+import org.apache.camel.support.ServiceSupport;
 
 /**
  *
@@ -60,7 +61,7 @@ public class DeadLetterChannelUnmarshalSetHeaderTest extends ContextTestSupport
         };
     }
 
-    private class MyDataFormat implements DataFormat {
+    private class MyDataFormat extends ServiceSupport implements DataFormat {
 
         @Override
         public void marshal(Exchange exchange, Object graph, OutputStream stream) throws
Exception {
@@ -71,5 +72,15 @@ public class DeadLetterChannelUnmarshalSetHeaderTest extends ContextTestSupport
         public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {
             throw new IllegalArgumentException("Damn");
         }
+
+        @Override
+        protected void doStart() throws Exception {
+            // noop
+        }
+
+        @Override
+        protected void doStop() throws Exception {
+            // noop
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/0a991eab/camel-core/src/test/java/org/apache/camel/processor/UnmarshalProcessorTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/UnmarshalProcessorTest.java
b/camel-core/src/test/java/org/apache/camel/processor/UnmarshalProcessorTest.java
index 01f83e8..7592ee3 100644
--- a/camel-core/src/test/java/org/apache/camel/processor/UnmarshalProcessorTest.java
+++ b/camel-core/src/test/java/org/apache/camel/processor/UnmarshalProcessorTest.java
@@ -27,6 +27,7 @@ import org.apache.camel.TestSupport;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.impl.DefaultMessage;
 import org.apache.camel.spi.DataFormat;
+import org.apache.camel.support.ServiceSupport;
 
 public class UnmarshalProcessorTest extends TestSupport {
 
@@ -72,7 +73,7 @@ public class UnmarshalProcessorTest extends TestSupport {
         assertSame("UnmarshalProcessor did not make use of the returned object being returned
while unmarshalling", unmarshalled, exchange.getOut().getBody());
     }
 
-    private static class MyDataFormat implements DataFormat {
+    private static class MyDataFormat extends ServiceSupport implements DataFormat {
 
         private final Object object;
 
@@ -97,6 +98,16 @@ public class UnmarshalProcessorTest extends TestSupport {
         public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {
             return object;
         }
+
+        @Override
+        protected void doStart() throws Exception {
+            // noop
+        }
+
+        @Override
+        protected void doStop() throws Exception {
+            // noop
+        }
     }
 
 }


Mime
View raw message