Remove trailing whitespace
[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.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 = new byte[headerExpected.length];
32         for (int i = 0; i < headerExpected.length; i++) {
33             this.headerExpected[i] = headerExpected[i];
34         }
35     }
36
37     @Override
38     public boolean eventExecuted() {
39         if (headerReceived == null) {
40             return false;
41         }
42         if (!Arrays.equals(headerExpected, headerReceived)) {
43             LOGGER.debug("expected msg: " + ByteBufUtils.bytesToHexString(headerExpected));
44             LOGGER.debug("received msg: " + ByteBufUtils.bytesToHexString(headerReceived));
45             return false;
46         }
47         LOGGER.debug("Headers OK");
48         return true;
49     }
50
51     /**
52      * @param headerReceived header (first 8 bytes) of expected message
53      */
54     public void setHeaderReceived(byte[] headerReceived) {
55         this.headerReceived = new byte[headerReceived.length];
56         for (int i = 0; i < headerReceived.length; i++) {
57             this.headerReceived[i] = headerReceived[i];
58         }
59     }
60 }