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