Decompose RPC implementation classes
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / services / sal / UpdateTableImpl.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.sal;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
12 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
13 import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider;
14 import org.opendaylight.openflowplugin.impl.services.multilayer.MultiLayerTableMultipartService;
15 import org.opendaylight.openflowplugin.impl.services.singlelayer.SingleLayerTableMultipartService;
16 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTable;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput;
20 import org.opendaylight.yangtools.yang.common.RpcResult;
21
22 public final class UpdateTableImpl implements UpdateTable {
23     private final SingleLayerTableMultipartService singleLayerService;
24     private final MultiLayerTableMultipartService multiLayerService;
25
26     public UpdateTableImpl(final RequestContextStack requestContextStack,
27                                final DeviceContext deviceContext,
28                                final ConvertorExecutor convertorExecutor,
29                                final MultipartWriterProvider multipartWriterProvider) {
30         singleLayerService = new SingleLayerTableMultipartService(requestContextStack, deviceContext,
31             multipartWriterProvider);
32         multiLayerService = new MultiLayerTableMultipartService(requestContextStack, deviceContext, convertorExecutor,
33             multipartWriterProvider);
34     }
35
36     @Override
37     public ListenableFuture<RpcResult<UpdateTableOutput>> invoke(final UpdateTableInput input) {
38         return singleLayerService.canUseSingleLayerSerialization()
39             ? singleLayerService.handleAndReply(input)
40             : multiLayerService.handleAndReply(input);
41     }
42 }