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
Branches
No related tags found
No related merge requests found
......@@ -49,7 +49,7 @@ public abstract class BaseEvent implements Constants, IRTMPEvent, Externalizable
/**
* Event listener
*/
protected IEventListener source;
protected transient IEventListener source;
/**
* Event timestamp
......@@ -102,8 +102,10 @@ public abstract class BaseEvent implements Constants, IRTMPEvent, Externalizable
return type;
}
@Deprecated(since = "1.3.26")
public void setType(Type type) {
this.type = type;
//this.type = type;
throw new UnsupportedOperationException("Type is immutable");
}
public byte getSourceType() {
......@@ -188,6 +190,35 @@ public abstract class BaseEvent implements Constants, IRTMPEvent, Externalizable
*/
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 {
type = Type.valueOf(in.readUTF());
sourceType = in.readByte();
......@@ -197,6 +228,7 @@ public abstract class BaseEvent implements Constants, IRTMPEvent, Externalizable
}
}
@Override
public void writeExternal(ObjectOutput out) throws IOException {
if (log.isTraceEnabled()) {
log.trace("writeExternal - type: {} sourceType: {} timestamp: {}", type, sourceType, timestamp);
......
......@@ -23,10 +23,12 @@ public class Invoke extends Notify {
private static final long serialVersionUID = -769677790148010729L;
{
dataType = TYPE_INVOKE;
}
/** Constructs a new Invoke. */
public Invoke() {
super();
dataType = TYPE_INVOKE;
}
/**
......@@ -37,7 +39,6 @@ public class Invoke extends Notify {
*/
public Invoke(IoBuffer data) {
super(data);
dataType = TYPE_INVOKE;
}
/**
......@@ -48,7 +49,6 @@ public class Invoke extends Notify {
*/
public Invoke(IPendingServiceCall call) {
super(call);
dataType = TYPE_INVOKE;
}
/**
......@@ -67,12 +67,6 @@ public class Invoke extends Notify {
return (IPendingServiceCall) call;
}
/** {@inheritDoc} */
@Override
public String toString() {
return String.format("Invoke #%d: %s", transactionId, (call != null ? call.toString() : "null"));
}
/** {@inheritDoc} */
@Override
public boolean equals(Object obj) {
......@@ -85,6 +79,12 @@ public class Invoke extends Notify {
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.
*
......
......@@ -61,6 +61,17 @@ public class Notify extends BaseEvent implements ICommand, IStreamData<Notify>,
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
*
......@@ -84,17 +95,6 @@ public class Notify extends BaseEvent implements ICommand, IStreamData<Notify>,
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} */
public byte getDataType() {
return dataType;
......@@ -193,6 +193,15 @@ public class Notify extends BaseEvent implements ICommand, IStreamData<Notify>,
return false;
}
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) {
return false;
}
......@@ -202,9 +211,6 @@ public class Notify extends BaseEvent implements ICommand, IStreamData<Notify>,
if (getConnectionParams() != null && !getConnectionParams().equals(other.getConnectionParams())) {
return false;
}
if (getTransactionId() != other.getTransactionId()) {
return false;
}
if (getCall() == null && other.getCall() != null) {
return false;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment