* 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.core;
import com.google.common.util.concurrent.ListenableFuture;
*/
public interface OnlineProvider {
- ListenableFuture<Boolean> getIsOnlineFuture();
+ ListenableFuture<Void> getIsOnlineFuture();
}
@Override
@SuppressWarnings("checkstyle:IllegalCatch")
- public ListenableFuture<Boolean> startup() {
+ public ListenableFuture<Void> startup() {
LOG.debug("Startup summoned");
try {
serverFacade = createAndConfigureServer();
* @author martin.uhlir
*/
public class TcpConnectionInitializer implements ServerFacade, ConnectionInitializer {
-
private static final Logger LOG = LoggerFactory.getLogger(TcpConnectionInitializer.class);
+ private final SettableFuture<Void> hasRun = SettableFuture.create();
private final EventLoopGroup workerGroup;
private final boolean isEpollEnabled;
- private final SettableFuture<Boolean> hasRun = SettableFuture.create();
private TcpChannelInitializer channelInitializer;
private Bootstrap bootstrap;
} else {
bootstrap.group(workerGroup).channel(NioSocketChannel.class).handler(channelInitializer);
}
- hasRun.set(true);
+ hasRun.set(null);
}
@Override
public ListenableFuture<Boolean> shutdown() {
- final SettableFuture<Boolean> result = SettableFuture.create();
+ final var result = SettableFuture.<Boolean>create();
workerGroup.shutdownGracefully();
return result;
}
@Override
- public ListenableFuture<Boolean> getIsOnlineFuture() {
+ public ListenableFuture<Void> getIsOnlineFuture() {
return hasRun;
}
private static final Logger LOG = LoggerFactory.getLogger(TcpHandler.class);
- private int port;
- private String address;
+ private final SettableFuture<Void> isOnlineFuture = SettableFuture.create();
private final InetAddress startupAddress;
private final Runnable readyRunnable;
+
+ private int port;
+ private String address;
private EventLoopGroup workerGroup;
private EventLoopGroup bossGroup;
- private final SettableFuture<Boolean> isOnlineFuture = SettableFuture.create();
private TcpChannelInitializer channelInitializer;
LOG.debug("address from tcphandler: {}", address);
LOG.info("Switch listener started and ready to accept incoming tcp/tls connections on port: {}", port);
readyRunnable.run();
- isOnlineFuture.set(true);
+ isOnlineFuture.set(null);
// This waits until this channel is closed, and rethrows the cause of the failure if this future failed.
f.channel().closeFuture().sync();
}
@Override
- public ListenableFuture<Boolean> getIsOnlineFuture() {
+ public ListenableFuture<Void> getIsOnlineFuture() {
return isOnlineFuture;
}
* @author michal.polkorab
*/
public final class UdpHandler implements ServerFacade {
-
private static final Logger LOG = LoggerFactory.getLogger(UdpHandler.class);
- private int port;
- private EventLoopGroup group;
+ private final SettableFuture<Void> isOnlineFuture = SettableFuture.create();
private final InetAddress startupAddress;
private final Runnable readyRunnable;
- private final SettableFuture<Boolean> isOnlineFuture = SettableFuture.create();
+ private int port;
+ private EventLoopGroup group;
private UdpChannelInitializer channelInitializer;
private Class<? extends DatagramChannel> datagramChannelClass;
LOG.debug("Address from udpHandler: {}", address);
LOG.info("Switch listener started and ready to accept incoming udp connections on port: {}", port);
readyRunnable.run();
- isOnlineFuture.set(true);
+ isOnlineFuture.set(null);
// This waits until this channel is closed, and rethrows the cause of the failure if this future failed.
f.channel().closeFuture().sync();
}
@Override
- public ListenableFuture<Boolean> getIsOnlineFuture() {
+ public ListenableFuture<Void> getIsOnlineFuture() {
return isOnlineFuture;
}
int serverPort = 28001;
Socket firstBinder = new Socket();
- try {
+ try (firstBinder) {
firstBinder.bind(new InetSocketAddress(serverAddress, serverPort));
tcpHandler = new TcpHandler(serverAddress, serverPort, () -> { });
tcpHandler.setChannelInitializer(mockChannelInitializer);
tcpHandler.initiateEventLoopGroups(null, false);
tcpHandler.run();
- } finally {
- firstBinder.close();
}
}
int serverPort = 28001;
Socket firstBinder = new Socket();
- try {
+ try (firstBinder) {
firstBinder.bind(new InetSocketAddress(serverAddress, serverPort));
tcpHandler = new TcpHandler(serverAddress, serverPort, () -> { });
fail("Expected BindException or Errors.NativeIoException");
} catch (BindException | Errors.NativeIoException e) {
// expected
- } finally {
- firstBinder.close();
}
}
assertEquals("shutdown failed", true, shutdownRet.get());
}
- private Boolean startupServer(boolean isEpollEnabled) throws InterruptedException {
- ListenableFuture<Boolean> online = tcpHandler.getIsOnlineFuture();
+ private Boolean startupServer(final boolean isEpollEnabled) throws InterruptedException {
+ final var online = tcpHandler.getIsOnlineFuture();
/**
* Test EPoll based native transport if isEpollEnabled is true.
* Else use Nio based transport.
while (online.isDone() != true && retry++ < 20) {
Thread.sleep(100);
}
- return online.isDone() ;
+ return online.isDone();
}
- private static Boolean clientConnection(int port) throws IOException {
+ private static Boolean clientConnection(final int port) throws IOException {
// Connect, and disconnect
Socket socket = new Socket(InetAddress.getLoopbackAddress(), port);
Boolean result = socket.isConnected();
*/
package org.opendaylight.openflowjava.protocol.impl.core.connection;
-import com.google.common.util.concurrent.ListenableFuture;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;
import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
-import org.opendaylight.openflowjava.protocol.impl.core.ServerFacade;
import org.opendaylight.openflowjava.protocol.impl.core.SwitchConnectionProviderImpl;
import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.ExperimenterActionSubType;
@Test
public void testServerFacade() throws UnknownHostException {
startUp(TransportProtocol.TCP);
- final ListenableFuture<Boolean> future = provider.startup();
- final ServerFacade serverFacade = provider.getServerFacade();
- Assert.assertNotNull("Wrong -- getServerFacade return null",serverFacade);
+ final var future = provider.startup();
+ final var serverFacade = provider.getServerFacade();
+ assertNotNull("Wrong -- getServerFacade return null", serverFacade);
}
/**
@Test
public void testUnregisterWrongKeys() throws UnknownHostException {
startUp(TransportProtocol.TCP);
- final ExperimenterInstructionSerializerKey testSerKey
- = new ExperimenterInstructionSerializerKey(EncodeConstants.OF_VERSION_1_0, 42L);
- Assert.assertFalse("Wrong -- unregisterSerializer",provider.unregisterSerializer(testSerKey));
- final ExperimenterInstructionDeserializerKey tesDeserKey
- = new ExperimenterInstructionDeserializerKey(EncodeConstants.OF_VERSION_1_0, 24L);
- Assert.assertFalse("Wrong -- unregisterDeserializer",provider.unregisterDeserializer(tesDeserKey));
+ final var testSerKey = new ExperimenterInstructionSerializerKey(EncodeConstants.OF_VERSION_1_0, 42L);
+ assertFalse("Wrong -- unregisterSerializer",provider.unregisterSerializer(testSerKey));
+ final var tesDeserKey = new ExperimenterInstructionDeserializerKey(EncodeConstants.OF_VERSION_1_0, 24L);
+ assertFalse("Wrong -- unregisterDeserializer",provider.unregisterDeserializer(tesDeserKey));
}
/**
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
-import com.google.common.util.concurrent.ListenableFuture;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;
@Test
public void testStartup1() throws UnknownHostException {
startUp(null);
- final ListenableFuture<Boolean> future = provider.startup();
+ final var future = provider.startup();
final var cause = assertThrows(ExecutionException.class, () -> future.get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS))
.getCause();
public void testStartup2() throws UnknownHostException {
startUp(null);
provider.setSwitchConnectionHandler(handler);
- final ListenableFuture<Boolean> future = provider.startup();
+ final var future = provider.startup();
final var cause = assertThrows(ExecutionException.class, () -> future.get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS))
.getCause();
@Test
public void testStartup3() throws UnknownHostException {
startUp(TransportProtocol.TCP);
- final ListenableFuture<Boolean> future = provider.startup();
+ final var future = provider.startup();
final var cause = assertThrows(ExecutionException.class, () -> future.get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS))
.getCause();
startUp(TransportProtocol.TCP);
provider.setSwitchConnectionHandler(handler);
- assertTrue("Failed to start", provider.startup().get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS));
+ provider.startup().get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS);
}
/**
startUp(TransportProtocol.TLS);
provider.setSwitchConnectionHandler(handler);
- assertTrue("Failed to start", provider.startup().get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS));
+ provider.startup().get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS);
}
/**
startUp(TransportProtocol.UDP);
provider.setSwitchConnectionHandler(handler);
- assertTrue("Failed to start", provider.startup().get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS));
+ provider.startup().get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS);
}
/**
startUp(TransportProtocol.TCP);
provider.setSwitchConnectionHandler(handler);
- assertTrue("Failed to start", provider.startup().get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS));
+ provider.startup().get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS);
assertTrue("Failed to stop", provider.shutdown().get(5 * WAIT_TIMEOUT, TimeUnit.MILLISECONDS));
}
}
*/
package org.opendaylight.openflowjava.protocol.impl.core.connection;
-import com.google.common.util.concurrent.ListenableFuture;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import java.net.InetAddress;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
-import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
public void testWithEmptyAddress() throws Exception {
udpHandler = new UdpHandler(null, 0, () -> { });
udpHandler.setChannelInitializer(udpChannelInitializerMock);
- Assert.assertTrue("Wrong - start server", startupServer(false));
- try {
- Assert.assertTrue(udpHandler.getIsOnlineFuture().get(1500, TimeUnit.MILLISECONDS));
- } catch (TimeoutException e) {
- Assert.fail("Wrong - getIsOnlineFuture timed out");
- }
- Assert.assertFalse("Wrong - port has been set to zero", udpHandler.getPort() == 0);
+ assertTrue("Wrong - start server", startupServer(false));
+ udpHandler.getIsOnlineFuture().get(1500, TimeUnit.MILLISECONDS);
+ assertFalse("Wrong - port has been set to zero", udpHandler.getPort() == 0);
shutdownServer();
}
public void testWithEmptyAddressOnEpoll() throws Exception {
udpHandler = new UdpHandler(null, 0, () -> { });
udpHandler.setChannelInitializer(udpChannelInitializerMock);
- Assert.assertTrue("Wrong - start server", startupServer(true));
- try {
- Assert.assertTrue(udpHandler.getIsOnlineFuture().get(1500,TimeUnit.MILLISECONDS));
- } catch (TimeoutException e) {
- Assert.fail("Wrong - getIsOnlineFuture timed out");
- }
- Assert.assertFalse("Wrong - port has been set to zero", udpHandler.getPort() == 0);
+ assertTrue("Wrong - start server", startupServer(true));
+ udpHandler.getIsOnlineFuture().get(1500,TimeUnit.MILLISECONDS);
+ assertFalse("Wrong - port has been set to zero", udpHandler.getPort() == 0);
shutdownServer();
}
int port = 9874;
udpHandler = new UdpHandler(InetAddress.getLocalHost(), port, () -> { });
udpHandler.setChannelInitializer(udpChannelInitializerMock);
- Assert.assertTrue("Wrong - start server", startupServer(false));
- try {
- Assert.assertTrue(udpHandler.getIsOnlineFuture().get(1500,TimeUnit.MILLISECONDS));
- } catch (TimeoutException e) {
- Assert.fail("Wrong - getIsOnlineFuture timed out");
- }
- Assert.assertEquals("Wrong - bad port number has been set", port, udpHandler.getPort());
+ assertTrue("Wrong - start server", startupServer(false));
+ udpHandler.getIsOnlineFuture().get(1500,TimeUnit.MILLISECONDS);
+ assertEquals("Wrong - bad port number has been set", port, udpHandler.getPort());
shutdownServer();
}
int port = 9874;
udpHandler = new UdpHandler(InetAddress.getLocalHost(), port, () -> { });
udpHandler.setChannelInitializer(udpChannelInitializerMock);
- Assert.assertTrue("Wrong - start server", startupServer(true));
- try {
- Assert.assertTrue(udpHandler.getIsOnlineFuture().get(1500,TimeUnit.MILLISECONDS));
- } catch (TimeoutException e) {
- Assert.fail("Wrong - getIsOnlineFuture timed out");
- }
- Assert.assertEquals("Wrong - bad port number has been set", port, udpHandler.getPort());
+ assertTrue("Wrong - start server", startupServer(true));
+ udpHandler.getIsOnlineFuture().get(1500,TimeUnit.MILLISECONDS);
+ assertEquals("Wrong - bad port number has been set", port, udpHandler.getPort());
shutdownServer();
}
private Boolean startupServer(final boolean isEpollEnabled)
throws InterruptedException, ExecutionException {
- ListenableFuture<Boolean> online = udpHandler.getIsOnlineFuture();
+ final var online = udpHandler.getIsOnlineFuture();
/**
* Test EPoll based native transport if isEpollEnabled is true.
* Else use Nio based transport.
}
private void shutdownServer() throws InterruptedException, ExecutionException, TimeoutException {
- ListenableFuture<Boolean> shutdownRet = udpHandler.shutdown() ;
- final Boolean shutdownSucceeded = shutdownRet.get(10, TimeUnit.SECONDS);
- Assert.assertTrue("Wrong - shutdown failed", shutdownSucceeded);
+ final var shutdownRet = udpHandler.shutdown() ;
+ assertTrue("Wrong - shutdown failed", shutdownRet.get(10, TimeUnit.SECONDS));
}
}
* Start listening to switches, but please don't forget to do
* {@link #setSwitchConnectionHandler(SwitchConnectionHandler)} first.
*
- * @return future, triggered to true, when listening channel is up and running
+ * @return future completing when the channel has been resolved
*/
- ListenableFuture<Boolean> startup();
+ ListenableFuture<Void> startup();
/**
* Stop listening to switches.
// Set handler of incoming connections and start switch connection provider
switchConnectionProvider.setSwitchConnectionHandler(connectionManager);
return switchConnectionProvider.startup();
- }).collect(Collectors.toSet())), new FutureCallback<List<Boolean>>() {
+ }).collect(Collectors.toSet())), new FutureCallback<List<Void>>() {
@Override
- public void onSuccess(final List<Boolean> result) {
+ public void onSuccess(final List<Void> result) {
LOG.info("All switchConnectionProviders are up and running ({}).", result.size());
diagStatusProvider.reportStatus(ServiceState.OPERATIONAL);
fullyStarted.set(null);
when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
doReturn(CommitInfo.emptyFluentFuture()).when(writeTransaction).commit();
when(entityOwnershipService.registerListener(any(), any())).thenReturn(entityOwnershipListenerRegistration);
- when(switchConnectionProvider.startup()).thenReturn(Futures.immediateFuture(true));
+ when(switchConnectionProvider.startup()).thenReturn(Futures.immediateFuture(null));
when(switchConnectionProvider.shutdown()).thenReturn(Futures.immediateFuture(true));
when(configurationService.getProperty(eq(ConfigurationProperty.USE_SINGLE_LAYER_SERIALIZATION.toString()),
any())).thenReturn(USE_SINGLE_LAYER_SERIALIZATION);