Fix statistics race condition on big flows
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / services / sal / SalExperimenterMpMessageServiceImpl.java
1 /*
2  * Copyright (c) 2016 Pantheon Technologies s.r.o. 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.impl.services.sal;
10
11 import java.util.concurrent.Future;
12 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
13 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
14 import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider;
15 import org.opendaylight.openflowplugin.impl.services.multilayer.MultiLayerExperimenterMultipartService;
16 import org.opendaylight.openflowplugin.impl.services.singlelayer.SingleLayerExperimenterMultipartService;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.mp.message.service.rev151020.SalExperimenterMpMessageService;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.mp.message.service.rev151020.SendExperimenterMpRequestInput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.mp.message.service.rev151020.SendExperimenterMpRequestOutput;
20 import org.opendaylight.yangtools.yang.common.RpcResult;
21
22 public class SalExperimenterMpMessageServiceImpl implements SalExperimenterMpMessageService {
23     private final MultiLayerExperimenterMultipartService multiLayerService;
24     private final SingleLayerExperimenterMultipartService singleLayerService;
25
26     public SalExperimenterMpMessageServiceImpl(final RequestContextStack requestContextStack,
27                                                final DeviceContext deviceContext,
28                                                final ExtensionConverterProvider extensionConverterProvider) {
29         this.singleLayerService = new SingleLayerExperimenterMultipartService(requestContextStack, deviceContext,
30             extensionConverterProvider);
31         this.multiLayerService = new MultiLayerExperimenterMultipartService(requestContextStack, deviceContext,
32             extensionConverterProvider);
33     }
34
35     @Override
36     public Future<RpcResult<SendExperimenterMpRequestOutput>> sendExperimenterMpRequest(SendExperimenterMpRequestInput input) {
37         return singleLayerService.canUseSingleLayerSerialization()
38             ? singleLayerService.handleAndReply(input)
39             : multiLayerService.handleAndReply(input);
40     }
41
42 }