- /* 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;
*
* @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;
private EventLoopGroup group;
private SettableFuture<Boolean> isOnlineFuture;
private SettableFuture<Boolean> scenarioDone;
- private SimpleClientInitializer clientInitializer;
private ScenarioHandler scenarioHandler;
-
+
/**
* Constructor of class
*
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();
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);
}
return group.shutdownGracefully();
}
- /**
- * @param securedClient
- */
+ @Override
public void setSecuredClient(boolean securedClient) {
this.securedClient = securedClient;
}
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());
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
+}