X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-restconf-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fbroker%2Fimpl%2FNotificationServiceImpl.java;h=c08f329f0d81d694e8c4f97a04fd2dfe69c25468;hb=5aa8f995feede44d69bc26e70a67e6c44b01c758;hp=617ec4fca1d81f1e1f26ab1a332a9d584df5eca2;hpb=432af2f4b92135c6ec61507ec4873b4d913da840;p=controller.git diff --git a/opendaylight/md-sal/sal-restconf-broker/src/main/java/org/opendaylight/controller/sal/restconf/broker/impl/NotificationServiceImpl.java b/opendaylight/md-sal/sal-restconf-broker/src/main/java/org/opendaylight/controller/sal/restconf/broker/impl/NotificationServiceImpl.java index 617ec4fca1..c08f329f0d 100644 --- a/opendaylight/md-sal/sal-restconf-broker/src/main/java/org/opendaylight/controller/sal/restconf/broker/impl/NotificationServiceImpl.java +++ b/opendaylight/md-sal/sal-restconf-broker/src/main/java/org/opendaylight/controller/sal/restconf/broker/impl/NotificationServiceImpl.java @@ -10,7 +10,6 @@ package org.opendaylight.controller.sal.restconf.broker.impl; import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.concurrent.ExecutorService; import org.opendaylight.controller.sal.binding.api.NotificationListener; import org.opendaylight.controller.sal.binding.api.NotificationService; @@ -18,78 +17,46 @@ import org.opendaylight.controller.sal.restconf.broker.listeners.RemoteNotificat import org.opendaylight.controller.sal.restconf.broker.tools.RemoteStreamTools; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.remote.rev140114.QName; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.remote.rev140114.SalRemoteService; +import org.opendaylight.yangtools.concepts.AbstractListenerRegistration; import org.opendaylight.yangtools.concepts.ListenerRegistration; -import org.opendaylight.yangtools.concepts.Registration; import org.opendaylight.yangtools.restconf.client.api.RestconfClientContext; import org.opendaylight.yangtools.restconf.client.api.event.EventStreamInfo; import org.opendaylight.yangtools.yang.binding.Notification; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Multimap; -import com.google.common.collect.Multimaps; -import com.google.common.collect.SetMultimap; - public class NotificationServiceImpl implements NotificationService { private final SalRemoteService salRemoteService; private final RestconfClientContext restconfClientContext; - private final Multimap,NotificationListener> listeners; - private ExecutorService _executor; - public NotificationServiceImpl(RestconfClientContext restconfClienetContext){ this.restconfClientContext = restconfClienetContext; this.salRemoteService = this.restconfClientContext.getRpcServiceContext(SalRemoteService.class).getRpcService(); - - HashMultimap,NotificationListener> _create = HashMultimap., NotificationListener>create(); - SetMultimap,NotificationListener> _synchronizedSetMultimap = Multimaps., NotificationListener>synchronizedSetMultimap(_create); - this.listeners = _synchronizedSetMultimap; - - } - public ExecutorService getExecutor() { - return this._executor; - } - - public void setExecutor(final ExecutorService executor) { - this._executor = executor; } @Override - public Registration> registerNotificationListener(Class notificationType, NotificationListener listener) { + public ListenerRegistration> registerNotificationListener(Class notificationType, NotificationListener listener) { //TODO implementation using sal-remote List notifications = new ArrayList(); notifications.add(new QName(notificationType.toString())); String notificationStreamName = RemoteStreamTools.createNotificationStream(salRemoteService, notifications); final Map desiredEventStream = RemoteStreamTools.createEventStream(restconfClientContext, notificationStreamName); RemoteNotificationListener remoteNotificationListener = new RemoteNotificationListener(listener); - ListenerRegistration listenerRegistration = restconfClientContext.getEventStreamContext(desiredEventStream.get(desiredEventStream.get(notificationStreamName))).registerNotificationListener(remoteNotificationListener); - return new SalNotificationRegistration(listenerRegistration); + + final ListenerRegistration listenerRegistration = restconfClientContext.getEventStreamContext(desiredEventStream.get(desiredEventStream.get(notificationStreamName))) + .registerNotificationListener(remoteNotificationListener); + + return new AbstractListenerRegistration>(listener) { + @Override + protected void removeRegistration() { + listenerRegistration.close(); + } + }; } @Override - public Registration registerNotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener listener) { + public ListenerRegistration registerNotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener listener) { //TODO implementation using sal-remote String notificationStreamName = RemoteStreamTools.createNotificationStream(salRemoteService, null); final Map desiredEventStream = RemoteStreamTools.createEventStream(restconfClientContext, notificationStreamName); return restconfClientContext.getEventStreamContext(desiredEventStream.get(desiredEventStream.get(notificationStreamName))).registerNotificationListener(listener); } - - private class SalNotificationRegistration implements Registration>{ - private final Registration registration; - - public SalNotificationRegistration(ListenerRegistration listenerRegistration){ - this.registration = listenerRegistration; - } - - @Override - public NotificationListener getInstance() { - return this.getInstance(); - } - - @Override - public void close() throws Exception { - this.registration.close(); - } - } - - }