-/**
+/*
* Copyright (c) 2014, 2017 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
*/
package org.opendaylight.openflowplugin.applications.frm.impl;
-import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FluentFuture;
import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.MoreExecutors;
import java.util.concurrent.Future;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.infrautils.utils.concurrent.LoggingFutures;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
+import org.opendaylight.mdsal.binding.api.WriteTransaction;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.openflowplugin.applications.frm.ForwardingRulesManager;
-import org.opendaylight.openflowplugin.common.wait.SimpleTaskRetryLooper;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter;
/**
* MeterForwarder It implements
- * {@link org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener}
+ * {@link org.opendaylight.mdsal.binding.api.DataTreeChangeListener}
* for WildCardedPath to {@link Meter} and ForwardingRulesCommiter interface for
* methods: add, update and remove {@link Meter} processing for
- * {@link org.opendaylight.controller.md.sal.binding.api.DataTreeModification}.
+ * {@link org.opendaylight.mdsal.binding.api.DataTreeModification}.
*
*/
public class MeterForwarder extends AbstractListeningCommiter<Meter> {
private static final Logger LOG = LoggerFactory.getLogger(MeterForwarder.class);
- private final DataBroker dataBroker;
private ListenerRegistration<MeterForwarder> listenerRegistration;
- @SuppressWarnings("IllegalCatch")
public MeterForwarder(final ForwardingRulesManager manager, final DataBroker db) {
- super(manager);
- dataBroker = Preconditions.checkNotNull(db, "DataBroker can not be null!");
- final DataTreeIdentifier<Meter> treeId = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION,
+ super(manager, db);
+ }
+
+ @SuppressWarnings("IllegalCatch")
+ @Override
+ public void registerListener() {
+ final DataTreeIdentifier<Meter> treeId = DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION,
getWildCardPath());
try {
- SimpleTaskRetryLooper looper = new SimpleTaskRetryLooper(ForwardingRulesManagerImpl.STARTUP_LOOP_TICK,
- ForwardingRulesManagerImpl.STARTUP_LOOP_MAX_RETRIES);
- listenerRegistration = looper
- .loopUntilNoException(() -> db.registerDataTreeChangeListener(treeId, MeterForwarder.this));
+ listenerRegistration = dataBroker.registerDataTreeChangeListener(treeId, MeterForwarder.this);
} catch (final Exception e) {
LOG.warn("FRM Meter DataTreeChange listener registration fail!");
LOG.debug("FRM Meter DataTreeChange listener registration fail ..", e);
}
}
+ @Override
+ public void deregisterListener() {
+ close();
+ }
+
@Override
public void close() {
if (listenerRegistration != null) {
builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class)));
builder.setMeterRef(new MeterRef(identifier));
builder.setTransactionUri(new Uri(provider.getNewTransactionId()));
- this.provider.getSalMeterService().removeMeter(builder.build());
+
+ LoggingFutures.addErrorLogging(this.provider.getSalMeterService().removeMeter(builder.build()), LOG,
+ "removeMeter");
}
@Override
builder.setUpdatedMeter(new UpdatedMeterBuilder(update).build());
builder.setOriginalMeter(new OriginalMeterBuilder(original).build());
- this.provider.getSalMeterService().updateMeter(builder.build());
+ LoggingFutures.addErrorLogging(this.provider.getSalMeterService().updateMeter(builder.build()), LOG,
+ "updateMeter");
}
@Override
@Override
public void createStaleMarkEntity(InstanceIdentifier<Meter> identifier, Meter del,
InstanceIdentifier<FlowCapableNode> nodeIdent) {
- LOG.debug("Creating Stale-Mark entry for the switch {} for meter {} ", nodeIdent.toString(), del.toString());
+ LOG.debug("Creating Stale-Mark entry for the switch {} for meter {} ", nodeIdent, del);
StaleMeter staleMeter = makeStaleMeter(del);
persistStaleMeter(staleMeter, nodeIdent);
}
writeTransaction.put(LogicalDatastoreType.CONFIGURATION, getStaleMeterInstanceIdentifier(staleMeter, nodeIdent),
staleMeter, false);
- CheckedFuture<Void, TransactionCommitFailedException> submitFuture = writeTransaction.submit();
+ FluentFuture<?> submitFuture = writeTransaction.commit();
handleStaleMeterResultFuture(submitFuture);
}
- private void handleStaleMeterResultFuture(CheckedFuture<Void, TransactionCommitFailedException> submitFuture) {
- Futures.addCallback(submitFuture, new FutureCallback<Void>() {
+ private void handleStaleMeterResultFuture(FluentFuture<?> submitFuture) {
+ submitFuture.addCallback(new FutureCallback<Object>() {
@Override
- public void onSuccess(Void result) {
+ public void onSuccess(Object result) {
LOG.debug("Stale Meter creation success");
}
@Override
public void onFailure(Throwable throwable) {
- LOG.error("Stale Meter creation failed {}", throwable);
+ LOG.error("Stale Meter creation failed", throwable);
}
- });
+ }, MoreExecutors.directExecutor());
}
private InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819