Fix Logger use
[openflowjava.git] / simple-client / src / main / java / org / opendaylight / openflowjava / protocol / impl / clients / SimpleClient.java
index b85b6b0e8a5ff8bca0d85e1a56e522f02518684d..5e98e3d601ad5c7d9ed731b48ba0d37a15dbe549 100644 (file)
@@ -1,4 +1,11 @@
- /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */
+/*
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.openflowjava.protocol.impl.clients;
 
 import io.netty.bootstrap.Bootstrap;
@@ -20,7 +27,7 @@ import com.google.common.util.concurrent.SettableFuture;
  *
  * @author michal.polkorab
  */
-public class SimpleClient extends Thread {
+public class SimpleClient implements OFClient {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(SimpleClient.class);
     private final String host;
@@ -29,9 +36,8 @@ public class SimpleClient extends Thread {
     private EventLoopGroup group;
     private SettableFuture<Boolean> isOnlineFuture;
     private SettableFuture<Boolean> scenarioDone;
-    private SimpleClientInitializer clientInitializer;
     private ScenarioHandler scenarioHandler;
-    
+
     /**
      * Constructor of class
      *
@@ -48,14 +54,14 @@ public class SimpleClient extends Thread {
         isOnlineFuture = SettableFuture.create();
         scenarioDone = SettableFuture.create();
     }
-    
+
     /**
      * Starting class of {@link SimpleClient}
      */
     @Override
     public void run() {
         group = new NioEventLoopGroup();
-        clientInitializer = new SimpleClientInitializer(isOnlineFuture, securedClient);
+        SimpleClientInitializer clientInitializer = new SimpleClientInitializer(isOnlineFuture, securedClient);
         clientInitializer.setScenario(scenarioHandler);
         try {
             Bootstrap b = new Bootstrap();
@@ -67,15 +73,17 @@ public class SimpleClient extends Thread {
 
             synchronized (scenarioHandler) {
                 LOGGER.debug("WAITING FOR SCENARIO");
-                scenarioHandler.wait();
+                while (! scenarioHandler.isScenarioFinished()) {
+                    scenarioHandler.wait();
+                }
             }
         } catch (Exception ex) {
             LOGGER.error(ex.getMessage(), ex);
         } finally {
-            LOGGER.info("shutting down");
+            LOGGER.debug("shutting down");
             try {
                 group.shutdownGracefully().get();
-                LOGGER.info("shutdown succesful");
+                LOGGER.debug("shutdown succesful");
             } catch (InterruptedException | ExecutionException e) {
                 LOGGER.error(e.getMessage(), e);
             }
@@ -91,9 +99,7 @@ public class SimpleClient extends Thread {
         return group.shutdownGracefully();
     }
 
-    /**
-     * @param securedClient
-     */
+    @Override
     public void setSecuredClient(boolean securedClient) {
         this.securedClient = securedClient;
     }
@@ -109,8 +115,7 @@ public class SimpleClient extends Thread {
         int port;
         SimpleClient sc;
         if (args.length != 3) {
-            LOGGER.error("Usage: " + SimpleClient.class.getSimpleName()
-                    + " <host> <port> <secured>");
+            LOGGER.error("Usage: {} <host> <port> <secured>", SimpleClient.class.getSimpleName());
             LOGGER.error("Trying to use default setting.");
             InetAddress ia = InetAddress.getLocalHost();
             InetAddress[] all = InetAddress.getAllByName(ia.getHostName());
@@ -124,28 +129,21 @@ public class SimpleClient extends Thread {
             sc = new SimpleClient(host, port);
             sc.setSecuredClient(Boolean.parseBoolean(args[2]));
         }
-        sc.start();
-        
+        sc.run();
     }
-    
-    /**
-     * @return the isOnlineFuture
-     */
+
+    @Override
     public SettableFuture<Boolean> getIsOnlineFuture() {
         return isOnlineFuture;
     }
-    
-    /**
-     * @return the scenarioDone
-     */
+
+    @Override
     public SettableFuture<Boolean> getScenarioDone() {
         return scenarioDone;
     }
-    
-    /**
-     * @param scenario list of wanted actions
-     */
+
+    @Override
     public void setScenarioHandler(ScenarioHandler scenario) {
         this.scenarioHandler = scenario;
     }
-}
\ No newline at end of file
+}