Simplify CommonService interface
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / services / SalMeterServiceImpl.java
1 /**
2  * Copyright (c) 2015 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.impl.services;
9
10 import java.util.concurrent.Future;
11 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
12 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterOutput;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.SalMeterService;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter;
21 import org.opendaylight.yangtools.yang.common.RpcResult;
22
23 public class SalMeterServiceImpl implements SalMeterService {
24     private final MeterService<AddMeterInput, AddMeterOutput> addMeter;
25     private final MeterService<Meter, UpdateMeterOutput> updateMeter;
26     private final MeterService<RemoveMeterInput, RemoveMeterOutput> removeMeter;
27
28     public SalMeterServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
29         addMeter = new MeterService<>(requestContextStack, deviceContext, AddMeterOutput.class);
30         updateMeter = new MeterService<>(requestContextStack, deviceContext, UpdateMeterOutput.class);
31         removeMeter = new MeterService<>(requestContextStack, deviceContext, RemoveMeterOutput.class);
32     }
33
34     @Override
35     public Future<RpcResult<AddMeterOutput>> addMeter(final AddMeterInput input) {
36         addMeter.getDeviceContext().getDeviceMeterRegistry().store(input.getMeterId());
37
38         return addMeter.handleServiceCall(input);
39     }
40
41     @Override
42     public Future<RpcResult<UpdateMeterOutput>> updateMeter(final UpdateMeterInput input) {
43         return updateMeter.handleServiceCall(input.getUpdatedMeter());
44     }
45
46     @Override
47     public Future<RpcResult<RemoveMeterOutput>> removeMeter(final RemoveMeterInput input) {
48         removeMeter.getDeviceContext().getDeviceMeterRegistry().markToBeremoved(input.getMeterId());
49         return removeMeter.handleServiceCall(input);
50     }
51 }