X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=simple-client%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowjava%2Fprotocol%2Fimpl%2Fclients%2FSimpleClient.java;h=5e98e3d601ad5c7d9ed731b48ba0d37a15dbe549;hb=272138f7081efbd9796a2a661c92c88727935235;hp=b85b6b0e8a5ff8bca0d85e1a56e522f02518684d;hpb=e5993fc9334ad0f8fa7c4b69f5abfb241f515e9b;p=openflowjava.git diff --git a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClient.java b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClient.java index b85b6b0e..5e98e3d6 100644 --- a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClient.java +++ b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClient.java @@ -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 isOnlineFuture; private SettableFuture 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() - + " "); + LOGGER.error("Usage: {} ", 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 getIsOnlineFuture() { return isOnlineFuture; } - - /** - * @return the scenarioDone - */ + + @Override public SettableFuture getScenarioDone() { return scenarioDone; } - - /** - * @param scenario list of wanted actions - */ + + @Override public void setScenarioHandler(ScenarioHandler scenario) { this.scenarioHandler = scenario; } -} \ No newline at end of file +}