2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.openflowplugin.openflow.core.internal;
11 import java.util.concurrent.Callable;
12 import java.util.concurrent.CountDownLatch;
14 import org.opendaylight.openflowplugin.openflow.core.ISwitch;
15 import org.openflow.protocol.OFBarrierRequest;
16 import org.openflow.protocol.OFError;
17 import org.openflow.protocol.OFMessage;
20 * This class implements synchronous operations on message send to a switch. If
21 * syncRequest is set to true, it sends the requested message to the switch
22 * followed by a Barrier request message. It returns the result once it gets the
23 * reply from the switch or after a timeout. If the protocol does not dictate
24 * the switch to reply the processing status for a particular message, the
25 * Barrier request forces the switch to reply saying whether or not the message
26 * processing was successful for messages sent to the switch up to this point.
27 * If syncRequest is false, it simply skips the message send and just waits for
30 public class SynchronousMessage implements Callable<Object> {
33 private OFMessage syncMsg;
34 protected CountDownLatch latch;
35 private Object result;
36 private boolean syncRequest;
38 public SynchronousMessage(ISwitch sw, Integer xid, OFMessage msg,
39 boolean syncRequest) {
43 latch = new CountDownLatch(1);
45 this.syncRequest = syncRequest;
49 public Object call() throws Exception {
51 * Send out message only if syncRequest is set to true. Otherwise, just
52 * wait for the Barrier response back.
55 sw.asyncSend(syncMsg, xid);
56 if (!(syncMsg instanceof OFBarrierRequest)) {
57 OFBarrierRequest barrierMsg = new OFBarrierRequest();
58 sw.asyncSend(barrierMsg, xid);
65 public Integer getXid() {
69 public void wakeup() {
70 this.latch.countDown();
73 public void wakeup(OFError e) {