BUG-731 : removed more warnings
[bgpcep.git] / pcep / testtool / src / main / java / org / opendaylight / protocol / pcep / testtool / Main.java
index d60f9c9eafd9a1f2fd0135197a49f88b8fda2318..5b1f0625b7cccb189ae81ffe50e4a9a5b30d02da 100644 (file)
@@ -10,6 +10,8 @@ package org.opendaylight.protocol.pcep.testtool;
 import io.netty.channel.nio.NioEventLoopGroup;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
+import java.net.UnknownHostException;
+import java.util.concurrent.ExecutionException;
 import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
 import org.opendaylight.protocol.pcep.ietf.initiated00.Stateful07SessionProposalFactory;
 import org.opendaylight.protocol.pcep.ietf.stateful07.StatefulActivator;
@@ -25,9 +27,9 @@ public final class Main {
     private static final Logger LOG = LoggerFactory.getLogger(Main.class);
 
     public static final String USAGE = "DESCRIPTION:\n"
-            + "\tCreates a server with given parameters. As long as it runs, it accepts connections " + "from PCCs.\n" + "USAGE:\n"
-            + "\t-a, --address\n" + "\t\tthe ip address to which is this server bound.\n"
-            + "\t\tFormat: x.x.x.x:y where y is port number.\n\n" +
+        + "\tCreates a server with given parameters. As long as it runs, it accepts connections " + "from PCCs.\n" + "USAGE:\n"
+        + "\t-a, --address\n" + "\t\tthe ip address to which is this server bound.\n"
+        + "\t\tFormat: x.x.x.x:y where y is port number.\n\n" +
 
             "\t-d, --deadtimer\n" + "\t\tin seconds, value of the desired deadtimer\n"
             + "\t\tAccording to RFC5440, recommended value for deadtimer is 4 times the value\n"
@@ -64,25 +66,28 @@ public final class Main {
 
     }
 
-    public static void main(final String[] args) throws Exception {
+    private static final int KA_TO_DEADTIMER_RATIO = 4;
+
+    private static final int KA_DEFAULT = 30;
+
+    public static void main(final String[] args) throws UnknownHostException, InterruptedException, ExecutionException {
         if (args.length == 0 || (args.length == 1 && args[0].equalsIgnoreCase("--help"))) {
             LOG.info(Main.USAGE);
             return;
         }
 
         InetSocketAddress address = null;
-        int keepAliveValue = 30;
+        int keepAliveValue = KA_DEFAULT;
         int deadTimerValue = 0;
         boolean stateful = false;
         boolean active = false;
-        final boolean versioned = false;
         boolean instant = false;
 
         int i = 0;
         while (i < args.length) {
             if (args[i].equalsIgnoreCase("-a") || args[i].equalsIgnoreCase("--address")) {
                 final String[] ip = args[i + 1].split(":");
-                address = new InetSocketAddress(InetAddress.getByName(ip[0]), Integer.valueOf(ip[1]));
+                address = new InetSocketAddress(InetAddress.getByName(ip[0]), Integer.parseInt(ip[1]));
                 i++;
             } else if (args[i].equalsIgnoreCase("-d") || args[i].equalsIgnoreCase("--deadtimer")) {
                 deadTimerValue = Integer.valueOf(args[i + 1]);
@@ -103,22 +108,23 @@ public final class Main {
             }
             i++;
         }
-        if (deadTimerValue != 0 && deadTimerValue != keepAliveValue * 4) {
+        if (deadTimerValue != 0 && deadTimerValue != keepAliveValue * KA_TO_DEADTIMER_RATIO) {
             LOG.warn("WARNING: The value of DeadTimer should be 4 times the value of KeepAlive.");
         }
         if (deadTimerValue == 0) {
-            deadTimerValue = keepAliveValue * 4;
+            deadTimerValue = keepAliveValue * KA_TO_DEADTIMER_RATIO;
         }
 
         final PCEPSessionProposalFactory spf = new Stateful07SessionProposalFactory(deadTimerValue, keepAliveValue, stateful, active, instant);
 
         final Open prefs = spf.getSessionProposal(address, 0);
 
-        final StatefulActivator activator07 = new StatefulActivator();
-        activator07.start(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance());
+        try (final StatefulActivator activator07 = new StatefulActivator()) {
+            activator07.start(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance());
 
-        final PCEPDispatcherImpl dispatcher = new PCEPDispatcherImpl(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry(), new DefaultPCEPSessionNegotiatorFactory(prefs, 5), new NioEventLoopGroup(), new NioEventLoopGroup());
+            final PCEPDispatcherImpl dispatcher = new PCEPDispatcherImpl(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry(), new DefaultPCEPSessionNegotiatorFactory(prefs, 5), new NioEventLoopGroup(), new NioEventLoopGroup());
 
-        dispatcher.createServer(address, new TestingSessionListenerFactory()).get();
+            dispatcher.createServer(address, new TestingSessionListenerFactory()).get();
+        }
     }
 }