Merge "Bug 5592 - NodeId+DatapathId in Services (remove dependency on DeviceContext...
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / statistics / services / dedicated / StatisticsGatheringService.java
index b06d99e0855c7009041f51b26c0ee0c0b63b30c9..c43ae604fc8af3fee422d8b2e9ef5d61055285ba 100644 (file)
@@ -8,20 +8,19 @@
 
 package org.opendaylight.openflowplugin.impl.statistics.services.dedicated;
 
-import com.google.common.base.Function;
-import com.google.common.util.concurrent.JdkFutureAdapters;
-import com.google.common.util.concurrent.ListenableFuture;
 import java.util.List;
 import java.util.concurrent.Future;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
+import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.EventIdentifier;
+import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.StatisticsGatherer;
 import org.opendaylight.openflowplugin.impl.common.MultipartRequestInputFactory;
-import org.opendaylight.openflowplugin.impl.services.CommonService;
-import org.opendaylight.openflowplugin.impl.services.DataCrate;
+import org.opendaylight.openflowplugin.impl.services.AbstractMultipartService;
+import org.opendaylight.openflowplugin.impl.statistics.ofpspecific.EventsTimeCounter;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -29,37 +28,24 @@ import org.slf4j.LoggerFactory;
 /**
  * Created by Martin Bobak <mbobak@cisco.com> on 4.4.2015.
  */
-public class StatisticsGatheringService extends CommonService {
+public class StatisticsGatheringService extends AbstractMultipartService<MultipartType> implements StatisticsGatherer {
 
     private static final Logger LOG = LoggerFactory.getLogger(StatisticsGatheringService.class);
 
     public StatisticsGatheringService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
-
         super(requestContextStack, deviceContext);
     }
 
-
-    public Future<RpcResult<List<MultipartReply>>> getStatisticsOfType(final MultipartType type) {
-        return handleServiceCall(
-                PRIMARY_CONNECTION, new Function<DataCrate<List<MultipartReply>>, ListenableFuture<RpcResult<Void>>>() {
-                    @Override
-                    public ListenableFuture<RpcResult<Void>> apply(final DataCrate<List<MultipartReply>> data) {
-
-                        LOG.info("Calling multipart request for type {}", type);
-                        final Xid xid = deviceContext.getNextXid();
-                        data.getRequestContext().setXid(xid);
-                        deviceContext.getOpenflowMessageListenerFacade().registerMultipartXid(xid.getValue());
-                        MultipartRequestInput multipartRequestInput = MultipartRequestInputFactory.
-                                makeMultipartRequestInput(xid.getValue(),
-                                        version,
-                                        type);
-                        final Future<RpcResult<Void>> resultFromOFLib = deviceContext.getPrimaryConnectionContext()
-                                .getConnectionAdapter().multipartRequest(multipartRequestInput);
-                        return JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
-                    }
-                }
-
-        );
+    @Override
+    public Future<RpcResult<List<MultipartReply>>> getStatisticsOfType(final EventIdentifier eventIdentifier, final MultipartType type) {
+        LOG.debug("Getting statistics for node {} of type {}", getNodeId(), type);
+        EventsTimeCounter.markStart(eventIdentifier);
+        setEventIdentifier(eventIdentifier);
+        return handleServiceCall(type);
     }
 
+    @Override
+    protected OfHeader buildRequest(final Xid xid, final MultipartType input) {
+        return MultipartRequestInputFactory.makeMultipartRequestInput(xid.getValue(), getVersion(), input);
+    }
 }