You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by el...@apache.org on 2016/09/19 09:30:15 UTC
mina git commit: o Fixed some javadoc o Replaced a throws Exception
by throws IOException o Fixed some Sonar warnings
Repository: mina
Updated Branches:
refs/heads/2.0 0a3742419 -> 8d5cde67c
o Fixed some javadoc
o Replaced a throws Exception by throws IOException
o Fixed some Sonar warnings
Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/8d5cde67
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/8d5cde67
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/8d5cde67
Branch: refs/heads/2.0
Commit: 8d5cde67cb3528cd49d6bc689987b25f02a35f16
Parents: 0a37424
Author: Emmanuel L�charny <el...@symas.com>
Authored: Mon Sep 19 11:29:58 2016 +0200
Committer: Emmanuel L�charny <el...@symas.com>
Committed: Mon Sep 19 11:29:58 2016 +0200
----------------------------------------------------------------------
.../core/session/AbstractIoSessionConfig.java | 27 ++++++
.../socket/DefaultSocketSessionConfig.java | 93 ++++++++++++++++++++
.../transport/socket/nio/NioSocketSession.java | 86 ++++++++++++++++--
3 files changed, 200 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina/blob/8d5cde67/mina-core/src/main/java/org/apache/mina/core/session/AbstractIoSessionConfig.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/core/session/AbstractIoSessionConfig.java b/mina-core/src/main/java/org/apache/mina/core/session/AbstractIoSessionConfig.java
index db693bf..200dbfe 100644
--- a/mina-core/src/main/java/org/apache/mina/core/session/AbstractIoSessionConfig.java
+++ b/mina-core/src/main/java/org/apache/mina/core/session/AbstractIoSessionConfig.java
@@ -61,6 +61,7 @@ public abstract class AbstractIoSessionConfig implements IoSessionConfig {
/**
* {@inheritDoc}
*/
+ @Override
public final void setAll(IoSessionConfig config) {
if (config == null) {
throw new IllegalArgumentException("config");
@@ -90,6 +91,7 @@ public abstract class AbstractIoSessionConfig implements IoSessionConfig {
/**
* {@inheritDoc}
*/
+ @Override
public int getReadBufferSize() {
return readBufferSize;
}
@@ -97,6 +99,7 @@ public abstract class AbstractIoSessionConfig implements IoSessionConfig {
/**
* {@inheritDoc}
*/
+ @Override
public void setReadBufferSize(int readBufferSize) {
if (readBufferSize <= 0) {
throw new IllegalArgumentException("readBufferSize: " + readBufferSize + " (expected: 1+)");
@@ -107,6 +110,7 @@ public abstract class AbstractIoSessionConfig implements IoSessionConfig {
/**
* {@inheritDoc}
*/
+ @Override
public int getMinReadBufferSize() {
return minReadBufferSize;
}
@@ -114,6 +118,7 @@ public abstract class AbstractIoSessionConfig implements IoSessionConfig {
/**
* {@inheritDoc}
*/
+ @Override
public void setMinReadBufferSize(int minReadBufferSize) {
if (minReadBufferSize <= 0) {
throw new IllegalArgumentException("minReadBufferSize: " + minReadBufferSize + " (expected: 1+)");
@@ -129,6 +134,7 @@ public abstract class AbstractIoSessionConfig implements IoSessionConfig {
/**
* {@inheritDoc}
*/
+ @Override
public int getMaxReadBufferSize() {
return maxReadBufferSize;
}
@@ -136,6 +142,7 @@ public abstract class AbstractIoSessionConfig implements IoSessionConfig {
/**
* {@inheritDoc}
*/
+ @Override
public void setMaxReadBufferSize(int maxReadBufferSize) {
if (maxReadBufferSize <= 0) {
throw new IllegalArgumentException("maxReadBufferSize: " + maxReadBufferSize + " (expected: 1+)");
@@ -152,6 +159,7 @@ public abstract class AbstractIoSessionConfig implements IoSessionConfig {
/**
* {@inheritDoc}
*/
+ @Override
public int getIdleTime(IdleStatus status) {
if (status == IdleStatus.BOTH_IDLE) {
return idleTimeForBoth;
@@ -171,6 +179,7 @@ public abstract class AbstractIoSessionConfig implements IoSessionConfig {
/**
* {@inheritDoc}
*/
+ @Override
public long getIdleTimeInMillis(IdleStatus status) {
return getIdleTime(status) * 1000L;
}
@@ -178,6 +187,7 @@ public abstract class AbstractIoSessionConfig implements IoSessionConfig {
/**
* {@inheritDoc}
*/
+ @Override
public void setIdleTime(IdleStatus status, int idleTime) {
if (idleTime < 0) {
throw new IllegalArgumentException("Illegal idle time: " + idleTime);
@@ -197,6 +207,7 @@ public abstract class AbstractIoSessionConfig implements IoSessionConfig {
/**
* {@inheritDoc}
*/
+ @Override
public final int getBothIdleTime() {
return getIdleTime(IdleStatus.BOTH_IDLE);
}
@@ -204,6 +215,7 @@ public abstract class AbstractIoSessionConfig implements IoSessionConfig {
/**
* {@inheritDoc}
*/
+ @Override
public final long getBothIdleTimeInMillis() {
return getIdleTimeInMillis(IdleStatus.BOTH_IDLE);
}
@@ -211,6 +223,7 @@ public abstract class AbstractIoSessionConfig implements IoSessionConfig {
/**
* {@inheritDoc}
*/
+ @Override
public final int getReaderIdleTime() {
return getIdleTime(IdleStatus.READER_IDLE);
}
@@ -218,6 +231,7 @@ public abstract class AbstractIoSessionConfig implements IoSessionConfig {
/**
* {@inheritDoc}
*/
+ @Override
public final long getReaderIdleTimeInMillis() {
return getIdleTimeInMillis(IdleStatus.READER_IDLE);
}
@@ -225,6 +239,7 @@ public abstract class AbstractIoSessionConfig implements IoSessionConfig {
/**
* {@inheritDoc}
*/
+ @Override
public final int getWriterIdleTime() {
return getIdleTime(IdleStatus.WRITER_IDLE);
}
@@ -232,6 +247,7 @@ public abstract class AbstractIoSessionConfig implements IoSessionConfig {
/**
* {@inheritDoc}
*/
+ @Override
public final long getWriterIdleTimeInMillis() {
return getIdleTimeInMillis(IdleStatus.WRITER_IDLE);
}
@@ -239,6 +255,7 @@ public abstract class AbstractIoSessionConfig implements IoSessionConfig {
/**
* {@inheritDoc}
*/
+ @Override
public void setBothIdleTime(int idleTime) {
setIdleTime(IdleStatus.BOTH_IDLE, idleTime);
}
@@ -246,6 +263,7 @@ public abstract class AbstractIoSessionConfig implements IoSessionConfig {
/**
* {@inheritDoc}
*/
+ @Override
public void setReaderIdleTime(int idleTime) {
setIdleTime(IdleStatus.READER_IDLE, idleTime);
}
@@ -253,6 +271,7 @@ public abstract class AbstractIoSessionConfig implements IoSessionConfig {
/**
* {@inheritDoc}
*/
+ @Override
public void setWriterIdleTime(int idleTime) {
setIdleTime(IdleStatus.WRITER_IDLE, idleTime);
}
@@ -260,6 +279,7 @@ public abstract class AbstractIoSessionConfig implements IoSessionConfig {
/**
* {@inheritDoc}
*/
+ @Override
public int getWriteTimeout() {
return writeTimeout;
}
@@ -267,6 +287,7 @@ public abstract class AbstractIoSessionConfig implements IoSessionConfig {
/**
* {@inheritDoc}
*/
+ @Override
public long getWriteTimeoutInMillis() {
return writeTimeout * 1000L;
}
@@ -274,6 +295,7 @@ public abstract class AbstractIoSessionConfig implements IoSessionConfig {
/**
* {@inheritDoc}
*/
+ @Override
public void setWriteTimeout(int writeTimeout) {
if (writeTimeout < 0) {
throw new IllegalArgumentException("Illegal write timeout: " + writeTimeout);
@@ -284,6 +306,7 @@ public abstract class AbstractIoSessionConfig implements IoSessionConfig {
/**
* {@inheritDoc}
*/
+ @Override
public boolean isUseReadOperation() {
return useReadOperation;
}
@@ -291,6 +314,7 @@ public abstract class AbstractIoSessionConfig implements IoSessionConfig {
/**
* {@inheritDoc}
*/
+ @Override
public void setUseReadOperation(boolean useReadOperation) {
this.useReadOperation = useReadOperation;
}
@@ -298,6 +322,7 @@ public abstract class AbstractIoSessionConfig implements IoSessionConfig {
/**
* {@inheritDoc}
*/
+ @Override
public int getThroughputCalculationInterval() {
return throughputCalculationInterval;
}
@@ -305,6 +330,7 @@ public abstract class AbstractIoSessionConfig implements IoSessionConfig {
/**
* {@inheritDoc}
*/
+ @Override
public void setThroughputCalculationInterval(int throughputCalculationInterval) {
if (throughputCalculationInterval < 0) {
throw new IllegalArgumentException("throughputCalculationInterval: " + throughputCalculationInterval);
@@ -316,6 +342,7 @@ public abstract class AbstractIoSessionConfig implements IoSessionConfig {
/**
* {@inheritDoc}
*/
+ @Override
public long getThroughputCalculationIntervalInMillis() {
return throughputCalculationInterval * 1000L;
}
http://git-wip-us.apache.org/repos/asf/mina/blob/8d5cde67/mina-core/src/main/java/org/apache/mina/transport/socket/DefaultSocketSessionConfig.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/transport/socket/DefaultSocketSessionConfig.java b/mina-core/src/main/java/org/apache/mina/transport/socket/DefaultSocketSessionConfig.java
index f88bd4c..dedd5b5 100644
--- a/mina-core/src/main/java/org/apache/mina/transport/socket/DefaultSocketSessionConfig.java
+++ b/mina-core/src/main/java/org/apache/mina/transport/socket/DefaultSocketSessionConfig.java
@@ -68,6 +68,11 @@ public class DefaultSocketSessionConfig extends AbstractSocketSessionConfig {
// Do nothing
}
+ /**
+ * Initialize this configuration.
+ *
+ * @param parent The parent IoService.
+ */
public void init(IoService parent) {
this.parent = parent;
@@ -80,105 +85,193 @@ public class DefaultSocketSessionConfig extends AbstractSocketSessionConfig {
reuseAddress = defaultReuseAddress;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public boolean isReuseAddress() {
return reuseAddress;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setReuseAddress(boolean reuseAddress) {
this.reuseAddress = reuseAddress;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public int getReceiveBufferSize() {
return receiveBufferSize;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setReceiveBufferSize(int receiveBufferSize) {
this.receiveBufferSize = receiveBufferSize;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public int getSendBufferSize() {
return sendBufferSize;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setSendBufferSize(int sendBufferSize) {
this.sendBufferSize = sendBufferSize;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public int getTrafficClass() {
return trafficClass;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setTrafficClass(int trafficClass) {
this.trafficClass = trafficClass;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public boolean isKeepAlive() {
return keepAlive;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setKeepAlive(boolean keepAlive) {
this.keepAlive = keepAlive;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public boolean isOobInline() {
return oobInline;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setOobInline(boolean oobInline) {
this.oobInline = oobInline;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public int getSoLinger() {
return soLinger;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setSoLinger(int soLinger) {
this.soLinger = soLinger;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public boolean isTcpNoDelay() {
return tcpNoDelay;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setTcpNoDelay(boolean tcpNoDelay) {
this.tcpNoDelay = tcpNoDelay;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
protected boolean isKeepAliveChanged() {
return keepAlive != DEFAULT_KEEP_ALIVE;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
protected boolean isOobInlineChanged() {
return oobInline != DEFAULT_OOB_INLINE;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
protected boolean isReceiveBufferSizeChanged() {
return receiveBufferSize != -1;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
protected boolean isReuseAddressChanged() {
return reuseAddress != defaultReuseAddress;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
protected boolean isSendBufferSizeChanged() {
return sendBufferSize != -1;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
protected boolean isSoLingerChanged() {
return soLinger != DEFAULT_SO_LINGER;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
protected boolean isTcpNoDelayChanged() {
return tcpNoDelay != DEFAULT_TCP_NO_DELAY;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
protected boolean isTrafficClassChanged() {
return trafficClass != DEFAULT_TRAFFIC_CLASS;
http://git-wip-us.apache.org/repos/asf/mina/blob/8d5cde67/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketSession.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketSession.java b/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketSession.java
index 4a3e93c..2892658 100644
--- a/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketSession.java
+++ b/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketSession.java
@@ -19,6 +19,7 @@
*/
package org.apache.mina.transport.socket.nio;
+import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketException;
@@ -49,10 +50,6 @@ class NioSocketSession extends NioSession {
static final TransportMetadata METADATA = new DefaultTransportMetadata("nio", "socket", false, true,
InetSocketAddress.class, SocketSessionConfig.class, IoBuffer.class, FileRegion.class);
- private Socket getSocket() {
- return ((SocketChannel) channel).socket();
- }
-
/**
*
* Creates a new instance of NioSocketSession.
@@ -64,9 +61,17 @@ class NioSocketSession extends NioSession {
public NioSocketSession(IoService service, IoProcessor<NioSession> processor, SocketChannel channel) {
super(processor, service, channel);
config = new SessionConfigImpl();
- this.config.setAll(service.getSessionConfig());
+ config.setAll(service.getSessionConfig());
+ }
+
+ private Socket getSocket() {
+ return ((SocketChannel) channel).socket();
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public TransportMetadata getTransportMetadata() {
return METADATA;
}
@@ -74,10 +79,14 @@ class NioSocketSession extends NioSession {
/**
* {@inheritDoc}
*/
+ @Override
public SocketSessionConfig getConfig() {
return (SocketSessionConfig) config;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
SocketChannel getChannel() {
return (SocketChannel) channel;
@@ -86,6 +95,7 @@ class NioSocketSession extends NioSession {
/**
* {@inheritDoc}
*/
+ @Override
public InetSocketAddress getRemoteAddress() {
if (channel == null) {
return null;
@@ -103,6 +113,7 @@ class NioSocketSession extends NioSession {
/**
* {@inheritDoc}
*/
+ @Override
public InetSocketAddress getLocalAddress() {
if (channel == null) {
return null;
@@ -117,7 +128,7 @@ class NioSocketSession extends NioSession {
return (InetSocketAddress) socket.getLocalSocketAddress();
}
- protected void destroy(NioSession session) throws Exception {
+ protected void destroy(NioSession session) throws IOException {
ByteChannel ch = session.getChannel();
SelectionKey key = session.getSelectionKey();
if (key != null) {
@@ -131,7 +142,16 @@ class NioSocketSession extends NioSession {
return (InetSocketAddress) super.getServiceAddress();
}
+ /**
+ * A private class storing a copy of the IoService configuration when the IoSession
+ * is created. That allows the session to have its own configuration setting, over
+ * the IoService default one.
+ */
private class SessionConfigImpl extends AbstractSocketSessionConfig {
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public boolean isKeepAlive() {
try {
return getSocket().getKeepAlive();
@@ -140,6 +160,10 @@ class NioSocketSession extends NioSession {
}
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setKeepAlive(boolean on) {
try {
getSocket().setKeepAlive(on);
@@ -148,6 +172,10 @@ class NioSocketSession extends NioSession {
}
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public boolean isOobInline() {
try {
return getSocket().getOOBInline();
@@ -156,6 +184,10 @@ class NioSocketSession extends NioSession {
}
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setOobInline(boolean on) {
try {
getSocket().setOOBInline(on);
@@ -164,6 +196,10 @@ class NioSocketSession extends NioSession {
}
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public boolean isReuseAddress() {
try {
return getSocket().getReuseAddress();
@@ -172,6 +208,10 @@ class NioSocketSession extends NioSession {
}
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setReuseAddress(boolean on) {
try {
getSocket().setReuseAddress(on);
@@ -180,6 +220,10 @@ class NioSocketSession extends NioSession {
}
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public int getSoLinger() {
try {
return getSocket().getSoLinger();
@@ -188,6 +232,10 @@ class NioSocketSession extends NioSession {
}
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setSoLinger(int linger) {
try {
if (linger < 0) {
@@ -200,6 +248,10 @@ class NioSocketSession extends NioSession {
}
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public boolean isTcpNoDelay() {
if (!isConnected()) {
return false;
@@ -212,6 +264,10 @@ class NioSocketSession extends NioSession {
}
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setTcpNoDelay(boolean on) {
try {
getSocket().setTcpNoDelay(on);
@@ -223,6 +279,7 @@ class NioSocketSession extends NioSession {
/**
* {@inheritDoc}
*/
+ @Override
public int getTrafficClass() {
try {
return getSocket().getTrafficClass();
@@ -234,6 +291,7 @@ class NioSocketSession extends NioSession {
/**
* {@inheritDoc}
*/
+ @Override
public void setTrafficClass(int tc) {
try {
getSocket().setTrafficClass(tc);
@@ -242,6 +300,10 @@ class NioSocketSession extends NioSession {
}
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public int getSendBufferSize() {
try {
return getSocket().getSendBufferSize();
@@ -250,6 +312,10 @@ class NioSocketSession extends NioSession {
}
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setSendBufferSize(int size) {
try {
getSocket().setSendBufferSize(size);
@@ -258,6 +324,10 @@ class NioSocketSession extends NioSession {
}
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public int getReceiveBufferSize() {
try {
return getSocket().getReceiveBufferSize();
@@ -266,6 +336,10 @@ class NioSocketSession extends NioSession {
}
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setReceiveBufferSize(int size) {
try {
getSocket().setReceiveBufferSize(size);