import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
-
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;
-
+import javax.annotation.concurrent.GuardedBy;
import org.opendaylight.bgpcep.topology.TopologyReference;
import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
private final RibReference locRibReference;
private final Class<T> idClass;
+ @GuardedBy("this")
+ private boolean closed = false;
+
protected AbstractTopologyBuilder(final DataBroker dataProvider, final RibReference locRibReference,
final TopologyId topologyId, final TopologyTypes types, final Class<T> idClass) {
this.locRibReference = Preconditions.checkNotNull(locRibReference);
try {
o = t.read(LogicalDatastoreType.OPERATIONAL, this.topology).get();
} catch (InterruptedException | ExecutionException e) {
- throw new IllegalStateException("Failed to read topology " + topology, e);
+ throw new IllegalStateException("Failed to read topology " + this.topology, e);
}
Preconditions.checkState(!o.isPresent(), "Data provider conflict detected on object {}", this.topology);
}
@Override
- public final void onLocRIBChange(final ReadWriteTransaction trans,
+ public synchronized final void onLocRIBChange(final ReadWriteTransaction trans,
final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event) {
LOG.debug("Received data change {} event with transaction {}", event, trans.getIdentifier());
+ if (this.closed) {
+ LOG.trace("Transaction chain was already closed, skipping update.");
+ return;
+ }
// FIXME: speed this up
final Set<InstanceIdentifier<T>> ids = new HashSet<>();
}
@Override
- public final void close() throws TransactionCommitFailedException {
+ public synchronized final void close() throws TransactionCommitFailedException {
LOG.info("Shutting down builder for {}", getInstanceIdentifier());
final WriteTransaction trans = this.chain.newWriteOnlyTransaction();
trans.delete(LogicalDatastoreType.OPERATIONAL, getInstanceIdentifier());
trans.submit().checkedGet();
this.chain.close();
+ this.closed = true;
}
@Override