All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.geode.management.cli.CommandService Maven / Gradle / Ivy

Go to download

Apache Geode provides a database-like consistency model, reliable transaction processing and a shared-nothing architecture to maintain very low latency performance with high concurrency processing

The newest version!
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
 * agreements. See the NOTICE file distributed with this work for additional information regarding
 * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance with the License. You may obtain a
 * copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package org.apache.geode.management.cli;

import java.util.Collections;
import java.util.Map;

import org.apache.geode.annotations.Immutable;
import org.apache.geode.annotations.internal.MakeNotStatic;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.CacheClosedException;
import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.management.DependenciesNotFoundException;
import org.apache.geode.management.internal.cli.CliUtils;

/**
 * Processes remote GemFire Command Line Interface (CLI) commands. Refer to the vFabric GemFire
 * documentation for information regarding local vs. remote commands.
 * 

* NOTE: CommandService is currently available only on GemFire Manager nodes. * * * @since GemFire 7.0 * * @deprecated since 1.3 use OnlineCommandProcessor directly */ @Deprecated public abstract class CommandService { @Immutable protected static final Map EMPTY_ENV = Collections.emptyMap(); @MakeNotStatic private static CommandService localCommandService; /* ************* Methods to be implemented by sub-classes START *********** */ /** * Returns whether the underlying Cache exists and is not closed. The Cache must be * ready in order for commands to be processed using this CommandService. A call to * this method should be made before attempting to process commands. * * @return True if the Cache exists and is not closed, false otherwise. */ public abstract boolean isUsable(); /** * Processes the specified command string. Only remote commands can be processed using this * method. Refer to the vFabric GemFire documentation for details. * * @param commandString Command string to be processed. * @return The {@link Result} of the execution of this command string. */ public abstract Result processCommand(String commandString); /** * Processes the specified command string. Only remote commands can be processed using this * method. Refer to the vFabric GemFire documentation for details. * * @param commandString Command string to be processed. * @param env Environmental values that will be used during the execution of this command. * @return The {@link Result} of the execution of this command string. */ protected abstract Result processCommand(String commandString, Map env); /** * Creates a CommandStatement from the specified command string. Only remote commands * can be processed using this method. Refer to the vFabric GemFire documentation for details. * * @param commandString Command string from which to create a CommandStatement. * @return A CommandStatement which can be used to repeatedly process the same * command. * * @see CommandStatement#process() * @deprecated since Geode 1.3, simply call processCommand to execute the command */ @Deprecated public abstract CommandStatement createCommandStatement(String commandString); /** * Creates a CommandStatement from the specified command string. Only remote commands * can be processed using this method. Refer to the vFabric GemFire documentation for details. * * @param commandString Command string from which to create a CommandStatement. * @param env Environmental values that will be used during the execution of this command. * @return A CommandStatement which can be used to repeatedly process the same * command. * * @see CommandStatement#process() * @deprecated since Geode 1.3, simply call processCommand to execute the command */ @Deprecated protected abstract CommandStatement createCommandStatement(String commandString, Map env); /* ************** Methods to be implemented by sub-classes END ************ */ /* **************************** factory methods *************************** */ /** * Returns a newly created or existing instance of the * CommandService associated with the * specified Cache. * * @param cache Underlying Cache instance to be used to create a Command Service. * @return a newly created or existing instance of the CommandService associated with * the specified Cache * @throws CommandServiceException If command service could not be initialized. */ public static CommandService createLocalCommandService(Cache cache) throws CommandServiceException { if (cache == null) { throw new CacheClosedException("Can not create command service as cache doesn't exist."); } else if (cache.isClosed()) { throw ((InternalCache) cache) .getCacheClosedException("Can not create command service as cache is closed."); } if (localCommandService == null || !localCommandService.isUsable()) { String nonExistingDependency = CliUtils.cliDependenciesExist(false); if (nonExistingDependency != null) { throw new DependenciesNotFoundException( String.format( "Could not find %s library which is needed for CLI/gfsh in classpath. Internal support for CLI & gfsh is not enabled. Note: For convenience, absolute path of gfsh-dependencies.jar from lib directory of GemFire product distribution can be included in CLASSPATH of an application.", nonExistingDependency)); } localCommandService = new org.apache.geode.management.internal.cli.remote.MemberCommandService( (InternalCache) cache); } return localCommandService; } /** * Returns an existing 'usable' CommandService. A CommandService is * considered usable if at has an underlying Cache which is not closed. * * @return A usable CommandService or null if one cannot be found. */ public static CommandService getUsableLocalCommandService() { if (localCommandService != null && localCommandService.isUsable()) { return localCommandService; } return null; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy