Skip to content
Snippets Groups Projects
Commit 6b4909f8 authored by Paul Gregoire's avatar Paul Gregoire
Browse files

Add and update of hashCode/equals for events

parent bf803c72
No related branches found
No related tags found
No related merge requests found
...@@ -49,7 +49,7 @@ public abstract class BaseEvent implements Constants, IRTMPEvent, Externalizable ...@@ -49,7 +49,7 @@ public abstract class BaseEvent implements Constants, IRTMPEvent, Externalizable
/** /**
* Event listener * Event listener
*/ */
protected IEventListener source; protected transient IEventListener source;
/** /**
* Event timestamp * Event timestamp
...@@ -102,8 +102,10 @@ public abstract class BaseEvent implements Constants, IRTMPEvent, Externalizable ...@@ -102,8 +102,10 @@ public abstract class BaseEvent implements Constants, IRTMPEvent, Externalizable
return type; return type;
} }
@Deprecated(since = "1.3.26")
public void setType(Type type) { public void setType(Type type) {
this.type = type; //this.type = type;
throw new UnsupportedOperationException("Type is immutable");
} }
public byte getSourceType() { public byte getSourceType() {
...@@ -188,6 +190,35 @@ public abstract class BaseEvent implements Constants, IRTMPEvent, Externalizable ...@@ -188,6 +190,35 @@ public abstract class BaseEvent implements Constants, IRTMPEvent, Externalizable
*/ */
protected abstract void releaseInternal(); protected abstract void releaseInternal();
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((type == null) ? 0 : type.hashCode());
result = prime * result + sourceType;
result = prime * result + timestamp;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
BaseEvent other = (BaseEvent) obj;
if (type != other.type)
return false;
if (sourceType != other.sourceType)
return false;
if (timestamp != other.timestamp)
return false;
return true;
}
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
type = Type.valueOf(in.readUTF()); type = Type.valueOf(in.readUTF());
sourceType = in.readByte(); sourceType = in.readByte();
...@@ -197,6 +228,7 @@ public abstract class BaseEvent implements Constants, IRTMPEvent, Externalizable ...@@ -197,6 +228,7 @@ public abstract class BaseEvent implements Constants, IRTMPEvent, Externalizable
} }
} }
@Override
public void writeExternal(ObjectOutput out) throws IOException { public void writeExternal(ObjectOutput out) throws IOException {
if (log.isTraceEnabled()) { if (log.isTraceEnabled()) {
log.trace("writeExternal - type: {} sourceType: {} timestamp: {}", type, sourceType, timestamp); log.trace("writeExternal - type: {} sourceType: {} timestamp: {}", type, sourceType, timestamp);
......
...@@ -23,10 +23,12 @@ public class Invoke extends Notify { ...@@ -23,10 +23,12 @@ public class Invoke extends Notify {
private static final long serialVersionUID = -769677790148010729L; private static final long serialVersionUID = -769677790148010729L;
{
dataType = TYPE_INVOKE;
}
/** Constructs a new Invoke. */ /** Constructs a new Invoke. */
public Invoke() { public Invoke() {
super();
dataType = TYPE_INVOKE;
} }
/** /**
...@@ -37,7 +39,6 @@ public class Invoke extends Notify { ...@@ -37,7 +39,6 @@ public class Invoke extends Notify {
*/ */
public Invoke(IoBuffer data) { public Invoke(IoBuffer data) {
super(data); super(data);
dataType = TYPE_INVOKE;
} }
/** /**
...@@ -48,7 +49,6 @@ public class Invoke extends Notify { ...@@ -48,7 +49,6 @@ public class Invoke extends Notify {
*/ */
public Invoke(IPendingServiceCall call) { public Invoke(IPendingServiceCall call) {
super(call); super(call);
dataType = TYPE_INVOKE;
} }
/** /**
...@@ -67,12 +67,6 @@ public class Invoke extends Notify { ...@@ -67,12 +67,6 @@ public class Invoke extends Notify {
return (IPendingServiceCall) call; return (IPendingServiceCall) call;
} }
/** {@inheritDoc} */
@Override
public String toString() {
return String.format("Invoke #%d: %s", transactionId, (call != null ? call.toString() : "null"));
}
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
...@@ -85,6 +79,12 @@ public class Invoke extends Notify { ...@@ -85,6 +79,12 @@ public class Invoke extends Notify {
return super.equals(obj); return super.equals(obj);
} }
/** {@inheritDoc} */
@Override
public String toString() {
return String.format("Invoke #%d: %s", transactionId, (call != null ? call.toString() : "null"));
}
/** /**
* Duplicate this Invoke message to future injection. Serialize to memory and deserialize, safe way. * Duplicate this Invoke message to future injection. Serialize to memory and deserialize, safe way.
* *
......
...@@ -61,6 +61,17 @@ public class Notify extends BaseEvent implements ICommand, IStreamData<Notify>, ...@@ -61,6 +61,17 @@ public class Notify extends BaseEvent implements ICommand, IStreamData<Notify>,
super(Type.SERVICE_CALL); super(Type.SERVICE_CALL);
} }
/**
* Create new notification event with given service call
*
* @param call
* Service call
*/
public Notify(IServiceCall call) {
super(Type.SERVICE_CALL);
this.call = call;
}
/** /**
* Create new notification event with given byte buffer * Create new notification event with given byte buffer
* *
...@@ -84,17 +95,6 @@ public class Notify extends BaseEvent implements ICommand, IStreamData<Notify>, ...@@ -84,17 +95,6 @@ public class Notify extends BaseEvent implements ICommand, IStreamData<Notify>,
this.action = action; this.action = action;
} }
/**
* Create new notification event with given service call
*
* @param call
* Service call
*/
public Notify(IServiceCall call) {
super(Type.SERVICE_CALL);
this.call = call;
}
/** {@inheritDoc} */ /** {@inheritDoc} */
public byte getDataType() { public byte getDataType() {
return dataType; return dataType;
...@@ -193,6 +193,15 @@ public class Notify extends BaseEvent implements ICommand, IStreamData<Notify>, ...@@ -193,6 +193,15 @@ public class Notify extends BaseEvent implements ICommand, IStreamData<Notify>,
return false; return false;
} }
Notify other = (Notify) obj; Notify other = (Notify) obj;
if (getType() != other.getType()) {
return false;
}
if (getTimestamp() != other.getTimestamp()) {
return false;
}
if (getTransactionId() != other.getTransactionId()) {
return false;
}
if (getConnectionParams() == null && other.getConnectionParams() != null) { if (getConnectionParams() == null && other.getConnectionParams() != null) {
return false; return false;
} }
...@@ -202,9 +211,6 @@ public class Notify extends BaseEvent implements ICommand, IStreamData<Notify>, ...@@ -202,9 +211,6 @@ public class Notify extends BaseEvent implements ICommand, IStreamData<Notify>,
if (getConnectionParams() != null && !getConnectionParams().equals(other.getConnectionParams())) { if (getConnectionParams() != null && !getConnectionParams().equals(other.getConnectionParams())) {
return false; return false;
} }
if (getTransactionId() != other.getTransactionId()) {
return false;
}
if (getCall() == null && other.getCall() != null) { if (getCall() == null && other.getCall() != null) {
return false; return false;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment