Skip to content

Commit

Permalink
Merge pull request mrniko#6 from YoonsooChang/brch_changjo
Browse files Browse the repository at this point in the history
Brch changjo
  • Loading branch information
YoonsooChang committed May 27, 2020
2 parents c20ef93 + 4636d17 commit fc135c7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
21 changes: 12 additions & 9 deletions src/main/java/com/corundumstudio/socketio/ack/AckManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,25 @@ class AckEntry {
final Map<Long, AckCallback<?>> ackCallbacks = PlatformDependent.newConcurrentHashMap();
final AtomicLong ackIndex = new AtomicLong(-1);

public long addAckCallback(AckCallback<?> callback) {
long addAckCallback(AckCallback<?> callback) {
long index = ackIndex.incrementAndGet();
ackCallbacks.put(index, callback);
return index;
}

public Set<Long> getAckIndexes() {
Set<Long> getAckIndexes() {
return ackCallbacks.keySet();
}

public AckCallback<?> getAckCallback(long index) {
AckCallback<?> getAckCallback(long index) {
return ackCallbacks.get(index);
}

public AckCallback<?> removeCallback(long index) {
AckCallback<?> removeCallback(long index) {
return ackCallbacks.remove(index);
}

public void initAckIndex(long index) {
void initAckIndex(long index) {
ackIndex.compareAndSet(-1, index);
}

Expand Down Expand Up @@ -123,8 +123,9 @@ private AckCallback<?> removeCallback(UUID sessionId, long index) {
// before timeout occurs
if (ackEntry != null) {
return ackEntry.removeCallback(index);
} else {
return null;
}
return null;
}

public AckCallback<?> getCallback(UUID sessionId, long index) {
Expand All @@ -137,15 +138,17 @@ public long registerAck(UUID sessionId, AckCallback<?> callback) {
ackEntry.initAckIndex(0);
long index = ackEntry.addAckCallback(callback);

if (log.isDebugEnabled()) {
log.debug("AckCallback registered with id: {} for client: {}", index, sessionId);
}
checkDebugEnabled(sessionId, index);

scheduleTimeout(index, sessionId, callback);

return index;
}

private void checkDebugEnabled(UUID sessionId, long index) {
if (log.isDebugEnabled()) log.debug("AckCallback registered with id: {} for client: {}", index, sessionId);
}

private void scheduleTimeout(final long index, final UUID sessionId, AckCallback<?> callback) {
if (callback.getTimeout() == -1) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class AckSchedulerKey extends SchedulerKey {

private final long index;

public AckSchedulerKey(Type type, UUID sessionId, long index) {
AckSchedulerKey(Type type, UUID sessionId, long index) {
super(type, sessionId);
this.index = index;
}
Expand All @@ -42,15 +42,14 @@ public int hashCode() {

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
boolean isObjectEqual = (this == obj);
boolean isObjectNotEqualSuper = (!super.equals(obj));
boolean isClassNotEqual = (getClass() != obj.getClass());
AckSchedulerKey other = (AckSchedulerKey) obj;
if (index != other.index)
return false;
boolean isIndexNotEqual = (index != other.index);

if ( isObjectEqual ) return true;
if ( isObjectNotEqualSuper || isClassNotEqual || isIndexNotEqual ) return false;
return true;
}

Expand Down

0 comments on commit fc135c7

Please sign in to comment.