Executor is the interface we need, not ExecutorService. ExecutorServices
are more complex, and we do not care about shutting them down anyway.
So require only an Executor, letting callers to deal with its lifecycle,
which allows us to use more efficient MoreExecutors.directExecutor()
instead.
Change-Id: Ide57266cc1fac395e545b466bf3b5ad86dee7b2f
Signed-off-by: Robert Varga <rovarga@cisco.com>
(cherry picked from commit
195ee42d6fe586b331ec949a0f3579a27bb51eed)
import com.google.common.annotations.Beta;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.annotations.Beta;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import java.util.ArrayList;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executor;
import javax.annotation.Nonnull;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener;
import javax.annotation.Nonnull;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener;
private final InMemoryDOMDataTreeShardChangePublisher shardChangePublisher;
private final ListeningExecutorService executor;
private final InMemoryDOMDataTreeShardChangePublisher shardChangePublisher;
private final ListeningExecutorService executor;
- private InMemoryDOMDataTreeShard(final DOMDataTreeIdentifier prefix, final ExecutorService dataTreeChangeExecutor,
+ private InMemoryDOMDataTreeShard(final DOMDataTreeIdentifier prefix, final Executor dataTreeChangeExecutor,
final int maxDataChangeListenerQueueSize, final int submitQueueSize) {
this.prefix = Preconditions.checkNotNull(prefix);
final int maxDataChangeListenerQueueSize, final int submitQueueSize) {
this.prefix = Preconditions.checkNotNull(prefix);
}
public static InMemoryDOMDataTreeShard create(final DOMDataTreeIdentifier id,
}
public static InMemoryDOMDataTreeShard create(final DOMDataTreeIdentifier id,
- final ExecutorService dataTreeChangeExecutor,
+ final Executor dataTreeChangeExecutor,
final int maxDataChangeListenerQueueSize) {
return new InMemoryDOMDataTreeShard(id, dataTreeChangeExecutor,
maxDataChangeListenerQueueSize, DEFAULT_SUBMIT_QUEUE_SIZE);
}
public static InMemoryDOMDataTreeShard create(final DOMDataTreeIdentifier id,
final int maxDataChangeListenerQueueSize) {
return new InMemoryDOMDataTreeShard(id, dataTreeChangeExecutor,
maxDataChangeListenerQueueSize, DEFAULT_SUBMIT_QUEUE_SIZE);
}
public static InMemoryDOMDataTreeShard create(final DOMDataTreeIdentifier id,
- final ExecutorService dataTreeChangeExecutor,
+ final Executor dataTreeChangeExecutor,
final int maxDataChangeListenerQueueSize,
final int submitQueueSize) {
return new InMemoryDOMDataTreeShard(id, dataTreeChangeExecutor,
final int maxDataChangeListenerQueueSize,
final int submitQueueSize) {
return new InMemoryDOMDataTreeShard(id, dataTreeChangeExecutor,
@VisibleForTesting
Map<DOMDataTreeIdentifier, DOMDataTreeShard> getChildShards() {
@VisibleForTesting
Map<DOMDataTreeIdentifier, DOMDataTreeShard> getChildShards() {
- final Map<DOMDataTreeIdentifier, DOMDataTreeShard> ret = new HashMap<>();
- for (final Entry<DOMDataTreeIdentifier, ChildShardContext> entry : childShards.entrySet()) {
- ret.put(entry.getKey(), entry.getValue().getShard());
- }
- return ret;
+ return ImmutableMap.copyOf(Maps.transformValues(childShards, ChildShardContext::getShard));
}
DataTreeSnapshot takeSnapshot() {
}
DataTreeSnapshot takeSnapshot() {
import com.google.common.collect.ImmutableList;
import java.util.Collection;
import java.util.Map;
import com.google.common.collect.ImmutableList;
import java.util.Collection;
import java.util.Map;
-import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executor;
import javax.annotation.Nonnull;
import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener;
import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
import javax.annotation.Nonnull;
import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener;
import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
private final QueuedNotificationManager<AbstractDOMDataTreeChangeListenerRegistration<?>,
DataTreeCandidate> notificationManager;
private final QueuedNotificationManager<AbstractDOMDataTreeChangeListenerRegistration<?>,
DataTreeCandidate> notificationManager;
- InMemoryDOMDataTreeShardChangePublisher(final ExecutorService executorService,
+ InMemoryDOMDataTreeShardChangePublisher(final Executor executor,
final int maxQueueSize,
final DataTree dataTree,
final YangInstanceIdentifier rootPath,
final Map<DOMDataTreeIdentifier, ChildShardContext> childShards) {
super(dataTree, rootPath, childShards);
notificationManager = new QueuedNotificationManager<>(
final int maxQueueSize,
final DataTree dataTree,
final YangInstanceIdentifier rootPath,
final Map<DOMDataTreeIdentifier, ChildShardContext> childShards) {
super(dataTree, rootPath, childShards);
notificationManager = new QueuedNotificationManager<>(
- executorService, MANAGER_INVOKER, maxQueueSize, "DataTreeChangeListenerQueueMgr");
+ executor, MANAGER_INVOKER, maxQueueSize, "DataTreeChangeListenerQueueMgr");
- protected void registrationRemoved(@Nonnull AbstractDOMDataTreeChangeListenerRegistration<?> registration) {
+ protected void registrationRemoved(@Nonnull final AbstractDOMDataTreeChangeListenerRegistration<?> registration) {
LOG.debug("Closing registration {}", registration);
}
LOG.debug("Closing registration {}", registration);
}
public <L extends DOMDataTreeChangeListener> AbstractDOMDataTreeChangeListenerRegistration<L>
public <L extends DOMDataTreeChangeListener> AbstractDOMDataTreeChangeListenerRegistration<L>
- registerTreeChangeListener(YangInstanceIdentifier path, L listener) {
+ registerTreeChangeListener(final YangInstanceIdentifier path, final L listener) {
return super.registerTreeChangeListener(path, listener);
}
return super.registerTreeChangeListener(path, listener);
}
private static final DataTreeCandidateNode DATA_TREE_CANDIDATE_NODE = mock(DataTreeCandidateNode.class);
private static final DataTreeModification DATA_TREE_MODIFICATION = mock(DataTreeModification.class);
private static final InMemoryDOMDataTreeShardChangePublisher IN_MEMORY_DOM_DATA_TREE_SHARD_CHANGE_PUBLISHER =
private static final DataTreeCandidateNode DATA_TREE_CANDIDATE_NODE = mock(DataTreeCandidateNode.class);
private static final DataTreeModification DATA_TREE_MODIFICATION = mock(DataTreeModification.class);
private static final InMemoryDOMDataTreeShardChangePublisher IN_MEMORY_DOM_DATA_TREE_SHARD_CHANGE_PUBLISHER =
- new InMemoryDOMDataTreeShardChangePublisher(MoreExecutors.newDirectExecutorService(), 1, DATA_TREE,
+ new InMemoryDOMDataTreeShardChangePublisher(MoreExecutors.directExecutor(), 1, DATA_TREE,
YangInstanceIdentifier.of(QName.create("test")), ImmutableMap.of());
private static final InMemoryDOMDataTreeShardThreePhaseCommitCohort
IN_MEMORY_DOM_DATA_TREE_SHARD_THREE_PHASE_COMMIT_COHORT =
YangInstanceIdentifier.of(QName.create("test")), ImmutableMap.of());
private static final InMemoryDOMDataTreeShardThreePhaseCommitCohort
IN_MEMORY_DOM_DATA_TREE_SHARD_THREE_PHASE_COMMIT_COHORT =
doReturn("testDataTreeCandidate").when(dataTreeCandidate).toString();
doReturn(dataTreeCandidate).when(DATA_TREE).prepare(any());
final InMemoryDOMDataTreeShardChangePublisher inMemoryDOMDataTreeShardChangePublisher =
doReturn("testDataTreeCandidate").when(dataTreeCandidate).toString();
doReturn(dataTreeCandidate).when(DATA_TREE).prepare(any());
final InMemoryDOMDataTreeShardChangePublisher inMemoryDOMDataTreeShardChangePublisher =
- new InMemoryDOMDataTreeShardChangePublisher(MoreExecutors.newDirectExecutorService(), 1, DATA_TREE,
+ new InMemoryDOMDataTreeShardChangePublisher(MoreExecutors.directExecutor(), 1, DATA_TREE,
YANG_INSTANCE_IDENTIFIER, CHILD_SHARDS);
mockProducer = mock(InMemoryDOMDataTreeShardProducer.class);
doNothing().when(mockProducer).transactionReady(any(), any());
YANG_INSTANCE_IDENTIFIER, CHILD_SHARDS);
mockProducer = mock(InMemoryDOMDataTreeShardProducer.class);
doNothing().when(mockProducer).transactionReady(any(), any());