Skip to content

Commit 6b4909f

Browse files
committed
Add and update of hashCode/equals for events
1 parent bf803c7 commit 6b4909f

File tree

3 files changed

+64
-26
lines changed

3 files changed

+64
-26
lines changed

common/src/main/java/org/red5/server/net/rtmp/event/BaseEvent.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public abstract class BaseEvent implements Constants, IRTMPEvent, Externalizable
4949
/**
5050
* Event listener
5151
*/
52-
protected IEventListener source;
52+
protected transient IEventListener source;
5353

5454
/**
5555
* Event timestamp
@@ -102,8 +102,10 @@ public Type getType() {
102102
return type;
103103
}
104104

105+
@Deprecated(since = "1.3.26")
105106
public void setType(Type type) {
106-
this.type = type;
107+
//this.type = type;
108+
throw new UnsupportedOperationException("Type is immutable");
107109
}
108110

109111
public byte getSourceType() {
@@ -188,6 +190,35 @@ public void release() {
188190
*/
189191
protected abstract void releaseInternal();
190192

193+
@Override
194+
public int hashCode() {
195+
final int prime = 31;
196+
int result = 1;
197+
result = prime * result + ((type == null) ? 0 : type.hashCode());
198+
result = prime * result + sourceType;
199+
result = prime * result + timestamp;
200+
return result;
201+
}
202+
203+
@Override
204+
public boolean equals(Object obj) {
205+
if (this == obj)
206+
return true;
207+
if (obj == null)
208+
return false;
209+
if (getClass() != obj.getClass())
210+
return false;
211+
BaseEvent other = (BaseEvent) obj;
212+
if (type != other.type)
213+
return false;
214+
if (sourceType != other.sourceType)
215+
return false;
216+
if (timestamp != other.timestamp)
217+
return false;
218+
return true;
219+
}
220+
221+
@Override
191222
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
192223
type = Type.valueOf(in.readUTF());
193224
sourceType = in.readByte();
@@ -197,6 +228,7 @@ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundExcept
197228
}
198229
}
199230

231+
@Override
200232
public void writeExternal(ObjectOutput out) throws IOException {
201233
if (log.isTraceEnabled()) {
202234
log.trace("writeExternal - type: {} sourceType: {} timestamp: {}", type, sourceType, timestamp);

common/src/main/java/org/red5/server/net/rtmp/event/Invoke.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ public class Invoke extends Notify {
2323

2424
private static final long serialVersionUID = -769677790148010729L;
2525

26+
{
27+
dataType = TYPE_INVOKE;
28+
}
29+
2630
/** Constructs a new Invoke. */
2731
public Invoke() {
28-
super();
29-
dataType = TYPE_INVOKE;
3032
}
3133

3234
/**
@@ -37,7 +39,6 @@ public Invoke() {
3739
*/
3840
public Invoke(IoBuffer data) {
3941
super(data);
40-
dataType = TYPE_INVOKE;
4142
}
4243

4344
/**
@@ -48,7 +49,6 @@ public Invoke(IoBuffer data) {
4849
*/
4950
public Invoke(IPendingServiceCall call) {
5051
super(call);
51-
dataType = TYPE_INVOKE;
5252
}
5353

5454
/**
@@ -67,12 +67,6 @@ public IPendingServiceCall getCall() {
6767
return (IPendingServiceCall) call;
6868
}
6969

70-
/** {@inheritDoc} */
71-
@Override
72-
public String toString() {
73-
return String.format("Invoke #%d: %s", transactionId, (call != null ? call.toString() : "null"));
74-
}
75-
7670
/** {@inheritDoc} */
7771
@Override
7872
public boolean equals(Object obj) {
@@ -85,6 +79,12 @@ public boolean equals(Object obj) {
8579
return super.equals(obj);
8680
}
8781

82+
/** {@inheritDoc} */
83+
@Override
84+
public String toString() {
85+
return String.format("Invoke #%d: %s", transactionId, (call != null ? call.toString() : "null"));
86+
}
87+
8888
/**
8989
* Duplicate this Invoke message to future injection. Serialize to memory and deserialize, safe way.
9090
*

common/src/main/java/org/red5/server/net/rtmp/event/Notify.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ public Notify() {
6161
super(Type.SERVICE_CALL);
6262
}
6363

64+
/**
65+
* Create new notification event with given service call
66+
*
67+
* @param call
68+
* Service call
69+
*/
70+
public Notify(IServiceCall call) {
71+
super(Type.SERVICE_CALL);
72+
this.call = call;
73+
}
74+
6475
/**
6576
* Create new notification event with given byte buffer
6677
*
@@ -84,17 +95,6 @@ public Notify(IoBuffer data, String action) {
8495
this.action = action;
8596
}
8697

87-
/**
88-
* Create new notification event with given service call
89-
*
90-
* @param call
91-
* Service call
92-
*/
93-
public Notify(IServiceCall call) {
94-
super(Type.SERVICE_CALL);
95-
this.call = call;
96-
}
97-
9898
/** {@inheritDoc} */
9999
public byte getDataType() {
100100
return dataType;
@@ -193,6 +193,15 @@ public boolean equals(Object obj) {
193193
return false;
194194
}
195195
Notify other = (Notify) obj;
196+
if (getType() != other.getType()) {
197+
return false;
198+
}
199+
if (getTimestamp() != other.getTimestamp()) {
200+
return false;
201+
}
202+
if (getTransactionId() != other.getTransactionId()) {
203+
return false;
204+
}
196205
if (getConnectionParams() == null && other.getConnectionParams() != null) {
197206
return false;
198207
}
@@ -202,9 +211,6 @@ public boolean equals(Object obj) {
202211
if (getConnectionParams() != null && !getConnectionParams().equals(other.getConnectionParams())) {
203212
return false;
204213
}
205-
if (getTransactionId() != other.getTransactionId()) {
206-
return false;
207-
}
208214
if (getCall() == null && other.getCall() != null) {
209215
return false;
210216
}

0 commit comments

Comments
 (0)