Search in sources :

Example 1 with Command

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);
        }
    }
}
Also used : GatewayReceiverCommand(org.apache.geode.internal.cache.tier.sockets.command.GatewayReceiverCommand) GetEntryCommand(org.apache.geode.internal.cache.tier.sockets.command.GetEntryCommand) TXSynchronizationCommand(org.apache.geode.internal.cache.tier.sockets.command.TXSynchronizationCommand) RollbackCommand(org.apache.geode.internal.cache.tier.sockets.command.RollbackCommand) CommitCommand(org.apache.geode.internal.cache.tier.sockets.command.CommitCommand) GetClientPartitionAttributesCommand(org.apache.geode.internal.cache.tier.sockets.command.GetClientPartitionAttributesCommand) TXFailoverCommand(org.apache.geode.internal.cache.tier.sockets.command.TXFailoverCommand) Command(org.apache.geode.internal.cache.tier.Command) GetClientPRMetadataCommand(org.apache.geode.internal.cache.tier.sockets.command.GetClientPRMetadataCommand) Version(org.apache.geode.internal.Version) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) InternalGemFireError(org.apache.geode.InternalGemFireError)

Example 2 with 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();
        }
    }
}
Also used : LocalizedMessage(org.apache.geode.internal.logging.log4j.LocalizedMessage) Command(org.apache.geode.internal.cache.tier.Command) ThreadState(org.apache.shiro.util.ThreadState) Subject(org.apache.shiro.subject.Subject)

Aggregations

Command (org.apache.geode.internal.cache.tier.Command)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 InternalGemFireError (org.apache.geode.InternalGemFireError)1 Version (org.apache.geode.internal.Version)1 CommitCommand (org.apache.geode.internal.cache.tier.sockets.command.CommitCommand)1 GatewayReceiverCommand (org.apache.geode.internal.cache.tier.sockets.command.GatewayReceiverCommand)1 GetClientPRMetadataCommand (org.apache.geode.internal.cache.tier.sockets.command.GetClientPRMetadataCommand)1 GetClientPartitionAttributesCommand (org.apache.geode.internal.cache.tier.sockets.command.GetClientPartitionAttributesCommand)1 GetEntryCommand (org.apache.geode.internal.cache.tier.sockets.command.GetEntryCommand)1 RollbackCommand (org.apache.geode.internal.cache.tier.sockets.command.RollbackCommand)1 TXFailoverCommand (org.apache.geode.internal.cache.tier.sockets.command.TXFailoverCommand)1 TXSynchronizationCommand (org.apache.geode.internal.cache.tier.sockets.command.TXSynchronizationCommand)1 LocalizedMessage (org.apache.geode.internal.logging.log4j.LocalizedMessage)1 Subject (org.apache.shiro.subject.Subject)1 ThreadState (org.apache.shiro.util.ThreadState)1