import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToasterRestocked;
import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToasterRestockedBuilder;
import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToasterService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.toaster.app.config.rev160503.ToasterAppConfig;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.toaster.app.config.rev160503.ToasterAppConfigBuilder;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcError;
// Thread safe holder for our darkness multiplier.
private final AtomicLong darknessFactor = new AtomicLong( 1000 );
+ private final ToasterAppConfig toasterAppConfig;
+
public OpendaylightToaster() {
+ this(new ToasterAppConfigBuilder().setManufacturer(TOASTER_MANUFACTURER).setModelNumber(TOASTER_MODEL_NUMBER).
+ setMaxMakeToastTries(2).build());
+ }
+
+ public OpendaylightToaster(ToasterAppConfig toasterAppConfig) {
super("OpendaylightToaster", "toaster-provider", null);
executor = Executors.newFixedThreadPool(1);
+ this.toasterAppConfig = toasterAppConfig;
}
public void setNotificationProvider(final NotificationPublishService notificationPublishService) {
// note - we are simulating a device whose manufacture and model are
// fixed (embedded) into the hardware.
// This is why the manufacture and model number are hardcoded.
- return new ToasterBuilder().setToasterManufacturer( TOASTER_MANUFACTURER )
- .setToasterModelNumber( TOASTER_MODEL_NUMBER )
+ return new ToasterBuilder().setToasterManufacturer( toasterAppConfig.getManufacturer() )
+ .setToasterModelNumber( toasterAppConfig.getModelNumber() )
.setToasterStatus( status )
.build();
}
final SettableFuture<RpcResult<Void>> futureResult = SettableFuture.create();
- checkStatusAndMakeToast( input, futureResult, 2 );
+ checkStatusAndMakeToast( input, futureResult, toasterAppConfig.getMaxMakeToastTries() );
return futureResult;
}
</cm:default-properties>
</cm:property-placeholder>
+ <!-- "clustered-app-config" is an ODL extension that obtains an application configuration yang container
+ from the MD-SAL data store and makes the binding DataObject available as a bean that can be injected
+ into other beans. Here we obtain the ToasterAppConfig container DataObject. This also shows how to
+ specify default data via the "default-config" child element. While default leaf values defined in the
+ yang are returned, one may have more complex data, eg lists, that require default data. The
+ "default-config" must contain the XML representation of the yang data, including namespace, wrapped
+ in a CDATA section to prevent the blueprint container from treating it as markup.
+ -->
+ <odl:clustered-app-config id="toasterAppConfig"
+ binding-class="org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.toaster.app.config.rev160503.ToasterAppConfig">
+ <odl:default-config><![CDATA[
+ <toaster-app-config xmlns="urn:opendaylight:params:xml:ns:yang:controller:toaster-app-config">
+ <max-make-toast-tries>3</max-make-toast-tries>
+ </toaster-app-config>
+ ]]></odl:default-config>
+ </odl:clustered-app-config>
+
<!-- Import MD-SAL services. For the DataBroker, we explicitly specify the odl:type which is configurable
via the cfg file. In this manner the toaster can be configured to use the default clustered DataBroker
or the specialized "pingpong" DataBroker (or any other DataBroker implementation).
<!-- Create the OpendaylightToaster instance and inject its dependencies -->
<bean id="toaster" class="org.opendaylight.controller.sample.toaster.provider.OpendaylightToaster"
init-method="register" destroy-method="unregister">
+ <argument ref="toasterAppConfig"/>
<property name="dataProvider" ref="dataBroker"/>
<property name="notificationProvider" ref="notificationService"/>
</bean>
--- /dev/null
+module toaster-app-config {
+ yang-version 1;
+
+ namespace "urn:opendaylight:params:xml:ns:yang:controller:toaster-app-config";
+ prefix toaster-app-config;
+
+ import toaster { prefix toaster; revision-date 2009-11-20; }
+
+ description
+ "Configuration for the Opendaylight toaster application.";
+
+ revision "2016-05-03" {
+ description
+ "Initial revision.";
+ }
+
+ container toaster-app-config {
+ leaf manufacturer {
+ type toaster:DisplayString;
+ default "Opendaylight";
+ }
+
+ leaf model-number {
+ type toaster:DisplayString;
+ default "Model 1 - Binding Aware";
+ }
+
+ leaf max-make-toast-tries {
+ type uint16;
+ default 2;
+ }
+ }
+}
\ No newline at end of file