X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-client%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fclient%2FNetconfClientSessionListener.java;h=21be3a8cabf4cf24edb6a9fc08530ebce76bcb53;hb=c7ec8db7f107b5e265f4e8b2fe3dd0f7b1163b64;hp=d3c1b22c845a9c0a30888cbd933e935322cfedd8;hpb=a92d9d6a21a0f6ca8d2153795721f500eaf29ee9;p=controller.git diff --git a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSessionListener.java b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSessionListener.java index d3c1b22c84..21be3a8cab 100644 --- a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSessionListener.java +++ b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSessionListener.java @@ -1,75 +1,14 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2014 Cisco Systems, Inc. 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.controller.netconf.client; -import com.google.common.base.Preconditions; -import com.google.common.collect.Lists; -import org.opendaylight.controller.netconf.api.NetconfMessage; -import org.opendaylight.controller.netconf.api.NetconfTerminationReason; -import org.opendaylight.protocol.framework.SessionListener; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; - -public class NetconfClientSessionListener implements - SessionListener { - - private static final Logger logger = LoggerFactory.getLogger(NetconfClientSessionListener.class); - private AtomicBoolean up = new AtomicBoolean(false); - - @Override - public void onSessionUp(NetconfClientSession clientSession) { - up.set(true); - } - - @Override - public void onSessionDown(NetconfClientSession clientSession, Exception e) { - logger.debug("Client Session {} down, reason: {}", clientSession, e.getMessage()); - up.set(false); - } - - @Override - public void onSessionTerminated(NetconfClientSession clientSession, - NetconfTerminationReason netconfTerminationReason) { - logger.debug("Client Session {} terminated, reason: {}", clientSession, - netconfTerminationReason.getErrorMessage()); - up.set(false); - } - - @Override - public synchronized void onMessage(NetconfClientSession session, NetconfMessage message) { - synchronized (messages) { - this.messages.add(message); - } - } - - private int lastReadMessage = -1; - private List messages = Lists.newArrayList(); - - public NetconfMessage getLastMessage(int attempts, int attemptMsDelay) throws InterruptedException { - Preconditions.checkState(up.get(), "Session was not up yet"); - - for (int i = 0; i < attempts; i++) { - synchronized (messages) { - if (messages.size() - 1 > lastReadMessage) { - lastReadMessage++; - return messages.get(lastReadMessage); - } - } +import org.opendaylight.controller.netconf.api.NetconfSessionListener; - if (up.get() == false) - throw new IllegalStateException("Session ended while trying to read message"); - Thread.sleep(attemptMsDelay); - } +public interface NetconfClientSessionListener extends NetconfSessionListener { - throw new IllegalStateException("No netconf message to read"); - } }