2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.openflowplugin.impl.services;
10 import java.util.List;
11 import java.util.Objects;
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.handlers.MultiMsgCollector;
15 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.EventIdentifier;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
17 import org.opendaylight.yangtools.yang.common.RpcError;
18 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
22 public abstract class AbstractMultipartRequestCallback<T extends OfHeader> extends AbstractRequestCallback<List<T>> {
23 private static final Logger LOG = LoggerFactory.getLogger(AbstractMultipartRequestCallback.class);
24 private final MultiMsgCollector<T> collector;
26 public AbstractMultipartRequestCallback(
27 final RequestContext<List<T>> context,
28 final Class<?> requestType,
29 final DeviceContext deviceContext,
30 final EventIdentifier eventIdentifier) {
31 super(context, requestType, deviceContext.getMessageSpy(), eventIdentifier);
32 collector = deviceContext.getMultiMsgCollector(context);
36 @SuppressWarnings("unchecked")
37 public void onSuccess(final OfHeader result) {
38 if (Objects.isNull(result)) {
39 LOG.info("Response received was null.");
40 collector.endCollecting(getEventIdentifier());
44 if (!isMultipart(result)) {
45 LOG.info("Unexpected response type received: {}.", result.getClass());
47 setResult(RpcResultBuilder
49 .withError(RpcError.ErrorType.APPLICATION,
50 String.format("Unexpected response type received: %s.", result.getClass()))
53 final T resultCast = (T) result;
54 collector.addMultipartMsg(resultCast, isReqMore(resultCast), getEventIdentifier());
59 * Check if result is multipart.
60 * @param result result
61 * @return true if result is multipart
63 protected abstract boolean isMultipart(OfHeader result);
66 * Check if result requests more multiparts.
67 * @param result result
68 * @return true if result requests more multiparts
70 protected abstract boolean isReqMore(T result);