BUG-614: convert NotificationBrokerImpl 59/7559/1
authorRobert Varga <rovarga@cisco.com>
Sat, 31 May 2014 07:34:09 +0000 (09:34 +0200)
committerRobert Varga <rovarga@cisco.com>
Sat, 31 May 2014 07:37:23 +0000 (09:37 +0200)
This does a straight xtend->java conversion by moving xtend-generated
java files into the repository instead of xtend. This is the first step
in optimizing NotificationBrokerImpl.

Change-Id: Ie8dc1dfb6c5b9e80a8d79a5de31410100b35c7fc
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/GeneratedListenerRegistration.java [new file with mode: 0644]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/GenericNotificationRegistration.java [new file with mode: 0644]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationBrokerImpl.java [new file with mode: 0644]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationBrokerImpl.xtend [deleted file]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/NotifyTask.java [new file with mode: 0644]

diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/GeneratedListenerRegistration.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/GeneratedListenerRegistration.java
new file mode 100644 (file)
index 0000000..cc8471f
--- /dev/null
@@ -0,0 +1,37 @@
+/**
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.controller.sal.binding.impl;
+
+import org.opendaylight.controller.sal.binding.spi.NotificationInvokerFactory.NotificationInvoker;
+import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.NotificationListener;
+
+public class GeneratedListenerRegistration extends AbstractObjectRegistration<NotificationListener> implements ListenerRegistration<NotificationListener> {
+    private final NotificationInvoker _invoker;
+
+    public NotificationInvoker getInvoker() {
+        return this._invoker;
+    }
+
+    private NotificationBrokerImpl notificationBroker;
+
+    public GeneratedListenerRegistration(final NotificationListener instance, final NotificationInvoker invoker, final NotificationBrokerImpl broker) {
+        super(instance);
+        this._invoker = invoker;
+        this.notificationBroker = broker;
+    }
+
+    @Override
+    protected void removeRegistration() {
+        this.notificationBroker.unregisterListener(this);
+        this.notificationBroker = null;
+        NotificationInvoker _invoker = this.getInvoker();
+        _invoker.close();
+    }
+}
diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/GenericNotificationRegistration.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/GenericNotificationRegistration.java
new file mode 100644 (file)
index 0000000..9567831
--- /dev/null
@@ -0,0 +1,35 @@
+/**
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.controller.sal.binding.impl;
+
+import org.opendaylight.controller.sal.binding.api.NotificationListener;
+import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.Notification;
+
+public class GenericNotificationRegistration<T extends Notification> extends AbstractObjectRegistration<NotificationListener<T>> implements ListenerRegistration<NotificationListener<T>> {
+    private final Class<T> _type;
+
+    public Class<T> getType() {
+        return this._type;
+    }
+
+    private NotificationBrokerImpl notificationBroker;
+
+    public GenericNotificationRegistration(final Class<T> type, final NotificationListener<T> instance, final NotificationBrokerImpl broker) {
+        super(instance);
+        this._type = type;
+        this.notificationBroker = broker;
+    }
+
+    @Override
+    protected void removeRegistration() {
+        this.notificationBroker.unregisterListener(this);
+        this.notificationBroker = null;
+    }
+}
diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationBrokerImpl.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationBrokerImpl.java
new file mode 100644 (file)
index 0000000..6de878f
--- /dev/null
@@ -0,0 +1,214 @@
+/**
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.controller.sal.binding.impl;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Set;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+
+import org.eclipse.xtext.xbase.lib.Conversions;
+import org.eclipse.xtext.xbase.lib.Exceptions;
+import org.eclipse.xtext.xbase.lib.Functions.Function0;
+import org.eclipse.xtext.xbase.lib.Functions.Function1;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+import org.opendaylight.controller.sal.binding.api.NotificationListener;
+import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.controller.sal.binding.codegen.impl.SingletonHolder;
+import org.opendaylight.controller.sal.binding.spi.NotificationInvokerFactory.NotificationInvoker;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.concepts.Registration;
+import org.opendaylight.yangtools.concepts.util.ListenerRegistry;
+import org.opendaylight.yangtools.yang.binding.Notification;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Objects;
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSet.Builder;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Multimap;
+import com.google.common.collect.Multimaps;
+import com.google.common.collect.SetMultimap;
+
+public class NotificationBrokerImpl implements NotificationProviderService, AutoCloseable {
+    private final ListenerRegistry<NotificationInterestListener> interestListeners = new Function0<ListenerRegistry<NotificationInterestListener>>() {
+        @Override
+        public ListenerRegistry<NotificationInterestListener> apply() {
+            ListenerRegistry<NotificationInterestListener> _create = ListenerRegistry.<NotificationInterestListener>create();
+            return _create;
+        }
+    }.apply();
+
+    private final Multimap<Class<? extends Notification>,NotificationListener<? extends Object>> listeners;
+
+    private ExecutorService _executor;
+
+    public ExecutorService getExecutor() {
+        return this._executor;
+    }
+
+    public void setExecutor(final ExecutorService executor) {
+        this._executor = executor;
+    }
+
+    private final Logger logger = new Function0<Logger>() {
+        @Override
+        public Logger apply() {
+            Logger _logger = LoggerFactory.getLogger(NotificationBrokerImpl.class);
+            return _logger;
+        }
+    }.apply();
+
+    public NotificationBrokerImpl() {
+        HashMultimap<Class<? extends Notification>,NotificationListener<? extends Object>> _create = HashMultimap.<Class<? extends Notification>, NotificationListener<? extends Object>>create();
+        SetMultimap<Class<? extends Notification>,NotificationListener<? extends Object>> _synchronizedSetMultimap = Multimaps.<Class<? extends Notification>, NotificationListener<? extends Object>>synchronizedSetMultimap(_create);
+        this.listeners = _synchronizedSetMultimap;
+    }
+
+    @Deprecated
+    public NotificationBrokerImpl(final ExecutorService executor) {
+        HashMultimap<Class<? extends Notification>,NotificationListener<? extends Object>> _create = HashMultimap.<Class<? extends Notification>, NotificationListener<? extends Object>>create();
+        SetMultimap<Class<? extends Notification>,NotificationListener<? extends Object>> _synchronizedSetMultimap = Multimaps.<Class<? extends Notification>, NotificationListener<? extends Object>>synchronizedSetMultimap(_create);
+        this.listeners = _synchronizedSetMultimap;
+        this.setExecutor(executor);
+    }
+
+    public Iterable<Class<? extends Object>> getNotificationTypes(final Notification notification) {
+        Class<? extends Notification> _class = notification.getClass();
+        Class<? extends Object>[] _interfaces = _class.getInterfaces();
+        final Function1<Class<? extends Object>,Boolean> _function = new Function1<Class<? extends Object>,Boolean>() {
+            @Override
+            public Boolean apply(final Class<? extends Object> it) {
+                boolean _and = false;
+                boolean _notEquals = (!Objects.equal(it, Notification.class));
+                if (!_notEquals) {
+                    _and = false;
+                } else {
+                    boolean _isAssignableFrom = Notification.class.isAssignableFrom(it);
+                    _and = (_notEquals && _isAssignableFrom);
+                }
+                return Boolean.valueOf(_and);
+            }
+        };
+        Iterable<Class<? extends Object>> _filter = IterableExtensions.<Class<? extends Object>>filter(((Iterable<Class<? extends Object>>)Conversions.doWrapArray(_interfaces)), _function);
+        return _filter;
+    }
+
+    @Override
+    public void publish(final Notification notification) {
+        ExecutorService _executor = this.getExecutor();
+        this.publish(notification, _executor);
+    }
+
+    @Override
+    public void publish(final Notification notification, final ExecutorService service) {
+        final Iterable<Class<? extends Object>> allTypes = this.getNotificationTypes(notification);
+        Iterable<NotificationListener<? extends Object>> listenerToNotify = Collections.<NotificationListener<? extends Object>>emptySet();
+        for (final Class<? extends Object> type : allTypes) {
+            Collection<NotificationListener<? extends Object>> _get = this.listeners.get(((Class<? extends Notification>) type));
+            Iterable<NotificationListener<? extends Object>> _plus = Iterables.<NotificationListener<? extends Object>>concat(listenerToNotify, _get);
+            listenerToNotify = _plus;
+        }
+        final Function1<NotificationListener<? extends Object>,NotifyTask> _function = new Function1<NotificationListener<? extends Object>,NotifyTask>() {
+            @Override
+            public NotifyTask apply(final NotificationListener<? extends Object> it) {
+                NotifyTask _notifyTask = new NotifyTask(it, notification);
+                return _notifyTask;
+            }
+        };
+        Iterable<NotifyTask> _map = IterableExtensions.<NotificationListener<? extends Object>, NotifyTask>map(listenerToNotify, _function);
+        final Set<NotifyTask> tasks = IterableExtensions.<NotifyTask>toSet(_map);
+        ExecutorService _executor = this.getExecutor();
+        this.submitAll(_executor, tasks);
+    }
+
+    public ImmutableSet<Future<Object>> submitAll(final ExecutorService service, final Set<NotifyTask> tasks) {
+        final Builder<Future<Object>> ret = ImmutableSet.<Future<Object>>builder();
+        for (final NotifyTask task : tasks) {
+            Future<Object> _submit = service.<Object>submit(task);
+            ret.add(_submit);
+        }
+        return ret.build();
+    }
+
+    @Override
+    public <T extends Notification> Registration<NotificationListener<T>> registerNotificationListener(final Class<T> notificationType, final NotificationListener<T> listener) {
+        GenericNotificationRegistration<T> _genericNotificationRegistration = new GenericNotificationRegistration<T>(notificationType, listener, this);
+        final GenericNotificationRegistration<T> reg = _genericNotificationRegistration;
+        this.listeners.put(notificationType, listener);
+        this.announceNotificationSubscription(notificationType);
+        return reg;
+    }
+
+    public void announceNotificationSubscription(final Class<? extends Notification> notification) {
+        for (final ListenerRegistration<NotificationInterestListener> listener : this.interestListeners) {
+            try {
+                NotificationInterestListener _instance = listener.getInstance();
+                _instance.onNotificationSubscribtion(notification);
+            } catch (final Throwable _t) {
+                if (_t instanceof Exception) {
+                    final Exception e = (Exception)_t;
+                    String _message = e.getMessage();
+                    this.logger.error("", _message);
+                } else {
+                    throw Exceptions.sneakyThrow(_t);
+                }
+            }
+        }
+    }
+
+    @Override
+    public Registration<org.opendaylight.yangtools.yang.binding.NotificationListener> registerNotificationListener(final org.opendaylight.yangtools.yang.binding.NotificationListener listener) {
+        final NotificationInvoker invoker = SingletonHolder.INVOKER_FACTORY.invokerFor(listener);
+        Set<Class<? extends Notification>> _supportedNotifications = invoker.getSupportedNotifications();
+        for (final Class<? extends Notification> notifyType : _supportedNotifications) {
+            {
+                NotificationListener<Notification> _invocationProxy = invoker.getInvocationProxy();
+                this.listeners.put(notifyType, _invocationProxy);
+                this.announceNotificationSubscription(notifyType);
+            }
+        }
+        GeneratedListenerRegistration _generatedListenerRegistration = new GeneratedListenerRegistration(listener, invoker, this);
+        final GeneratedListenerRegistration registration = _generatedListenerRegistration;
+        return (registration);
+    }
+
+    protected boolean unregisterListener(final GenericNotificationRegistration<? extends Object> reg) {
+        Class<? extends Notification> _type = reg.getType();
+        NotificationListener<? extends Notification> _instance = reg.getInstance();
+        boolean _remove = this.listeners.remove(_type, _instance);
+        return _remove;
+    }
+
+    protected void unregisterListener(final GeneratedListenerRegistration reg) {
+        NotificationInvoker _invoker = reg.getInvoker();
+        Set<Class<? extends Notification>> _supportedNotifications = _invoker.getSupportedNotifications();
+        for (final Class<? extends Notification> notifyType : _supportedNotifications) {
+            NotificationInvoker _invoker_1 = reg.getInvoker();
+            NotificationListener<Notification> _invocationProxy = _invoker_1.getInvocationProxy();
+            this.listeners.remove(notifyType, _invocationProxy);
+        }
+    }
+
+    @Override
+    public void close() {
+    }
+
+    @Override
+    public ListenerRegistration<NotificationInterestListener> registerInterestListener(final NotificationInterestListener interestListener) {
+        final ListenerRegistration<NotificationInterestListener> registration = this.interestListeners.register(interestListener);
+        Set<Class<? extends Notification>> _keySet = this.listeners.keySet();
+        for (final Class<? extends Notification> notification : _keySet) {
+            interestListener.onNotificationSubscribtion(notification);
+        }
+        return registration;
+    }
+}
diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationBrokerImpl.xtend b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationBrokerImpl.xtend
deleted file mode 100644 (file)
index 6d675b4..0000000
+++ /dev/null
@@ -1,201 +0,0 @@
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.sal.binding.impl\r
-\r
-import com.google.common.collect.HashMultimap\r
-import com.google.common.collect.ImmutableSet\r
-import com.google.common.collect.Multimap\r
-import com.google.common.collect.Multimaps\r
-import java.util.Collections\r
-import java.util.concurrent.Callable\r
-import java.util.concurrent.ExecutorService\r
-import java.util.concurrent.Future\r
-import java.util.Set\r
-import org.opendaylight.controller.sal.binding.api.NotificationListener\r
-import org.opendaylight.controller.sal.binding.api.NotificationProviderService\r
-import org.opendaylight.controller.sal.binding.api.NotificationProviderService.NotificationInterestListener\r
-import org.opendaylight.controller.sal.binding.codegen.impl.SingletonHolder\r
-import org.opendaylight.controller.sal.binding.spi.NotificationInvokerFactory.NotificationInvoker\r
-import org.opendaylight.yangtools.concepts.AbstractObjectRegistration\r
-import org.opendaylight.yangtools.concepts.ListenerRegistration\r
-import org.opendaylight.yangtools.concepts.Registration\r
-import org.opendaylight.yangtools.concepts.util.ListenerRegistry\r
-import org.opendaylight.yangtools.yang.binding.Notification\r
-import org.slf4j.LoggerFactory\r
-\r
-class NotificationBrokerImpl implements NotificationProviderService, AutoCloseable {\r
-    \r
-    val ListenerRegistry<NotificationInterestListener> interestListeners = ListenerRegistry.create;\r
-    \r
-    val Multimap<Class<? extends Notification>, NotificationListener<?>> listeners;\r
-\r
-    @Property\r
-    var ExecutorService executor;\r
-    \r
-    val logger = LoggerFactory.getLogger(NotificationBrokerImpl)\r
-\r
-    new() {\r
-        listeners = Multimaps.synchronizedSetMultimap(HashMultimap.create())\r
-    }\r
-\r
-    @Deprecated\r
-    new(ExecutorService executor) {\r
-        listeners = Multimaps.synchronizedSetMultimap(HashMultimap.create())\r
-        this.executor = executor;\r
-    }\r
-\r
-    def getNotificationTypes(Notification notification) {\r
-        notification.class.interfaces.filter[it != Notification && Notification.isAssignableFrom(it)]\r
-    }\r
-\r
-    override publish(Notification notification) {\r
-        publish(notification, executor)\r
-    }\r
-\r
-    override publish(Notification notification, ExecutorService service) {\r
-        val allTypes = notification.notificationTypes\r
-\r
-        var Iterable<NotificationListener<? extends Object>> listenerToNotify = Collections.emptySet();\r
-        for (type : allTypes) {\r
-            listenerToNotify = listenerToNotify + listeners.get(type as Class<? extends Notification>)\r
-        }\r
-        val tasks = listenerToNotify.map[new NotifyTask(it, notification)].toSet;\r
-        submitAll(executor,tasks);\r
-    }\r
-    \r
-    def submitAll(ExecutorService service, Set<NotifyTask> tasks) {\r
-        val ret = ImmutableSet.<Future<Object>>builder();\r
-        for(task : tasks) {\r
-            ret.add(service.submit(task));\r
-        }\r
-        return ret.build();\r
-    }\r
-    \r
-    override <T extends Notification> registerNotificationListener(Class<T> notificationType,\r
-        NotificationListener<T> listener) {\r
-        val reg = new GenericNotificationRegistration<T>(notificationType, listener, this);\r
-        listeners.put(notificationType, listener);\r
-        announceNotificationSubscription(notificationType);\r
-        return reg;\r
-    }\r
-    \r
-    def announceNotificationSubscription(Class<? extends Notification> notification) {\r
-        for (listener : interestListeners) {\r
-            try {\r
-                listener.instance.onNotificationSubscribtion(notification);\r
-            } catch (Exception e) {\r
-                logger.error("", e.message)\r
-            }\r
-        }\r
-    }\r
-\r
-    override registerNotificationListener(\r
-        org.opendaylight.yangtools.yang.binding.NotificationListener listener) {\r
-        val invoker = SingletonHolder.INVOKER_FACTORY.invokerFor(listener);\r
-        for (notifyType : invoker.supportedNotifications) {\r
-            listeners.put(notifyType, invoker.invocationProxy)\r
-            announceNotificationSubscription(notifyType)\r
-        }\r
-        val registration = new GeneratedListenerRegistration(listener, invoker,this);\r
-        return registration as Registration<org.opendaylight.yangtools.yang.binding.NotificationListener>;\r
-    }\r
-\r
-    protected def unregisterListener(GenericNotificationRegistration<?> reg) {\r
-        listeners.remove(reg.type, reg.instance);\r
-    }\r
-\r
-    protected def unregisterListener(GeneratedListenerRegistration reg) {\r
-        for (notifyType : reg.invoker.supportedNotifications) {\r
-            listeners.remove(notifyType, reg.invoker.invocationProxy)\r
-        }\r
-    }\r
-    \r
-    override close()  {\r
-        //FIXME: implement properly.\r
-    }\r
-    \r
-    override registerInterestListener(NotificationInterestListener interestListener) {\r
-        val registration = interestListeners.register(interestListener);\r
-        \r
-        for(notification : listeners.keySet) {\r
-            interestListener.onNotificationSubscribtion(notification);\r
-        }\r
-        return registration\r
-    }\r
-}\r
-\r
-class GenericNotificationRegistration<T extends Notification> extends AbstractObjectRegistration<NotificationListener<T>> implements ListenerRegistration<NotificationListener<T>> {\r
-\r
-    @Property\r
-    val Class<T> type;\r
-\r
-    var NotificationBrokerImpl notificationBroker;\r
-\r
-    public new(Class<T> type, NotificationListener<T> instance, NotificationBrokerImpl broker) {\r
-        super(instance);\r
-        _type = type;\r
-        notificationBroker = broker;\r
-    }\r
-\r
-    override protected removeRegistration() {\r
-        notificationBroker.unregisterListener(this);\r
-        notificationBroker = null;\r
-    }\r
-}\r
-\r
-class GeneratedListenerRegistration extends AbstractObjectRegistration<org.opendaylight.yangtools.yang.binding.NotificationListener> implements ListenerRegistration<org.opendaylight.yangtools.yang.binding.NotificationListener> {\r
-\r
-    @Property\r
-    val NotificationInvoker invoker;\r
-    \r
-    var NotificationBrokerImpl notificationBroker;\r
-    \r
-\r
-    new(org.opendaylight.yangtools.yang.binding.NotificationListener instance, NotificationInvoker invoker, NotificationBrokerImpl broker) {\r
-        super(instance);\r
-        _invoker = invoker;\r
-        notificationBroker = broker;\r
-    }\r
-\r
-    override protected removeRegistration() {\r
-        notificationBroker.unregisterListener(this);\r
-        notificationBroker = null;\r
-        invoker.close();\r
-    }\r
-}\r
-\r
-@Data\r
-class NotifyTask implements Callable<Object> {\r
-\r
-    private static val log = LoggerFactory.getLogger(NotifyTask);\r
-\r
-    @SuppressWarnings("rawtypes")\r
-    val NotificationListener listener;\r
-    val Notification notification;\r
-\r
-    override call() {\r
-        //Only logging the complete notification in debug mode\r
-        try {\r
-            if(log.isDebugEnabled){\r
-                log.debug("Delivering notification {} to {}",notification,listener);\r
-            } else {\r
-                log.trace("Delivering notification {} to {}",notification.class.name,listener);\r
-            }\r
-            listener.onNotification(notification);\r
-            if(log.isDebugEnabled){\r
-                log.debug("Notification delivered {} to {}",notification,listener);\r
-            } else {\r
-                log.trace("Notification delivered {} to {}",notification.class.name,listener);\r
-            }\r
-        } catch (Exception e) {\r
-            log.error("Unhandled exception thrown by listener: {}", listener, e);\r
-        }\r
-        return null;\r
-    }\r
-\r
-}\r
diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/NotifyTask.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/NotifyTask.java
new file mode 100644 (file)
index 0000000..9471616
--- /dev/null
@@ -0,0 +1,126 @@
+/**
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.controller.sal.binding.impl;
+
+import java.util.concurrent.Callable;
+
+import org.eclipse.xtext.xbase.lib.Exceptions;
+import org.eclipse.xtext.xbase.lib.Functions.Function0;
+import org.eclipse.xtext.xbase.lib.util.ToStringHelper;
+import org.opendaylight.controller.sal.binding.api.NotificationListener;
+import org.opendaylight.yangtools.yang.binding.Notification;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NotifyTask implements Callable<Object> {
+    private static Logger log = new Function0<Logger>() {
+        @Override
+        public Logger apply() {
+            Logger _logger = LoggerFactory.getLogger(NotifyTask.class);
+            return _logger;
+        }
+    }.apply();
+
+    @SuppressWarnings("rawtypes")
+    private final NotificationListener _listener;
+
+    public NotificationListener getListener() {
+        return this._listener;
+    }
+
+    private final Notification _notification;
+
+    public Notification getNotification() {
+        return this._notification;
+    }
+
+    @Override
+    public Object call() {
+        try {
+            boolean _isDebugEnabled = NotifyTask.log.isDebugEnabled();
+            if (_isDebugEnabled) {
+                Notification _notification = this.getNotification();
+                NotificationListener _listener = this.getListener();
+                NotifyTask.log.debug("Delivering notification {} to {}", _notification, _listener);
+            } else {
+                Notification _notification_1 = this.getNotification();
+                Class<? extends Notification> _class = _notification_1.getClass();
+                String _name = _class.getName();
+                NotificationListener _listener_1 = this.getListener();
+                NotifyTask.log.trace("Delivering notification {} to {}", _name, _listener_1);
+            }
+            NotificationListener _listener_2 = this.getListener();
+            Notification _notification_2 = this.getNotification();
+            _listener_2.onNotification(_notification_2);
+            boolean _isDebugEnabled_1 = NotifyTask.log.isDebugEnabled();
+            if (_isDebugEnabled_1) {
+                Notification _notification_3 = this.getNotification();
+                NotificationListener _listener_3 = this.getListener();
+                NotifyTask.log.debug("Notification delivered {} to {}", _notification_3, _listener_3);
+            } else {
+                Notification _notification_4 = this.getNotification();
+                Class<? extends Notification> _class_1 = _notification_4.getClass();
+                String _name_1 = _class_1.getName();
+                NotificationListener _listener_4 = this.getListener();
+                NotifyTask.log.trace("Notification delivered {} to {}", _name_1, _listener_4);
+            }
+        } catch (final Throwable _t) {
+            if (_t instanceof Exception) {
+                final Exception e = (Exception)_t;
+                NotificationListener _listener_5 = this.getListener();
+                NotifyTask.log.error("Unhandled exception thrown by listener: {}", _listener_5, e);
+            } else {
+                throw Exceptions.sneakyThrow(_t);
+            }
+        }
+        return null;
+    }
+
+    public NotifyTask(final NotificationListener listener, final Notification notification) {
+        super();
+        this._listener = listener;
+        this._notification = notification;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((_listener== null) ? 0 : _listener.hashCode());
+        result = prime * result + ((_notification== null) ? 0 : _notification.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(final Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        NotifyTask other = (NotifyTask) obj;
+        if (_listener == null) {
+            if (other._listener != null)
+                return false;
+        } else if (!_listener.equals(other._listener))
+            return false;
+        if (_notification == null) {
+            if (other._notification != null)
+                return false;
+        } else if (!_notification.equals(other._notification))
+            return false;
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        String result = new ToStringHelper().toString(this);
+        return result;
+    }
+}