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 2013/06/06 15:41:17 UTC
git commit: removed IOException for bind/unbind
Updated Branches:
refs/heads/trunk c7791be78 -> c885df4b7
removed IOException for bind/unbind
Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/c885df4b
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/c885df4b
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/c885df4b
Branch: refs/heads/trunk
Commit: c885df4b7e8eac97e12de2316e81945284315170
Parents: c7791be
Author: jvermillard <jv...@apache.org>
Authored: Thu Jun 6 15:33:33 2013 +0200
Committer: jvermillard <jv...@apache.org>
Committed: Thu Jun 6 15:33:33 2013 +0200
----------------------------------------------------------------------
.../main/java/org/apache/mina/api/IoServer.java | 11 +--
.../apache/mina/transport/bio/BioUdpServer.java | 51 +++++++++------
.../apache/mina/transport/nio/NioTcpServer.java | 30 ++++++---
.../apache/mina/transport/nio/NioUdpServer.java | 28 +++++---
4 files changed, 71 insertions(+), 49 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina/blob/c885df4b/core/src/main/java/org/apache/mina/api/IoServer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mina/api/IoServer.java b/core/src/main/java/org/apache/mina/api/IoServer.java
index 7ed47e0..7f55838 100644
--- a/core/src/main/java/org/apache/mina/api/IoServer.java
+++ b/core/src/main/java/org/apache/mina/api/IoServer.java
@@ -19,7 +19,6 @@
*/
package org.apache.mina.api;
-import java.io.IOException;
import java.net.SocketAddress;
/**
@@ -37,24 +36,20 @@ public interface IoServer {
/**
* Binds to the specified local addresses and start to accept incoming connections.
- *
- * @throws IOException if failed to bind
*/
- void bind(SocketAddress localAddress) throws IOException;
+ void bind(SocketAddress localAddress);
/**
* Binds the server to the specified port.
*
* @param port the local TCP port to bind.
- * @throws IOException if failed to bind.
*/
- void bind(int port) throws IOException;
+ void bind(int port);
/**
* Unbinds from the local addresses that this service is bound to and stops to accept incoming connections. This
* method returns silently if no local address is bound yet.
*
- * @throws IOException if failed to unbind
*/
- void unbind() throws IOException;
+ void unbind();
}
http://git-wip-us.apache.org/repos/asf/mina/blob/c885df4b/core/src/main/java/org/apache/mina/transport/bio/BioUdpServer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mina/transport/bio/BioUdpServer.java b/core/src/main/java/org/apache/mina/transport/bio/BioUdpServer.java
index d3d617b..b10b578 100644
--- a/core/src/main/java/org/apache/mina/transport/bio/BioUdpServer.java
+++ b/core/src/main/java/org/apache/mina/transport/bio/BioUdpServer.java
@@ -31,6 +31,7 @@ import java.util.concurrent.ConcurrentHashMap;
import org.apache.mina.api.IdleStatus;
import org.apache.mina.api.IoFuture;
import org.apache.mina.api.IoSession;
+import org.apache.mina.api.MinaRuntimeException;
import org.apache.mina.service.executor.IoHandlerExecutor;
import org.apache.mina.service.idlechecker.IdleChecker;
import org.apache.mina.service.idlechecker.IndexedIdleChecker;
@@ -90,36 +91,40 @@ public class BioUdpServer extends AbstractUdpServer {
}
@Override
- public void bind(SocketAddress localAddress) throws IOException {
+ public void bind(SocketAddress localAddress) {
LOG.info("binding to address {}", localAddress);
if (bound) {
throw new IllegalStateException("already bound");
}
boundAddress = localAddress;
- channel = DatagramChannel.open();
- channel.socket().bind(localAddress);
- Boolean reuseAddress = config.isReuseAddress();
+ try {
+ channel = DatagramChannel.open();
+ channel.socket().bind(localAddress);
+ Boolean reuseAddress = config.isReuseAddress();
- if (reuseAddress != null) {
- channel.socket().setReuseAddress(reuseAddress);
- }
+ if (reuseAddress != null) {
+ channel.socket().setReuseAddress(reuseAddress);
+ }
- Integer readBufferSize = config.getReadBufferSize();
+ Integer readBufferSize = config.getReadBufferSize();
- if (readBufferSize != null) {
- channel.socket().setReceiveBufferSize(readBufferSize);
- }
+ if (readBufferSize != null) {
+ channel.socket().setReceiveBufferSize(readBufferSize);
+ }
- Integer sendBufferSize = config.getSendBufferSize();
+ Integer sendBufferSize = config.getSendBufferSize();
- if (sendBufferSize != null) {
- channel.socket().setSendBufferSize(sendBufferSize);
- }
+ if (sendBufferSize != null) {
+ channel.socket().setSendBufferSize(sendBufferSize);
+ }
- Integer trafficClass = config.getTrafficClass();
+ Integer trafficClass = config.getTrafficClass();
- if (trafficClass != null) {
- channel.socket().setTrafficClass(trafficClass);
+ if (trafficClass != null) {
+ channel.socket().setTrafficClass(trafficClass);
+ }
+ } catch (IOException e) {
+ throw new MinaRuntimeException("Can't open and configure a new udp socket", e);
}
worker = new Worker();
@@ -129,18 +134,22 @@ public class BioUdpServer extends AbstractUdpServer {
}
@Override
- public void bind(int port) throws IOException {
+ public void bind(int port) {
bind(new InetSocketAddress(port));
}
@Override
- public void unbind() throws IOException {
+ public void unbind() {
if (!bound) {
throw new IllegalStateException("not bound");
}
bound = false;
try {
- channel.close();
+ try {
+ channel.close();
+ } catch (IOException e) {
+ throw new MinaRuntimeException("can't unbind the udp channel", e);
+ }
boundAddress = null;
idleChecker.destroy();
worker.join();
http://git-wip-us.apache.org/repos/asf/mina/blob/c885df4b/core/src/main/java/org/apache/mina/transport/nio/NioTcpServer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mina/transport/nio/NioTcpServer.java b/core/src/main/java/org/apache/mina/transport/nio/NioTcpServer.java
index 7842770..2031a08 100644
--- a/core/src/main/java/org/apache/mina/transport/nio/NioTcpServer.java
+++ b/core/src/main/java/org/apache/mina/transport/nio/NioTcpServer.java
@@ -28,6 +28,7 @@ import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import org.apache.mina.api.IdleStatus;
+import org.apache.mina.api.MinaRuntimeException;
import org.apache.mina.service.executor.IoHandlerExecutor;
import org.apache.mina.service.executor.OrderedHandlerExecutor;
import org.apache.mina.service.idlechecker.IdleChecker;
@@ -161,7 +162,7 @@ public class NioTcpServer extends AbstractTcpServer implements SelectorListener
* {@inheritDoc}
*/
@Override
- public void bind(final int port) throws IOException {
+ public void bind(final int port) {
bind(new InetSocketAddress(port));
}
@@ -169,21 +170,25 @@ public class NioTcpServer extends AbstractTcpServer implements SelectorListener
* {@inheritDoc}
*/
@Override
- public synchronized void bind(final SocketAddress localAddress) throws IOException {
+ public synchronized void bind(final SocketAddress localAddress) {
Assert.assertNotNull(localAddress, "localAddress");
// check if the address is already bound
if (this.address != null) {
- throw new IOException("address " + address + " already bound");
+ throw new IllegalStateException("address " + address + " already bound");
}
LOG.info("binding address {}", localAddress);
this.address = localAddress;
- serverChannel = ServerSocketChannel.open();
- serverChannel.socket().setReuseAddress(isReuseAddress());
- serverChannel.socket().bind(address);
- serverChannel.configureBlocking(false);
+ try {
+ serverChannel = ServerSocketChannel.open();
+ serverChannel.socket().setReuseAddress(isReuseAddress());
+ serverChannel.socket().bind(address);
+ serverChannel.configureBlocking(false);
+ } catch (IOException e) {
+ throw new MinaRuntimeException("can't bind address" + address, e);
+ }
acceptSelectorLoop.register(true, false, false, false, this, serverChannel, null);
@@ -206,13 +211,18 @@ public class NioTcpServer extends AbstractTcpServer implements SelectorListener
* {@inheritDoc}
*/
@Override
- public synchronized void unbind() throws IOException {
+ public synchronized void unbind() {
LOG.info("unbinding {}", address);
if (this.address == null) {
throw new IllegalStateException("server not bound");
}
- serverChannel.socket().close();
- serverChannel.close();
+ try {
+ serverChannel.socket().close();
+ serverChannel.close();
+ } catch (IOException e) {
+ throw new MinaRuntimeException("can't unbind server", e);
+ }
+
acceptSelectorLoop.unregister(this, serverChannel);
this.address = null;
http://git-wip-us.apache.org/repos/asf/mina/blob/c885df4b/core/src/main/java/org/apache/mina/transport/nio/NioUdpServer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mina/transport/nio/NioUdpServer.java b/core/src/main/java/org/apache/mina/transport/nio/NioUdpServer.java
index 9d3475c..62cf520 100644
--- a/core/src/main/java/org/apache/mina/transport/nio/NioUdpServer.java
+++ b/core/src/main/java/org/apache/mina/transport/nio/NioUdpServer.java
@@ -31,6 +31,7 @@ import java.util.concurrent.ConcurrentHashMap;
import org.apache.mina.api.IdleStatus;
import org.apache.mina.api.IoFuture;
import org.apache.mina.api.IoSession;
+import org.apache.mina.api.MinaRuntimeException;
import org.apache.mina.service.executor.IoHandlerExecutor;
import org.apache.mina.service.executor.OrderedHandlerExecutor;
import org.apache.mina.service.idlechecker.IdleChecker;
@@ -136,7 +137,7 @@ public class NioUdpServer extends AbstractUdpServer implements SelectorListener
* {@inheritDoc}
*/
@Override
- public void bind(final int port) throws IOException {
+ public void bind(final int port) {
bind(new InetSocketAddress(port));
}
@@ -144,7 +145,7 @@ public class NioUdpServer extends AbstractUdpServer implements SelectorListener
* {@inheritDoc}
*/
@Override
- public void bind(final SocketAddress localAddress) throws IOException {
+ public void bind(final SocketAddress localAddress) {
if (localAddress == null) {
// We should at least have one address to bind on
throw new IllegalArgumentException("LocalAdress cannot be null");
@@ -152,17 +153,20 @@ public class NioUdpServer extends AbstractUdpServer implements SelectorListener
// check if the address is already bound
if (this.address != null) {
- throw new IOException("address " + address + " already bound");
+ throw new IllegalStateException("address " + address + " already bound");
}
address = localAddress;
LOG.info("binding address {}", localAddress);
- datagramChannel = DatagramChannel.open();
-
- datagramChannel.socket().setReuseAddress(isReuseAddress());
- datagramChannel.socket().bind(address);
- datagramChannel.configureBlocking(false);
+ try {
+ datagramChannel = DatagramChannel.open();
+ datagramChannel.socket().setReuseAddress(isReuseAddress());
+ datagramChannel.socket().bind(address);
+ datagramChannel.configureBlocking(false);
+ } catch (IOException e) {
+ throw new MinaRuntimeException("can't open the address " + address, e);
+ }
readSelectorLoop.register(false, false, true, false, this, datagramChannel, null);
@@ -179,7 +183,7 @@ public class NioUdpServer extends AbstractUdpServer implements SelectorListener
* {@inheritDoc}
*/
@Override
- public void unbind() throws IOException {
+ public void unbind() {
LOG.info("unbinding {}", address);
if (this.address == null) {
throw new IllegalStateException("server not bound");
@@ -187,7 +191,11 @@ public class NioUdpServer extends AbstractUdpServer implements SelectorListener
readSelectorLoop.unregister(this, datagramChannel);
datagramChannel.socket().close();
- datagramChannel.close();
+ try {
+ datagramChannel.close();
+ } catch (IOException e) {
+ throw new MinaRuntimeException("can't close the datagram socket", e);
+ }
this.address = null;
this.fireServiceInactivated();