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 org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
12 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
13 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
14 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.EventIdentifier;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
16 import org.opendaylight.yangtools.yang.common.ErrorType;
17 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 public abstract class AbstractMultipartRequestCallback<T extends OfHeader> extends AbstractRequestCallback<List<T>> {
22 private static final Logger LOG = LoggerFactory.getLogger(AbstractMultipartRequestCallback.class);
23 private final MultiMsgCollector<T> collector;
25 public AbstractMultipartRequestCallback(
26 final RequestContext<List<T>> context,
27 final Class<?> requestType,
28 final DeviceContext deviceContext,
29 final EventIdentifier eventIdentifier) {
30 super(context, requestType, deviceContext.getMessageSpy(), eventIdentifier);
31 collector = deviceContext.getMultiMsgCollector(context);
35 @SuppressWarnings("unchecked")
36 public void onSuccess(final OfHeader result) {
38 LOG.info("Response received was null.");
39 collector.endCollecting(getEventIdentifier());
43 if (!isMultipart(result)) {
44 LOG.info("Unexpected response type received: {}.", result.getClass());
46 setResult(RpcResultBuilder
48 .withError(ErrorType.APPLICATION,
49 String.format("Unexpected response type received: %s.", result.getClass()))
52 final T resultCast = (T) result;
53 collector.addMultipartMsg(resultCast, isReqMore(resultCast), getEventIdentifier());
58 * Check if result is multipart.
59 * @param result result
60 * @return true if result is multipart
62 protected abstract boolean isMultipart(OfHeader result);
65 * Check if result requests more multiparts.
66 * @param result result
67 * @return true if result requests more multiparts
69 protected abstract boolean isReqMore(T result);