Eliminate use of checkArgument()
[netconf.git] / protocol / netconf-server / src / main / java / org / opendaylight / netconf / server / NetconfServerSessionNegotiatorFactory.java
index cbbcb246eeac482c83ea95887a9f00b97e1c9bad..c93740eb5d998f5466964daf5e3a4535e50e15b8 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.netconf.server;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.Collections2;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Sets;
@@ -18,10 +17,8 @@ import java.net.SocketAddress;
 import java.util.Set;
 import org.checkerframework.checker.index.qual.NonNegative;
 import org.opendaylight.netconf.api.CapabilityURN;
-import org.opendaylight.netconf.api.NetconfSessionListenerFactory;
 import org.opendaylight.netconf.api.messages.HelloMessage;
-import org.opendaylight.netconf.nettyutil.AbstractNetconfSessionNegotiator;
-import org.opendaylight.netconf.nettyutil.NetconfSessionNegotiatorFactory;
+import org.opendaylight.netconf.nettyutil.NetconfSessionNegotiator;
 import org.opendaylight.netconf.server.api.SessionIdProvider;
 import org.opendaylight.netconf.server.api.monitoring.NetconfMonitoringService;
 import org.opendaylight.netconf.server.api.operations.NetconfOperationService;
@@ -31,9 +28,8 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.re
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Capabilities;
 
-public class NetconfServerSessionNegotiatorFactory
-    implements NetconfSessionNegotiatorFactory<NetconfServerSession, NetconfServerSessionListener> {
-
+// non-final for testing and netconf-testtool (for some reason)
+public class NetconfServerSessionNegotiatorFactory {
     public static final Set<String> DEFAULT_BASE_CAPABILITIES = ImmutableSet.of(
         CapabilityURN.BASE,
         CapabilityURN.BASE_1_1,
@@ -61,7 +57,7 @@ public class NetconfServerSessionNegotiatorFactory
             final long connectionTimeoutMillis,  final NetconfMonitoringService monitoringService,
             final Set<String> baseCapabilities) {
         this(timer, netconfOperationProvider, idProvider, connectionTimeoutMillis, monitoringService, baseCapabilities,
-            AbstractNetconfSessionNegotiator.DEFAULT_MAXIMUM_INCOMING_CHUNK_SIZE);
+            NetconfSessionNegotiator.DEFAULT_MAXIMUM_INCOMING_CHUNK_SIZE);
     }
 
     protected NetconfServerSessionNegotiatorFactory(final Timer timer,
@@ -81,10 +77,11 @@ public class NetconfServerSessionNegotiatorFactory
     private static ImmutableSet<String> validateBaseCapabilities(final Set<String> baseCapabilities) {
         // Check base capabilities to be supported by the server
         final var unknownBaseCaps = Sets.difference(baseCapabilities, DEFAULT_BASE_CAPABILITIES);
-        Preconditions.checkArgument(unknownBaseCaps.isEmpty(),
-                "Base capabilities that will be supported by netconf server have to be subset of %s, "
-                        + "unknown base capabilities: %s",
-                DEFAULT_BASE_CAPABILITIES, unknownBaseCaps);
+        if (!unknownBaseCaps.isEmpty()) {
+            throw new IllegalArgumentException(
+                "Base capabilities that will be supported by netconf server have to be subset of "
+                    + DEFAULT_BASE_CAPABILITIES + ", unknown base capabilities: " + unknownBaseCaps);
+        }
 
         return ImmutableSet.<String>builder()
             .addAll(baseCapabilities)
@@ -96,18 +93,12 @@ public class NetconfServerSessionNegotiatorFactory
     /**
      * Get session negotiator.
      *
-     * @param defunctSessionListenerFactory will not be taken into account as session listener factory can
-     *                                      only be created after snapshot is opened, thus this method constructs
-     *                                      proper session listener factory.
      * @param channel                       Underlying channel
      * @param promise                       Promise to be notified
      * @return session negotiator
      */
-    @Deprecated
-    @Override
-    public NetconfServerSessionNegotiator getSessionNegotiator(
-            final NetconfSessionListenerFactory<NetconfServerSessionListener> defunctSessionListenerFactory,
-            final Channel channel, final Promise<NetconfServerSession> promise) {
+    public NetconfServerSessionNegotiator getSessionNegotiator(final Channel channel,
+            final Promise<NetconfServerSession> promise) {
         final var sessionId = idProvider.getNextSessionId();
         final var socketAddress = channel.parent() == null ? null : channel.parent().localAddress();
         final var service = getOperationServiceForAddress(sessionId, socketAddress);