CAMEL-6555 Added DefaultChannelHandlerFactory to reduce the code of 
ChannelHandlerFactories


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

Branch: refs/heads/master
Commit: c7617314be50f9aad88494644f8068be8bd0359b
Parents: f603642
Author: Willem Jiang <willem.ji...@gmail.com>
Authored: Tue Jul 22 15:17:52 2014 +0800
Committer: Willem Jiang <willem.ji...@gmail.com>
Committed: Tue Jul 22 21:25:19 2014 +0800

----------------------------------------------------------------------
 .../netty4/ChannelHandlerFactories.java         | 63 ++------------------
 .../netty4/DefaultChannelHandlerFactory.java    | 37 ++++++++++++
 .../netty4/ShareableChannelHandlerFactory.java  | 23 +------
 3 files changed, 44 insertions(+), 79 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/c7617314/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/ChannelHandlerFactories.java
----------------------------------------------------------------------
diff --git 
a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/ChannelHandlerFactories.java
 
b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/ChannelHandlerFactories.java
index 66678e3..65d1162 100644
--- 
a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/ChannelHandlerFactories.java
+++ 
b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/ChannelHandlerFactories.java
@@ -20,7 +20,6 @@ import java.nio.charset.Charset;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.channel.ChannelHandler;
-import io.netty.channel.ChannelHandlerContext;
 import io.netty.handler.codec.DelimiterBasedFrameDecoder;
 import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
 import io.netty.handler.codec.serialization.ClassResolvers;
@@ -29,6 +28,8 @@ import io.netty.handler.codec.serialization.ObjectEncoder;
 import io.netty.handler.codec.string.StringDecoder;
 import io.netty.handler.codec.string.StringEncoder;
 
+
+
 /**
  * Helper to create commonly used {@link ChannelHandlerFactory} instances.
  */
@@ -46,29 +47,11 @@ public final class ChannelHandlerFactories {
     }
 
     public static ChannelHandlerFactory newObjectDecoder() {
-        return new ChannelHandlerFactory() {
+        return new DefaultChannelHandlerFactory() {
             @Override
             public ChannelHandler newChannelHandler() {
                 return new 
ObjectDecoder(ClassResolvers.weakCachingResolver(null));
             }
-
-            @Override
-            public void handlerAdded(ChannelHandlerContext ctx) throws 
Exception {
-                // TODO Auto-generated method stub
-                
-            }
-
-            @Override
-            public void handlerRemoved(ChannelHandlerContext ctx) throws 
Exception {
-                // TODO Auto-generated method stub
-                
-            }
-
-            @Override
-            public void exceptionCaught(ChannelHandlerContext ctx, Throwable 
cause) throws Exception {
-                // TODO Auto-generated method stub
-                
-            }
         };
     }
 
@@ -77,58 +60,22 @@ public final class ChannelHandlerFactories {
     }
 
     public static ChannelHandlerFactory newDelimiterBasedFrameDecoder(final 
int maxFrameLength, final ByteBuf[] delimiters) {
-        return new ChannelHandlerFactory() {
+        return new DefaultChannelHandlerFactory() {
             @Override
             public ChannelHandler newChannelHandler() {
                 return new DelimiterBasedFrameDecoder(maxFrameLength, true, 
delimiters);
             }
-
-            @Override
-            public void handlerAdded(ChannelHandlerContext ctx) throws 
Exception {
-                // TODO Auto-generated method stub
-                
-            }
-
-            @Override
-            public void handlerRemoved(ChannelHandlerContext ctx) throws 
Exception {
-                // TODO Auto-generated method stub
-                
-            }
-
-            @Override
-            public void exceptionCaught(ChannelHandlerContext ctx, Throwable 
cause) throws Exception {
-                // TODO Auto-generated method stub
-                
-            }
         };
     }
 
     public static ChannelHandlerFactory newLengthFieldBasedFrameDecoder(final 
int maxFrameLength, final int lengthFieldOffset,
                                                                         final 
int lengthFieldLength, final int lengthAdjustment,
                                                                         final 
int initialBytesToStrip) {
-        return new ChannelHandlerFactory() {
+        return new DefaultChannelHandlerFactory() {
             @Override
             public ChannelHandler newChannelHandler() {
                 return new LengthFieldBasedFrameDecoder(maxFrameLength, 
lengthFieldOffset, lengthFieldLength, lengthAdjustment, initialBytesToStrip);
             }
-
-            @Override
-            public void handlerAdded(ChannelHandlerContext ctx) throws 
Exception {
-                // TODO Auto-generated method stub
-                
-            }
-
-            @Override
-            public void handlerRemoved(ChannelHandlerContext ctx) throws 
Exception {
-                // TODO Auto-generated method stub
-                
-            }
-
-            @Override
-            public void exceptionCaught(ChannelHandlerContext ctx, Throwable 
cause) throws Exception {
-                // TODO Auto-generated method stub
-                
-            }
         };
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/c7617314/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/DefaultChannelHandlerFactory.java
----------------------------------------------------------------------
diff --git 
a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/DefaultChannelHandlerFactory.java
 
b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/DefaultChannelHandlerFactory.java
new file mode 100644
index 0000000..02201f4
--- /dev/null
+++ 
b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/DefaultChannelHandlerFactory.java
@@ -0,0 +1,37 @@
+/**
+ * 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.component.netty4;
+
+import io.netty.channel.ChannelHandlerContext;
+
+public abstract class DefaultChannelHandlerFactory implements 
ChannelHandlerFactory {
+
+    @Override
+    public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
+        //Do nothing here
+    }
+
+    @Override
+    public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
+        //Do nothing here
+    }
+
+    @Override
+    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) 
throws Exception {
+        //Do nothing here
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/c7617314/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/ShareableChannelHandlerFactory.java
----------------------------------------------------------------------
diff --git 
a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/ShareableChannelHandlerFactory.java
 
b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/ShareableChannelHandlerFactory.java
index b4b7daf..9fbcf8a 100644
--- 
a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/ShareableChannelHandlerFactory.java
+++ 
b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/ShareableChannelHandlerFactory.java
@@ -17,39 +17,20 @@
 package org.apache.camel.component.netty4;
 
 import io.netty.channel.ChannelHandler;
-import io.netty.channel.ChannelHandlerContext;
 
 /**
  * A {@link ChannelHandlerFactory} returning a shareable {@link 
ChannelHandler}.
  */
-public class ShareableChannelHandlerFactory implements ChannelHandlerFactory {
+public class ShareableChannelHandlerFactory extends 
DefaultChannelHandlerFactory {
 
     private final ChannelHandler channelHandler;
 
     public ShareableChannelHandlerFactory(ChannelHandler channelHandler) {
         this.channelHandler = channelHandler;
     }
-
-    @Override
+    
     public ChannelHandler newChannelHandler() {
         return channelHandler;
     }
 
-    @Override
-    public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
-        // TODO Auto-generated method stub
-        
-    }
-
-    @Override
-    public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
-        // TODO Auto-generated method stub
-        
-    }
-
-    @Override
-    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) 
throws Exception {
-        // TODO Auto-generated method stub
-        
-    }
 }

Reply via email to