Bump mdsal to 5.0.2
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / services / AbstractMultipartCollectorService.java
1 /*
2  * Copyright (c) 2017 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 package org.opendaylight.openflowplugin.impl.services;
9
10 import com.google.common.util.concurrent.FutureCallback;
11 import java.util.List;
12 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
13 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
14 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
15 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
16 import org.opendaylight.openflowplugin.impl.common.MultipartRequestInputFactory;
17 import org.opendaylight.openflowplugin.impl.util.DeviceInitializationUtil;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
20
21 public abstract class AbstractMultipartCollectorService<T extends OfHeader>
22         extends AbstractMultipartService<MultipartType, T> {
23
24     protected AbstractMultipartCollectorService(final RequestContextStack requestContextStack,
25                                                 final DeviceContext deviceContext) {
26         super(requestContextStack, deviceContext);
27     }
28
29     @Override
30     protected FutureCallback<OfHeader> createCallback(final RequestContext<List<T>> context,
31             final Class<?> requestType) {
32         final FutureCallback<OfHeader> callback = super.createCallback(context, requestType);
33
34         return new FutureCallback<>() {
35             @Override
36             public void onSuccess(final OfHeader result) {
37                 callback.onSuccess(result);
38             }
39
40             @Override
41             public void onFailure(final Throwable throwable) {
42                 // If we failed getting table features, at least create empty tables
43                 if (MultipartType.OFPMPTABLEFEATURES.getClass().equals(requestType)) {
44                     DeviceInitializationUtil.makeEmptyTables(
45                         getTxFacade(),
46                         getDeviceInfo(),
47                         getDeviceContext().getPrimaryConnectionContext().getFeatures().getTables().toJava());
48                 }
49
50                 callback.onFailure(throwable);
51             }
52         };
53     }
54
55     @Override
56     protected OfHeader buildRequest(final Xid xid, final MultipartType input) {
57         return MultipartRequestInputFactory.makeMultipartRequest(xid.getValue().toJava(),
58                                                                  getVersion(),
59                                                                  input,
60                                                                  canUseSingleLayerSerialization());
61     }
62 }