From: Tony Tkacik Date: Tue, 25 Feb 2014 11:54:25 +0000 (+0000) Subject: Merge changes I1b834def,Iece78be2 X-Git-Tag: autorelease-tag-v20140601202136_82eb3f9~390 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=1a3336307cfe9d4d7cf3ee3b44dd1664c35b1114;hp=80c075a37991b8eacb7ac27af3a57ed366682ecd Merge changes I1b834def,Iece78be2 * changes: Removed duplicated dependency declaration: ietf-netconf-monitoring,ietf-netconf-monitoring-extension from commons.opendaylight. Move xtend dependency definition from md-sal pom to commons.opendaylight --- diff --git a/opendaylight/md-sal/sal-restconf-broker/src/main/java/org/opendaylight/controller/sal/restconf/broker/client/SalRemoteClient.java b/opendaylight/md-sal/sal-restconf-broker/src/main/java/org/opendaylight/controller/sal/restconf/broker/client/SalRemoteClient.java new file mode 100644 index 0000000000..0044d367f8 --- /dev/null +++ b/opendaylight/md-sal/sal-restconf-broker/src/main/java/org/opendaylight/controller/sal/restconf/broker/client/SalRemoteClient.java @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2014 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.restconf.broker.client; + +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext; + +public interface SalRemoteClient extends AutoCloseable { + + ConsumerContext registerConsumer(); + +} diff --git a/opendaylight/md-sal/sal-restconf-broker/src/main/java/org/opendaylight/controller/sal/restconf/broker/client/SalRemoteClientDeployer.java b/opendaylight/md-sal/sal-restconf-broker/src/main/java/org/opendaylight/controller/sal/restconf/broker/client/SalRemoteClientDeployer.java new file mode 100644 index 0000000000..a1bb81b0bb --- /dev/null +++ b/opendaylight/md-sal/sal-restconf-broker/src/main/java/org/opendaylight/controller/sal/restconf/broker/client/SalRemoteClientDeployer.java @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2014 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.restconf.broker.client; + +import java.net.URL; + +public class SalRemoteClientDeployer { + + public static SalRemoteClient createSalRemoteClient(final URL url) { + return new SalRemoteClientImpl(url); + } + +} diff --git a/opendaylight/md-sal/sal-restconf-broker/src/main/java/org/opendaylight/controller/sal/restconf/broker/client/SalRemoteClientImpl.java b/opendaylight/md-sal/sal-restconf-broker/src/main/java/org/opendaylight/controller/sal/restconf/broker/client/SalRemoteClientImpl.java new file mode 100644 index 0000000000..ec62568a1b --- /dev/null +++ b/opendaylight/md-sal/sal-restconf-broker/src/main/java/org/opendaylight/controller/sal/restconf/broker/client/SalRemoteClientImpl.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2014 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.restconf.broker.client; + +import java.net.URL; + +import javassist.ClassPool; + +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext; +import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer; +import org.opendaylight.controller.sal.restconf.broker.SalRemoteServiceBroker; +import org.opendaylight.yangtools.restconf.client.RestconfClientFactory; +import org.opendaylight.yangtools.restconf.client.api.RestconfClientContext; +import org.opendaylight.yangtools.restconf.client.api.UnsupportedProtocolException; +import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext; +import org.opendaylight.yangtools.sal.binding.generator.impl.RuntimeGeneratedMappingServiceImpl; +import org.opendaylight.yangtools.yang.binding.Augmentation; +import org.opendaylight.yangtools.yang.binding.util.BindingReflections; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.Preconditions; + +class SalRemoteClientImpl implements SalRemoteClient { + + private static final Logger logger = LoggerFactory.getLogger(SalRemoteClientImpl.class); + + private final RestconfClientContext restconfClientContext; + private final SalRemoteServiceBroker salRemoteBroker; + private final RuntimeGeneratedMappingServiceImpl mappingService; + + public SalRemoteClientImpl(final URL url) { + Preconditions.checkNotNull(url); + + this.mappingService = new RuntimeGeneratedMappingServiceImpl(); + this.mappingService.setPool(ClassPool.getDefault()); + this.mappingService.init(); + + final ModuleInfoBackedContext moduleInfo = ModuleInfoBackedContext.create(); + moduleInfo.addModuleInfos(BindingReflections.loadModuleInfos()); + this.mappingService.onGlobalContextUpdated(moduleInfo.tryToCreateSchemaContext().get()); + + try { + this.restconfClientContext = new RestconfClientFactory().getRestconfClientContext(url, this.mappingService, + this.mappingService); + + this.salRemoteBroker = new SalRemoteServiceBroker("remote-broker", restconfClientContext); + this.salRemoteBroker.start(); + } catch (UnsupportedProtocolException e) { + logger.error("Unsupported protocol {}.", url.getProtocol(), e); + throw new IllegalArgumentException("Unsupported protocol.", e); + } + } + + @Override + public ConsumerContext registerConsumer() { + return this.salRemoteBroker.registerConsumer(new BindingAwareConsumer() { + + @Override + public void onSessionInitialized(ConsumerContext session) { + } + }, null); + } + + @Override + public void close() throws Exception { + this.restconfClientContext.close(); + this.salRemoteBroker.close(); + } + +} 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(); + } + }; } }