X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflow-protocol-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowjava%2Fprotocol%2Fimpl%2Fconnection%2FSwitchConnectionProviderImpl.java;h=3e45b174623e7e2cbf3ec183fda1bc99f649db63;hb=cbe4871cddf78adab335b5270269b6e704eb8bf9;hp=8d21a2fdc8b89db6a7c5a82db0f554cb7bed8f21;hpb=1fe648172a622601f42a3b1c5e53e17f4d41d14b;p=openflowjava.git diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/SwitchConnectionProviderImpl.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/SwitchConnectionProviderImpl.java index 8d21a2fd..3e45b174 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/SwitchConnectionProviderImpl.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/SwitchConnectionProviderImpl.java @@ -1,113 +1,109 @@ -/* 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.connection; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; import java.util.concurrent.Future; import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration; +import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration.FEATURE_SUPPORT; import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler; import org.opendaylight.openflowjava.protocol.impl.core.TcpHandler; import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.SettableFuture; /** + * Exposed class for server handling * @author mirehak * @author michal.polkorab */ public class SwitchConnectionProviderImpl implements SwitchConnectionProvider { - private static final Logger LOG = LoggerFactory + private static final Logger LOGGER = LoggerFactory .getLogger(SwitchConnectionProviderImpl.class); private SwitchConnectionHandler switchConnectionHandler; - private Set serverLot; + private ServerFacade serverFacade; + private ConnectionConfiguration connConfig; @Override - public void configure(Collection connConfigs) { - LOG.debug("Configurating .."); - - //TODO - configure servers according to configuration - serverLot = new HashSet<>(); - for (Iterator iterator = connConfigs.iterator(); iterator.hasNext();) { - ConnectionConfiguration connConfig = iterator.next(); - TcpHandler server = new TcpHandler(connConfig.getAddress(), connConfig.getPort()); - server.setSwitchConnectionHandler(switchConnectionHandler); - serverLot.add(server); - } + public void setConfiguration(ConnectionConfiguration connConfig) { + this.connConfig = connConfig; } @Override public void setSwitchConnectionHandler(SwitchConnectionHandler switchConnectionHandler) { - LOG.debug("setSwitchConnectionHanler"); + LOGGER.debug("setSwitchConnectionHandler"); this.switchConnectionHandler = switchConnectionHandler; } @Override - public Future> shutdown() { - LOG.debug("Shutdown summoned"); - ListenableFuture> result = SettableFuture.create(); - try { - List> shutdownChain = new ArrayList<>(); - for (ServerFacade server : serverLot) { - ListenableFuture shutdownFuture = server.shutdown(); - shutdownChain.add(shutdownFuture); - } - if (!shutdownChain.isEmpty()) { - result = Futures.allAsList(shutdownChain); - } else { - throw new IllegalStateException("No servers configured"); - } - } catch (Exception e) { - SettableFuture> exFuture = SettableFuture.create(); - exFuture.setException(e); - result = exFuture; - } + public ListenableFuture shutdown() { + LOGGER.debug("Shutdown summoned"); + //TODO: provide exception in case of: not started, not configured (already stopped) + ListenableFuture result = serverFacade.shutdown(); return result; } @Override - public Future> startup() { - LOG.debug("startup summoned"); - ListenableFuture> result = SettableFuture.create(); + public ListenableFuture startup() { + LOGGER.debug("Startup summoned"); + serverFacade = createAndConfigureServer(); + + LOGGER.debug("Starting .."); + ListenableFuture result = null; try { - if (serverLot.isEmpty()) { - throw new IllegalStateException("No servers configured"); + if (serverFacade == null) { + throw new IllegalStateException("No server configured"); } - for (ServerFacade server : serverLot) { - if (server.getIsOnlineFuture().isDone()) { - throw new IllegalStateException("Servers already running"); - } + if (serverFacade.getIsOnlineFuture().isDone()) { + throw new IllegalStateException("Server already running"); } if (switchConnectionHandler == null) { throw new IllegalStateException("switchConnectionHandler is not set"); } - List> starterChain = new ArrayList<>(); - for (ServerFacade server : serverLot) { - new Thread(server).start(); - ListenableFuture isOnlineFuture = server.getIsOnlineFuture(); - starterChain.add(isOnlineFuture); - } - if (!starterChain.isEmpty()) { - result = Futures.allAsList(starterChain); - } else { - throw new IllegalStateException("No servers configured"); - } + new Thread(serverFacade).start(); + result = serverFacade.getIsOnlineFuture(); } catch (Exception e) { - SettableFuture> exFuture = SettableFuture.create(); - exFuture.setException(e); - result = exFuture; + SettableFuture exResult = SettableFuture.create(); + exResult.setException(e); + result = exResult; } return result; } + /** + * @return + */ + private TcpHandler createAndConfigureServer() { + LOGGER.debug("Configuring .."); + TcpHandler server = new TcpHandler(connConfig.getAddress(), connConfig.getPort()); + server.setSwitchConnectionHandler(switchConnectionHandler); + server.setSwitchIdleTimeout(connConfig.getSwitchIdleTimeout()); + boolean tlsSupported = FEATURE_SUPPORT.REQUIRED.equals(connConfig.getTlsSupport()); + server.setEncryption(tlsSupported); + + return server; + } + + /** + * @return servers + */ + public ServerFacade getServerFacade() { + return serverFacade; + } + + @Override + public void close() throws Exception { + shutdown(); + } }