Code Review
/
netconf.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Bump versions to 4.0.0-SNAPSHOT
[netconf.git]
/
restconf
/
restconf-nb-bierman02
/
src
/
main
/
java
/
org
/
opendaylight
/
netconf
/
sal
/
streams
/
websockets
/
WebSocketServer.java
diff --git
a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/streams/websockets/WebSocketServer.java
b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/streams/websockets/WebSocketServer.java
index b8093dcb7a38077f6da9a2646ab5e493f4434f3a..a295c54a3f9351fa37574cd82d7fbb61362d09a8 100644
(file)
--- a/
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/streams/websockets/WebSocketServer.java
+++ b/
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/streams/websockets/WebSocketServer.java
@@
-5,10
+5,12
@@
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.netconf.sal.streams.websockets;
package org.opendaylight.netconf.sal.streams.websockets;
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static java.util.Objects.requireNonNull;
+
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.EventLoopGroup;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.EventLoopGroup;
@@
-54,11
+56,11
@@
public final class WebSocketServer implements Runnable {
}
public static WebSocketServer createInstance(final String address, final int port) {
}
public static WebSocketServer createInstance(final String address, final int port) {
- Preconditions.checkState(instance == null, "createInstance() has already been called");
- Preconditions.checkNotNull(address, "Address cannot be null.");
- Preconditions.checkArgument(port >= 1024, "Privileged port (below 1024) is not allowed");
+ checkState(instance == null, "createInstance() has already been called");
+ checkArgument(port >= 1024, "Privileged port (below 1024) is not allowed");
- instance = new WebSocketServer(address, port);
+ instance = new WebSocketServer(requireNonNull(address, "Address cannot be null."), port);
+ LOG.info("Created WebSocketServer on {}:{}", address, port);
return instance;
}
return instance;
}
@@
-77,8
+79,7
@@
public final class WebSocketServer implements Runnable {
* @return instance of {@link WebSocketServer}
*/
public static WebSocketServer getInstance() {
* @return instance of {@link WebSocketServer}
*/
public static WebSocketServer getInstance() {
- Preconditions.checkNotNull(instance, "createInstance() must be called prior to getInstance()");
- return instance;
+ return requireNonNull(instance, "createInstance() must be called prior to getInstance()");
}
/**
}
/**
@@
-100,13
+101,15
@@
public final class WebSocketServer implements Runnable {
* Destroy the existing instance.
*/
public static void destroyInstance() {
* Destroy the existing instance.
*/
public static void destroyInstance() {
-
Preconditions.
checkState(instance != null, "createInstance() must be called prior to destroyInstance()");
+ checkState(instance != null, "createInstance() must be called prior to destroyInstance()");
instance.stop();
instance = null;
instance.stop();
instance = null;
+ LOG.info("Destroyed WebSocketServer.");
}
@Override
}
@Override
+ @SuppressWarnings("checkstyle:IllegalCatch")
public void run() {
bossGroup = new NioEventLoopGroup();
workerGroup = new NioEventLoopGroup();
public void run() {
bossGroup = new NioEventLoopGroup();
workerGroup = new NioEventLoopGroup();
@@
-121,6
+124,10
@@
public final class WebSocketServer implements Runnable {
channel.closeFuture().sync();
} catch (final InterruptedException e) {
LOG.error("Web socket server encountered an error during startup attempt on port {}", port, e);
channel.closeFuture().sync();
} catch (final InterruptedException e) {
LOG.error("Web socket server encountered an error during startup attempt on port {}", port, e);
+ } catch (Throwable throwable) {
+ // sync() re-throws exceptions declared as Throwable, so the compiler doesn't see them
+ LOG.error("Error while binding to address {}, port {}", address, port, throwable);
+ throw throwable;
} finally {
stop();
}
} finally {
stop();
}