You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by tr...@apache.org on 2008/03/11 11:18:19 UTC
svn commit: r635867 - in /mina/trunk:
core/src/main/java/org/apache/mina/common/
core/src/main/java/org/apache/mina/transport/socket/
core/src/main/java/org/apache/mina/transport/socket/nio/
transport-apr/src/main/java/org/apache/mina/transport/socket/...
Author: trustin
Date: Tue Mar 11 03:18:11 2008
New Revision: 635867
URL: http://svn.apache.org/viewvc?rev=635867&view=rev
Log:
Resolved issue: DIRMINA-546 (Reduce unnecessary system calls when a new session is created)
Added:
mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramSessionConfig.java (with props)
Modified:
mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoService.java
mina/trunk/core/src/main/java/org/apache/mina/common/DefaultIoFilterChain.java
mina/trunk/core/src/main/java/org/apache/mina/transport/socket/AbstractDatagramSessionConfig.java
mina/trunk/core/src/main/java/org/apache/mina/transport/socket/AbstractSocketSessionConfig.java
mina/trunk/core/src/main/java/org/apache/mina/transport/socket/DefaultDatagramSessionConfig.java
mina/trunk/core/src/main/java/org/apache/mina/transport/socket/DefaultSocketSessionConfig.java
mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptor.java
mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramSession.java
mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketAcceptor.java
mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketConnector.java
mina/trunk/transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprSocketAcceptor.java
mina/trunk/transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprSocketConnector.java
Modified: mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoService.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoService.java?rev=635867&r1=635866&r2=635867&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoService.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoService.java Tue Mar 11 03:18:11 2008
@@ -741,7 +741,7 @@
if (future != null && future instanceof ConnectFuture) {
// DefaultIoFilterChain will notify the future. (We support ConnectFuture only for now).
- session.setAttribute(DefaultIoFilterChain.SESSION_OPENED_FUTURE, future);
+ session.setAttribute(DefaultIoFilterChain.SESSION_CREATED_FUTURE, future);
}
if (sessionInitializer != null) {
Modified: mina/trunk/core/src/main/java/org/apache/mina/common/DefaultIoFilterChain.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/DefaultIoFilterChain.java?rev=635867&r1=635866&r2=635867&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/common/DefaultIoFilterChain.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/common/DefaultIoFilterChain.java Tue Mar 11 03:18:11 2008
@@ -41,10 +41,10 @@
/**
* A session attribute that stores an {@link IoFuture} related with
* the {@link IoSession}. {@link DefaultIoFilterChain} clears this
- * attribute and notifies the future when {@link #fireSessionOpened()}
+ * attribute and notifies the future when {@link #fireSessionCreated()}
* or {@link #fireExceptionCaught(Throwable)} is invoked.
*/
- static final AttributeKey SESSION_OPENED_FUTURE = new AttributeKey(DefaultIoFilterChain.class, "connectFuture");
+ static final AttributeKey SESSION_CREATED_FUTURE = new AttributeKey(DefaultIoFilterChain.class, "connectFuture");
private final AbstractIoSession session;
@@ -440,7 +440,7 @@
private void callNextExceptionCaught(Entry entry, IoSession session,
Throwable cause) {
// Notify the related future.
- ConnectFuture future = (ConnectFuture) session.removeAttribute(SESSION_OPENED_FUTURE);
+ ConnectFuture future = (ConnectFuture) session.removeAttribute(SESSION_CREATED_FUTURE);
if (future == null) {
try {
entry.getFilter().exceptionCaught(entry.getNextFilter(), session,
@@ -671,7 +671,7 @@
session.getHandler().sessionCreated(session);
} finally {
// Notify the related future.
- ConnectFuture future = (ConnectFuture) session.removeAttribute(SESSION_OPENED_FUTURE);
+ ConnectFuture future = (ConnectFuture) session.removeAttribute(SESSION_CREATED_FUTURE);
if (future != null) {
future.setSession(session);
}
Modified: mina/trunk/core/src/main/java/org/apache/mina/transport/socket/AbstractDatagramSessionConfig.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/transport/socket/AbstractDatagramSessionConfig.java?rev=635867&r1=635866&r2=635867&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/transport/socket/AbstractDatagramSessionConfig.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/transport/socket/AbstractDatagramSessionConfig.java Tue Mar 11 03:18:11 2008
@@ -34,17 +34,92 @@
@Override
protected void doSetAll(IoSessionConfig config) {
- if (config instanceof DatagramSessionConfig) {
+ if (!(config instanceof DatagramSessionConfig)) {
+ return;
+ }
+
+ if (config instanceof AbstractDatagramSessionConfig) {
+ // Minimize unnecessary system calls by checking all 'propertyChanged' properties.
+ AbstractDatagramSessionConfig cfg = (AbstractDatagramSessionConfig) config;
+ if (cfg.isBroadcastChanged()) {
+ setBroadcast(cfg.isBroadcast());
+ }
+ if (cfg.isReceiveBufferSizeChanged()) {
+ setReceiveBufferSize(cfg.getReceiveBufferSize());
+ }
+ if (cfg.isReuseAddressChanged()) {
+ setReuseAddress(cfg.isReuseAddress());
+ }
+ if (cfg.isSendBufferSizeChanged()) {
+ setSendBufferSize(cfg.getSendBufferSize());
+ }
+ if (cfg.isTrafficClassChanged() && getTrafficClass() != cfg.getTrafficClass()) {
+ setTrafficClass(cfg.getTrafficClass());
+ }
+ } else {
DatagramSessionConfig cfg = (DatagramSessionConfig) config;
setBroadcast(cfg.isBroadcast());
setReceiveBufferSize(cfg.getReceiveBufferSize());
setReuseAddress(cfg.isReuseAddress());
setSendBufferSize(cfg.getSendBufferSize());
-
if (getTrafficClass() != cfg.getTrafficClass()) {
setTrafficClass(cfg.getTrafficClass());
}
}
}
+
+ /**
+ * Returns <tt>true</tt> if and only if the <tt>broadcast</tt> property
+ * has been changed by its setter method. The system call related with
+ * the property is made only when this method returns <tt>true</tt>. By
+ * default, this method always returns <tt>true</tt> to simplify implementation
+ * of subclasses, but overriding the default behavior is always encouraged.
+ */
+ protected boolean isBroadcastChanged() {
+ return true;
+ }
+
+ /**
+ * Returns <tt>true</tt> if and only if the <tt>receiveBufferSize</tt> property
+ * has been changed by its setter method. The system call related with
+ * the property is made only when this method returns <tt>true</tt>. By
+ * default, this method always returns <tt>true</tt> to simplify implementation
+ * of subclasses, but overriding the default behavior is always encouraged.
+ */
+ protected boolean isReceiveBufferSizeChanged() {
+ return true;
+ }
+
+ /**
+ * Returns <tt>true</tt> if and only if the <tt>reuseAddress</tt> property
+ * has been changed by its setter method. The system call related with
+ * the property is made only when this method returns <tt>true</tt>. By
+ * default, this method always returns <tt>true</tt> to simplify implementation
+ * of subclasses, but overriding the default behavior is always encouraged.
+ */
+ protected boolean isReuseAddressChanged() {
+ return true;
+ }
+
+ /**
+ * Returns <tt>true</tt> if and only if the <tt>sendBufferSize</tt> property
+ * has been changed by its setter method. The system call related with
+ * the property is made only when this method returns <tt>true</tt>. By
+ * default, this method always returns <tt>true</tt> to simplify implementation
+ * of subclasses, but overriding the default behavior is always encouraged.
+ */
+ protected boolean isSendBufferSizeChanged() {
+ return true;
+ }
+ /**
+ * Returns <tt>true</tt> if and only if the <tt>trafficClass</tt> property
+ * has been changed by its setter method. The system call related with
+ * the property is made only when this method returns <tt>true</tt>. By
+ * default, this method always returns <tt>true</tt> to simplify implementation
+ * of subclasses, but overriding the default behavior is always encouraged.
+ */
+ protected boolean isTrafficClassChanged() {
+ return true;
+ }
}
Modified: mina/trunk/core/src/main/java/org/apache/mina/transport/socket/AbstractSocketSessionConfig.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/transport/socket/AbstractSocketSessionConfig.java?rev=635867&r1=635866&r2=635867&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/transport/socket/AbstractSocketSessionConfig.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/transport/socket/AbstractSocketSessionConfig.java Tue Mar 11 03:18:11 2008
@@ -34,7 +34,38 @@
@Override
protected final void doSetAll(IoSessionConfig config) {
- if (config instanceof SocketSessionConfig) {
+ if (!(config instanceof SocketSessionConfig)) {
+ return;
+ }
+
+// if (config instanceof AbstractSocketSessionConfig) {
+// // Minimize unnecessary system calls by checking all 'propertyChanged' properties.
+// AbstractSocketSessionConfig cfg = (AbstractSocketSessionConfig) config;
+// if (cfg.isKeepAliveChanged()) {
+// setKeepAlive(cfg.isKeepAlive());
+// }
+// if (cfg.isOobInlineChanged()) {
+// setOobInline(cfg.isOobInline());
+// }
+// if (cfg.isReceiveBufferSizeChanged()) {
+// setReceiveBufferSize(cfg.getReceiveBufferSize());
+// }
+// if (cfg.isReuseAddressChanged()) {
+// setReuseAddress(cfg.isReuseAddress());
+// }
+// if (cfg.isSendBufferSizeChanged()) {
+// setSendBufferSize(cfg.getSendBufferSize());
+// }
+// if (cfg.isSoLingerChanged()) {
+// setSoLinger(cfg.getSoLinger());
+// }
+// if (cfg.isTcpNoDelayChanged()) {
+// setTcpNoDelay(cfg.isTcpNoDelay());
+// }
+// if (cfg.isTrafficClassChanged() && getTrafficClass() != cfg.getTrafficClass()) {
+// setTrafficClass(cfg.getTrafficClass());
+// }
+// } else {
SocketSessionConfig cfg = (SocketSessionConfig) config;
setKeepAlive(cfg.isKeepAlive());
setOobInline(cfg.isOobInline());
@@ -43,11 +74,97 @@
setSendBufferSize(cfg.getSendBufferSize());
setSoLinger(cfg.getSoLinger());
setTcpNoDelay(cfg.isTcpNoDelay());
-
if (getTrafficClass() != cfg.getTrafficClass()) {
setTrafficClass(cfg.getTrafficClass());
}
- }
+// }
+ }
+
+ /**
+ * Returns <tt>true</tt> if and only if the <tt>keepAlive</tt> property
+ * has been changed by its setter method. The system call related with
+ * the property is made only when this method returns <tt>true</tt>. By
+ * default, this method always returns <tt>true</tt> to simplify implementation
+ * of subclasses, but overriding the default behavior is always encouraged.
+ */
+ protected boolean isKeepAliveChanged() {
+ return true;
+ }
+
+ /**
+ * Returns <tt>true</tt> if and only if the <tt>oobInline</tt> property
+ * has been changed by its setter method. The system call related with
+ * the property is made only when this method returns <tt>true</tt>. By
+ * default, this method always returns <tt>true</tt> to simplify implementation
+ * of subclasses, but overriding the default behavior is always encouraged.
+ */
+ protected boolean isOobInlineChanged() {
+ return true;
}
+ /**
+ * Returns <tt>true</tt> if and only if the <tt>receiveBufferSize</tt> property
+ * has been changed by its setter method. The system call related with
+ * the property is made only when this method returns <tt>true</tt>. By
+ * default, this method always returns <tt>true</tt> to simplify implementation
+ * of subclasses, but overriding the default behavior is always encouraged.
+ */
+ protected boolean isReceiveBufferSizeChanged() {
+ return true;
+ }
+
+ /**
+ * Returns <tt>true</tt> if and only if the <tt>reuseAddress</tt> property
+ * has been changed by its setter method. The system call related with
+ * the property is made only when this method returns <tt>true</tt>. By
+ * default, this method always returns <tt>true</tt> to simplify implementation
+ * of subclasses, but overriding the default behavior is always encouraged.
+ */
+ protected boolean isReuseAddressChanged() {
+ return true;
+ }
+
+ /**
+ * Returns <tt>true</tt> if and only if the <tt>sendBufferSize</tt> property
+ * has been changed by its setter method. The system call related with
+ * the property is made only when this method returns <tt>true</tt>. By
+ * default, this method always returns <tt>true</tt> to simplify implementation
+ * of subclasses, but overriding the default behavior is always encouraged.
+ */
+ protected boolean isSendBufferSizeChanged() {
+ return true;
+ }
+
+ /**
+ * Returns <tt>true</tt> if and only if the <tt>soLinger</tt> property
+ * has been changed by its setter method. The system call related with
+ * the property is made only when this method returns <tt>true</tt>. By
+ * default, this method always returns <tt>true</tt> to simplify implementation
+ * of subclasses, but overriding the default behavior is always encouraged.
+ */
+ protected boolean isSoLingerChanged() {
+ return true;
+ }
+
+ /**
+ * Returns <tt>true</tt> if and only if the <tt>tcpNoDelay</tt> property
+ * has been changed by its setter method. The system call related with
+ * the property is made only when this method returns <tt>true</tt>. By
+ * default, this method always returns <tt>true</tt> to simplify implementation
+ * of subclasses, but overriding the default behavior is always encouraged.
+ */
+ protected boolean isTcpNoDelayChanged() {
+ return true;
+ }
+
+ /**
+ * Returns <tt>true</tt> if and only if the <tt>trafficClass</tt> property
+ * has been changed by its setter method. The system call related with
+ * the property is made only when this method returns <tt>true</tt>. By
+ * default, this method always returns <tt>true</tt> to simplify implementation
+ * of subclasses, but overriding the default behavior is always encouraged.
+ */
+ protected boolean isTrafficClassChanged() {
+ return true;
+ }
}
Modified: mina/trunk/core/src/main/java/org/apache/mina/transport/socket/DefaultDatagramSessionConfig.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/transport/socket/DefaultDatagramSessionConfig.java?rev=635867&r1=635866&r2=635867&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/transport/socket/DefaultDatagramSessionConfig.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/transport/socket/DefaultDatagramSessionConfig.java Tue Mar 11 03:18:11 2008
@@ -33,21 +33,13 @@
public class DefaultDatagramSessionConfig extends AbstractDatagramSessionConfig {
private static boolean SET_RECEIVE_BUFFER_SIZE_AVAILABLE = false;
-
private static boolean SET_SEND_BUFFER_SIZE_AVAILABLE = false;
-
private static boolean GET_TRAFFIC_CLASS_AVAILABLE = false;
-
private static final boolean SET_TRAFFIC_CLASS_AVAILABLE = false;
-
private static boolean DEFAULT_BROADCAST = false;
-
private static boolean DEFAULT_REUSE_ADDRESS = false;
-
private static int DEFAULT_RECEIVE_BUFFER_SIZE = 1024;
-
private static int DEFAULT_SEND_BUFFER_SIZE = 1024;
-
private static int DEFAULT_TRAFFIC_CLASS = 0;
static {
@@ -114,15 +106,11 @@
}
private boolean broadcast = DEFAULT_BROADCAST;
-
private boolean reuseAddress = DEFAULT_REUSE_ADDRESS;
-
private int receiveBufferSize = DEFAULT_RECEIVE_BUFFER_SIZE;
-
private int sendBufferSize = DEFAULT_SEND_BUFFER_SIZE;
-
private int trafficClass = DEFAULT_TRAFFIC_CLASS;
-
+
/**
* Creates a new instance.
*/
@@ -198,4 +186,30 @@
public void setTrafficClass(int trafficClass) {
this.trafficClass = trafficClass;
}
+
+ @Override
+ protected boolean isBroadcastChanged() {
+ return broadcast != DEFAULT_BROADCAST;
+ }
+
+ @Override
+ protected boolean isReceiveBufferSizeChanged() {
+ return receiveBufferSize != DEFAULT_RECEIVE_BUFFER_SIZE;
+ }
+
+ @Override
+ protected boolean isReuseAddressChanged() {
+ return reuseAddress != DEFAULT_REUSE_ADDRESS;
+ }
+
+ @Override
+ protected boolean isSendBufferSizeChanged() {
+ return sendBufferSize != DEFAULT_SEND_BUFFER_SIZE;
+ }
+
+ @Override
+ protected boolean isTrafficClassChanged() {
+ return trafficClass != DEFAULT_TRAFFIC_CLASS;
+ }
+
}
Modified: mina/trunk/core/src/main/java/org/apache/mina/transport/socket/DefaultSocketSessionConfig.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/transport/socket/DefaultSocketSessionConfig.java?rev=635867&r1=635866&r2=635867&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/transport/socket/DefaultSocketSessionConfig.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/transport/socket/DefaultSocketSessionConfig.java Tue Mar 11 03:18:11 2008
@@ -43,27 +43,16 @@
private static Map<InetSocketAddress, InetAddress> TEST_ADDRESSES = new LinkedHashMap<InetSocketAddress, InetAddress>();
private static boolean SET_RECEIVE_BUFFER_SIZE_AVAILABLE = false;
-
private static boolean SET_SEND_BUFFER_SIZE_AVAILABLE = false;
-
private static boolean GET_TRAFFIC_CLASS_AVAILABLE = false;
-
private static boolean SET_TRAFFIC_CLASS_AVAILABLE = false;
-
private static boolean DEFAULT_REUSE_ADDRESS = false;
-
private static int DEFAULT_RECEIVE_BUFFER_SIZE = 1024;
-
private static int DEFAULT_SEND_BUFFER_SIZE = 1024;
-
private static int DEFAULT_TRAFFIC_CLASS = 0;
-
private static boolean DEFAULT_KEEP_ALIVE = false;
-
private static boolean DEFAULT_OOB_INLINE = false;
-
private static int DEFAULT_SO_LINGER = -1;
-
private static boolean DEFAULT_TCP_NO_DELAY = false;
static {
@@ -217,26 +206,26 @@
return SET_TRAFFIC_CLASS_AVAILABLE;
}
- private boolean reuseAddress = DEFAULT_REUSE_ADDRESS;
-
+ private final boolean defaultReuseAddress;
+ private boolean reuseAddress;
private int receiveBufferSize = DEFAULT_RECEIVE_BUFFER_SIZE;
-
private int sendBufferSize = DEFAULT_SEND_BUFFER_SIZE;
-
private int trafficClass = DEFAULT_TRAFFIC_CLASS;
-
private boolean keepAlive = DEFAULT_KEEP_ALIVE;
-
private boolean oobInline = DEFAULT_OOB_INLINE;
-
private int soLinger = DEFAULT_SO_LINGER;
-
private boolean tcpNoDelay = DEFAULT_TCP_NO_DELAY;
-
+
/**
* Creates a new instance.
*/
- public DefaultSocketSessionConfig() {
+ public DefaultSocketSessionConfig(boolean server) {
+ if (server) {
+ defaultReuseAddress = true;
+ } else {
+ defaultReuseAddress = DEFAULT_REUSE_ADDRESS;
+ }
+ reuseAddress = defaultReuseAddress;
}
public boolean isReuseAddress() {
@@ -301,5 +290,45 @@
public void setTcpNoDelay(boolean tcpNoDelay) {
this.tcpNoDelay = tcpNoDelay;
+ }
+
+ @Override
+ protected boolean isKeepAliveChanged() {
+ return keepAlive != DEFAULT_KEEP_ALIVE;
+ }
+
+ @Override
+ protected boolean isOobInlineChanged() {
+ return oobInline != DEFAULT_OOB_INLINE;
+ }
+
+ @Override
+ protected boolean isReceiveBufferSizeChanged() {
+ return receiveBufferSize != DEFAULT_RECEIVE_BUFFER_SIZE;
+ }
+
+ @Override
+ protected boolean isReuseAddressChanged() {
+ return reuseAddress != defaultReuseAddress;
+ }
+
+ @Override
+ protected boolean isSendBufferSizeChanged() {
+ return sendBufferSize != DEFAULT_SEND_BUFFER_SIZE;
+ }
+
+ @Override
+ protected boolean isSoLingerChanged() {
+ return soLinger != DEFAULT_SO_LINGER;
+ }
+
+ @Override
+ protected boolean isTcpNoDelayChanged() {
+ return tcpNoDelay != DEFAULT_TCP_NO_DELAY;
+ }
+
+ @Override
+ protected boolean isTrafficClassChanged() {
+ return trafficClass != DEFAULT_TRAFFIC_CLASS;
}
}
Modified: mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptor.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptor.java?rev=635867&r1=635866&r2=635867&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptor.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptor.java Tue Mar 11 03:18:11 2008
@@ -100,19 +100,10 @@
@Override
protected DatagramChannel open(SocketAddress localAddress) throws Exception {
- DatagramChannel c = DatagramChannel.open();
+ final DatagramChannel c = DatagramChannel.open();
boolean success = false;
try {
- DatagramSessionConfig cfg = getSessionConfig();
- c.socket().setReuseAddress(cfg.isReuseAddress());
- c.socket().setBroadcast(cfg.isBroadcast());
- c.socket().setReceiveBufferSize(cfg.getReceiveBufferSize());
- c.socket().setSendBufferSize(cfg.getSendBufferSize());
-
- if (c.socket().getTrafficClass() != cfg.getTrafficClass()) {
- c.socket().setTrafficClass(cfg.getTrafficClass());
- }
-
+ new NioDatagramSessionConfig(c).setAll(getSessionConfig());
c.configureBlocking(false);
c.socket().bind(localAddress);
c.register(selector, SelectionKey.OP_READ);
Modified: mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramSession.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramSession.java?rev=635867&r1=635866&r2=635867&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramSession.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramSession.java Tue Mar 11 03:18:11 2008
@@ -21,7 +21,6 @@
import java.net.InetSocketAddress;
import java.net.SocketAddress;
-import java.net.SocketException;
import java.nio.channels.DatagramChannel;
import java.nio.channels.SelectionKey;
@@ -33,12 +32,9 @@
import org.apache.mina.common.IoProcessor;
import org.apache.mina.common.IoService;
import org.apache.mina.common.IoSession;
-import org.apache.mina.common.RuntimeIoException;
import org.apache.mina.common.TransportMetadata;
-import org.apache.mina.transport.socket.AbstractDatagramSessionConfig;
import org.apache.mina.transport.socket.DatagramSession;
import org.apache.mina.transport.socket.DatagramSessionConfig;
-import org.apache.mina.transport.socket.DefaultDatagramSessionConfig;
/**
* An {@link IoSession} for datagram transport (UDP/IP).
@@ -55,19 +51,12 @@
DatagramSessionConfig.class, IoBuffer.class);
private final IoService service;
-
- private final DatagramSessionConfig config = new SessionConfigImpl();
-
+ private final DatagramSessionConfig config;
private final IoFilterChain filterChain = new DefaultIoFilterChain(this);
-
private final DatagramChannel ch;
-
private final IoHandler handler;
-
private final InetSocketAddress localAddress;
-
private final InetSocketAddress remoteAddress;
-
private final IoProcessor<NioSession> processor;
private SelectionKey key;
@@ -80,13 +69,11 @@
SocketAddress remoteAddress) {
this.service = service;
this.ch = ch;
+ this.config = new NioDatagramSessionConfig(ch);
this.handler = service.getHandler();
this.processor = processor;
this.remoteAddress = (InetSocketAddress) remoteAddress;
- this.localAddress = (InetSocketAddress) ch.socket()
- .getLocalSocketAddress();
-
- this.config.setAll(service.getSessionConfig());
+ this.localAddress = (InetSocketAddress) ch.socket().getLocalSocketAddress();
}
/**
@@ -148,100 +135,5 @@
@Override
public InetSocketAddress getServiceAddress() {
return (InetSocketAddress) super.getServiceAddress();
- }
-
- private class SessionConfigImpl extends AbstractDatagramSessionConfig {
-
- public int getReceiveBufferSize() {
- try {
- return ch.socket().getReceiveBufferSize();
- } catch (SocketException e) {
- throw new RuntimeIoException(e);
- }
- }
-
- public void setReceiveBufferSize(int receiveBufferSize) {
- if (DefaultDatagramSessionConfig.isSetReceiveBufferSizeAvailable()) {
- try {
- ch.socket().setReceiveBufferSize(receiveBufferSize);
- // Re-retrieve the effective receive buffer size.
- receiveBufferSize = ch.socket().getReceiveBufferSize();
- } catch (SocketException e) {
- throw new RuntimeIoException(e);
- }
- }
- }
-
- public boolean isBroadcast() {
- try {
- return ch.socket().getBroadcast();
- } catch (SocketException e) {
- throw new RuntimeIoException(e);
- }
- }
-
- public void setBroadcast(boolean broadcast) {
- try {
- ch.socket().setBroadcast(broadcast);
- } catch (SocketException e) {
- throw new RuntimeIoException(e);
- }
- }
-
- public int getSendBufferSize() {
- try {
- return ch.socket().getSendBufferSize();
- } catch (SocketException e) {
- throw new RuntimeIoException(e);
- }
- }
-
- public void setSendBufferSize(int sendBufferSize) {
- if (DefaultDatagramSessionConfig.isSetSendBufferSizeAvailable()) {
- try {
- ch.socket().setSendBufferSize(sendBufferSize);
- } catch (SocketException e) {
- throw new RuntimeIoException(e);
- }
- }
- }
-
- public boolean isReuseAddress() {
- try {
- return ch.socket().getReuseAddress();
- } catch (SocketException e) {
- throw new RuntimeIoException(e);
- }
- }
-
- public void setReuseAddress(boolean reuseAddress) {
- try {
- ch.socket().setReuseAddress(reuseAddress);
- } catch (SocketException e) {
- throw new RuntimeIoException(e);
- }
- }
-
- public int getTrafficClass() {
- if (DefaultDatagramSessionConfig.isGetTrafficClassAvailable()) {
- try {
- return ch.socket().getTrafficClass();
- } catch (SocketException e) {
- throw new RuntimeIoException(e);
- }
- } else {
- return 0;
- }
- }
-
- public void setTrafficClass(int trafficClass) {
- if (DefaultDatagramSessionConfig.isSetTrafficClassAvailable()) {
- try {
- ch.socket().setTrafficClass(trafficClass);
- } catch (SocketException e) {
- throw new RuntimeIoException(e);
- }
- }
- }
}
}
Added: mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramSessionConfig.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramSessionConfig.java?rev=635867&view=auto
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramSessionConfig.java (added)
+++ mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramSessionConfig.java Tue Mar 11 03:18:11 2008
@@ -0,0 +1,111 @@
+/**
+ *
+ */
+package org.apache.mina.transport.socket.nio;
+
+import java.net.SocketException;
+import java.nio.channels.DatagramChannel;
+
+import org.apache.mina.common.RuntimeIoException;
+import org.apache.mina.transport.socket.AbstractDatagramSessionConfig;
+import org.apache.mina.transport.socket.DefaultDatagramSessionConfig;
+
+class NioDatagramSessionConfig extends AbstractDatagramSessionConfig {
+ private final DatagramChannel c;
+
+ NioDatagramSessionConfig(DatagramChannel c) {
+ this.c = c;
+ }
+
+ public int getReceiveBufferSize() {
+ try {
+ return c.socket().getReceiveBufferSize();
+ } catch (SocketException e) {
+ throw new RuntimeIoException(e);
+ }
+ }
+
+ public void setReceiveBufferSize(int receiveBufferSize) {
+ if (DefaultDatagramSessionConfig.isSetReceiveBufferSizeAvailable()) {
+ try {
+ c.socket().setReceiveBufferSize(receiveBufferSize);
+ // Re-retrieve the effective receive buffer size.
+ receiveBufferSize = c.socket().getReceiveBufferSize();
+ } catch (SocketException e) {
+ throw new RuntimeIoException(e);
+ }
+ }
+ }
+
+ public boolean isBroadcast() {
+ try {
+ return c.socket().getBroadcast();
+ } catch (SocketException e) {
+ throw new RuntimeIoException(e);
+ }
+ }
+
+ public void setBroadcast(boolean broadcast) {
+ try {
+ c.socket().setBroadcast(broadcast);
+ } catch (SocketException e) {
+ throw new RuntimeIoException(e);
+ }
+ }
+
+ public int getSendBufferSize() {
+ try {
+ return c.socket().getSendBufferSize();
+ } catch (SocketException e) {
+ throw new RuntimeIoException(e);
+ }
+ }
+
+ public void setSendBufferSize(int sendBufferSize) {
+ if (DefaultDatagramSessionConfig.isSetSendBufferSizeAvailable()) {
+ try {
+ c.socket().setSendBufferSize(sendBufferSize);
+ } catch (SocketException e) {
+ throw new RuntimeIoException(e);
+ }
+ }
+ }
+
+ public boolean isReuseAddress() {
+ try {
+ return c.socket().getReuseAddress();
+ } catch (SocketException e) {
+ throw new RuntimeIoException(e);
+ }
+ }
+
+ public void setReuseAddress(boolean reuseAddress) {
+ try {
+ c.socket().setReuseAddress(reuseAddress);
+ } catch (SocketException e) {
+ throw new RuntimeIoException(e);
+ }
+ }
+
+ public int getTrafficClass() {
+ if (DefaultDatagramSessionConfig.isGetTrafficClassAvailable()) {
+ try {
+ return c.socket().getTrafficClass();
+ } catch (SocketException e) {
+ throw new RuntimeIoException(e);
+ }
+ } else {
+ return 0;
+ }
+ }
+
+ public void setTrafficClass(int trafficClass) {
+ if (DefaultDatagramSessionConfig.isSetTrafficClassAvailable()) {
+ try {
+ c.socket().setTrafficClass(trafficClass);
+ } catch (SocketException e) {
+ throw new RuntimeIoException(e);
+ }
+ }
+ }
+}
\ No newline at end of file
Propchange: mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramSessionConfig.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramSessionConfig.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketAcceptor.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketAcceptor.java?rev=635867&r1=635866&r2=635867&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketAcceptor.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketAcceptor.java Tue Mar 11 03:18:11 2008
@@ -57,25 +57,23 @@
* Create an acceptor with a single processing thread using a NewThreadExecutor
*/
public NioSocketAcceptor() {
- super(new DefaultSocketSessionConfig(), NioProcessor.class);
+ super(new DefaultSocketSessionConfig(true), NioProcessor.class);
}
public NioSocketAcceptor(int processorCount) {
- super(new DefaultSocketSessionConfig(), NioProcessor.class, processorCount);
+ super(new DefaultSocketSessionConfig(true), NioProcessor.class, processorCount);
}
public NioSocketAcceptor(IoProcessor<NioSession> processor) {
- super(new DefaultSocketSessionConfig(), processor);
+ super(new DefaultSocketSessionConfig(true), processor);
}
public NioSocketAcceptor(Executor executor, IoProcessor<NioSession> processor) {
- super(new DefaultSocketSessionConfig(), executor, processor);
+ super(new DefaultSocketSessionConfig(true), executor, processor);
}
@Override
protected void init() throws Exception {
- // The default reuseAddress of an accepted socket should be 'true'.
- getSessionConfig().setReuseAddress(true);
this.selector = Selector.open();
}
@@ -167,6 +165,7 @@
c.configureBlocking(false);
// Configure the server socket,
c.socket().setReuseAddress(isReuseAddress());
+ // XXX: Do we need to provide this property? (I think we need to remove it.)
c.socket().setReceiveBufferSize(
getSessionConfig().getReceiveBufferSize());
// and bind.
Modified: mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketConnector.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketConnector.java?rev=635867&r1=635866&r2=635867&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketConnector.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketConnector.java Tue Mar 11 03:18:11 2008
@@ -49,19 +49,19 @@
private volatile Selector selector;
public NioSocketConnector() {
- super(new DefaultSocketSessionConfig(), NioProcessor.class);
+ super(new DefaultSocketSessionConfig(false), NioProcessor.class);
}
public NioSocketConnector(int processorCount) {
- super(new DefaultSocketSessionConfig(), NioProcessor.class, processorCount);
+ super(new DefaultSocketSessionConfig(false), NioProcessor.class, processorCount);
}
public NioSocketConnector(IoProcessor<NioSession> processor) {
- super(new DefaultSocketSessionConfig(), processor);
+ super(new DefaultSocketSessionConfig(false), processor);
}
public NioSocketConnector(Executor executor, IoProcessor<NioSession> processor) {
- super(new DefaultSocketSessionConfig(), executor, processor);
+ super(new DefaultSocketSessionConfig(false), executor, processor);
}
@Override
@@ -141,7 +141,6 @@
protected SocketChannel newHandle(SocketAddress localAddress)
throws Exception {
SocketChannel ch = SocketChannel.open();
- ch.socket().setReuseAddress(true);
if (localAddress != null) {
ch.socket().bind(localAddress);
}
Modified: mina/trunk/transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprSocketAcceptor.java
URL: http://svn.apache.org/viewvc/mina/trunk/transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprSocketAcceptor.java?rev=635867&r1=635866&r2=635867&view=diff
==============================================================================
--- mina/trunk/transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprSocketAcceptor.java (original)
+++ mina/trunk/transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprSocketAcceptor.java Tue Mar 11 03:18:11 2008
@@ -39,20 +39,20 @@
new CircularQueue<Long>(POLLSET_SIZE);
public AprSocketAcceptor() {
- super(new DefaultSocketSessionConfig(), AprIoProcessor.class);
+ super(new DefaultSocketSessionConfig(true), AprIoProcessor.class);
}
public AprSocketAcceptor(int processorCount) {
- super(new DefaultSocketSessionConfig(), AprIoProcessor.class, processorCount);
+ super(new DefaultSocketSessionConfig(true), AprIoProcessor.class, processorCount);
}
public AprSocketAcceptor(IoProcessor<AprSession> processor) {
- super(new DefaultSocketSessionConfig(), processor);
+ super(new DefaultSocketSessionConfig(true), processor);
}
public AprSocketAcceptor(Executor executor,
IoProcessor<AprSession> processor) {
- super(new DefaultSocketSessionConfig(), executor, processor);
+ super(new DefaultSocketSessionConfig(true), executor, processor);
}
@Override
Modified: mina/trunk/transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprSocketConnector.java
URL: http://svn.apache.org/viewvc/mina/trunk/transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprSocketConnector.java?rev=635867&r1=635866&r2=635867&view=diff
==============================================================================
--- mina/trunk/transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprSocketConnector.java (original)
+++ mina/trunk/transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprSocketConnector.java Tue Mar 11 03:18:11 2008
@@ -68,19 +68,19 @@
private volatile ByteBuffer dummyBuffer;
public AprSocketConnector() {
- super(new DefaultSocketSessionConfig(), AprIoProcessor.class);
+ super(new DefaultSocketSessionConfig(false), AprIoProcessor.class);
}
public AprSocketConnector(int processorCount) {
- super(new DefaultSocketSessionConfig(), AprIoProcessor.class, processorCount);
+ super(new DefaultSocketSessionConfig(false), AprIoProcessor.class, processorCount);
}
public AprSocketConnector(IoProcessor<AprSession> processor) {
- super(new DefaultSocketSessionConfig(), processor);
+ super(new DefaultSocketSessionConfig(false), processor);
}
public AprSocketConnector(Executor executor, IoProcessor<AprSession> processor) {
- super(new DefaultSocketSessionConfig(), executor, processor);
+ super(new DefaultSocketSessionConfig(false), executor, processor);
}
@Override