Merge "Do not retain module through NotificationListener"
authorTony Tkacik <ttkacik@cisco.com>
Thu, 20 Nov 2014 12:48:25 +0000 (12:48 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 20 Nov 2014 12:48:25 +0000 (12:48 +0000)
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dependencyresolver/DependencyResolverManager.java
opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/notify/NotificationPublishService.java
opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/notify/NotificationSubscriptionService.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/util/NetconfMessageTransformUtil.java

index 15f5d48a6f51f43decd567129ce5d0854cc9ddcb..da6349ac5386c75ef17a8120a8c5a10b16726367 100644 (file)
@@ -8,7 +8,7 @@
 package org.opendaylight.controller.config.manager.impl.dependencyresolver;
 
 import static com.google.common.base.Preconditions.checkState;
-
+import com.google.common.base.Preconditions;
 import com.google.common.reflect.AbstractInvocationHandler;
 import com.google.common.reflect.Reflection;
 import java.lang.reflect.InvocationTargetException;
@@ -54,10 +54,10 @@ public class DependencyResolverManager implements DependencyResolverFactory, Aut
     private final DeadlockMonitor deadlockMonitor;
     private final MBeanServer mBeanServer;
 
-    public DependencyResolverManager(TransactionIdentifier transactionIdentifier,
-                                     TransactionStatus transactionStatus,
-                                     ServiceReferenceReadableRegistry readableRegistry, CodecRegistry codecRegistry,
-                                     MBeanServer mBeanServer) {
+    public DependencyResolverManager(final TransactionIdentifier transactionIdentifier,
+                                     final TransactionStatus transactionStatus,
+                                     final ServiceReferenceReadableRegistry readableRegistry, final CodecRegistry codecRegistry,
+                                     final MBeanServer mBeanServer) {
         this.transactionIdentifier = transactionIdentifier;
         this.modulesHolder = new ModulesHolder(transactionIdentifier);
         this.transactionStatus = transactionStatus;
@@ -68,11 +68,11 @@ public class DependencyResolverManager implements DependencyResolverFactory, Aut
     }
 
     @Override
-    public DependencyResolver createDependencyResolver(ModuleIdentifier moduleIdentifier) {
+    public DependencyResolver createDependencyResolver(final ModuleIdentifier moduleIdentifier) {
         return getOrCreate(moduleIdentifier);
     }
 
-    public synchronized DependencyResolverImpl getOrCreate(ModuleIdentifier name) {
+    public synchronized DependencyResolverImpl getOrCreate(final ModuleIdentifier name) {
         DependencyResolverImpl dependencyResolver = moduleIdentifiersToDependencyResolverMap.get(name);
         if (dependencyResolver == null) {
             transactionStatus.checkNotCommitted();
@@ -109,7 +109,7 @@ public class DependencyResolverManager implements DependencyResolverFactory, Aut
     }
 
     public ModuleInternalTransactionalInfo destroyModule(
-            ModuleIdentifier moduleIdentifier) {
+            final ModuleIdentifier moduleIdentifier) {
         transactionStatus.checkNotCommitted();
         ModuleInternalTransactionalInfo found = modulesHolder
                 .destroyModule(moduleIdentifier);
@@ -119,52 +119,62 @@ public class DependencyResolverManager implements DependencyResolverFactory, Aut
 
     // protect write access
 
+    private static final class ModuleInvocationHandler extends AbstractInvocationHandler {
+        private final DeadlockMonitor deadlockMonitor;
+        private final ModuleIdentifier moduleIdentifier;
+        private final Module module;
+
+        // optimization: subsequent calls to getInstance MUST return the same value during transaction,
+        // so it is safe to cache the response
+        private Object cachedInstance;
+
+        ModuleInvocationHandler(final DeadlockMonitor deadlockMonitor, final ModuleIdentifier moduleIdentifier, final Module module) {
+            this.deadlockMonitor = Preconditions.checkNotNull(deadlockMonitor);
+            this.moduleIdentifier = Preconditions.checkNotNull(moduleIdentifier);
+            this.module = Preconditions.checkNotNull(module);
+        }
+
+        @Override
+        protected Object handleInvocation(final Object proxy, final Method method, final Object[] args) throws Throwable {
+            boolean isGetInstance = "getInstance".equals(method.getName());
+            if (isGetInstance) {
+                if (cachedInstance != null) {
+                    return cachedInstance;
+                }
+
+                checkState(deadlockMonitor.isAlive(), "Deadlock monitor is not alive");
+                deadlockMonitor.setCurrentlyInstantiatedModule(moduleIdentifier);
+            }
+            try {
+                Object response = method.invoke(module, args);
+                if (isGetInstance) {
+                    cachedInstance = response;
+                }
+                return response;
+            } catch(InvocationTargetException e) {
+                throw e.getCause();
+            } finally {
+                if (isGetInstance) {
+                    deadlockMonitor.setCurrentlyInstantiatedModule(null);
+                }
+            }
+        }
+    }
+
     public void put(
             final ModuleIdentifier moduleIdentifier,
             final Module module,
-            ModuleFactory moduleFactory,
-            ModuleInternalInfo maybeOldInternalInfo,
-            TransactionModuleJMXRegistration transactionModuleJMXRegistration,
-            boolean isDefaultBean, BundleContext bundleContext) {
+            final ModuleFactory moduleFactory,
+            final ModuleInternalInfo maybeOldInternalInfo,
+            final TransactionModuleJMXRegistration transactionModuleJMXRegistration,
+            final boolean isDefaultBean, final BundleContext bundleContext) {
         transactionStatus.checkNotCommitted();
 
         Class<? extends Module> moduleClass = Module.class;
         if (module instanceof RuntimeBeanRegistratorAwareModule) {
             moduleClass = RuntimeBeanRegistratorAwareModule.class;
         }
-        Module proxiedModule = Reflection.newProxy(moduleClass, new AbstractInvocationHandler() {
-            // optimization: subsequent calls to getInstance MUST return the same value during transaction,
-            // so it is safe to cache the response
-            private Object cachedInstance;
-
-            @Override
-            protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable {
-                boolean isGetInstance = "getInstance".equals(method.getName());
-                if (isGetInstance) {
-                    if (cachedInstance != null) {
-                        return cachedInstance;
-                    }
-
-                    checkState(deadlockMonitor.isAlive(), "Deadlock monitor is not alive");
-                    deadlockMonitor.setCurrentlyInstantiatedModule(moduleIdentifier);
-                }
-                try {
-                    Object response = method.invoke(module, args);
-                    if (isGetInstance) {
-                        cachedInstance = response;
-                    }
-                    return response;
-                } catch(InvocationTargetException e) {
-                    throw e.getCause();
-                } finally {
-                    if (isGetInstance) {
-                        deadlockMonitor.setCurrentlyInstantiatedModule(null);
-                    }
-                }
-            }
-        });
-
-
+        Module proxiedModule = Reflection.newProxy(moduleClass, new ModuleInvocationHandler(deadlockMonitor, moduleIdentifier, module));
         ModuleInternalTransactionalInfo moduleInternalTransactionalInfo = new ModuleInternalTransactionalInfo(
                 moduleIdentifier, proxiedModule, moduleFactory,
                 maybeOldInternalInfo, transactionModuleJMXRegistration, isDefaultBean, module, bundleContext);
@@ -177,18 +187,18 @@ public class DependencyResolverManager implements DependencyResolverFactory, Aut
         return modulesHolder.toCommitInfo();
     }
 
-    public Module findModule(ModuleIdentifier moduleIdentifier,
-                             JmxAttribute jmxAttributeForReporting) {
+    public Module findModule(final ModuleIdentifier moduleIdentifier,
+                             final JmxAttribute jmxAttributeForReporting) {
         return modulesHolder.findModule(moduleIdentifier,
                 jmxAttributeForReporting);
     }
 
-    public ModuleInternalTransactionalInfo findModuleInternalTransactionalInfo(ModuleIdentifier moduleIdentifier) {
+    public ModuleInternalTransactionalInfo findModuleInternalTransactionalInfo(final ModuleIdentifier moduleIdentifier) {
         return modulesHolder.findModuleInternalTransactionalInfo(moduleIdentifier);
     }
 
-    public ModuleFactory findModuleFactory(ModuleIdentifier moduleIdentifier,
-                                           JmxAttribute jmxAttributeForReporting) {
+    public ModuleFactory findModuleFactory(final ModuleIdentifier moduleIdentifier,
+                                           final JmxAttribute jmxAttributeForReporting) {
         return modulesHolder.findModuleFactory(moduleIdentifier,
                 jmxAttributeForReporting);
     }
@@ -197,12 +207,12 @@ public class DependencyResolverManager implements DependencyResolverFactory, Aut
         return modulesHolder.getAllModules();
     }
 
-    public void assertNotExists(ModuleIdentifier moduleIdentifier)
+    public void assertNotExists(final ModuleIdentifier moduleIdentifier)
             throws InstanceAlreadyExistsException {
         modulesHolder.assertNotExists(moduleIdentifier);
     }
 
-    public List<ModuleIdentifier> findAllByFactory(ModuleFactory factory) {
+    public List<ModuleIdentifier> findAllByFactory(final ModuleFactory factory) {
         List<ModuleIdentifier> result = new ArrayList<>();
         for (ModuleInternalTransactionalInfo info : modulesHolder.getAllInfos()) {
             if (factory.equals(info.getModuleFactory())) {
@@ -212,6 +222,7 @@ public class DependencyResolverManager implements DependencyResolverFactory, Aut
         return result;
     }
 
+    @Override
     public void close() {
         deadlockMonitor.close();
     }
index bb866f276e713151ccf18b0e57e589c65633647f..0dd04d539c93617d95d4f6bffc834dc4c99947f8 100644 (file)
@@ -15,7 +15,7 @@ import java.util.concurrent.ExecutorService;
  * Users of this interface can publish any YANG-modeled notification which will
  * be delivered to all subscribed listeners.
  * <p>
- * Prefered way of publishing of notifications is done by invoking {@link #publish(Object)}.
+ * Preferred way of publishing of notifications is done by invoking {@link #publish(Object)}.
  *
  * <p>You may consider using {@link #publish(Object, ExecutorService)} if and only if
  * your use-case requires customized  execution policy or run-to-completion
@@ -50,7 +50,7 @@ public interface NotificationPublishService<N> {
      * Publishes a notification and notifies subscribed listeners. All listener
      * notifications are done via the provided executor.
      * <p>
-     * <b>Note:</b> Use only if ineccessary. Consider using
+     * <b>Note:</b> Use only if necessary. Consider using
      * {@link #publish(Object)} for most use-cases.
      *
      * <p>
index feccbbad92f694fb070af73c355376acbf26e928..a83610fe9166b537defe8f790c5e6369ee634674 100644 (file)
@@ -8,10 +8,9 @@
 package org.opendaylight.controller.md.sal.common.api.notify;
 
 import java.util.EventListener;
-
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 
-public interface NotificationSubscriptionService<T,N,L extends EventListener> {
+public interface NotificationSubscriptionService<T, N, L extends EventListener> {
 
-    ListenerRegistration<L> registerNotificationListener(T type,L listener);
+    ListenerRegistration<L> registerNotificationListener(T type, L listener);
 }
index efc020ecd0044ef4e8d13f081611972e20db1efa..e3a7441caf746fdb56cc8d0a4cc87287908c41b9 100644 (file)
@@ -7,15 +7,21 @@
  */
 package org.opendaylight.controller.sal.connect.netconf.util;
 
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Sets;
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
-
 import javax.annotation.Nullable;
-
 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.api.NetconfMessage;
 import org.opendaylight.controller.netconf.util.messages.NetconfMessageUtil;
@@ -40,15 +46,6 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Collections2;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Sets;
-
 public class NetconfMessageTransformUtil {
 
     public static final String MESSAGE_ID_ATTR = "message-id";
@@ -62,34 +59,34 @@ public class NetconfMessageTransformUtil {
     public static final QName IETF_NETCONF_MONITORING_SCHEMA_VERSION = QName.create(IETF_NETCONF_MONITORING, "version");
     public static final QName IETF_NETCONF_MONITORING_SCHEMA_NAMESPACE = QName.create(IETF_NETCONF_MONITORING, "namespace");
 
-    public static URI NETCONF_URI = URI.create("urn:ietf:params:xml:ns:netconf:base:1.0");
-    public static QName NETCONF_QNAME = QName.create(NETCONF_URI, null, "netconf");
-    public static QName NETCONF_DATA_QNAME = QName.create(NETCONF_QNAME, "data");
-    public static QName NETCONF_RPC_REPLY_QNAME = QName.create(NETCONF_QNAME, "rpc-reply");
-    public static QName NETCONF_ERROR_OPTION_QNAME = QName.create(NETCONF_QNAME, "error-option");
-    public static QName NETCONF_RUNNING_QNAME = QName.create(NETCONF_QNAME, "running");
-    static List<Node<?>> RUNNING = Collections.<Node<?>> singletonList(new SimpleNodeTOImpl<>(NETCONF_RUNNING_QNAME, null, null));
-    public static QName NETCONF_SOURCE_QNAME = QName.create(NETCONF_QNAME, "source");
-    public static CompositeNode CONFIG_SOURCE_RUNNING = new CompositeNodeTOImpl(NETCONF_SOURCE_QNAME, null, RUNNING);
-    public static QName NETCONF_CANDIDATE_QNAME = QName.create(NETCONF_QNAME, "candidate");
-    public static QName NETCONF_TARGET_QNAME = QName.create(NETCONF_QNAME, "target");
-    public static QName NETCONF_CONFIG_QNAME = QName.create(NETCONF_QNAME, "config");
-    public static QName NETCONF_COMMIT_QNAME = QName.create(NETCONF_QNAME, "commit");
-    public static QName NETCONF_OPERATION_QNAME = QName.create(NETCONF_QNAME, "operation");
-    public static QName NETCONF_DEFAULT_OPERATION_QNAME = QName.create(NETCONF_OPERATION_QNAME, "default-operation");
-    public static QName NETCONF_EDIT_CONFIG_QNAME = QName.create(NETCONF_QNAME, "edit-config");
-    public static QName NETCONF_GET_CONFIG_QNAME = QName.create(NETCONF_QNAME, "get-config");
-    public static QName NETCONF_DISCARD_CHANGES_QNAME = QName.create(NETCONF_QNAME, "discard-changes");
-    public static QName NETCONF_TYPE_QNAME = QName.create(NETCONF_QNAME, "type");
-    public static QName NETCONF_FILTER_QNAME = QName.create(NETCONF_QNAME, "filter");
-    public static QName NETCONF_GET_QNAME = QName.create(NETCONF_QNAME, "get");
-    public static QName NETCONF_RPC_QNAME = QName.create(NETCONF_QNAME, "rpc");
-
-    public static URI NETCONF_ROLLBACK_ON_ERROR_URI = URI
+    public static final URI NETCONF_URI = URI.create("urn:ietf:params:xml:ns:netconf:base:1.0");
+    public static final QName NETCONF_QNAME = QName.create(NETCONF_URI, null, "netconf");
+    public static final QName NETCONF_DATA_QNAME = QName.create(NETCONF_QNAME, "data");
+    public static final QName NETCONF_RPC_REPLY_QNAME = QName.create(NETCONF_QNAME, "rpc-reply");
+    public static final QName NETCONF_ERROR_OPTION_QNAME = QName.create(NETCONF_QNAME, "error-option");
+    public static final QName NETCONF_RUNNING_QNAME = QName.create(NETCONF_QNAME, "running");
+    static final List<Node<?>> RUNNING = Collections.<Node<?>> singletonList(new SimpleNodeTOImpl<>(NETCONF_RUNNING_QNAME, null, null));
+    public static final QName NETCONF_SOURCE_QNAME = QName.create(NETCONF_QNAME, "source");
+    public static final CompositeNode CONFIG_SOURCE_RUNNING = new CompositeNodeTOImpl(NETCONF_SOURCE_QNAME, null, RUNNING);
+    public static final QName NETCONF_CANDIDATE_QNAME = QName.create(NETCONF_QNAME, "candidate");
+    public static final QName NETCONF_TARGET_QNAME = QName.create(NETCONF_QNAME, "target");
+    public static final QName NETCONF_CONFIG_QNAME = QName.create(NETCONF_QNAME, "config");
+    public static final QName NETCONF_COMMIT_QNAME = QName.create(NETCONF_QNAME, "commit");
+    public static final QName NETCONF_OPERATION_QNAME = QName.create(NETCONF_QNAME, "operation");
+    public static final QName NETCONF_DEFAULT_OPERATION_QNAME = QName.create(NETCONF_OPERATION_QNAME, "default-operation");
+    public static final QName NETCONF_EDIT_CONFIG_QNAME = QName.create(NETCONF_QNAME, "edit-config");
+    public static final QName NETCONF_GET_CONFIG_QNAME = QName.create(NETCONF_QNAME, "get-config");
+    public static final QName NETCONF_DISCARD_CHANGES_QNAME = QName.create(NETCONF_QNAME, "discard-changes");
+    public static final QName NETCONF_TYPE_QNAME = QName.create(NETCONF_QNAME, "type");
+    public static final QName NETCONF_FILTER_QNAME = QName.create(NETCONF_QNAME, "filter");
+    public static final QName NETCONF_GET_QNAME = QName.create(NETCONF_QNAME, "get");
+    public static final QName NETCONF_RPC_QNAME = QName.create(NETCONF_QNAME, "rpc");
+
+    public static final URI NETCONF_ROLLBACK_ON_ERROR_URI = URI
             .create("urn:ietf:params:netconf:capability:rollback-on-error:1.0");
-    public static String ROLLBACK_ON_ERROR_OPTION = "rollback-on-error";
+    public static final String ROLLBACK_ON_ERROR_OPTION = "rollback-on-error";
 
-    public static URI NETCONF_CANDIDATE_URI = URI
+    public static final URI NETCONF_CANDIDATE_URI = URI
             .create("urn:ietf:params:netconf:capability:candidate:1.0");
 
     // Discard changes message