Replace EqualsBuilder, HashBuilder, ReflectionToString
[controller.git] / opendaylight / protocol_plugins / openflow / src / main / java / org / opendaylight / controller / protocol_plugin / openflow / core / internal / PriorityMessage.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. 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.controller.protocol_plugin.openflow.core.internal;
10
11 import java.util.concurrent.atomic.AtomicLong;
12
13 import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
14 import org.openflow.protocol.OFMessage;
15
16 /**
17  * This class describes an OpenFlow message with priority
18  */
19 class PriorityMessage {
20     OFMessage msg;
21     int priority;
22     final static AtomicLong seq = new AtomicLong();
23     final long seqNum;
24     boolean syncReply; // set to true if we want to be blocked until the response arrives
25     
26     public PriorityMessage(OFMessage msg, int priority) {
27         this.msg = msg;
28         this.priority = priority;
29         this.seqNum = seq.getAndIncrement();
30         this.syncReply = false;
31     }
32
33     public PriorityMessage(OFMessage msg, int priority, boolean syncReply) {
34         this(msg, priority);
35         this.syncReply = syncReply;
36     }
37
38     public OFMessage getMsg() {
39         return msg;
40     }
41
42     public void setMsg(OFMessage msg) {
43         this.msg = msg;
44     }
45
46     public int getPriority() {
47         return priority;
48     }
49
50     public void setPriority(int priority) {
51         this.priority = priority;
52     }
53
54     @Override
55     public int hashCode() {
56         final int prime = 31;
57         int result = 1;
58         result = prime * result + ((msg == null) ? 0 : msg.hashCode());
59         result = prime * result + priority;
60         result = prime * result + (int) (seqNum ^ (seqNum >>> 32));
61         result = prime * result + (syncReply ? 1231 : 1237);
62         return result;
63     }
64
65     @Override
66     public boolean equals(Object obj) {
67         if (this == obj)
68             return true;
69         if (obj == null)
70             return false;
71         if (getClass() != obj.getClass())
72             return false;
73         PriorityMessage other = (PriorityMessage) obj;
74         if (msg == null) {
75             if (other.msg != null)
76                 return false;
77         } else if (!msg.equals(other.msg))
78             return false;
79         if (priority != other.priority)
80             return false;
81         if (seqNum != other.seqNum)
82             return false;
83         if (syncReply != other.syncReply)
84             return false;
85         return true;
86     }
87
88     @Override
89     public String toString() {
90         return "PriorityMessage [msg=" + msg + ", priority=" + priority
91                 + ", seqNum=" + seqNum + ", syncReply=" + syncReply + "]";
92     }
93 }