com.alachisoft.ncache.client.internal.communication.ResponseList Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ncache-professional-client Show documentation
Show all versions of ncache-professional-client Show documentation
NCache Professional client for java.
package com.alachisoft.ncache.client.internal.communication;
import com.alachisoft.ncache.client.internal.command.Command;
import com.alachisoft.ncache.client.internal.command.CommandResponse;
class ResponseList {
private static final int FIRST_CHUNK = 1;
private Object _mutex = new Object();
private Command privateCommand;
private long privateRequestId = -1;
private java.util.HashMap _responses = new java.util.HashMap<>();
public ResponseList(Command command) {
privateCommand = command;
}
public final Command getCommand() {
return privateCommand;
}
public final long getRequestId() {
return privateRequestId;
}
public final void setRequestId(long value) {
privateRequestId = value;
}
public final java.util.List getResponses() {
java.util.List responses = new java.util.ArrayList(_responses.size());
for (int i = 1; i <= _responses.size(); i++) {
responses.add(_responses.get(i));
}
return responses;
}
public final boolean IsComplete(boolean includeFailedRespnosesOnly) {
synchronized (_mutex) {
boolean result = _responses.containsKey(FIRST_CHUNK);
if (result) {
CommandResponse firstChunk = _responses.get(FIRST_CHUNK);
if (includeFailedRespnosesOnly) {
result = _responses.size() == firstChunk.getNumberOfChunks() && firstChunk.getIsSendFailure();
} else {
result = _responses.size() == firstChunk.getNumberOfChunks();
}
}
return result;
}
}
public final void AddResponse(CommandResponse response) {
synchronized (_mutex) {
CommandResponse commandResponse = null;
if (!((commandResponse = _responses.get(response.getSequenceId())) != null)) {
_responses.put(response.getSequenceId(), response);
} else if (commandResponse.isBrokerReset() && response.getIsSendFailure()) {
_responses.put(response.getSequenceId(), response);
}
}
}
public final void Clear() {
synchronized (_mutex) {
_responses.clear();
}
}
public final void MergeWith(ResponseList rspList) {
for (java.util.Map.Entry response : rspList._responses.entrySet()) {
_responses.put(response.getKey(), response.getValue());
}
}
}