Copyright update
[openflowjava.git] / simple-client / src / main / java / org / opendaylight / openflowjava / protocol / impl / clients / WaitForMessageEvent.java
1 /*
2  * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.openflowjava.protocol.impl.clients;
10
11 import java.util.Arrays;
12
13 import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 /**
18  * Class representing waiting on message
19  * @author michal.polkorab
20  */
21 public class WaitForMessageEvent implements ClientEvent {
22     
23     private static final Logger LOGGER = LoggerFactory.getLogger(WaitForMessageEvent.class);
24     private byte[] headerExpected;
25     private byte[] headerReceived;
26
27     /**
28      * @param headerExpected header (first 8 bytes) of expected message
29      */
30     public WaitForMessageEvent(byte[] headerExpected) {
31         this.headerExpected = headerExpected;
32     }
33
34     @Override
35     public boolean eventExecuted() {
36         if (headerReceived == null) {
37             return false;
38         }
39         if (!Arrays.equals(headerExpected, headerReceived)) {
40             LOGGER.debug("expected msg: " + ByteBufUtils.bytesToHexString(headerExpected));
41             LOGGER.debug("received msg: " + ByteBufUtils.bytesToHexString(headerReceived));
42             return false;
43         }
44         LOGGER.info("Headers OK");
45         return true;
46     }
47
48     /**
49      * @param headerReceived header (first 8 bytes) of expected message
50      */
51     public void setHeaderReceived(byte[] headerReceived) {
52         this.headerReceived = headerReceived;
53     }
54
55     
56 }