tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1358591 - in /tomcat/tc7.0.x/trunk: ./ java/org/apache/catalina/tribes/transport/nio/NioReceiver.java java/org/apache/catalina/tribes/transport/nio/NioSender.java webapps/docs/changelog.xml webapps/docs/config/cluster-receiver.xml
Date Sat, 07 Jul 2012 15:27:33 GMT
Author: markt
Date: Sat Jul  7 15:27:33 2012
New Revision: 1358591

URL: http://svn.apache.org/viewvc?rev=1358591&view=rev
Log:
Java 7 throws an exception when a socket option cannot be set.
Move option setting to before connection is completed since at least one option (traffic class)
can not be set after the connection is completed.
For NioReceiver, I don't see a way to set traffic class on an accepted connection so simply
remove it (it is ignored when using Java 6)

Modified:
    tomcat/tc7.0.x/trunk/   (props changed)
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/transport/nio/NioReceiver.java
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/transport/nio/NioSender.java
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
    tomcat/tc7.0.x/trunk/webapps/docs/config/cluster-receiver.xml

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
  Merged /tomcat/trunk:r1358586,1358590

Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/transport/nio/NioReceiver.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/transport/nio/NioReceiver.java?rev=1358591&r1=1358590&r2=1358591&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/transport/nio/NioReceiver.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/transport/nio/NioReceiver.java Sat
Jul  7 15:27:33 2012
@@ -149,13 +149,19 @@ public class NioReceiver extends Receive
         //set up the datagram channel
         if (this.getUdpPort()>0) {
             datagramChannel = DatagramChannel.open();
-            datagramChannel.configureBlocking(false);
+            configureDatagraChannel();
             //bind to the address to avoid security checks
             bindUdp(datagramChannel.socket(),getUdpPort(),getAutoBind());
         }
+    }
 
