8e2837aa7212c617e5f0ed7864ba38461489f4c6
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / statistics / services / dedicated / StatisticsGatheringOnTheFlyService.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. 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
9 package org.opendaylight.openflowplugin.impl.statistics.services.dedicated;
10
11 import com.google.common.util.concurrent.ListenableFuture;
12 import java.util.List;
13 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
14 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
15 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
16 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.EventIdentifier;
17 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.StatisticsGatherer;
18 import org.opendaylight.openflowplugin.impl.common.MultipartRequestInputFactory;
19 import org.opendaylight.openflowplugin.impl.services.AbstractMultipartOnTheFlyService;
20 import org.opendaylight.openflowplugin.impl.services.util.ServiceException;
21 import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider;
22 import org.opendaylight.openflowplugin.impl.statistics.ofpspecific.EventsTimeCounter;
23 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
26 import org.opendaylight.yangtools.yang.common.RpcResult;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 /**
31  * collects statistics and processes them on the fly
32  */
33 public class StatisticsGatheringOnTheFlyService<T extends OfHeader>
34     extends AbstractMultipartOnTheFlyService<MultipartType, T>
35     implements StatisticsGatherer<T> {
36
37     private static final Logger LOG = LoggerFactory.getLogger(StatisticsGatheringOnTheFlyService.class);
38
39     public StatisticsGatheringOnTheFlyService(final RequestContextStack requestContextStack,
40                                               final DeviceContext deviceContext,
41                                               final ConvertorExecutor convertorExecutor,
42                                               final MultipartWriterProvider statisticsWriterProvider) {
43         super(requestContextStack, deviceContext, convertorExecutor, statisticsWriterProvider);
44     }
45
46     @Override
47     public ListenableFuture<RpcResult<List<T>>> getStatisticsOfType(final EventIdentifier eventIdentifier, final MultipartType type) {
48         LOG.debug("Getting statistics (onTheFly) for node {} of type {}", getDeviceInfo().getNodeId(), type);
49         EventsTimeCounter.markStart(eventIdentifier);
50         setEventIdentifier(eventIdentifier);
51         return handleServiceCall(type);
52     }
53
54     @Override
55     protected OfHeader buildRequest(final Xid xid, final MultipartType input) throws ServiceException {
56         return MultipartRequestInputFactory.makeMultipartRequest(xid.getValue(), getVersion(), input, canUseSingleLayerSerialization());
57     }
58
59 }