use of org.apache.geode.internal.cache.tier.Command in project geode by apache.
the class CommandInitializer method registerCommand.
/**
* Register a new command with the system.
*
* @param messageType - An ordinal for this message. This must be something defined in MessageType
* that has not already been allocated to a different command.
* @param versionToNewCommand The command to register, for different versions. The key is the
* earliest version for which this command class is valid (starting with GFE_57). The value
* is the command object for clients starting with that version.
*/
public static void registerCommand(int messageType, Map<Version, Command> versionToNewCommand) {
Command command = null;
// add a command to the map for that version
for (Map.Entry<Version, Map<Integer, Command>> entry : ALL_COMMANDS.entrySet()) {
Version version = entry.getKey();
// Get the current set of commands for this version.
Map<Integer, Command> commandMap = entry.getValue();
// See if we have a new command to insert into this map. Otherwise, keep using the command we
// have
// already read
Command newerVersion = versionToNewCommand.get(version);
if (newerVersion != null) {
command = newerVersion;
}
if (command != null) {
Command oldCommand = commandMap.get(messageType);
if (oldCommand != null && oldCommand != command) {
throw new InternalGemFireError("Command is already defined int the map for message Type " + MessageType.getString(messageType) + ". Old Value=" + commandMap.get(messageType) + ", newValue=" + command + ", version=" + version);
}
commandMap.put(messageType, command);
}
}
}
use of org.apache.geode.internal.cache.tier.Command in project geode by apache.
the class ServerConnection method doNormalMsg.
private void doNormalMsg() {
Message msg = null;
msg = BaseCommand.readRequest(this);
ThreadState threadState = null;
try {
if (msg != null) {
// launches.
if (!this.processMessages || (crHelper.isShutdown())) {
if (logger.isDebugEnabled()) {
logger.debug("{} ignoring message of type {} from client {} due to shutdown.", getName(), MessageType.getString(msg.getMessageType()), this.proxyId);
}
return;
}
if (msg.getMessageType() != MessageType.PING) {
// check for invalid number of message parts
if (msg.getNumberOfParts() <= 0) {
failureCount++;
if (failureCount > 3) {
this.processMessages = false;
return;
} else {
return;
}
}
}
if (logger.isTraceEnabled()) {
logger.trace("{} received {} with txid {}", getName(), MessageType.getString(msg.getMessageType()), msg.getTransactionId());
if (msg.getTransactionId() < -1) {
// TODO: why is this happening?
msg.setTransactionId(-1);
}
}
if (msg.getMessageType() != MessageType.PING) {
// we have a real message (non-ping),
// so let's call receivedPing to let the CHM know client is busy
acceptor.getClientHealthMonitor().receivedPing(this.proxyId);
}
Command command = getCommand(Integer.valueOf(msg.getMessageType()));
if (command == null) {
command = Default.getCommand();
}
// authorization later
if (AcceptorImpl.isIntegratedSecurity() && !isInternalMessage() && this.communicationMode != Acceptor.GATEWAY_TO_GATEWAY) {
long uniqueId = getUniqueId();
Subject subject = this.clientUserAuths.getSubject(uniqueId);
if (subject != null) {
threadState = securityService.bindSubject(subject);
}
}
command.execute(msg, this);
}
} finally {
// Keep track of the fact that a message is no longer being
// processed.
setNotProcessingMessage();
clearRequestMsg();
if (threadState != null) {
threadState.clear();
}
}
}
Aggregations