2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.clustering.it.listener;
11 import com.google.common.util.concurrent.FutureCallback;
12 import com.google.common.util.concurrent.Futures;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
15 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.people.rev140818.CarPeople;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.people.rev140818.car.people.CarPerson;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.people.rev140818.car.people.CarPersonBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.people.rev140818.car.people.CarPersonKey;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.purchase.rev140818.CarBought;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.purchase.rev140818.CarPurchaseListener;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 public class PeopleCarListener implements CarPurchaseListener {
29 private static final Logger log = LoggerFactory.getLogger(PeopleCarListener.class);
31 private DataBroker dataProvider;
35 public void setDataProvider(final DataBroker salDataProvider) {
36 this.dataProvider = salDataProvider;
40 public void onCarBought(CarBought notification) {
41 log.info("onCarBought notification : Adding car person entry");
43 final CarPersonBuilder carPersonBuilder = new CarPersonBuilder();
44 carPersonBuilder.setCarId(notification.getCarId());
45 carPersonBuilder.setPersonId(notification.getPersonId());
46 CarPersonKey key = new CarPersonKey(notification.getCarId(), notification.getPersonId());
47 carPersonBuilder.setKey(key);
48 final CarPerson carPerson = carPersonBuilder.build();
50 InstanceIdentifier<CarPerson> carPersonIId =
51 InstanceIdentifier.<CarPeople>builder(CarPeople.class).child(CarPerson.class, carPerson.getKey()).build();
54 WriteTransaction tx = dataProvider.newWriteOnlyTransaction();
55 tx.put(LogicalDatastoreType.CONFIGURATION, carPersonIId, carPerson);
57 Futures.addCallback(tx.submit(), new FutureCallback<Void>() {
59 public void onSuccess(final Void result) {
60 log.info("Car bought, entry added to map of people and car [{}]", carPerson);
64 public void onFailure(final Throwable t) {
65 log.info("Car bought, Failed entry addition to map of people and car [{}]", carPerson);