2 * Copyright (c) 2015 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
8 package org.opendaylight.openflowplugin.impl.connection;
10 import java.util.concurrent.ThreadPoolExecutor;
11 import java.util.concurrent.TimeUnit;
12 import org.opendaylight.openflowplugin.api.openflow.connection.HandshakeContext;
13 import org.opendaylight.openflowplugin.api.openflow.md.core.HandshakeManager;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
20 public class HandshakeContextImpl implements HandshakeContext {
22 private static final Logger LOG = LoggerFactory.getLogger(HandshakeContextImpl.class);
24 private ThreadPoolExecutor handshakePool;
25 private HandshakeManager handshakeManager;
28 * @param handshakePool
29 * @param handshakeManager
31 public HandshakeContextImpl(ThreadPoolExecutor handshakePool, HandshakeManager handshakeManager) {
32 this.handshakePool = handshakePool;
33 this.handshakeManager = handshakeManager;
37 public HandshakeManager getHandshakeManager() {
38 return handshakeManager;
42 public ThreadPoolExecutor getHandshakePool() {
47 public void close() throws Exception {
48 shutdownPoolPolitely();
51 private void shutdownPoolPolitely() {
52 LOG.debug("terminating handshake pool");
53 handshakePool.shutdown();
55 handshakePool.awaitTermination(1, TimeUnit.SECONDS);
56 } catch (InterruptedException e) {
57 LOG.error("Error while awaiting termination on pool. Will use shutdownNow method.");
59 handshakePool.purge();
60 if (! handshakePool.isTerminated()) {
61 handshakePool.shutdownNow();
63 LOG.debug("pool is terminated: {}", handshakePool.isTerminated());