* 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.netconf.topology.singleton.impl;
import static org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologyUtils.DEFAULT_SCHEMA_REPOSITORY;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.annotation.Nonnull;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
+import org.opendaylight.mdsal.dom.api.DOMMountPointService;
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
import org.slf4j.LoggerFactory;
import scala.concurrent.Future;
-class NetconfTopologyContext implements ClusterSingletonService {
+class NetconfTopologyContext implements ClusterSingletonService, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(NetconfTopologyContext.class);
private RemoteDeviceConnector remoteDeviceConnector;
private NetconfNodeManager netconfNodeManager;
private ActorRef masterActorRef;
- private boolean finalClose = false;
private final AtomicBoolean closed = new AtomicBoolean(false);
- private boolean isMaster;
+ private final AtomicBoolean stopped = new AtomicBoolean(false);
+ private volatile boolean isMaster;
NetconfTopologyContext(final NetconfTopologySetup netconfTopologyDeviceSetup,
final ServiceGroupIdentifier serviceGroupIdent,
this.mountService = mountService;
remoteDeviceId = NetconfTopologyUtils.createRemoteDeviceId(netconfTopologyDeviceSetup.getNode().getNodeId(),
- netconfTopologyDeviceSetup.getNode().getAugmentation(NetconfNode.class));
+ netconfTopologyDeviceSetup.getNode().augmentation(NetconfNode.class));
- remoteDeviceConnector = new RemoteDeviceConnectorImpl(netconfTopologyDeviceSetup, remoteDeviceId,
- actorResponseWaitTime, mountService);
+ remoteDeviceConnector = new RemoteDeviceConnectorImpl(netconfTopologyDeviceSetup, remoteDeviceId);
netconfNodeManager = createNodeDeviceManager();
}
netconfNodeManager = null;
}
- if (!finalClose) {
+ if (!closed.get()) {
final String masterAddress =
Cluster.get(netconfTopologyDeviceSetup.getActorSystem()).selfAddress().toString();
masterActorRef = netconfTopologyDeviceSetup.getActorSystem().actorOf(NetconfNodeActor.props(
actorResponseWaitTime, mountService),
NetconfTopologyUtils.createMasterActorName(remoteDeviceId.getName(), masterAddress));
- remoteDeviceConnector.startRemoteDeviceConnection(masterActorRef);
+ remoteDeviceConnector.startRemoteDeviceConnection(newMasterSalFacade());
}
}
@Override
public ListenableFuture<Void> closeServiceInstance() {
- if (!finalClose) {
+ if (!closed.get()) {
// in case that master changes role to slave, new NodeDeviceManager must be created and listener registered
netconfNodeManager = createNodeDeviceManager();
}
stopDeviceConnectorAndActor();
- return Futures.immediateCheckedFuture(null);
+ return Futures.immediateFuture(null);
}
@Override
final NetconfNodeManager ndm =
new NetconfNodeManager(netconfTopologyDeviceSetup, remoteDeviceId, actorResponseWaitTime, mountService);
ndm.registerDataTreeChangeListener(netconfTopologyDeviceSetup.getTopologyId(),
- netconfTopologyDeviceSetup.getNode().getKey());
+ netconfTopologyDeviceSetup.getNode().key());
return ndm;
}
- void closeFinal() throws Exception {
- finalClose = true;
+ @Override
+ public void close() {
+ if (!closed.compareAndSet(false, true)) {
+ return;
+ }
if (netconfNodeManager != null) {
netconfNodeManager.close();
void refresh(@Nonnull final NetconfTopologySetup setup) {
netconfTopologyDeviceSetup = Preconditions.checkNotNull(setup);
remoteDeviceId = NetconfTopologyUtils.createRemoteDeviceId(netconfTopologyDeviceSetup.getNode().getNodeId(),
- netconfTopologyDeviceSetup.getNode().getAugmentation(NetconfNode.class));
+ netconfTopologyDeviceSetup.getNode().augmentation(NetconfNode.class));
if (isMaster) {
remoteDeviceConnector.stopRemoteDeviceConnection();
if (!isMaster) {
netconfNodeManager.refreshDevice(netconfTopologyDeviceSetup, remoteDeviceId);
}
- remoteDeviceConnector = new RemoteDeviceConnectorImpl(netconfTopologyDeviceSetup, remoteDeviceId,
- actorResponseWaitTime, mountService);
+ remoteDeviceConnector = new RemoteDeviceConnectorImpl(netconfTopologyDeviceSetup, remoteDeviceId);
if (isMaster) {
final Future<Object> future = Patterns.ask(masterActorRef, new RefreshSetupMasterActorData(
future.onComplete(new OnComplete<Object>() {
@Override
- public void onComplete(final Throwable failure, final Object success) throws Throwable {
+ public void onComplete(final Throwable failure, final Object success) {
if (failure != null) {
- LOG.error("Failed to refresh master actor data: {}", failure);
+ LOG.error("Failed to refresh master actor data", failure);
return;
}
- remoteDeviceConnector.startRemoteDeviceConnection(masterActorRef);
+ remoteDeviceConnector.startRemoteDeviceConnection(newMasterSalFacade());
}
}, netconfTopologyDeviceSetup.getActorSystem().dispatcher());
}
}
private void stopDeviceConnectorAndActor() {
- if (!closed.compareAndSet(false, true)) {
+ if (!stopped.compareAndSet(false, true)) {
return;
}
if (remoteDeviceConnector != null) {
masterActorRef = null;
}
}
+
+ protected MasterSalFacade newMasterSalFacade() {
+ return new MasterSalFacade(remoteDeviceId, netconfTopologyDeviceSetup.getActorSystem(), masterActorRef,
+ actorResponseWaitTime, mountService, netconfTopologyDeviceSetup.getDataBroker());
+ }
}