ConnectionManager proposal
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / connection / listener / ConnectionReadyListenerImpl.java
1 /**
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  * 
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
7  */
8 package org.opendaylight.openflowplugin.impl.connection.listener;
9
10 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionReadyListener;
11 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
12 import org.opendaylight.openflowplugin.api.openflow.connection.HandshakeContext;
13 import org.opendaylight.openflowplugin.openflow.md.core.HandshakeStepWrapper;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 /**
18  * oneshot listener - once connection is ready, initiate handshake (if not already started by device)
19  */
20 public class ConnectionReadyListenerImpl implements ConnectionReadyListener {
21     
22     private static final Logger LOG = LoggerFactory.getLogger(ConnectionReadyListenerImpl.class);
23     
24     private ConnectionContext connectionContext;
25     private HandshakeContext handshakeContext;
26
27     /**
28      * @param connectionContext
29      * @param handshakeContext
30      */
31     public ConnectionReadyListenerImpl(ConnectionContext connectionContext,
32             HandshakeContext handshakeContext) {
33                 this.connectionContext = connectionContext;
34                 this.handshakeContext = handshakeContext;
35     }
36
37     @Override
38     public void onConnectionReady() {
39         LOG.debug("device is connected and ready-to-use (pipeline prepared)");
40         if (connectionContext.getConnectionState() == null) {
41             HandshakeStepWrapper handshakeStepWrapper = new HandshakeStepWrapper(
42                     null, handshakeContext.getHandshakeManager(), connectionContext.getConnectionAdapter());
43             handshakeContext.getHandshakePool().execute(handshakeStepWrapper);
44             connectionContext.setConnectionState(ConnectionContext.CONNECTION_STATE.HANDSHAKING);
45         } else {
46             LOG.debug("already touched by hello message");
47         }
48     }
49
50 }