Author: elecharny
Date: Tue Nov 18 14:53:14 2008
New Revision: 718753
URL: http://svn.apache.org/viewvc?rev=718753&view=rev
Log:
More removal of Config related values, as we don't create a socket anymore to
check what are the local values.
Modified:
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/NioDatagramSessionConfig.java
mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketSession.java
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=718753&r1=718752&r2=718753&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 Nov 18 14:53:14 2008
@@ -28,33 +28,12 @@
* @version $Rev: 439913 $, $Date: 2006-09-04 05:12:43 +0200 (mån, 04 sep
2006) $
*/
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;
- public static boolean isSetReceiveBufferSizeAvailable() {
- return SET_RECEIVE_BUFFER_SIZE_AVAILABLE;
- }
-
- public static boolean isSetSendBufferSizeAvailable() {
- return SET_SEND_BUFFER_SIZE_AVAILABLE;
- }
-
- public static boolean isGetTrafficClassAvailable() {
- return GET_TRAFFIC_CLASS_AVAILABLE;
- }
-
- public static boolean isSetTrafficClassAvailable() {
- return SET_TRAFFIC_CLASS_AVAILABLE;
- }
-
private boolean broadcast = DEFAULT_BROADCAST;
private boolean reuseAddress = DEFAULT_REUSE_ADDRESS;
private int receiveBufferSize = DEFAULT_RECEIVE_BUFFER_SIZE;
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=718753&r1=718752&r2=718753&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 Nov 18 14:53:14 2008
@@ -28,10 +28,6 @@
* @version $Rev$, $Date$
*/
public class DefaultSocketSessionConfig extends AbstractSocketSessionConfig {
- 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;
@@ -41,22 +37,6 @@
private static int DEFAULT_SO_LINGER = -1;
private static boolean DEFAULT_TCP_NO_DELAY = false;
- public static boolean isSetReceiveBufferSizeAvailable() {
- return SET_RECEIVE_BUFFER_SIZE_AVAILABLE;
- }
-
- public static boolean isSetSendBufferSizeAvailable() {
- return SET_SEND_BUFFER_SIZE_AVAILABLE;
- }
-
- public static boolean isGetTrafficClassAvailable() {
- return GET_TRAFFIC_CLASS_AVAILABLE;
- }
-
- public static boolean isSetTrafficClassAvailable() {
- return SET_TRAFFIC_CLASS_AVAILABLE;
- }
-
private IoService parent;
private boolean defaultReuseAddress;
private int defaultReceiveBufferSize = DEFAULT_RECEIVE_BUFFER_SIZE;
Modified:
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=718753&r1=718752&r2=718753&view=diff
==============================================================================
---
mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramSessionConfig.java
(original)
+++
mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramSessionConfig.java
Tue Nov 18 14:53:14 2008
@@ -19,55 +19,80 @@
*/
package org.apache.mina.transport.socket.nio;
+import java.net.DatagramSocket;
import java.net.SocketException;
import java.nio.channels.DatagramChannel;
import org.apache.mina.core.RuntimeIoException;
import org.apache.mina.transport.socket.AbstractDatagramSessionConfig;
-import org.apache.mina.transport.socket.DefaultDatagramSessionConfig;
/**
- * TODO Add documentation
+ * Define the configuration for a Datagram based session.
*
* @author The Apache MINA Project ([EMAIL PROTECTED])
* @version $Rev$, $Date$
*/
class NioDatagramSessionConfig extends AbstractDatagramSessionConfig {
- private final DatagramChannel c;
-
- NioDatagramSessionConfig(DatagramChannel c) {
- this.c = c;
- }
+ /** The associated channel */
+ private final DatagramChannel channel;
+ /**
+ * Creates a new instance of NioDatagramSessionConfig, associated
+ * with the given DatagramChannel.
+ *
+ * @param channel The associated DatagramChannel
+ */
+ NioDatagramSessionConfig(DatagramChannel channel) {
+ this.channel = channel;
+ }
+
+ /**
+ * Get the Socket receive buffer size for this DatagramChannel.
+ *
+ * @return the DatagramChannel receive buffer size.
+ * @throws RuntimeIoException if the socket is closed or if we
+ * had a SocketException
+ *
+ * @see DatagramSocket#getReceiveBufferSize()
+ */
public int getReceiveBufferSize() {
try {
- return c.socket().getReceiveBufferSize();
+ return channel.socket().getReceiveBufferSize();
} catch (SocketException e) {
throw new RuntimeIoException(e);
}
}
+ /**
+ * Set the Socket receive buffer size for this DatagramChannel. <br>
+ * <br>
+ * Note : The underlying Socket may not accept the new buffer's size.
+ * The user has to check that the new value has been set.
+ *
+ * @param receiveBufferSize the DatagramChannel receive buffer size.
+ * @throws RuntimeIoException if the socket is closed or if we
+ * had a SocketException
+ *
+ * @see DatagramSocket#setReceiveBufferSize()
+ */
public void setReceiveBufferSize(int receiveBufferSize) {
- if (DefaultDatagramSessionConfig.isSetReceiveBufferSizeAvailable()) {
- try {
- c.socket().setReceiveBufferSize(receiveBufferSize);
- // Re-retrieve the effective receive buffer size.
-
- // TODO clean this dead code.
- // Do we really need to do this ???
- // Is there any secret reason why we should read the
- // receiveBufferSize just after having set it ? I don't think
so...
- // Commented :
- //c.socket().getReceiveBufferSize();
- } catch (SocketException e) {
- throw new RuntimeIoException(e);
- }
+ try {
+ channel.socket().setReceiveBufferSize(receiveBufferSize);
+ } catch (SocketException e) {
+ throw new RuntimeIoException(e);
}
}
+ /**
+ * Tells if SO_BROADCAST is enabled.
+ *
+ * @return <code>true</code> if SO_BROADCAST is enabled
+ * @throws RuntimeIoException If the socket is closed or if we get an
+ * [EMAIL PROTECTED] SocketException}
+ */
public boolean isBroadcast() {
try {
- return c.socket().getBroadcast();
+ return channel.socket().getBroadcast();
} catch (SocketException e) {
throw new RuntimeIoException(e);
}
@@ -75,65 +100,93 @@
public void setBroadcast(boolean broadcast) {
try {
- c.socket().setBroadcast(broadcast);
+ channel.socket().setBroadcast(broadcast);
} catch (SocketException e) {
throw new RuntimeIoException(e);
}
}
+ /**
+ *
+ * @throws RuntimeIoException If the socket is closed or if we get an
+ * [EMAIL PROTECTED] SocketException}
+ */
public int getSendBufferSize() {
try {
- return c.socket().getSendBufferSize();
+ return channel.socket().getSendBufferSize();
} catch (SocketException e) {
throw new RuntimeIoException(e);
}
}
+ /**
+ *
+ * @throws RuntimeIoException If the socket is closed or if we get an
+ * [EMAIL PROTECTED] SocketException}
+ */
public void setSendBufferSize(int sendBufferSize) {
- if (DefaultDatagramSessionConfig.isSetSendBufferSizeAvailable()) {
- try {
- c.socket().setSendBufferSize(sendBufferSize);
- } catch (SocketException e) {
- throw new RuntimeIoException(e);
- }
+ try {
+ channel.socket().setSendBufferSize(sendBufferSize);
+ } catch (SocketException e) {
+ throw new RuntimeIoException(e);
}
}
+ /**
+ * Tells if SO_REUSEADDR is enabled.
+ *
+ * @return <code>true</code> if SO_REUSEADDR is enabled
+ * @throws RuntimeIoException If the socket is closed or if we get an
+ * [EMAIL PROTECTED] SocketException}
+ */
public boolean isReuseAddress() {
try {
- return c.socket().getReuseAddress();
+ return channel.socket().getReuseAddress();
} catch (SocketException e) {
throw new RuntimeIoException(e);
}
}
+ /**
+ *
+ * @throws RuntimeIoException If the socket is closed or if we get an
+ * [EMAIL PROTECTED] SocketException}
+ */
public void setReuseAddress(boolean reuseAddress) {
try {
- c.socket().setReuseAddress(reuseAddress);
+ channel.socket().setReuseAddress(reuseAddress);
} catch (SocketException e) {
throw new RuntimeIoException(e);
}
}
+ /**
+ * Get the current Traffic Class for this Socket, if any. As this is
+ * not a mandatory feature, the returned value should be considered as
+ * a hint.
+ *
+ * @return The Traffic Class supported by this Socket
+ * @throws RuntimeIoException If the socket is closed or if we get an
+ * [EMAIL PROTECTED] SocketException}
+ */
public int getTrafficClass() {
- if (DefaultDatagramSessionConfig.isGetTrafficClassAvailable()) {
- try {
- return c.socket().getTrafficClass();
- } catch (SocketException e) {
- throw new RuntimeIoException(e);
- }
- } else {
- return 0;
+ try {
+ return channel.socket().getTrafficClass();
+ } catch (SocketException e) {
+ throw new RuntimeIoException(e);
}
}
+ /**
+ * [EMAIL PROTECTED]
+ * @throws RuntimeIoException If the socket is closed or if we get an
+ * [EMAIL PROTECTED] SocketException}
+ */
public void setTrafficClass(int trafficClass) {
- if (DefaultDatagramSessionConfig.isSetTrafficClassAvailable()) {
- try {
- c.socket().setTrafficClass(trafficClass);
- } catch (SocketException e) {
- throw new RuntimeIoException(e);
- }
+ try {
+ channel.socket().setTrafficClass(trafficClass);
+ } catch (SocketException e) {
+ throw new RuntimeIoException(e);
}
}
}
\ No newline at end of file
Modified:
mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketSession.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketSession.java?rev=718753&r1=718752&r2=718753&view=diff
==============================================================================
---
mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketSession.java
(original)
+++
mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketSession.java
Tue Nov 18 14:53:14 2008
@@ -36,7 +36,6 @@
import org.apache.mina.core.service.TransportMetadata;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.transport.socket.AbstractSocketSessionConfig;
-import org.apache.mina.transport.socket.DefaultSocketSessionConfig;
import org.apache.mina.transport.socket.SocketSessionConfig;
/**
@@ -227,28 +226,25 @@
}
}
+ /**
+ * [EMAIL PROTECTED]
+ */
public int getTrafficClass() {
- if (DefaultSocketSessionConfig.isGetTrafficClassAvailable()) {
- try {
- return ch.socket().getTrafficClass();
- } catch (SocketException e) {
- // Throw an exception only when setTrafficClass is also
available.
- if
(DefaultSocketSessionConfig.isSetTrafficClassAvailable()) {
- throw new RuntimeIoException(e);
- }
- }
+ try {
+ return ch.socket().getTrafficClass();
+ } catch (SocketException e) {
+ throw new RuntimeIoException(e);
}
-
- return 0;
}
+ /**
+ * [EMAIL PROTECTED]
+ */
public void setTrafficClass(int tc) {
- if (DefaultSocketSessionConfig.isSetTrafficClassAvailable()) {
- try {
- ch.socket().setTrafficClass(tc);
- } catch (SocketException e) {
- throw new RuntimeIoException(e);
- }
+ try {
+ ch.socket().setTrafficClass(tc);
+ } catch (SocketException e) {
+ throw new RuntimeIoException(e);
}
}
@@ -261,12 +257,10 @@
}
public void setSendBufferSize(int size) {
- if (DefaultSocketSessionConfig.isSetSendBufferSizeAvailable()) {
- try {
- ch.socket().setSendBufferSize(size);
- } catch (SocketException e) {
- throw new RuntimeIoException(e);
- }
+ try {
+ ch.socket().setSendBufferSize(size);
+ } catch (SocketException e) {
+ throw new RuntimeIoException(e);
}
}
@@ -279,12 +273,10 @@
}
public void setReceiveBufferSize(int size) {
- if (DefaultSocketSessionConfig.isSetReceiveBufferSizeAvailable()) {
- try {
- ch.socket().setReceiveBufferSize(size);
- } catch (SocketException e) {
- throw new RuntimeIoException(e);
- }
+ try {
+ ch.socket().setReceiveBufferSize(size);
+ } catch (SocketException e) {
+ throw new RuntimeIoException(e);
}
}
}