Author: davsclaus
Date: Fri Oct  5 15:14:20 2012
New Revision: 1394577

URL: http://svn.apache.org/viewvc?rev=1394577&view=rev
Log:
Polished and use netty helper to write to channel.

Modified:
    
camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyHelper.java
    
camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyProducer.java
    
camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ClientChannelHandler.java
    
camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ServerChannelHandler.java

Modified: 
camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyHelper.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyHelper.java?rev=1394577&r1=1394576&r2=1394577&view=diff
==============================================================================
--- 
camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyHelper.java
 (original)
+++ 
camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyHelper.java
 Fri Oct  5 15:14:20 2012
@@ -86,8 +86,14 @@ public final class NettyHelper {
         // the write operation is asynchronous. Use future to wait until the 
session has been written
         ChannelFuture future;
         if (remoteAddress != null) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Writing to channel: {} remote address: {} with 
body: {}", new Object[]{channel, remoteAddress, body});
+            }
             future = channel.write(body, remoteAddress);
         } else {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Writing to channel: {} with body: {}", new 
Object[]{channel, body});
+            }
             future = channel.write(body);
         }
 

Modified: 
camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyProducer.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyProducer.java?rev=1394577&r1=1394576&r2=1394577&view=diff
==============================================================================
--- 
camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyProducer.java
 (original)
+++ 
camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyProducer.java
 Fri Oct  5 15:14:20 2012
@@ -188,15 +188,10 @@ public class NettyProducer extends Defau
             return true;
         }
 
-        // log what we are writing
-        LOG.debug("Writing body: {}", body);
-        // write the body asynchronously
-        ChannelFuture future = channel.write(body);
-
-        // add listener which handles the operation
-        future.addListener(new ChannelFutureListener() {
+        // write body
+        NettyHelper.writeBodyAsync(channel, null, body, exchange, new 
ChannelFutureListener() {
             public void operationComplete(ChannelFuture channelFuture) throws 
Exception {
-                LOG.debug("Operation complete {}", channelFuture);
+                LOG.trace("Operation complete {}", channelFuture);
                 if (!channelFuture.isSuccess()) {
                     // no success the set the caused exception and signal 
callback and break
                     exchange.setException(channelFuture.getCause());
@@ -221,8 +216,8 @@ public class NettyProducer extends Defau
                             disconnect = close;
                         }
                         if (disconnect) {
-                            if (LOG.isDebugEnabled()) {
-                                LOG.debug("Closing channel when complete at 
address: {}", getEndpoint().getConfiguration().getAddress());
+                            if (LOG.isTraceEnabled()) {
+                                LOG.trace("Closing channel when complete at 
address: {}", getEndpoint().getConfiguration().getAddress());
                             }
                             NettyHelper.close(channel);
                         }

Modified: 
camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ClientChannelHandler.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ClientChannelHandler.java?rev=1394577&r1=1394576&r2=1394577&view=diff
==============================================================================
--- 
camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ClientChannelHandler.java
 (original)
+++ 
camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ClientChannelHandler.java
 Fri Oct  5 15:14:20 2012
@@ -117,7 +117,9 @@ public class ClientChannelHandler extend
         AsyncCallback callback = getAsyncCallback(ctx);
 
         Object body = messageEvent.getMessage();
-        LOG.debug("Message received: {}", body);
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Receiving from channel: {} body: {}", new 
Object[]{messageEvent.getChannel(), body});
+        }
 
         // if textline enabled then covert to a String which must be used for 
textline
         if (producer.getConfiguration().isTextline()) {
@@ -152,8 +154,8 @@ public class ClientChannelHandler extend
                 disconnect = close;
             }
             if (disconnect) {
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug("Closing channel when complete at address: {}", 
producer.getConfiguration().getAddress());
+                if (LOG.isTraceEnabled()) {
+                    LOG.trace("Closing channel when complete at address: {}", 
producer.getConfiguration().getAddress());
                 }
                 NettyHelper.close(ctx.getChannel());
             }

Modified: 
camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ServerChannelHandler.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ServerChannelHandler.java?rev=1394577&r1=1394576&r2=1394577&view=diff
==============================================================================
--- 
camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ServerChannelHandler.java
 (original)
+++ 
camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ServerChannelHandler.java
 Fri Oct  5 15:14:20 2012
@@ -54,14 +54,18 @@ public class ServerChannelHandler extend
 
     @Override
     public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) 
throws Exception {
-        LOG.trace("Channel open: {}", e.getChannel());
+        if (LOG.isTraceEnabled()) {
+            LOG.trace("Channel open: {}", e.getChannel());
+        }
         // to keep track of open sockets
         consumer.getAllChannels().add(e.getChannel());
     }
 
     @Override
     public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) 
throws Exception {
-        LOG.trace("Channel closed: {}", e.getChannel());
+        if (LOG.isTraceEnabled()) {
+            LOG.trace("Channel closed: {}", e.getChannel());
+        }
     }
 
     @Override
@@ -78,7 +82,9 @@ public class ServerChannelHandler extend
     @Override
     public void messageReceived(final ChannelHandlerContext ctx, final 
MessageEvent messageEvent) throws Exception {
         Object in = messageEvent.getMessage();
-        LOG.debug("Incoming message: {}", in);
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Receiving from channel: {} body: {}", new 
Object[]{messageEvent.getChannel(), in});
+        }
 
         // create Exchange and let the consumer process it
         final Exchange exchange = consumer.getEndpoint().createExchange(ctx, 
messageEvent);
@@ -148,8 +154,8 @@ public class ServerChannelHandler extend
             if (consumer.getConfiguration().isDisconnectOnNoReply()) {
                 // must close session if no data to write otherwise client 
will never receive a response
                 // and wait forever (if not timing out)
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug("Closing channel as no payload to send as reply 
at address: {}", messageEvent.getRemoteAddress());
+                if (LOG.isTraceEnabled()) {
+                    LOG.trace("Closing channel as no payload to send as reply 
at address: {}", messageEvent.getRemoteAddress());
                 }
                 NettyHelper.close(messageEvent.getChannel());
             }
@@ -160,7 +166,6 @@ public class ServerChannelHandler extend
             }
 
             // we got a body to write
-            LOG.debug("Writing body: {}", body);
             ChannelFutureListener listener = new 
ResponseFutureListener(exchange, messageEvent.getRemoteAddress());
             if (consumer.getConfiguration().isTcp()) {
                 NettyHelper.writeBodyAsync(messageEvent.getChannel(), null, 
body, exchange, listener);
@@ -206,8 +211,8 @@ public class ServerChannelHandler extend
                 disconnect = close;
             }
             if (disconnect) {
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug("Closing channel when complete at address: {}", 
remoteAddress);
+                if (LOG.isTraceEnabled()) {
+                    LOG.trace("Closing channel when complete at address: {}", 
remoteAddress);
                 }
                 NettyHelper.close(future.getChannel());
             }


Reply via email to