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