2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowjava.protocol.impl.connection;
11 import java.util.ArrayList;
12 import java.util.Collection;
13 import java.util.HashSet;
14 import java.util.List;
16 import java.util.concurrent.Future;
18 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration;
19 import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler;
20 import org.opendaylight.openflowjava.protocol.impl.core.TcpHandler;
21 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 import com.google.common.util.concurrent.Futures;
26 import com.google.common.util.concurrent.ListenableFuture;
27 import com.google.common.util.concurrent.SettableFuture;
33 public class SwitchConnectionProviderImpl implements SwitchConnectionProvider {
35 private static final Logger LOG = LoggerFactory
36 .getLogger(SwitchConnectionProviderImpl.class);
37 private SwitchConnectionHandler switchConnectionHandler;
38 private Set<ServerFacade> serverLot;
41 public void configure(Collection<ConnectionConfiguration> connConfigs) {
42 LOG.debug("configurating ..");
44 //TODO - add and configure servers according to configuration
45 serverLot = new HashSet<>();
46 serverLot.add(new TcpHandler(6633));
50 public void setSwitchConnectionListener(SwitchConnectionHandler switchConnectionHandler) {
51 this.switchConnectionHandler = switchConnectionHandler;
55 public Future<Boolean> shutdown() {
56 LOG.debug("shutdown summoned");
57 for (ServerFacade server : serverLot) {
64 public Future<List<Boolean>> startup() {
65 LOG.debug("startup summoned");
66 ListenableFuture<List<Boolean>> result = SettableFuture.create();
68 //TODO - check config, status of servers
69 if (switchConnectionHandler == null) {
70 throw new IllegalStateException("switchConnectionHandler is not set");
74 List<ListenableFuture<Boolean>> starterChain = new ArrayList<>();
75 for (ServerFacade server : serverLot) {
76 new Thread(server).start();
77 ListenableFuture<Boolean> isOnlineFuture = server.getIsOnlineFuture();
78 starterChain.add(isOnlineFuture);
81 if (!starterChain.isEmpty()) {
82 result = Futures.allAsList(starterChain);
84 throw new IllegalStateException("no servers configured");
86 } catch (Exception e) {
87 SettableFuture<List<Boolean>> exFuture = SettableFuture.create();
88 exFuture.setException(e);