X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fprotocol_plugins%2Fopenflow%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fprotocol_plugin%2Fopenflow%2Fcore%2Finternal%2FSynchronousMessage.java;fp=opendaylight%2Fprotocol_plugins%2Fopenflow%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fprotocol_plugin%2Fopenflow%2Fcore%2Finternal%2FSynchronousMessage.java;h=5e613e8642489c0dce449fdcb242700406142f20;hb=29f7cfb54b580928c7feac63abce028a7014b0d5;hp=0000000000000000000000000000000000000000;hpb=42210c03b0a4c54706320ba9f55794c0abd4d201;p=controller.git diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/SynchronousMessage.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/SynchronousMessage.java new file mode 100644 index 0000000000..5e613e8642 --- /dev/null +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/SynchronousMessage.java @@ -0,0 +1,68 @@ + +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.protocol_plugin.openflow.core.internal; + +import java.util.concurrent.Callable; +import java.util.concurrent.CountDownLatch; + +import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitch; +import org.openflow.protocol.OFBarrierRequest; +import org.openflow.protocol.OFError; +import org.openflow.protocol.OFMessage; + +/** + * Implements the synchronous message send to a switch + * It sends the requested message to the switch followed by a barrier request message + * It returns the result once it gets the reply from the switch or after a timeout + * If the protocol does not dictate the switch to reply the processing status for a particular message + * the barrier request forces the switch to reply saying whether or not the message processing was + * successful for messages sent to the switch up to this point + * + * + * + */ +public class SynchronousMessage implements Callable { + private ISwitch sw; + private Integer xid; + private OFMessage syncMsg; + protected CountDownLatch latch; + private Object result; + + public SynchronousMessage(ISwitch sw, Integer xid, OFMessage msg) { + this.sw = sw; + this.xid = xid; + syncMsg = msg; + latch = new CountDownLatch(1); + result = null; + } + + @Override + public Object call() throws Exception { + sw.asyncSend(syncMsg, xid); + OFBarrierRequest barrierMsg = new OFBarrierRequest(); + sw.asyncSend(barrierMsg, xid); + latch.await(); + return result; + } + + public Integer getXid() { + return this.xid; + } + + public void wakeup() { + this.latch.countDown(); + } + + public void wakeup(OFError e) { + result = e; + wakeup(); + } + +} \ No newline at end of file