X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fimpl%2Fdevice%2Flistener%2FMultiMsgCollectorImpl.java;h=9d0a6449eddc03a0e5e6ca69d7d087c3c27969d0;hb=cd93e3a04858cd9d62b8b41e31dc7b3635bea246;hp=b0d2b122f9fcc2d01bdf5be655af6a5c6645cadf;hpb=27f402a23af92655acb275cf01bd2aa289d7e756;p=openflowplugin.git diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/listener/MultiMsgCollectorImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/listener/MultiMsgCollectorImpl.java index b0d2b122f9..9d0a6449ed 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/listener/MultiMsgCollectorImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/listener/MultiMsgCollectorImpl.java @@ -17,25 +17,31 @@ import com.google.common.cache.RemovalNotification; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContext; import org.opendaylight.openflowplugin.api.openflow.device.Xid; import org.opendaylight.openflowplugin.api.openflow.device.exception.DeviceDataException; import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceReplyProcessor; import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector; 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.OfHeader; +import org.opendaylight.yangtools.yang.common.RpcError; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.common.RpcResultBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** + *

* openflowplugin-api * org.opendaylight.openflowplugin.impl.openflow.device - *

+ * * Implementation for {@link MultiMsgCollector} interface * * @author Vaclav Demcak * @author Timotej Kubas - *

+ *

* Created: Mar 23, 2015 */ @VisibleForTesting @@ -77,8 +83,8 @@ public class MultiMsgCollectorImpl implements MultiMsgCollector { } @Override - public void registerMultipartXid(final long xid) { - cache.put(xid, new MultiCollectorObject()); + public void registerMultipartRequestContext(final RequestContext requestContext) { + cache.put(requestContext.getXid().getValue(), new MultiCollectorObject(requestContext)); } @Override @@ -91,7 +97,7 @@ public class MultiMsgCollectorImpl implements MultiMsgCollector { MultipartType multipartType = reply.getType(); LOG.trace("Orphaned multipart msg with XID : {} of type {}", xid, multipartType); deviceReplyProcessor.processException(new Xid(xid), - new DeviceDataException("unknown xid received for multipart of type "+multipartType)); + new DeviceDataException("unknown xid received for multipart of type " + multipartType)); return; } @@ -116,9 +122,11 @@ public class MultiMsgCollectorImpl implements MultiMsgCollector { private class MultiCollectorObject { private final List replyCollection; private MultipartType msgType; + private final RequestContext requestContext; - MultiCollectorObject() { + MultiCollectorObject(final RequestContext requestContext) { replyCollection = new ArrayList<>(); + this.requestContext = requestContext; } void add(final MultipartReply reply) throws DeviceDataException { @@ -128,12 +136,39 @@ public class MultiMsgCollectorImpl implements MultiMsgCollector { } void publishCollection(final long xid) { + final RpcResult> rpcResult = RpcResultBuilder + .>success() + .withResult(replyCollection) + .build(); + requestContext.setResult(rpcResult); + try { + requestContext.close(); + } catch (final Exception e) { + LOG.warn("Closing RequestContext failed: {}", e.getMessage()); + LOG.debug("Closing RequestContext failed.. ", e); + } deviceReplyProcessor.processReply(new Xid(xid), replyCollection); } void invalidateFutureByTimeout(final long key) { final String msg = "MultiMsgCollector can not wait for last multipart any more"; - deviceReplyProcessor.processException(new Xid(key), new DeviceDataException(msg)); + DeviceDataException deviceDataException = new DeviceDataException(msg); + final RpcResult> rpcResult = RpcResultBuilder + .>failed() + .withError(RpcError.ErrorType.APPLICATION, String.format("Message processing failed : %s", deviceDataException.getError()), deviceDataException) + .build(); + requestContext.setResult(rpcResult); + try { + requestContext.close(); + } catch (final Exception e) { + LOG.warn("Closing RequestContext failed: ", e); + LOG.debug("Closing RequestContext failed..", e); + } + deviceReplyProcessor.processException(new Xid(key), deviceDataException); + } + + public RequestContext getRequestContext() { + return requestContext; } private void msgTypeValidation(final MultipartType type, final long key) throws DeviceDataException {