You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by jv...@apache.org on 2011/10/12 16:32:59 UTC
svn commit: r1182401 - in /mina/trunk/core/src/main/java/org/apache/mina:
api/ transport/tcp/
Author: jvermillard
Date: Wed Oct 12 14:32:59 2011
New Revision: 1182401
URL: http://svn.apache.org/viewvc?rev=1182401&view=rev
Log:
DIRMINA-863
prxoy for session socket configuration
Added:
mina/trunk/core/src/main/java/org/apache/mina/api/ConfigurationException.java (with props)
mina/trunk/core/src/main/java/org/apache/mina/transport/tcp/ProxySocketSessionConfig.java (with props)
Modified:
mina/trunk/core/src/main/java/org/apache/mina/api/IoSessionConfig.java
mina/trunk/core/src/main/java/org/apache/mina/transport/tcp/DefaultSocketSessionConfig.java
mina/trunk/core/src/main/java/org/apache/mina/transport/tcp/NioSelectorProcessor.java
mina/trunk/core/src/main/java/org/apache/mina/transport/tcp/NioTcpSession.java
Added: mina/trunk/core/src/main/java/org/apache/mina/api/ConfigurationException.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/api/ConfigurationException.java?rev=1182401&view=auto
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/api/ConfigurationException.java (added)
+++ mina/trunk/core/src/main/java/org/apache/mina/api/ConfigurationException.java Wed Oct 12 14:32:59 2011
@@ -0,0 +1,44 @@
+/**
+ * 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.mina.api;
+
+/**
+ * A {@link RuntimeException} thrown when something wrong happened during {@link IoService} or {@link IoSession} configuration.
+ *
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public class ConfigurationException extends RuntimeException {
+
+ public ConfigurationException() {
+ super();
+ }
+
+ public ConfigurationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ConfigurationException(String message) {
+ super(message);
+ }
+
+ public ConfigurationException(Throwable cause) {
+ super(cause);
+ }
+
+}
Propchange: mina/trunk/core/src/main/java/org/apache/mina/api/ConfigurationException.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: mina/trunk/core/src/main/java/org/apache/mina/api/IoSessionConfig.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/api/IoSessionConfig.java?rev=1182401&r1=1182400&r2=1182401&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/api/IoSessionConfig.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/api/IoSessionConfig.java Wed Oct 12 14:32:59 2011
@@ -19,7 +19,6 @@
*/
package org.apache.mina.api;
-import org.apache.mina.service.SelectorProcessor;
/**
* The configuration of {@link IoSession}.
@@ -44,16 +43,4 @@ public interface IoSessionConfig {
*/
void setIdleTimeInMillis(IdleStatus status, long ildeTimeInMilli);
- /**
- * Returns the size of the read buffer the {@link SelectorProcessor} allocates
- * per each read.
- */
- int getReadBufferSize();
-
- /**
- * Sets the size of the read buffer the {@link SelectorProcessor} allocates
- * per each read.
- */
- void setReadBufferSize(int readBufferSize);
-
}
Modified: mina/trunk/core/src/main/java/org/apache/mina/transport/tcp/DefaultSocketSessionConfig.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/transport/tcp/DefaultSocketSessionConfig.java?rev=1182401&r1=1182400&r2=1182401&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/transport/tcp/DefaultSocketSessionConfig.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/transport/tcp/DefaultSocketSessionConfig.java Wed Oct 12 14:32:59 2011
@@ -18,9 +18,6 @@
*/
package org.apache.mina.transport.tcp;
-import java.net.Socket;
-import java.net.SocketException;
-
import org.apache.mina.api.IdleStatus;
/**
@@ -32,25 +29,6 @@ import org.apache.mina.api.IdleStatus;
*/
public class DefaultSocketSessionConfig implements SocketSessionConfig {
- /**
- * Create a socket configuration with the default value of the given {@link Socket}.
- * Will help to create
- *
- * @param socket
- * @throws SocketException
- */
- public DefaultSocketSessionConfig(Socket socket) throws SocketException {
- this.receiveBufferSize = socket.getReceiveBufferSize();
- this.sendBufferSize = socket.getSendBufferSize();
- this.tcpNoDelay = socket.getTcpNoDelay();
- this.reuseAddress = socket.getReuseAddress();
- this.trafficClass = socket.getTrafficClass();
- this.keepAlive = socket.getKeepAlive();
- this.oobInline = socket.getOOBInline();
- this.soLinger = socket.getSoLinger();
- this.readBufferSize = 1024; // FIXME : dumb default value
- }
-
//=====================
// idle management
//=====================
@@ -66,7 +44,6 @@ public class DefaultSocketSessionConfig
switch (status) {
case READ_IDLE:
return idleTimeRead;
-
case WRITE_IDLE:
return idleTimeWrite;
case READ_WRITE_IDLE:
@@ -97,18 +74,6 @@ public class DefaultSocketSessionConfig
// buffers
//=====================
- private int readBufferSize;
-
- @Override
- public int getReadBufferSize() {
- return readBufferSize;
- }
-
- @Override
- public void setReadBufferSize(int readBufferSize) {
- this.readBufferSize = readBufferSize;
- }
-
private Integer receiveBufferSize = null;
@Override
Modified: mina/trunk/core/src/main/java/org/apache/mina/transport/tcp/NioSelectorProcessor.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/transport/tcp/NioSelectorProcessor.java?rev=1182401&r1=1182400&r2=1182401&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/transport/tcp/NioSelectorProcessor.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/transport/tcp/NioSelectorProcessor.java Wed Oct 12 14:32:59 2011
@@ -155,10 +155,10 @@ public class NioSelectorProcessor implem
@Override
public void createSession(IoService service, Object clientSocket) {
LOGGER.debug("create session");
- SocketChannel socketChannel = (SocketChannel) clientSocket;
- NioTcpSession session = new NioTcpSession((NioTcpServer) service, socketChannel,
+ final SocketChannel socketChannel = (SocketChannel) clientSocket;
+ final SocketSessionConfig defaultConfig = (SocketSessionConfig) service.getSessionConfig();
+ final NioTcpSession session = new NioTcpSession((NioTcpServer) service, socketChannel,
strategy.getSelectorForNewSession(this));
- SocketSessionConfig sessionConfig = (SocketSessionConfig) service.getSessionConfig();
try {
socketChannel.configureBlocking(false);
@@ -166,6 +166,38 @@ public class NioSelectorProcessor implem
LOGGER.error("Unexpected exception, while configuring socket as non blocking", e);
}
+ // apply the default service socket configuration
+
+ Boolean keepAlive = defaultConfig.isKeepAlive();
+ if (keepAlive != null) {
+ session.getConfig().setKeepAlive(keepAlive);
+ }
+
+ Boolean oobInline = defaultConfig.isOobInline();
+ if (oobInline != null) {
+ session.getConfig().setOobInline(oobInline);
+ }
+
+ Boolean reuseAddress = defaultConfig.isReuseAddress();
+ if (reuseAddress != null) {
+ session.getConfig().setReuseAddress(reuseAddress);
+ }
+
+ Boolean tcpNoDelay = defaultConfig.isTcpNoDelay();
+ if (tcpNoDelay != null) {
+ session.getConfig().setTcpNoDelay(tcpNoDelay);
+ }
+
+ Integer receiveBufferSize = defaultConfig.getReceiveBufferSize();
+ if (receiveBufferSize != null) {
+ session.getConfig().setReceiveBufferSize(receiveBufferSize);
+ }
+
+ Integer sendBufferSize = defaultConfig.getSendBufferSize();
+ if (sendBufferSize != null) {
+ session.getConfig().setSendBufferSize(sendBufferSize);
+ }
+
// event session created
session.getFilterChain().processSessionCreated(session);
Modified: mina/trunk/core/src/main/java/org/apache/mina/transport/tcp/NioTcpSession.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/transport/tcp/NioTcpSession.java?rev=1182401&r1=1182400&r2=1182401&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/transport/tcp/NioTcpSession.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/transport/tcp/NioTcpSession.java Wed Oct 12 14:32:59 2011
@@ -24,7 +24,6 @@ import java.net.Socket;
import java.nio.channels.SocketChannel;
import org.apache.mina.api.IoFuture;
-import org.apache.mina.api.IoSessionConfig;
import org.apache.mina.service.SelectorProcessor;
import org.apache.mina.session.AbstractIoSession;
import org.apache.mina.transport.tcp.nio.NioTcpServer;
@@ -39,9 +38,12 @@ public class NioTcpSession extends Abstr
private SocketChannel channel;
+ private final SocketSessionConfig configuration;
+
NioTcpSession(NioTcpServer service, SocketChannel channel, SelectorProcessor writeProcessor) {
super(service, writeProcessor);
this.channel = channel;
+ this.configuration = new ProxySocketSessionConfig(channel.socket());
}
public SocketChannel getSocketChannel() {
@@ -138,9 +140,8 @@ public class NioTcpSession extends Abstr
}
@Override
- public IoSessionConfig getConfig() {
- // TODO Auto-generated method stub
- return null;
+ public SocketSessionConfig getConfig() {
+ return configuration;
}
void setConnected() {
Added: mina/trunk/core/src/main/java/org/apache/mina/transport/tcp/ProxySocketSessionConfig.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/transport/tcp/ProxySocketSessionConfig.java?rev=1182401&view=auto
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/transport/tcp/ProxySocketSessionConfig.java (added)
+++ mina/trunk/core/src/main/java/org/apache/mina/transport/tcp/ProxySocketSessionConfig.java Wed Oct 12 14:32:59 2011
@@ -0,0 +1,226 @@
+/**
+ * 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.mina.transport.tcp;
+
+import java.net.Socket;
+import java.net.SocketException;
+
+import org.apache.mina.api.ConfigurationException;
+import org.apache.mina.api.IdleStatus;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class proxy the inner java.net.Socket configuration with the SocketSessionConfig of the session.
+ *
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public class ProxySocketSessionConfig implements SocketSessionConfig {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ProxySocketSessionConfig.class);
+
+ private final Socket socket;
+
+ public ProxySocketSessionConfig(Socket socket) {
+ this.socket = socket;
+ }
+
+ private long idleTimeRead = -1;
+
+ private long idleTimeWrite = -1;
+
+ private long idleTimeReadWrite = -1;
+
+ @Override
+ public long getIdleTimeInMillis(IdleStatus status) {
+ switch (status) {
+ case READ_IDLE:
+ return idleTimeRead;
+
+ case WRITE_IDLE:
+ return idleTimeWrite;
+ case READ_WRITE_IDLE:
+ return idleTimeReadWrite;
+ default:
+ throw new RuntimeException("unexpected excetion, unknown idle status : " + status);
+ }
+ }
+
+ @Override
+ public void setIdleTimeInMillis(IdleStatus status, long ildeTimeInMilli) {
+ switch (status) {
+ case READ_IDLE:
+ this.idleTimeRead = ildeTimeInMilli;
+ break;
+ case WRITE_IDLE:
+ this.idleTimeWrite = ildeTimeInMilli;
+ break;
+ case READ_WRITE_IDLE:
+ this.idleTimeReadWrite = ildeTimeInMilli;
+ break;
+ default:
+ throw new RuntimeException("unexpected excetion, unknown idle status : " + status);
+ }
+ }
+
+ @Override
+ public Boolean isTcpNoDelay() {
+ try {
+ return socket.getTcpNoDelay();
+ } catch (SocketException e) {
+ throw new ConfigurationException(e);
+ }
+ }
+
+ @Override
+ public void setTcpNoDelay(boolean tcpNoDelay) {
+ try {
+ socket.setTcpNoDelay(tcpNoDelay);
+ } catch (SocketException e) {
+ throw new ConfigurationException(e);
+ }
+ }
+
+ @Override
+ public Boolean isReuseAddress() {
+ try {
+ return socket.getReuseAddress();
+ } catch (SocketException e) {
+ throw new ConfigurationException(e);
+ }
+ }
+
+ @Override
+ public void setReuseAddress(boolean reuseAddress) {
+ try {
+ socket.setReuseAddress(reuseAddress);
+ } catch (SocketException e) {
+ throw new ConfigurationException(e);
+ }
+ }
+
+ @Override
+ public Integer getReceiveBufferSize() {
+ try {
+ return socket.getReceiveBufferSize();
+ } catch (SocketException e) {
+ throw new ConfigurationException(e);
+ }
+ }
+
+ @Override
+ public void setReceiveBufferSize(int receiveBufferSize) {
+ try {
+ socket.setReceiveBufferSize(receiveBufferSize);
+ } catch (SocketException e) {
+ throw new ConfigurationException(e);
+ }
+ }
+
+ @Override
+ public Integer getSendBufferSize() {
+ try {
+ return socket.getSendBufferSize();
+ } catch (SocketException e) {
+ throw new ConfigurationException(e);
+ }
+ }
+
+ @Override
+ public void setSendBufferSize(int sendBufferSize) {
+ try {
+ socket.setSendBufferSize(sendBufferSize);
+ } catch (SocketException e) {
+ throw new ConfigurationException(e);
+ }
+ }
+
+ @Override
+ public Integer getTrafficClass() {
+ try {
+ return socket.getTrafficClass();
+ } catch (SocketException e) {
+ throw new ConfigurationException(e);
+ }
+ }
+
+ @Override
+ public void setTrafficClass(int trafficClass) {
+ try {
+ socket.setTrafficClass(trafficClass);
+ } catch (SocketException e) {
+ throw new ConfigurationException(e);
+ }
+ }
+
+ @Override
+ public Boolean isKeepAlive() {
+ try {
+ return socket.getKeepAlive();
+ } catch (SocketException e) {
+ throw new ConfigurationException(e);
+ }
+ }
+
+ @Override
+ public void setKeepAlive(boolean keepAlive) {
+ try {
+ socket.setKeepAlive(keepAlive);
+ } catch (SocketException e) {
+ throw new ConfigurationException(e);
+ }
+ }
+
+ @Override
+ public Boolean isOobInline() {
+ try {
+ return socket.getOOBInline();
+ } catch (SocketException e) {
+ throw new ConfigurationException(e);
+ }
+ }
+
+ @Override
+ public void setOobInline(boolean oobInline) {
+ try {
+ socket.setOOBInline(oobInline);
+ } catch (SocketException e) {
+ throw new ConfigurationException(e);
+ }
+ }
+
+ @Override
+ public Integer getSoLinger() {
+ try {
+ return socket.getSoLinger();
+ } catch (SocketException e) {
+ throw new ConfigurationException(e);
+ }
+ }
+
+ @Override
+ public void setSoLinger(int soLinger) {
+ try {
+ socket.setSoLinger(soLinger > 0, soLinger);
+ } catch (SocketException e) {
+ throw new ConfigurationException(e);
+ }
+ }
+
+}
Propchange: mina/trunk/core/src/main/java/org/apache/mina/transport/tcp/ProxySocketSessionConfig.java
------------------------------------------------------------------------------
svn:mime-type = text/plain