45b4afaa6e4954c7ed13fac6f24791e77b7dd90c
[controller.git] / opendaylight / md-sal / samples / clustering-test-app / provider / src / main / java / org / opendaylight / controller / config / yang / config / clustering_it_provider / ClusteringItProviderModule.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.config.yang.config.clustering_it_provider;
10
11
12 import org.opendaylight.controller.clustering.it.listener.PeopleCarListener;
13 import org.opendaylight.controller.clustering.it.provider.CarProvider;
14 import org.opendaylight.controller.clustering.it.provider.PeopleProvider;
15 import org.opendaylight.controller.clustering.it.provider.PurchaseCarProvider;
16 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
17 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
18 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.purchase.rev140818.CarPurchaseService;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.CarService;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.people.rev140818.PeopleService;
22 import org.opendaylight.yangtools.concepts.ListenerRegistration;
23 import org.opendaylight.yangtools.yang.binding.NotificationListener;
24
25 public class ClusteringItProviderModule extends org.opendaylight.controller.config.yang.config.clustering_it_provider.AbstractClusteringItProviderModule {
26     public ClusteringItProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
27         super(identifier, dependencyResolver);
28     }
29
30     public ClusteringItProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.controller.config.yang.config.clustering_it_provider.ClusteringItProviderModule oldModule, java.lang.AutoCloseable oldInstance) {
31         super(identifier, dependencyResolver, oldModule, oldInstance);
32     }
33
34     @Override
35     public void customValidation() {
36         // add custom validation form module attributes here.
37     }
38
39     @Override
40     public java.lang.AutoCloseable createInstance() {
41       DataBroker dataBrokerService = getDataBrokerDependency();
42       NotificationProviderService notificationProvider = getNotificationServiceDependency();
43
44       // Add routed RPC registration for car purchase
45       final PurchaseCarProvider purchaseCar = new PurchaseCarProvider();
46       purchaseCar.setNotificationProvider(notificationProvider);
47
48       final BindingAwareBroker.RoutedRpcRegistration<CarPurchaseService> purchaseCarRpc = getRpcRegistryDependency()
49           .addRoutedRpcImplementation(CarPurchaseService.class, purchaseCar);
50
51       // Add people provider registration
52       final PeopleProvider people = new PeopleProvider();
53       people.setDataProvider(dataBrokerService);
54
55       people.setRpcRegistration(purchaseCarRpc);
56
57       CarProvider carProvider = new CarProvider(dataBrokerService, getOwnershipServiceDependency());
58       getRpcRegistryDependency().addRpcImplementation(CarService.class, carProvider);
59
60       final BindingAwareBroker.RpcRegistration<PeopleService> peopleRpcReg = getRpcRegistryDependency()
61           .addRpcImplementation(PeopleService.class, people);
62
63
64
65       final PeopleCarListener peopleCarListener = new PeopleCarListener();
66       peopleCarListener.setDataProvider(dataBrokerService);
67
68       final ListenerRegistration<NotificationListener> listenerReg =
69           getNotificationServiceDependency().registerNotificationListener( peopleCarListener );
70
71       // Wrap toaster as AutoCloseable and close registrations to md-sal at
72       // close()
73       final class AutoCloseableToaster implements AutoCloseable {
74
75         @Override
76         public void close() throws Exception {
77           peopleRpcReg.close();
78           purchaseCarRpc.close();
79           people.close();
80           purchaseCar.close();
81           listenerReg.close();
82         }
83       }
84
85       AutoCloseable ret = new AutoCloseableToaster();
86       return ret;
87     }
88
89 }