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/12/07 18:51:21 UTC
[2/4] mina git commit: o Added some mising Javadoc o Fixing some
Sonarlint warnings
o Added some mising Javadoc
o Fixing some Sonarlint warnings
Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/37239fd0
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/37239fd0
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/37239fd0
Branch: refs/heads/2.0
Commit: 37239fd01f0483e74e0bfd78abc5aca86dcb48c4
Parents: 9b26714
Author: Emmanuel L�charny <el...@symas.com>
Authored: Wed Dec 7 11:25:25 2016 +0100
Committer: Emmanuel L�charny <el...@symas.com>
Committed: Wed Dec 7 11:25:25 2016 +0100
----------------------------------------------------------------------
.../socket/nio/NioDatagramAcceptor.java | 26 ++++++---
.../socket/nio/NioDatagramConnector.java | 60 +++++++++++++++++++-
.../socket/nio/NioDatagramSession.java | 19 +++++++
.../socket/nio/NioDatagramSessionConfig.java | 12 +++-
4 files changed, 105 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina/blob/37239fd0/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptor.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptor.java b/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptor.java
index 1577ff2..d4c0000 100644
--- a/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptor.java
+++ b/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptor.java
@@ -81,11 +81,11 @@ public final class NioDatagramAcceptor extends AbstractIoAcceptor implements Dat
private final Semaphore lock = new Semaphore(1);
/** A queue used to store the list of pending Binds */
- private final Queue<AcceptorOperationFuture> registerQueue = new ConcurrentLinkedQueue<AcceptorOperationFuture>();
+ private final Queue<AcceptorOperationFuture> registerQueue = new ConcurrentLinkedQueue<>();
- private final Queue<AcceptorOperationFuture> cancelQueue = new ConcurrentLinkedQueue<AcceptorOperationFuture>();
+ private final Queue<AcceptorOperationFuture> cancelQueue = new ConcurrentLinkedQueue<>();
- private final Queue<NioSession> flushingSessions = new ConcurrentLinkedQueue<NioSession>();
+ private final Queue<NioSession> flushingSessions = new ConcurrentLinkedQueue<>();
private final Map<SocketAddress, DatagramChannel> boundHandles = Collections
.synchronizedMap(new HashMap<SocketAddress, DatagramChannel>());
@@ -150,6 +150,7 @@ public final class NioDatagramAcceptor extends AbstractIoAcceptor implements Dat
* the registered handles have been removed (unbound).
*/
private class Acceptor implements Runnable {
+ @Override
public void run() {
int nHandles = 0;
lastIdleCheckTime = System.currentTimeMillis();
@@ -220,7 +221,7 @@ public final class NioDatagramAcceptor extends AbstractIoAcceptor implements Dat
break;
}
- Map<SocketAddress, DatagramChannel> newHandles = new HashMap<SocketAddress, DatagramChannel>();
+ Map<SocketAddress, DatagramChannel> newHandles = new HashMap<>();
List<SocketAddress> localAddresses = req.getLocalAddresses();
try {
@@ -494,6 +495,7 @@ public final class NioDatagramAcceptor extends AbstractIoAcceptor implements Dat
/**
* {@inheritDoc}
*/
+ @Override
public void add(NioSession session) {
// Nothing to do for UDP
}
@@ -538,7 +540,7 @@ public final class NioDatagramAcceptor extends AbstractIoAcceptor implements Dat
// Update the local addresses.
// setLocalAddresses() shouldn't be called from the worker thread
// because of deadlock.
- Set<SocketAddress> newLocalAddresses = new HashSet<SocketAddress>();
+ Set<SocketAddress> newLocalAddresses = new HashSet<>();
for (DatagramChannel handle : boundHandles.values()) {
newLocalAddresses.add(localAddress(handle));
@@ -577,6 +579,7 @@ public final class NioDatagramAcceptor extends AbstractIoAcceptor implements Dat
/**
* {@inheritDoc}
*/
+ @Override
public void flush(NioSession session) {
if (scheduleFlush(session)) {
wakeup();
@@ -596,14 +599,17 @@ public final class NioDatagramAcceptor extends AbstractIoAcceptor implements Dat
/**
* {@inheritDoc}
*/
+ @Override
public DatagramSessionConfig getSessionConfig() {
return (DatagramSessionConfig) sessionConfig;
}
+ @Override
public final IoSessionRecycler getSessionRecycler() {
return sessionRecycler;
}
+ @Override
public TransportMetadata getTransportMetadata() {
return NioDatagramSession.METADATA;
}
@@ -665,6 +671,7 @@ public final class NioDatagramAcceptor extends AbstractIoAcceptor implements Dat
/**
* {@inheritDoc}
*/
+ @Override
public final IoSession newSession(SocketAddress remoteAddress, SocketAddress localAddress) {
if (isDisposing()) {
throw new IllegalStateException("The Acceptor is being disposed.");
@@ -681,9 +688,7 @@ public final class NioDatagramAcceptor extends AbstractIoAcceptor implements Dat
try {
return newSessionWithoutLock(remoteAddress, localAddress);
- } catch (RuntimeException e) {
- throw e;
- } catch (Error e) {
+ } catch (RuntimeException | Error e) {
throw e;
} catch (Exception e) {
throw new RuntimeIoException("Failed to create a session.", e);
@@ -732,6 +737,7 @@ public final class NioDatagramAcceptor extends AbstractIoAcceptor implements Dat
/**
* {@inheritDoc}
*/
+ @Override
public void remove(NioSession session) {
getSessionRecycler().remove(session);
getListeners().fireSessionDestroyed(session);
@@ -753,6 +759,7 @@ public final class NioDatagramAcceptor extends AbstractIoAcceptor implements Dat
return ((DatagramChannel) session.getChannel()).send(buffer.buf(), remoteAddress);
}
+ @Override
public void setDefaultLocalAddress(InetSocketAddress localAddress) {
setDefaultLocalAddress((SocketAddress) localAddress);
}
@@ -775,6 +782,7 @@ public final class NioDatagramAcceptor extends AbstractIoAcceptor implements Dat
key.interestOps(newInterestOps);
}
+ @Override
public final void setSessionRecycler(IoSessionRecycler sessionRecycler) {
synchronized (bindLock) {
if (isActive()) {
@@ -810,6 +818,7 @@ public final class NioDatagramAcceptor extends AbstractIoAcceptor implements Dat
/**
* {@inheritDoc}
*/
+ @Override
public void updateTrafficControl(NioSession session) {
throw new UnsupportedOperationException();
}
@@ -821,6 +830,7 @@ public final class NioDatagramAcceptor extends AbstractIoAcceptor implements Dat
/**
* {@inheritDoc}
*/
+ @Override
public void write(NioSession session, WriteRequest writeRequest) {
// We will try to write the message directly
long currentTime = System.currentTimeMillis();
http://git-wip-us.apache.org/repos/asf/mina/blob/37239fd0/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramConnector.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramConnector.java b/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramConnector.java
index 9da09de..c101448 100644
--- a/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramConnector.java
+++ b/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramConnector.java
@@ -93,35 +93,56 @@ DatagramConnector {
*
* @param processorClass the processor class.
* @see SimpleIoProcessorPool#SimpleIoProcessorPool(Class, Executor, int, java.nio.channels.spi.SelectorProvider)
- * @see org.apache.mina.core.service.SimpleIoProcessorPool#DEFAULT_SIZE
* @since 2.0.0-M4
*/
public NioDatagramConnector(Class<? extends IoProcessor<NioSession>> processorClass) {
super(new DefaultDatagramSessionConfig(), processorClass);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public TransportMetadata getTransportMetadata() {
return NioDatagramSession.METADATA;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public DatagramSessionConfig getSessionConfig() {
return (DatagramSessionConfig) sessionConfig;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public InetSocketAddress getDefaultRemoteAddress() {
return (InetSocketAddress) super.getDefaultRemoteAddress();
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setDefaultRemoteAddress(InetSocketAddress defaultRemoteAddress) {
super.setDefaultRemoteAddress(defaultRemoteAddress);
}
+ /**
+ @Override
+ * {@inheritDoc}
+ */
@Override
protected void init() throws Exception {
// Do nothing
}
+ /**
+ * {@inheritDoc}
+ */
@Override
protected DatagramChannel newHandle(SocketAddress localAddress) throws Exception {
DatagramChannel ch = DatagramChannel.open();
@@ -155,12 +176,18 @@ DatagramConnector {
}
}
+ /**
+ * {@inheritDoc}
+ */
@Override
protected boolean connect(DatagramChannel handle, SocketAddress remoteAddress) throws Exception {
handle.connect(remoteAddress);
return true;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
protected NioSession newSession(IoProcessor<NioSession> processor, DatagramChannel handle) {
NioSession session = new NioDatagramSession(this, handle, processor);
@@ -168,50 +195,77 @@ DatagramConnector {
return session;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
protected void close(DatagramChannel handle) throws Exception {
handle.disconnect();
handle.close();
}
+ /**
+ * {@inheritDoc}
+ */
// Unused extension points.
@Override
@SuppressWarnings("unchecked")
protected Iterator<DatagramChannel> allHandles() {
- return Collections.EMPTY_LIST.iterator();
+ return Collections.emptyIterator();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
protected ConnectionRequest getConnectionRequest(DatagramChannel handle) {
throw new UnsupportedOperationException();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
protected void destroy() throws Exception {
// Do nothing
}
+ /**
+ * {@inheritDoc}
+ */
@Override
protected boolean finishConnect(DatagramChannel handle) throws Exception {
throw new UnsupportedOperationException();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
protected void register(DatagramChannel handle, ConnectionRequest request) throws Exception {
throw new UnsupportedOperationException();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
protected int select(int timeout) throws Exception {
return 0;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
@SuppressWarnings("unchecked")
protected Iterator<DatagramChannel> selectedHandles() {
- return Collections.EMPTY_LIST.iterator();
+ return Collections.emptyIterator();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
protected void wakeup() {
// Do nothing
http://git-wip-us.apache.org/repos/asf/mina/blob/37239fd0/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramSession.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramSession.java b/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramSession.java
index 9ca2ba3..180ddfc 100644
--- a/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramSession.java
+++ b/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramSession.java
@@ -66,27 +66,46 @@ class NioDatagramSession extends NioSession {
/**
* {@inheritDoc}
*/
+ @Override
public DatagramSessionConfig getConfig() {
return (DatagramSessionConfig) config;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
DatagramChannel getChannel() {
return (DatagramChannel) channel;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public TransportMetadata getTransportMetadata() {
return METADATA;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public InetSocketAddress getRemoteAddress() {
return remoteAddress;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public InetSocketAddress getLocalAddress() {
return localAddress;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public InetSocketAddress getServiceAddress() {
return (InetSocketAddress) super.getServiceAddress();
http://git-wip-us.apache.org/repos/asf/mina/blob/37239fd0/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramSessionConfig.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramSessionConfig.java b/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramSessionConfig.java
index 552feaf..94df01e 100644
--- a/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramSessionConfig.java
+++ b/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramSessionConfig.java
@@ -54,6 +54,7 @@ class NioDatagramSessionConfig extends AbstractDatagramSessionConfig {
*
* @see DatagramSocket#getReceiveBufferSize()
*/
+ @Override
public int getReceiveBufferSize() {
try {
return channel.socket().getReceiveBufferSize();
@@ -72,8 +73,9 @@ class NioDatagramSessionConfig extends AbstractDatagramSessionConfig {
* @throws RuntimeIoException if the socket is closed or if we
* had a SocketException
*
- * @see DatagramSocket#setReceiveBufferSize()
+ * @see DatagramSocket#setReceiveBufferSize(int)
*/
+ @Override
public void setReceiveBufferSize(int receiveBufferSize) {
try {
channel.socket().setReceiveBufferSize(receiveBufferSize);
@@ -89,6 +91,7 @@ class NioDatagramSessionConfig extends AbstractDatagramSessionConfig {
* @throws RuntimeIoException If the socket is closed or if we get an
* {@link SocketException}
*/
+ @Override
public boolean isBroadcast() {
try {
return channel.socket().getBroadcast();
@@ -97,6 +100,7 @@ class NioDatagramSessionConfig extends AbstractDatagramSessionConfig {
}
}
+ @Override
public void setBroadcast(boolean broadcast) {
try {
channel.socket().setBroadcast(broadcast);
@@ -110,6 +114,7 @@ class NioDatagramSessionConfig extends AbstractDatagramSessionConfig {
* @throws RuntimeIoException If the socket is closed or if we get an
* {@link SocketException}
*/
+ @Override
public int getSendBufferSize() {
try {
return channel.socket().getSendBufferSize();
@@ -123,6 +128,7 @@ class NioDatagramSessionConfig extends AbstractDatagramSessionConfig {
* @throws RuntimeIoException If the socket is closed or if we get an
* {@link SocketException}
*/
+ @Override
public void setSendBufferSize(int sendBufferSize) {
try {
channel.socket().setSendBufferSize(sendBufferSize);
@@ -138,6 +144,7 @@ class NioDatagramSessionConfig extends AbstractDatagramSessionConfig {
* @throws RuntimeIoException If the socket is closed or if we get an
* {@link SocketException}
*/
+ @Override
public boolean isReuseAddress() {
try {
return channel.socket().getReuseAddress();
@@ -151,6 +158,7 @@ class NioDatagramSessionConfig extends AbstractDatagramSessionConfig {
* @throws RuntimeIoException If the socket is closed or if we get an
* {@link SocketException}
*/
+ @Override
public void setReuseAddress(boolean reuseAddress) {
try {
channel.socket().setReuseAddress(reuseAddress);
@@ -168,6 +176,7 @@ class NioDatagramSessionConfig extends AbstractDatagramSessionConfig {
* @throws RuntimeIoException If the socket is closed or if we get an
* {@link SocketException}
*/
+ @Override
public int getTrafficClass() {
try {
return channel.socket().getTrafficClass();
@@ -181,6 +190,7 @@ class NioDatagramSessionConfig extends AbstractDatagramSessionConfig {
* @throws RuntimeIoException If the socket is closed or if we get an
* {@link SocketException}
*/
+ @Override
public void setTrafficClass(int trafficClass) {
try {
channel.socket().setTrafficClass(trafficClass);