Simplify CommonService interface
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / services / SalGroupServiceImpl.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.group.service.rev130918.AddGroupInput;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupOutput;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.SalGroupService;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group;
21 import org.opendaylight.yangtools.yang.common.RpcResult;
22
23 public class SalGroupServiceImpl implements SalGroupService {
24     private final GroupService<AddGroupInput, AddGroupOutput> addGroup;
25     private final GroupService<Group, UpdateGroupOutput> updateGroup;
26     private final GroupService<RemoveGroupInput, RemoveGroupOutput> removeGroup;
27
28     public SalGroupServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
29         addGroup = new GroupService<>(requestContextStack, deviceContext, AddGroupOutput.class);
30         updateGroup = new GroupService<>(requestContextStack, deviceContext, UpdateGroupOutput.class);
31         removeGroup = new GroupService<>(requestContextStack, deviceContext, RemoveGroupOutput.class);
32     }
33
34     @Override
35     public Future<RpcResult<AddGroupOutput>> addGroup(final AddGroupInput input) {
36         addGroup.getDeviceContext().getDeviceGroupRegistry().store(input.getGroupId());
37         return addGroup.handleServiceCall(input);
38     }
39
40     @Override
41     public Future<RpcResult<UpdateGroupOutput>> updateGroup(final UpdateGroupInput input) {
42         return updateGroup.handleServiceCall(input.getUpdatedGroup());
43     }
44
45     @Override
46     public Future<RpcResult<RemoveGroupOutput>> removeGroup(final RemoveGroupInput input) {
47         removeGroup.getDeviceContext().getDeviceGroupRegistry().markToBeremoved(input.getGroupId());
48         return removeGroup.handleServiceCall(input);
49     }
50 }