Merge "OPNFLWPLUG-929 : Remove deprecated guava library"
[openflowplugin.git] / test-provider / src / main / java / org / opendaylight / openflowplugin / test / OpenflowpluginGroupTestServiceProvider.java
1 /**
2  * Copyright (c) 2013 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.openflowplugin.test;
10
11 import java.util.concurrent.Future;
12 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
13 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
14 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupOutput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.SalGroupService;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInput;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeContext;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
27 import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
28 import org.opendaylight.yangtools.concepts.ObjectRegistration;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
31 import org.opendaylight.yangtools.yang.common.RpcResult;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35 public class OpenflowpluginGroupTestServiceProvider implements AutoCloseable,
36         SalGroupService {
37
38     private static final Logger LOG = LoggerFactory
39             .getLogger(OpenflowpluginGroupTestServiceProvider.class);
40     private RoutedRpcRegistration<SalGroupService> groupRegistration;
41     private NotificationProviderService notificationService;
42
43     /**
44      * get group registration
45      *
46      * @return {@link #groupRegistration}
47      */
48     public RoutedRpcRegistration<SalGroupService> getGroupRegistration() {
49         return groupRegistration;
50     }
51
52     /**
53      * set {@link #groupRegistration}
54      *
55      * @param groupRegistration
56      */
57     public void setGroupRegistration(
58             final RoutedRpcRegistration<SalGroupService> groupRegistration) {
59         this.groupRegistration = groupRegistration;
60     }
61
62     /**
63      * get notification service
64      *
65      * @return {@link #notificationService}
66      */
67     public NotificationProviderService getNotificationService() {
68         return notificationService;
69     }
70
71     /**
72      * set {@link #notificationService}
73      *
74      * @param notificationService
75      */
76     public void setNotificationService(
77             final NotificationProviderService notificationService) {
78         this.notificationService = notificationService;
79     }
80
81     public void start() {
82         OpenflowpluginGroupTestServiceProvider.LOG
83                 .info("SalGroupServiceProvider Started.");
84     }
85
86     /*
87      * (non-Javadoc)
88      *
89      * @see java.lang.AutoCloseable#close()
90      */
91     @Override
92     public void close() throws Exception {
93         OpenflowpluginGroupTestServiceProvider.LOG
94                 .info("SalGroupServiceProvide stopped.");
95         groupRegistration.close();
96     }
97
98     /*
99      * (non-Javadoc)
100      *
101      * @see
102      * org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918
103      * .SalGroupService
104      * #addGroup(org.opendaylight.yang.gen.v1.urn.opendaylight.group
105      * .service.rev130918.AddGroupInput)
106      */
107     @Override
108     public Future<RpcResult<AddGroupOutput>> addGroup(AddGroupInput input) {
109         String plus = ("addGroup - " + input);
110         OpenflowpluginGroupTestServiceProvider.LOG.info(plus);
111         return null;
112     }
113
114     /*
115      * (non-Javadoc)
116      *
117      * @see
118      * org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918
119      * .SalGroupService
120      * #removeGroup(org.opendaylight.yang.gen.v1.urn.opendaylight
121      * .group.service.rev130918.RemoveGroupInput)
122      */
123     @Override
124     public Future<RpcResult<RemoveGroupOutput>> removeGroup(
125             RemoveGroupInput input) {
126         String plus = ("removeGroup - " + input);
127         OpenflowpluginGroupTestServiceProvider.LOG.info(plus);
128         return null;
129     }
130
131     /*
132      * (non-Javadoc)
133      *
134      * @see
135      * org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918
136      * .SalGroupService
137      * #updateGroup(org.opendaylight.yang.gen.v1.urn.opendaylight
138      * .group.service.rev130918.UpdateGroupInput)
139      */
140     @Override
141     public Future<RpcResult<UpdateGroupOutput>> updateGroup(
142             UpdateGroupInput input) {
143         String plus = ("updateGroup - " + input);
144         OpenflowpluginGroupTestServiceProvider.LOG.info(plus);
145         return null;
146     }
147
148     /**
149      * @param ctx
150      * @return {@link ObjectRegistration}
151      */
152     public ObjectRegistration<OpenflowpluginGroupTestServiceProvider> register(
153             final ProviderContext ctx) {
154         RoutedRpcRegistration<SalGroupService> addRoutedRpcImplementation = ctx
155                 .<SalGroupService> addRoutedRpcImplementation(
156                         SalGroupService.class, this);
157         setGroupRegistration(addRoutedRpcImplementation);
158
159         InstanceIdentifierBuilder<Nodes> builder1 = InstanceIdentifier
160                 .<Nodes> builder(Nodes.class);
161
162         NodeId nodeId = new NodeId(OpenflowpluginTestActivator.NODE_ID);
163         NodeKey nodeKey = new NodeKey(nodeId);
164
165         InstanceIdentifierBuilder<Node> nodeIndentifier = builder1
166                 .<Node, NodeKey> child(Node.class, nodeKey);
167         InstanceIdentifier<Node> instance = nodeIndentifier.build();
168         groupRegistration.registerPath(NodeContext.class, instance);
169         RoutedRpcRegistration<SalGroupService> groupRegistration1 = this
170                 .getGroupRegistration();
171         return new AbstractObjectRegistration<OpenflowpluginGroupTestServiceProvider>(this) {
172             @Override
173             protected void removeRegistration() {
174                 groupRegistration1.close();
175             }
176         };
177     }
178
179 }