summary |
shortlog |
log |
commit | commitdiff |
review |
tree
raw |
patch |
inline | side by side (from parent 1:
3e3f54e)
It is good pratice to handle specific exceptions rather than using the
catch all generic Exception.
This code change handles the java.net.BindException such that if an port
is already in use we skip creating the simulated device on that port.
IOException will display the failure message and exception and not cause
additional attempts.
Change-Id: I7cbf3aa7016b0589f8fdd3f6476006954068a9a0
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.management.ManagementFactory;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.management.ManagementFactory;
+import java.net.BindException;
import java.net.Inet4Address;
import java.net.InetSocketAddress;
import java.net.URI;
import java.net.Inet4Address;
import java.net.InetSocketAddress;
import java.net.URI;
final SshProxyServer sshServer = new SshProxyServer(minaTimerExecutor, nettyThreadgroup, nioExecutor);
sshServer.bind(getSshConfiguration(bindingAddress, tcpLocalAddress));
sshWrappers.add(sshServer);
final SshProxyServer sshServer = new SshProxyServer(minaTimerExecutor, nettyThreadgroup, nioExecutor);
sshServer.bind(getSshConfiguration(bindingAddress, tcpLocalAddress));
sshWrappers.add(sshServer);
- } catch (final Exception e) {
- LOG.warn("Cannot start simulated device on {}, skipping", address, e);
+ } catch (final BindException e) {
+ LOG.warn("Cannot start simulated device on {}, port already in use. Skipping.", address);
// Close local server and continue
server.cancel(true);
if(server.isDone()) {
server.channel().close();
}
continue;
// Close local server and continue
server.cancel(true);
if(server.isDone()) {
server.channel().close();
}
continue;
+ } catch (final IOException e) {
+ LOG.warn("Cannot start simulated device on {} due to IOException.", address, e);
+ break;
} finally {
currentPort++;
}
} finally {
currentPort++;
}