Fix RpcResultBuilder/RpcContext raw references
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / statistics / services / dedicated / StatisticsGatheringService.java
index 0c4a4b8885c7f8ab8a1e4541413e0f29589e6f48..7a5685327c93a1e3724590b2d65dd5634f591fcb 100644 (file)
@@ -16,12 +16,13 @@ import java.util.List;
 import java.util.concurrent.Future;
 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
 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.RequestContextUtil;
 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;
@@ -46,10 +47,10 @@ public class StatisticsGatheringService extends CommonService {
 
 
     public Future<RpcResult<List<MultipartReply>>> getStatisticsOfType(final MultipartType type) {
-        return handleServiceCall(new Function<DataCrate<List<MultipartReply>>, ListenableFuture<RpcResult<Void>>>() {
+        return handleServiceCall(new Function<RequestContext<List<MultipartReply>>, ListenableFuture<RpcResult<Void>>>() {
                                      @Override
-                                     public ListenableFuture<RpcResult<Void>> apply(final DataCrate<List<MultipartReply>> data) {
-                                         final Xid xid = data.getRequestContext().getXid();
+                                     public ListenableFuture<RpcResult<Void>> apply(final RequestContext<List<MultipartReply>> requestContext) {
+                                         final Xid xid = requestContext.getXid();
                                          final DeviceContext deviceContext = getDeviceContext();
                                          final MultiMsgCollector multiMsgCollector = deviceContext.getMultiMsgCollector();
 
@@ -58,7 +59,7 @@ public class StatisticsGatheringService extends CommonService {
                                                  makeMultipartRequestInput(xid.getValue(),
                                                          getVersion(),
                                                          type);
-                                         final OutboundQueue outboundQueue = deviceContext.getPrimaryConnectionContext().getOutboundQueueProvider().getOutboundQueue();
+                                         final OutboundQueue outboundQueue = deviceContext.getPrimaryConnectionContext().getOutboundQueueProvider();
                                          final SettableFuture<RpcResult<Void>> settableFuture = SettableFuture.create();
                                          outboundQueue.commitEntry(xid.getValue(), multipartRequestInput, new FutureCallback<OfHeader>() {
                                              @Override
@@ -71,15 +72,17 @@ public class StatisticsGatheringService extends CommonService {
                                                      if (null != ofHeader) {
                                                          LOG.info("Unexpected response type received {}.", ofHeader.getClass());
                                                      } else {
-                                                         LOG.info("Unexpected response type received {}.", ofHeader.getClass());
+                                                         LOG.info("Ofheader was null.");
                                                      }
                                                  }
-
                                              }
 
                                              @Override
                                              public void onFailure(final Throwable throwable) {
-                                                 RpcResultBuilder rpcResultBuilder = RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, throwable.getMessage());
+                                                 RpcResultBuilder<Void> rpcResultBuilder = RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, throwable.getMessage());
+                                                 getDeviceContext().unhookRequestCtx(requestContext.getXid());
+                                                 RequestContextUtil.closeRequstContext(requestContext);
+
                                                  settableFuture.set(rpcResultBuilder.build());
                                              }
                                          });