Revert "WIP: Bump upstreams"
[openflowplugin.git] / test-provider / src / main / java / org / opendaylight / openflowplugin / test / OpenflowpluginTestServiceProvider.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 package org.opendaylight.openflowplugin.test;
9
10 import com.google.common.collect.ImmutableSet;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import org.opendaylight.mdsal.binding.api.DataBroker;
13 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
14 import org.opendaylight.mdsal.binding.api.RpcProviderService;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
26 import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
27 import org.opendaylight.yangtools.concepts.ObjectRegistration;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 import org.opendaylight.yangtools.yang.common.RpcResult;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 public class OpenflowpluginTestServiceProvider implements AutoCloseable,
34         SalFlowService {
35
36     private static final Logger LOG = LoggerFactory
37             .getLogger(OpenflowpluginTestServiceProvider.class);
38
39     private final DataBroker dataService;
40     private ObjectRegistration<SalFlowService> flowRegistration;
41     private final NotificationPublishService notificationProviderService;
42
43     public OpenflowpluginTestServiceProvider(final DataBroker dataService,
44             final NotificationPublishService notificationProviderService) {
45         this.dataService = dataService;
46         this.notificationProviderService = notificationProviderService;
47     }
48
49     /**
50      * Get data service.
51      *
52      * @return {@link #dataService}
53      */
54     public DataBroker getDataService() {
55         return dataService;
56     }
57
58     /**
59      * Get flow registration.
60      *
61      * @return {@link #flowRegistration}
62      */
63     public ObjectRegistration<SalFlowService> getFlowRegistration() {
64         return flowRegistration;
65     }
66
67     /**
68      * Set {@link #flowRegistration}.
69      */
70     public void setFlowRegistration(final ObjectRegistration<SalFlowService> flowRegistration) {
71         this.flowRegistration = flowRegistration;
72     }
73
74     /**
75      * Get notification service.
76      *
77      * @return {@link #notificationProviderService}
78      */
79     public NotificationPublishService getNotificationService() {
80         return notificationProviderService;
81     }
82
83     /*
84      * (non-Javadoc)
85      *
86      * @see java.lang.AutoCloseable#close()
87      */
88     @Override
89     public void close() {
90         OpenflowpluginTestServiceProvider.LOG
91                 .info("SalFlowServiceProvide stopped.");
92         flowRegistration.close();
93     }
94
95     /*
96      * (non-Javadoc)
97      *
98      * @see
99      * org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.
100      * SalFlowService
101      * #addFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.
102      * service.rev130819.AddFlowInput)
103      */
104     @Override
105     public ListenableFuture<RpcResult<AddFlowOutput>> addFlow(final AddFlowInput input) {
106         OpenflowpluginTestServiceProvider.LOG.info("addFlow - {}", input);
107         return null;
108     }
109
110     /*
111      * (non-Javadoc)
112      *
113      * @see
114      * org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.
115      * SalFlowService
116      * #removeFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow
117      * .service.rev130819.RemoveFlowInput)
118      */
119     @Override
120     public ListenableFuture<RpcResult<RemoveFlowOutput>> removeFlow(final RemoveFlowInput input) {
121         OpenflowpluginTestServiceProvider.LOG.info("removeFlow - {}", input);
122         return null;
123     }
124
125     /*
126      * (non-Javadoc)
127      *
128      * @see
129      * org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.
130      * SalFlowService
131      * #updateFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow
132      * .service.rev130819.UpdateFlowInput)
133      */
134     @Override
135     public ListenableFuture<RpcResult<UpdateFlowOutput>> updateFlow(final UpdateFlowInput input) {
136         OpenflowpluginTestServiceProvider.LOG.info("updateFlow - {}", input);
137         return null;
138     }
139
140     public ObjectRegistration<OpenflowpluginTestServiceProvider> register(final RpcProviderService rpcRegistry) {
141         setFlowRegistration(rpcRegistry.registerRpcImplementation(SalFlowService.class, this, ImmutableSet.of(
142             InstanceIdentifier.create(Nodes.class)
143             .child(Node.class, new NodeKey(new NodeId(OpenflowpluginTestActivator.NODE_ID))))));
144
145         return new AbstractObjectRegistration<>(this) {
146             @Override
147             protected void removeRegistration() {
148                 flowRegistration.close();
149             }
150         };
151     }
152 }