From: Robert Varga Date: Wed, 19 Feb 2014 02:54:03 +0000 (+0100) Subject: Reuse AbstractListenerRegistration X-Git-Tag: autorelease-tag-v20140601202136_82eb3f9~392^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=0ace6d34a0b5220398adf4c57c782fc5accc49bd;p=controller.git Reuse AbstractListenerRegistration No sense in defining a new class -- just reuse what's already there. Also uncovers the fact that we're losing an underlying registration -- but let's deal with that once the ListenerRegistration API changes not to throw exceptions on close(). Change-Id: I5a12b1d7ca89f1608bc54b3f1a520223e650d53f Signed-off-by: Robert Varga --- diff --git a/opendaylight/md-sal/sal-restconf-broker/src/main/java/org/opendaylight/controller/sal/restconf/broker/impl/DataBrokerServiceImpl.java b/opendaylight/md-sal/sal-restconf-broker/src/main/java/org/opendaylight/controller/sal/restconf/broker/impl/DataBrokerServiceImpl.java index 9410d17007..e31d576d01 100644 --- a/opendaylight/md-sal/sal-restconf-broker/src/main/java/org/opendaylight/controller/sal/restconf/broker/impl/DataBrokerServiceImpl.java +++ b/opendaylight/md-sal/sal-restconf-broker/src/main/java/org/opendaylight/controller/sal/restconf/broker/impl/DataBrokerServiceImpl.java @@ -22,6 +22,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controll import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.remote.rev140114.CreateDataChangeEventSubscriptionInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.remote.rev140114.CreateDataChangeEventSubscriptionOutput; 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.restconf.client.api.RestconfClientContext; import org.opendaylight.yangtools.restconf.client.api.event.EventStreamInfo; @@ -149,22 +150,12 @@ public class DataBrokerServiceImpl implements DataBrokerService { final Map desiredEventStream = RemoteStreamTools.createEventStream(restconfClientContext,streamName); ListenableEventStreamContext restConfListenableEventStreamContext = restconfClientContext.getEventStreamContext(desiredEventStream.get(streamName)); RemoteDataChangeNotificationListener remoteDataChangeNotificationListener = new RemoteDataChangeNotificationListener(listener); - restConfListenableEventStreamContext.registerNotificationListener(remoteDataChangeNotificationListener); - return new SalRemoteDataListenerRegistration(listener); - } - - private class SalRemoteDataListenerRegistration implements ListenerRegistration { - private final DataChangeListener dataChangeListener; - public SalRemoteDataListenerRegistration(DataChangeListener dataChangeListener){ - this.dataChangeListener = dataChangeListener; - } - @Override - public DataChangeListener getInstance() { - return this.dataChangeListener; - } - @Override - public void close() { - //noop - } + final ListenerRegistration reg = restConfListenableEventStreamContext.registerNotificationListener(remoteDataChangeNotificationListener); + return new AbstractListenerRegistration(listener) { + @Override + protected void removeRegistration() { + reg.close(); + } + }; } }