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