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.device.listener;
10 import com.google.common.base.Preconditions;
11 import java.util.ArrayList;
12 import java.util.List;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.eclipse.jdt.annotation.Nullable;
15 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
16 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceReplyProcessor;
17 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
18 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.EventIdentifier;
19 import org.opendaylight.openflowplugin.impl.statistics.ofpspecific.EventsTimeCounter;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
21 import org.opendaylight.yangtools.yang.common.RpcResult;
22 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * Implementation for {@link MultiMsgCollector} interface.
29 * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
30 * @author <a href="mailto:tkubas@cisco.com">Timotej Kubas</a>
32 public class MultiMsgCollectorImpl<T extends OfHeader> implements MultiMsgCollector<T> {
33 private static final Logger LOG = LoggerFactory.getLogger(MultiMsgCollectorImpl.class);
34 private final List<T> replyCollection = new ArrayList<>();
35 private final RequestContext<List<T>> requestContext;
36 private final DeviceReplyProcessor deviceReplyProcessor;
38 public MultiMsgCollectorImpl(final DeviceReplyProcessor deviceReplyProcessor,
39 final RequestContext<List<T>> requestContext) {
40 this.deviceReplyProcessor = Preconditions.checkNotNull(deviceReplyProcessor);
41 this.requestContext = Preconditions.checkNotNull(requestContext);
45 public void addMultipartMsg(@NonNull final T reply, final boolean reqMore,
46 @Nullable final EventIdentifier eventIdentifier) {
47 Preconditions.checkNotNull(reply);
48 Preconditions.checkNotNull(requestContext.getXid());
49 Preconditions.checkArgument(requestContext.getXid().getValue().equals(reply.getXid()));
50 LOG.trace("Try to add Multipart reply msg with XID {}", reply.getXid());
51 replyCollection.add(reply);
54 endCollecting(eventIdentifier);
59 public void endCollecting(@Nullable final EventIdentifier eventIdentifier) {
60 final RpcResult<List<T>> rpcResult = RpcResultBuilder.success(replyCollection).build();
62 if (eventIdentifier != null) {
63 EventsTimeCounter.markEnd(eventIdentifier);
66 requestContext.setResult(rpcResult);
67 requestContext.close();
68 deviceReplyProcessor.processReply(requestContext.getXid(), replyCollection);