Bump odlparent to 5.0.0
[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(RequestContext<List<T>> context, Class<?> requestType) {
31         final FutureCallback<OfHeader> callback = super.createCallback(context, requestType);
32
33         return new FutureCallback<OfHeader>() {
34             @Override
35             public void onSuccess(final OfHeader result) {
36                 callback.onSuccess(result);
37             }
38
39             @Override
40             public void onFailure(final Throwable throwable) {
41                 // If we failed getting table features, at least create empty tables
42                 if (MultipartType.OFPMPTABLEFEATURES.getClass().equals(requestType)) {
43                     DeviceInitializationUtil.makeEmptyTables(
44                         getTxFacade(),
45                         getDeviceInfo(),
46                         getDeviceContext().getPrimaryConnectionContext().getFeatures().getTables());
47                 }
48
49                 callback.onFailure(throwable);
50             }
51         };
52     }
53
54     @Override
55     protected OfHeader buildRequest(final Xid xid, final MultipartType input) {
56         return MultipartRequestInputFactory.makeMultipartRequest(xid.getValue(),
57                                                                  getVersion(),
58                                                                  input,
59                                                                  canUseSingleLayerSerialization());
60     }
61 }