-
-
+    private void configureDatagraChannel() throws IOException {
+        datagramChannel.configureBlocking(false);
+        datagramChannel.socket().setSendBufferSize(getUdpTxBufSize());
+        datagramChannel.socket().setReceiveBufferSize(getUdpRxBufSize());
+        datagramChannel.socket().setReuseAddress(getSoReuseAddress());
+        datagramChannel.socket().setSoTimeout(getTimeout());
+        datagramChannel.socket().setTrafficClass(getSoTrafficClass());
     }
 
     public void addEvent(Runnable event) {
@@ -261,11 +267,6 @@ public class NioReceiver extends Receive
 
         if (selector!=null && datagramChannel!=null) {
             ObjectReader oreader = new ObjectReader(MAX_UDP_SIZE); //max size for a datagram
packet
-            datagramChannel.socket().setSendBufferSize(getUdpTxBufSize());
-            datagramChannel.socket().setReceiveBufferSize(getUdpRxBufSize());
-            datagramChannel.socket().setReuseAddress(getSoReuseAddress());
-            datagramChannel.socket().setSoTimeout(getTimeout());
-            datagramChannel.socket().setTrafficClass(getSoTrafficClass());
             registerChannel(selector,datagramChannel,SelectionKey.OP_READ,oreader);
         }
 
@@ -298,14 +299,13 @@ public class NioReceiver extends Receive
                     if (key.isAcceptable()) {
                         ServerSocketChannel server = (ServerSocketChannel) key.channel();
                         SocketChannel channel = server.accept();
-                        channel.socket().setReceiveBufferSize(getRxBufSize());
+                        channel.socket().setReceiveBufferSize(getTxBufSize());
                         channel.socket().setSendBufferSize(getTxBufSize());
                         channel.socket().setTcpNoDelay(getTcpNoDelay());
                         channel.socket().setKeepAlive(getSoKeepAlive());
                         channel.socket().setOOBInline(getOoBInline());
                         channel.socket().setReuseAddress(getSoReuseAddress());
                         channel.socket().setSoLinger(getSoLingerOn(),getSoLingerTime());
-                        channel.socket().setTrafficClass(getSoTrafficClass());
                         channel.socket().setSoTimeout(getTimeout());
                         Object attach = new ObjectReader(channel);
                         registerChannel(selector,

Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/transport/nio/NioSender.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/transport/nio/NioSender.java?rev=1358591&r1=1358590&r2=1358591&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/transport/nio/NioSender.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/transport/nio/NioSender.java Sat
Jul  7 15:27:33 2012
@@ -20,7 +20,6 @@ package org.apache.catalina.tribes.trans
 import java.io.EOFException;
 import java.io.IOException;
 import java.net.InetSocketAddress;
-import java.net.SocketException;
 import java.nio.ByteBuffer;
 import java.nio.channels.DatagramChannel;
 import java.nio.channels.SelectionKey;
@@ -132,13 +131,9 @@ public class NioSender extends AbstractS
         return false;
     }
 
-    private void completeConnect() throws SocketException {
-        //we connected, register ourselves for writing
-        setConnected(true);
-        connecting = false;
-        setRequestCount(0);
-        setConnectTime(System.currentTimeMillis());
+    private void configureSocket() throws IOException {
         if (socketChannel!=null) {
+            socketChannel.configureBlocking(false);
             socketChannel.socket().setSendBufferSize(getTxBufSize());
             socketChannel.socket().setReceiveBufferSize(getRxBufSize());
             socketChannel.socket().setSoTimeout((int)getTimeout());
@@ -150,6 +145,7 @@ public class NioSender extends AbstractS
             socketChannel.socket().setSoLinger(getSoLingerOn(),getSoLingerTime());
             socketChannel.socket().setTrafficClass(getSoTrafficClass());
         } else if (dataChannel!=null) {
+            dataChannel.configureBlocking(false);
             dataChannel.socket().setSendBufferSize(getUdpTxBufSize());
             dataChannel.socket().setReceiveBufferSize(getUdpRxBufSize());
             dataChannel.socket().setSoTimeout((int)getTimeout());
@@ -158,6 +154,13 @@ public class NioSender extends AbstractS
         }
     }
 
+    private void completeConnect() {
+        //we connected, register ourselves for writing
+        setConnected(true);
+        connecting = false;
+        setRequestCount(0);
+        setConnectTime(System.currentTimeMillis());
+    }
 
 
     protected boolean read(SelectionKey key) throws IOException {
@@ -232,7 +235,7 @@ public class NioSender extends AbstractS
             InetSocketAddress daddr = new InetSocketAddress(getAddress(),getUdpPort());
             if ( dataChannel != null ) throw new IOException("Datagram channel has already
been established. Connection might be in progress.");
             dataChannel = DatagramChannel.open();
-            dataChannel.configureBlocking(false);
+            configureSocket();
             dataChannel.connect(daddr);
             completeConnect();
             dataChannel.register(getSelector(),SelectionKey.OP_WRITE, this);
@@ -241,7 +244,7 @@ public class NioSender extends AbstractS
             InetSocketAddress addr = new InetSocketAddress(getAddress(),getPort());
             if ( socketChannel != null ) throw new IOException("Socket channel has already
been established. Connection might be in progress.");
             socketChannel = SocketChannel.open();
-            socketChannel.configureBlocking(false);
+            configureSocket();
             if ( socketChannel.connect(addr) ) {
                 completeConnect();
                 socketChannel.register(getSelector(), SelectionKey.OP_WRITE, this);

Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1358591&r1=1358590&r2=1358591&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Sat Jul  7 15:27:33 2012
@@ -68,6 +68,16 @@
       </fix>
     </changelog>
   </subsection>
+  <subsection name="Cluster">
+    <changelog>
+      <fix>
+        Fix an issue when running under Java 7 which throws exceptions when
+        trying to set an invalid option whereas Java 6 silently swallowed them.
+        The option using the problem was <code>soTrafficClass</code>. Note that
+        <code>soTrafficClass</code> is ignored for the NioReceiver. (markt)
+      </fix>
+    </changelog>
+  </subsection>
   <subsection name="Web applications">
     <changelog>
       <fix>

Modified: tomcat/tc7.0.x/trunk/webapps/docs/config/cluster-receiver.xml
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/config/cluster-receiver.xml?rev=1358591&r1=1358590&r2=1358591&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/config/cluster-receiver.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/config/cluster-receiver.xml Sat Jul  7 15:27:33 2012
@@ -145,7 +145,8 @@
     <attribute name="soTrafficClass" required="false">
      Sets the traffic class level for the socket, the value is between 0 and 255.
      Different values are defined in <a href="http://docs.oracle.com/javase/6/docs/api/java/net/Socket.html#setTrafficClass(int)">
-     java.net.Socket#setTrafficClass(int)</a>.
+     java.net.Socket#setTrafficClass(int)</a>. Note that this option is ignored
+     for the NioReceiver implementation.
     </attribute>
     <attribute name="tcpNoDelay" required="false">
      Boolean value for the socket TCP_NODELAY option. Possible values are <code>true</code>
or <code>false</code>.



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message