You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by up...@apache.org on 2015/09/10 01:59:24 UTC
[41/50] [abbrv] incubator-geode git commit: GEODE-287: Remove old
gfsh code
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/GfshVersion.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/GfshVersion.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/GfshVersion.java
deleted file mode 100644
index 9215598..0000000
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/GfshVersion.java
+++ /dev/null
@@ -1,455 +0,0 @@
-/*
- * =========================================================================
- * Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved.
- * This product is protected by U.S. and international copyright
- * and intellectual property laws. Pivotal products are covered by
- * more patents listed at http://www.pivotal.io/patents.
- * ========================================================================
- */
-package com.gemstone.gemfire.internal.tools.gfsh.app;
-
-import java.io.InputStream;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.net.InetAddress;
-import java.util.Properties;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import com.gemstone.gemfire.SystemFailure;
-import com.gemstone.gemfire.cache.Cache;
-import com.gemstone.gemfire.cache.CacheClosedException;
-import com.gemstone.gemfire.cache.CacheFactory;
-import com.gemstone.gemfire.internal.ClassPathLoader;
-import com.gemstone.gemfire.internal.GemFireVersion;
-import com.gemstone.gemfire.internal.SocketCreator;
-import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
-
-/**
- * This class provides build and version information about gfsh.
- * It gathers this information from the resource property file
- * for this class.
- *
- * @author abhishek
- */
-/* This class has most of the code 'copied' from GemFireVersion.java.
- * The differences are:
- * 1. RESOURCE_NAME is "GfshVersion.properties";
- * 2. Uses same error strings as GemFireVersion - only resource name/path differs
- * 3. Methods asString & print accept different argument and have slightly
- * different behaviour.
- */
-public class GfshVersion {
- protected static String RESOURCE_NAME = "GfshVersion.properties";
-
- private static final Pattern MAJOR_MINOR = Pattern.compile("(\\d+)\\.(\\d*)(.*)");
-
- /** The singleton instance */
- private static GfshVersion instance;
-
- /** Constant for the GemFire version Resource Property entry */
- private static final String PRODUCT_NAME = "Product-Name";
-
- /** Constant for the GemFire version Resource Property entry */
- private static final String PRODUCT_VERSION = "Product-Version";
-
- /** Constant for the source code date Resource Property entry */
- private static final String SOURCE_DATE = "Source-Date";
-
- /** Constant for the source code revision Resource Property entry */
- private static final String SOURCE_REVISION = "Source-Revision";
-
- /** Constant for the source code repository Resource Property entry */
- private static final String SOURCE_REPOSITORY = "Source-Repository";
-
- /** Constant for the build date Resource Property entry */
- private static final String BUILD_DATE = "Build-Date";
-
- /** Constant for the build id Resource Property entry */
- private static final String BUILD_ID = "Build-Id";
-
- /** Constant for the build Java version Resource Property entry */
- private static final String BUILD_PLATFORM = "Build-Platform";
-
- /** Constant for the build Java version Resource Property entry */
- private static final String BUILD_JAVA_VERSION = "Build-Java-Version";
-
- //////////////////// Instance Fields ////////////////////
-
- /** Error message to display instead of the version information */
- private String error = null;
-
- /** The name of this product */
- private String productName;
-
- /** This product's version */
- private String gfshVersion;
-
- /** The date that the source code for GemFire was last updated */
- private String sourceDate;
-
- /** The revision of the source code used to build GemFire */
- private String sourceRevision;
-
- /** The repository in which the source code for GemFire resides */
- private String sourceRepository;
-
- /** The date on which GemFire was built */
- private String buildDate;
-
- /** The ID of the GemFire build */
- private String buildId;
-
- /** The platform on which GemFire was built */
- private String buildPlatform;
-
- /** The version of Java that was used to build GemFire */
- private String buildJavaVersion;
-
- /* Just to log gfsh jar version in GemFire Server logs */
- static {
- try {
- Cache cache = CacheFactory.getAnyInstance();
- if (cache != null && cache.isServer() && cache.getLogger() != null) {
- cache.getLogger().config("gfsh version: " + getJavaCodeVersion());
- }
- } catch (CacheClosedException e) {
- // Ignore, this is just to get handle on log writer.
- }
- }
-
- //////////////////// Constructor ////////////////////
-
- /**
- * Private constructor that read the resource properties
- * and extracts interesting pieces of information from it
- */
- private GfshVersion() {
- String gfeVersionPath = GemFireVersion.class.getPackage().getName().replace('.', '/');
- String gfshVersionPath = GfshVersion.class.getPackage().getName().replace('.', '/');
- gfshVersionPath = gfshVersionPath + "/" + RESOURCE_NAME;
-
- String xtraGfshVersionPath = gfshVersionPath.substring(gfeVersionPath.length() + 1);
-
- InputStream is = ClassPathLoader.getLatest().getResourceAsStream(getClass(), gfshVersionPath);
- if (is == null) {
- error = LocalizedStrings.GemFireVersion_COULD_NOT_FIND_RESOURCE_COM_GEMSTONE_GEMFIRE_INTERNAL_0.toLocalizedString(xtraGfshVersionPath);
- return;
- }
-
- Properties props = new Properties();
- try {
- props.load(is);
- } catch (Exception ex) {
- error = LocalizedStrings.GemFireVersion_COULD_NOT_READ_PROPERTIES_FROM_RESOURCE_COM_GEMSTONE_GEMFIRE_INTERNAL_0_BECAUSE_1.toLocalizedString(new Object[] {xtraGfshVersionPath, ex});
- return;
- }
-
- this.productName = props.getProperty(PRODUCT_NAME);
- if (this.productName == null) {
- error = LocalizedStrings.GemFireVersion_MISSING_PROPERTY_0_FROM_RESOURCE_COM_GEMSTONE_GEMFIRE_INTERNAL_1.toLocalizedString(new Object[] {PRODUCT_NAME, xtraGfshVersionPath});
- return;
- }
- this.gfshVersion = props.getProperty(PRODUCT_VERSION);
- if (this.gfshVersion == null) {
- error = LocalizedStrings.GemFireVersion_MISSING_PROPERTY_0_FROM_RESOURCE_COM_GEMSTONE_GEMFIRE_INTERNAL_1.toLocalizedString(new Object[] {PRODUCT_VERSION, xtraGfshVersionPath});
- return;
- }
- this.sourceDate = props.getProperty(SOURCE_DATE);
- if (this.sourceDate == null) {
- error = LocalizedStrings.GemFireVersion_MISSING_PROPERTY_0_FROM_RESOURCE_COM_GEMSTONE_GEMFIRE_INTERNAL_1.toLocalizedString(new Object[] {SOURCE_DATE, xtraGfshVersionPath});
- return;
- }
- this.sourceRevision = props.getProperty(SOURCE_REVISION);
- if (this.sourceRevision == null) {
- error = LocalizedStrings.GemFireVersion_MISSING_PROPERTY_0_FROM_RESOURCE_COM_GEMSTONE_GEMFIRE_INTERNAL_1.toLocalizedString(new Object[] {SOURCE_REVISION, xtraGfshVersionPath});
- return;
- }
- this.sourceRepository = props.getProperty(SOURCE_REPOSITORY);
- if (this.sourceRepository == null) {
- error = LocalizedStrings.GemFireVersion_MISSING_PROPERTY_0_FROM_RESOURCE_COM_GEMSTONE_GEMFIRE_INTERNAL_1.toLocalizedString(new Object[] {SOURCE_REPOSITORY, xtraGfshVersionPath});
- return;
- }
- this.buildDate = props.getProperty(BUILD_DATE);
- if (this.buildDate == null) {
- error = LocalizedStrings.GemFireVersion_MISSING_PROPERTY_0_FROM_RESOURCE_COM_GEMSTONE_GEMFIRE_INTERNAL_1.toLocalizedString(new Object[] {BUILD_DATE, xtraGfshVersionPath});
- return;
- }
- this.buildId = props.getProperty(BUILD_ID);
- if (this.buildId == null) {
- error = LocalizedStrings.GemFireVersion_MISSING_PROPERTY_0_FROM_RESOURCE_COM_GEMSTONE_GEMFIRE_INTERNAL_1.toLocalizedString(new Object[] {BUILD_ID, xtraGfshVersionPath});
- return;
- }
- this.buildPlatform = props.getProperty(BUILD_PLATFORM);
- if (this.buildPlatform == null) {
- error = LocalizedStrings.GemFireVersion_MISSING_PROPERTY_0_FROM_RESOURCE_COM_GEMSTONE_GEMFIRE_INTERNAL_1.toLocalizedString(new Object[] {BUILD_PLATFORM, xtraGfshVersionPath});
- return;
- }
- this.buildJavaVersion = props.getProperty(BUILD_JAVA_VERSION);
- if (this.buildJavaVersion == null) {
- error = LocalizedStrings.GemFireVersion_MISSING_PROPERTY_0_FROM_RESOURCE_COM_GEMSTONE_GEMFIRE_INTERNAL_1.toLocalizedString(new Object[] {BUILD_JAVA_VERSION, xtraGfshVersionPath});
- return;
- }
- }
-
- //////////////////// Static Methods ////////////////////
-
- /**
- * Returns (or creates) the singleton instance of this class
- */
- private static GfshVersion getInstance() {
- if (instance == null) {
- instance = new GfshVersion();
- }
-
- return instance;
- }
-
- /**
- * Returns the name of this product
- */
- public static String getProductName() {
- GfshVersion v = getInstance();
- if (v.error != null) {
- return v.error;
-
- } else {
- return v.productName;
- }
- }
-
- /**
- * Returns the version of GemFire being used
- */
- public static String getGfshVersion() {
- GfshVersion v = getInstance();
- if (v.error != null) {
- return v.error;
-
- } else {
- return v.gfshVersion;
- }
- }
-
- public static String getJavaCodeVersion() {
- GfshVersion v = getInstance();
- if (v.error != null) {
- return v.error;
-
- } else {
- StringBuilder result = new StringBuilder(80);
- result.append(GfshVersion.getGfshVersion())
- .append(' ')
- .append(GfshVersion.getBuildId())
- .append(' ')
- .append(GfshVersion.getBuildDate())
- .append(" javac ")
- .append(GfshVersion.getBuildJavaVersion());
- return result.toString();
- }
- }
-
- /**
- * Returns the date of the source code from which GemFire was built
- */
- public static String getSourceDate() {
- GfshVersion v = getInstance();
- if (v.error != null) {
- return v.error;
-
- } else {
- return v.sourceDate;
- }
- }
-
- /**
- * Returns the revision of the source code on which GemFire was
- * built.
- *
- */
- public static String getSourceRevision() {
- GfshVersion v = getInstance();
- if (v.error != null) {
- return v.error;
-
- } else {
- return v.sourceRevision;
- }
- }
-
- /**
- * Returns the source code repository from which GemFire was built.
- *
- */
- public static String getSourceRepository() {
- GfshVersion v = getInstance();
- if (v.error != null) {
- return v.error;
-
- } else {
- return v.sourceRepository;
- }
- }
-
- /**
- * Returns the date on which GemFire was built
- */
- public static String getBuildDate() {
- GfshVersion v = getInstance();
- if (v.error != null) {
- return v.error;
-
- } else {
- return v.buildDate;
- }
- }
-
- /**
- * Returns the id of the GemFire build
- */
- public static String getBuildId() {
- GfshVersion v = getInstance();
- if (v.error != null) {
- return v.error;
-
- } else {
- return v.buildId;
- }
- }
-
- /**
- * Returns the platform on which GemFire was built
- */
- public static String getBuildPlatform() {
- GfshVersion v = getInstance();
- if (v.error != null) {
- return v.error;
-
- } else {
- return v.buildPlatform;
- }
- }
-
- /**
- * Returns the version of Java used to build GemFire
- */
- public static String getBuildJavaVersion() {
- GfshVersion v = getInstance();
- if (v.error != null) {
- return v.error;
-
- } else {
- return v.buildJavaVersion;
- }
- }
-
- /**
- * Encodes all available version information into a string and then
- * returns that string.
- *
- * @param printSourceInfo
- * Should information about the source code be printed?
- */
- public static String asString(boolean printSourceInfo) {
- StringWriter sw = new StringWriter(256);
- PrintWriter pw = new PrintWriter(sw);
- print(pw, printSourceInfo);
- pw.flush();
- return sw.toString();
- }
-
- /**
- * Prints all available version information to the given
- * <code>PrintWriter</code> in a standard format.
- *
- * @param pw
- * writer to write version info to
- * @param printSourceInfo
- * Should information about the source code be printed?
- */
- protected static void print(PrintWriter pw, boolean printSourceInfo) {
- String jarVersion = GfshVersion.getJavaCodeVersion().trim();
- pw.println(getProductName() + " version: " + jarVersion);
-
- /*
- * TODO: GemFireVersion here compares the version info read by
- * GemFireVersion and available in product/lib directory. The 'version
- * CREATE' option to create the gfsh version file is not added currently. As
- * gfsh releases could be different than GemFire release, could we still use
- * product/lib?
- */
-
- if (printSourceInfo) {
- String sourceRevision = GfshVersion.getSourceRevision();
- pw.println("Source revision: " + sourceRevision);
-
- String sourceRepository = GfshVersion.getSourceRepository();
- pw.println("Source repository: " + sourceRepository);
- }
-
- InetAddress host = null;
- try {
- host = SocketCreator.getLocalHost();
- } catch (VirtualMachineError err) {
- SystemFailure.initiateFailure(err);
- // If this ever returns, rethrow the error. We're poisoned
- // now, so don't let this thread continue.
- throw err;
- } catch (Throwable t) {
- // Whenever you catch Error or Throwable, you must also
- // catch VirtualMachineError (see above). However, there is
- // _still_ a possibility that you are dealing with a cascading
- // error condition, so you also need to check to see if the JVM
- // is still usable:
- SystemFailure.checkFailure();
- }
-
- int cpuCount = Runtime.getRuntime().availableProcessors();
- pw.println(LocalizedStrings.GemFireVersion_RUNNING_ON_0
- .toLocalizedString(host + ", " + cpuCount + " cpu(s)" + ", "
- + System.getProperty("os.arch") + " "
- + System.getProperty("os.name") + " "
- + System.getProperty("os.version")));
-
- pw.flush();
- }
-
- public static int getMajorVersion(String v) {
- int majorVersion = 0;
- Matcher m = MAJOR_MINOR.matcher(v);
- if (m.matches()) {
- String digits = m.group(1);
- if (digits != null && digits.length() > 0) {
- majorVersion = Integer.decode(digits).intValue();
- }
- }
- return majorVersion;
- }
-
- public static int getMinorVersion(String v) {
- int minorVersion = 0;
- Matcher m = MAJOR_MINOR.matcher(v);
- if (m.matches()) {
- String digits = m.group(2);
- if (digits != null && digits.length() > 0) {
- minorVersion = Integer.decode(digits).intValue();
- }
- }
- return minorVersion;
- }
-
- /////////////////////// Main Program ////////////////////
-
- /**
- * Populates the gemfireVersion.properties file
- */
- public final static void main(String args[]) {
-// System.out.println("-------------------------------------------------");
-//
-// System.out.println(asString(false));
-//
-// System.out.println("-------------------------------------------------");
-//
- System.out.println(asString(true));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/Nextable.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/Nextable.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/Nextable.java
deleted file mode 100644
index 54b9c22..0000000
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/Nextable.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.gemstone.gemfire.internal.tools.gfsh.app;
-
-import java.util.List;
-
-public interface Nextable
-{
- List next(Object arg) throws Exception;
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/ServerExecutable.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/ServerExecutable.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/ServerExecutable.java
deleted file mode 100644
index 9ad2f6a..0000000
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/ServerExecutable.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.gemstone.gemfire.internal.tools.gfsh.app;
-
-public interface ServerExecutable
-{
- Object execute(String command, String regionPath, Object arg) throws Exception;
-
- byte getCode();
-
- String getCodeMessage();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/aggregator/AggregateFunctionTask.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/aggregator/AggregateFunctionTask.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/aggregator/AggregateFunctionTask.java
deleted file mode 100644
index 7b3eb4f..0000000
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/aggregator/AggregateFunctionTask.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package com.gemstone.gemfire.internal.tools.gfsh.app.aggregator;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-
-import com.gemstone.gemfire.DataSerializer;
-import com.gemstone.gemfire.internal.tools.gfsh.aggregator.AggregateFunction;
-import com.gemstone.gemfire.internal.tools.gfsh.command.AbstractCommandTask;
-import com.gemstone.gemfire.internal.tools.gfsh.command.CommandResults;
-
-/**
- * AggregateFunctionTask is used by Aggregator.
- *
- * @author dpark
- */
-public class AggregateFunctionTask extends AbstractCommandTask
-{
- private static final long serialVersionUID = 1L;
-
- private String regionFullPath;
- private AggregateFunction function;
-
- // Default constructor required for serialization
- public AggregateFunctionTask()
- {
- }
-
- public AggregateFunctionTask(AggregateFunction function, String regionFullPath)
- {
- this.function = function;
- this.regionFullPath = regionFullPath;
- }
-
- public CommandResults runTask(Object userData)
- {
- CommandResults results = new CommandResults();
- try {
- AggregatorPeer aggregator = new AggregatorPeer(regionFullPath);
- results.setDataObject(aggregator.aggregate(function));
- } catch (Exception ex) {
- results.setCode(CommandResults.CODE_ERROR);
- results.setException(ex);
- }
- return results;
- }
-
- public void fromData(DataInput input) throws IOException, ClassNotFoundException
- {
- super.fromData(input);
- regionFullPath = DataSerializer.readString(input);
- function = (AggregateFunction)DataSerializer.readObject(input);
- }
-
- public void toData(DataOutput output) throws IOException
- {
- super.toData(output);
- DataSerializer.writeString(regionFullPath, output);
- DataSerializer.writeObject(function, output);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/aggregator/Aggregator.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/aggregator/Aggregator.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/aggregator/Aggregator.java
deleted file mode 100644
index e09d72c..0000000
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/aggregator/Aggregator.java
+++ /dev/null
@@ -1,549 +0,0 @@
-package com.gemstone.gemfire.internal.tools.gfsh.app.aggregator;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-
-import com.gemstone.gemfire.internal.tools.gfsh.aggregator.AggregateFunction;
-import com.gemstone.gemfire.internal.tools.gfsh.app.command.CommandClient;
-import com.gemstone.gemfire.internal.tools.gfsh.app.command.CommandException;
-import com.gemstone.gemfire.internal.tools.gfsh.command.CommandResults;
-
-
-/**
- * Aggregator invokes a specified aggregate function on a specified region.
- * Aggregator works only in the client/server topology. As such, it requires endpoints
- * that specifies one or more cache servers to connect to. It also requires
- * the full path of a command region with which it will communicate with the
- * cache server(s) listed in the endpoints. The command region path must be
- * unique per distributed system. If there are multiple distributed systems
- * that an aggregation needs to be performed on, then the command region
- * path must be unique for each distributed system. For example, given DS1
- * and DS2, DS1 can be assigned to "/command1" and DS2 to "/command2". It is
- * not permitted to share, however, "/command1" with both distributed systems.
- * <p>
- * Aggregator internally keeps track of all aggregators created. If an
- * aggregator already exists under a given commandRegionFullPath,
- * then the endpoints of the existing aggregator will be used for all
- * subsequently created aggregators. This also applies to the aggregators created
- * by the addAggregator() method.
- * <p>
- * To remove all aggregators, invoke the static method closeAll(). Use this
- * method with a care. All aggregators will be closed, and hence, none of them will
- * be valid after this call.
- *
- * @author dpark
- *
- */
-public class Aggregator
-{
- /**
- * The hashmap that contains the global aggregator counts.
- */
- private static HashMap allAggregatorsMap = new HashMap();
-
- /**
- * SingleAggregator owned by this aggregator.
- */
- private SingleAggregator thisAggregator;
-
- /**
- * All SingleAggregator objects added by addAggregator() and the constructor.
- */
- private SingleAggregator singleAggregators[];
-
- /**
- * The aggregator map that contains all SingleAggregator objects added by
- * addAggregator() and the constructor. it contains
- * (commandRegionFullPath, SingleAggregator) pairs.
- */
- private HashMap aggregatorMap = new HashMap(3);
-
- /**
- * The aggregate invokation timeout in msec. The default value is 30000 msec (or 30 sec).
- */
- private long timeout = 30000;
-
- /**
- * Creates an aggregator with the specified command region path and endpoints.
- * The cache servers specified in the endpoints must have also defined
- * the specified command region, otherwise, aggregate() will throw an exception.
- *
- * @param commandRegionFullPath The full path of the command region used to
- * communicate with the cache servers listed in
- * the endpoints. The cache servers must pre-define
- * the command region, otherwise, aggregate() will
- * throw an exception.
- * @param endpoints The endpoints of cache server(s) that host the command region.
- * The endpoints format is "end1=host1:port1,end2=host2:port2".
- */
- public Aggregator(String commandRegionFullPath, String endpoints)
- {
- commandRegionFullPath = getCanonicalRegionPath(commandRegionFullPath);
- thisAggregator = new SingleAggregator(commandRegionFullPath, endpoints);
- synchronized (aggregatorMap) {
- singleAggregators = new SingleAggregator[1];
- singleAggregators[0] = thisAggregator;
- aggregatorMap.put(commandRegionFullPath, thisAggregator);
- allAggregatorsMap.put(commandRegionFullPath, new AggregatorCount(thisAggregator));
- incrementCount(commandRegionFullPath);
- }
- }
-
- /**
- * Creates an aggregator with the specified command client.
- * The cache servers must have also defined the command region defined,
- * otherwise, aggregate() will throw an exception.
- *
- * @param commandClient The command client to be used for sending aggregate requests
- * to the cache servers.
- */
- public Aggregator(CommandClient commandClient)
- {
- thisAggregator = new SingleAggregator(commandClient);
- String commandRegionFullPath = commandClient.getOutboxRegionFullPath();
- synchronized (aggregatorMap) {
- singleAggregators = new SingleAggregator[1];
- singleAggregators[0] = thisAggregator;
- aggregatorMap.put(commandRegionFullPath, thisAggregator);
- allAggregatorsMap.put(commandRegionFullPath, new AggregatorCount(thisAggregator));
- incrementCount(commandRegionFullPath);
- }
- }
-
- /**
- * Increments the reference count of the specified aggregator.
- * @param commandRegionFullPath The full path of the command region.
- * @return The incremented count. Returns -1 if the specified aggregator
- * does not exist.
- */
- private static int incrementCount(String commandRegionFullPath)
- {
- AggregatorCount ac = (AggregatorCount)allAggregatorsMap.get(commandRegionFullPath);
- if (ac == null) {
- return -1;
- }
- ac.count++;
- return ac.count;
- }
-
- /**
- * Decrements the reference count of the specified aggregator.
- * If the decremented count is 0, then the aggregator is removed
- * from allAggregateorsMap. The caller must close the aggregator
- * if the decremented count is 0.
- * @param commandRegionFullPath The full path of the command region.
- * @return The decremented count. Returns -1 if the specified aggregator
- * does not exist.
- */
- private static int decrementCount(String commandRegionFullPath)
- {
- AggregatorCount ac = (AggregatorCount)allAggregatorsMap.get(commandRegionFullPath);
- if (ac == null) {
- return -1;
- }
- ac.count--;
- if (ac.count <= 0) {
- allAggregatorsMap.remove(commandRegionFullPath);
- }
-
- return ac.count;
- }
-
- /**
- * Returns the reference count of the specified aggregator.
- * @param commandRegionFullPath The full path of the command region.
- */
- private static int getCount(String commandRegionFullPath)
- {
- AggregatorCount ac = (AggregatorCount)allAggregatorsMap.get(commandRegionFullPath);
- if (ac == null) {
- return 0;
- }
-
- return ac.count;
- }
-
- /**
- * Adds an aggregator. If the specified commandRegionFullPath has already been added
- * in this aggregator, this call is silently ignored. It is important to note that
- * the specified endpoints is honored per unique commandRegionFullPath. That means
- * if another aggregator is already created or added with the same commandRegionFullPath,
- * then that aggregator is used instead. A new aggregator will be created only if
- * there is no aggregator found with the same commandRegionFullPath. In other words,
- * the endpoints will not be assigned if there exist another aggregator that has
- * the same commandRegionFullPath. It is ignored silently and the exiting aggregator
- * is used instead. Note that the exiting aggregator might have been assigned
- * to a different endpoints.
- *
- * @param commandRegionFullPath The full path of the command region used to
- * communicate with the cache servers listed in
- * the endpoints. The cache servers must pre-define
- * the command region, otherwise, aggregate() will
- * throw an exception.
- * @param endpoints The endpoints of cache server(s) that host the command region.
- * The endpoints format is "end1=host1:port1,end2=host2:port2".
- * @throws AggregatorException Thrown if there is a cache related error.
- */
- public void addAggregator(String commandRegionFullPath, String endpoints) throws AggregatorException
- {
- if (isClosed()) {
- throw new AggregatorException("Aggregator closed. Unable to add the specified aggregator. Please create a new Aggregator first.");
- }
-
- synchronized (aggregatorMap) {
- commandRegionFullPath = getCanonicalRegionPath(commandRegionFullPath);
- SingleAggregator aggregator = (SingleAggregator)aggregatorMap.get(commandRegionFullPath);
- if (aggregator == null) {
- aggregator = new SingleAggregator(commandRegionFullPath, endpoints);
- aggregatorMap.put(commandRegionFullPath, aggregator);
- incrementCount(commandRegionFullPath);
- allAggregatorsMap.put(commandRegionFullPath, new AggregatorCount(aggregator));
- singleAggregators = (SingleAggregator[])aggregatorMap.values().toArray(new SingleAggregator[0]);
- }
- }
- }
-
- /**
- * Removes the aggregator identified by the commandRegionFullPath from this aggregator.
- * @param commandRegionFullPath The full path of the command region used to
- * communicate with the cache servers listed in
- * the endpoints.
- * @throws AggregatorException Thrown if there is a cache related error or
- * this aggregator's commandRegionFullPath is same
- * as the specified commandRegionFullPath. To remove
- * this aggregator, invoke close() instead.
- */
- public void removeAggregator(String commandRegionFullPath) throws AggregatorException
- {
- commandRegionFullPath = getCanonicalRegionPath(commandRegionFullPath);
- if (thisAggregator.getCommandRegionFullPath().equals(commandRegionFullPath)) {
- throw new AggregatorException("Removing the primary (this) aggregator is not allowed. Please use close() instead.");
- }
-
- remove(commandRegionFullPath);
- }
-
- /**
- * Removes the specified aggregator. It closes the aggregator if the
- * reference count is 0.
- *
- * @param commandRegionFullPath The full path of the command region used to
- * communicate with the cache servers listed in
- * the endpoints.
- * @throws AggregatorException
- */
- private void remove(String commandRegionFullPath) throws AggregatorException
- {
- synchronized (aggregatorMap) {
- SingleAggregator aggregator = (SingleAggregator)aggregatorMap.remove(commandRegionFullPath);
- if (aggregator != null) {
- decrementCount(commandRegionFullPath);
- if (getCount(commandRegionFullPath) <= 0) {
- aggregator.close();
- }
- }
- }
- }
-
- /**
- * Closes this aggregator and removes all added aggregator. This aggregator
- * is empty upon return of this call and no longer valid. The aggregate()
- * method will throw an exception if close() has been invoked.
- *
- * @throws AggregatorException Thrown if there is a cache related error.
- */
- public void close() throws AggregatorException
- {
- synchronized (aggregatorMap) {
-
- String paths[] = (String[])aggregatorMap.keySet().toArray(new String[0]);
- for (int i = 0; i < paths.length; i++) {
- remove(paths[i]);
- }
- aggregatorMap.clear();
- singleAggregators = new SingleAggregator[0];
- thisAggregator = null;
- }
- }
-
- /**
- * Returns true if this aggregator is closed. If true, then this
- * aggregator is no longer valid. All references to this object
- * should be set to null so that it can be garbage collected.
- * @return whether aggregator is closed
- */
- public boolean isClosed()
- {
- return thisAggregator == null;
- }
-
- /**
- * Closes all aggregators. All aggregators will be no longer valid
- * after this call.
- */
- public static void closeAll()
- {
- AggregatorCount acs[] = (AggregatorCount[])allAggregatorsMap.keySet().toArray(new AggregatorCount[0]);
- for (int i = 0; i < acs.length; i++) {
- try {
- acs[i].aggregator.close();
- } catch (AggregatorException e) {
- // ignore - do not throw an exception
- // because one of them failed. continue
- // closing all others.
- }
- }
- allAggregatorsMap.clear();
- }
-
- /**
- * Executes the specified function and returns an aggregated result defined
- * by the function.
- *
- * @param function The aggregate function to execute.
- * @param regionFullPath The region on which the aggregate function to be
- * performed.
- * @return Returns the result from the specified function. See the function
- * definition for the return type.
- * @throws AggregatorException Thrown if there is a cache related error.
- */
- public synchronized Object aggregate(AggregateFunction function, String regionFullPath) throws AggregatorException
- {
- if (isClosed()) {
- throw new AggregatorException("Aggregator closed. Unable to aggregate. Please create a new Aggregator.");
- }
-
- SingleAggregator aggregators[] = this.singleAggregators;
-
- // If only one aggregator then no need to use separate threads.
- // Return the result using the current thread.
- if (aggregators.length == 1) {
- return aggregators[0].aggregate(function, regionFullPath);
- }
-
- // Need to spawn threads to parallelize the aggregate fuction
- // execution on different distributed systems. Assign
- // a thread per aggregator (or distributed system).
- ArrayList resultsList = new ArrayList();
- ArrayList exceptionList = new ArrayList();
- long count = aggregators.length;
- for (int i = 0; i < count; i++) {
- new Thread(new DSAggregator(function, aggregators[i], regionFullPath, resultsList, exceptionList)).start();
- }
-
- // Wait and collect results returned by all aggregators.
- // resultsList contains results from all distributed systems.
- boolean allResponded = false;
- long startTime = System.currentTimeMillis();
- do {
- try {
- wait(timeout);
- synchronized (resultsList) {
- allResponded = resultsList.size() == count;
- if (allResponded == false) {
- if (exceptionList.isEmpty() == false) {
- break;
- }
- }
- }
- if (allResponded == false && System.currentTimeMillis() - startTime >= timeout) {
- break;
- }
- } catch (InterruptedException e) {
- // ignore
- }
- } while (allResponded == false);
-
- // If all responded then aggregate the results by invoking the
- // AggregateFunction.aggregateDistributedSystems(), which is
- // responsible for aggregating the results.
- if (allResponded == false) {
-
- // Throw exception if not all responded
- if (exceptionList.isEmpty() == false) {
-
- throw new AggregatorException("Distributed System Error. Errors from "
- + exceptionList.size()
- + " distributed system(s). See getClientExceptions()",
- (Throwable[])exceptionList.toArray(new Throwable[0]));
- } else {
- throw new AggregatorException("The aggregate operation timed out. Not all distributed systems responded within the timeout period of " + timeout + " msec.");
- }
- } else {
- Object results[] = resultsList.toArray();
- return function.aggregateDistributedSystems(results);
- }
- }
-
- /**
- * Returns the timeout value in msec. The default value is 30000 msec (or 30 seconds)
- */
- public long getTimeout()
- {
- return timeout;
- }
-
- /**
- * Sets the timeout in msec. The default value is 30000 msec (or 30 seconds)
- * @param timeout The timeout value in msec.
- */
- public void setTimeout(long timeout)
- {
- this.timeout = timeout;
- }
-
- /**
- * Returns the full path of the command region.
- */
- public String getCommandRegionFullPath()
- {
- return thisAggregator.getCommandRegionFullPath();
- }
-
- /**
- * Returns the endpoints.
- */
- public String getEndpoints()
- {
- return thisAggregator.getEndpoints();
- }
-
- /**
- * Returns the canonical region path.
- * @param regionPath The region path to convert to a canonical form.
- */
- private String getCanonicalRegionPath(String regionPath)
- {
- // Remove leading and trailing spaces.
- regionPath = regionPath.trim();
-
- // must begin with '/'.
- if (regionPath.startsWith("/") == false) {
- regionPath = "/" + regionPath;
- }
-
- return regionPath;
- }
-
- /**
- * Notifies the results.
- */
- private synchronized void notifyResults()
- {
- notify();
- }
-
- /**
- * DSAggregator is a Runnable that each aggregate thread uses
- * to keep aggregate context information separate from others.
- */
- class DSAggregator implements Runnable
- {
- private AggregateFunction function;
- private SingleAggregator aggregator;
- private ArrayList resultsList;
- private ArrayList exceptionList;
- private String regionFullPath;
-
- DSAggregator(AggregateFunction function, SingleAggregator aggregator, String regionFullPath, ArrayList resultsList, ArrayList exceptionList)
- {
- this.function = function;
- this.aggregator = aggregator;
- this.regionFullPath = regionFullPath;
- this.resultsList = resultsList;
- this.exceptionList = exceptionList;
- }
-
- public void run()
- {
- try {
- Object results = aggregator.aggregate(function, regionFullPath);
- synchronized (resultsList) {
- resultsList.add(results);
- }
- notifyResults();
- } catch (AggregatorException ex) {
- synchronized (resultsList) {
- exceptionList.add(ex);
- }
- notifyResults();
- }
- }
- }
-
- //FindBugs - make static inner class
- static class AggregatorCount
- {
- public int count = 0;
- public SingleAggregator aggregator;
-
- AggregatorCount(SingleAggregator aggregator)
- {
- this.aggregator = aggregator;
- }
- }
-}
-
-/**
- * SingleAggregator holds CommandClient information of an aggregator.
- */
-class SingleAggregator
-{
- private CommandClient commandClient;
-
- SingleAggregator(String commandRegionFullPath, String endpoints)
- {
- commandClient = new CommandClient(commandRegionFullPath, endpoints);
- }
-
- SingleAggregator(CommandClient commandClient)
- {
- this.commandClient = commandClient;
- }
-
- /**
- *
- * @param function
- * @param regionFullPath
- * @return Returns null of isListenerEnabled() is true. In that case, the
- * aggregated results are delivered to the registered AggregatedDataListeners.
- * @throws AggregatorException
- */
- Object aggregate(AggregateFunction function, String regionFullPath) throws AggregatorException
- {
- try {
- CommandResults results = commandClient.execute(new AggregateFunctionTask(function, regionFullPath));
- if (results.getCode() != CommandResults.CODE_NORMAL) {
- throw new AggregatorException(results.getCodeMessage(), results.getException());
- }
- return results.getDataObject();
- } catch (Exception ex) {
- throw new AggregatorException(ex);
- }
- }
-
- String getCommandRegionFullPath()
- {
- return commandClient.getOutboxRegionFullPath();
- }
-
- String getEndpoints()
- {
- return commandClient.getEndpoints();
- }
-
- public void close() throws AggregatorException
- {
- try {
- commandClient.close();
- } catch (CommandException ex) {
- throw new AggregatorException(ex);
- }
- }
-
- public boolean isClosed()
- {
- return commandClient.isClosed();
- }
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/aggregator/AggregatorException.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/aggregator/AggregatorException.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/aggregator/AggregatorException.java
deleted file mode 100644
index 0e59aba..0000000
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/aggregator/AggregatorException.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package com.gemstone.gemfire.internal.tools.gfsh.app.aggregator;
-
-/**
- * AggregatorException is thrown by Aggregator if there is
- * any error related to the aggregator.
- *
- * @author dpark
- *
- */
-public class AggregatorException extends Exception
-{
- private static final long serialVersionUID = 1L;
-
- private Throwable functionExceptions[];
-
- public AggregatorException()
- {
- super();
- }
- public AggregatorException(String message)
- {
- super(message);
- }
-
- public AggregatorException(String message, Throwable cause)
- {
- super(message, cause);
- }
-
- public AggregatorException(Throwable cause)
- {
- super(cause);
- }
-
- public AggregatorException(String message, Throwable functionExceptions[])
- {
- super(message);
- this.functionExceptions = functionExceptions;
- }
-
- /**
- * The exception caught in AggregateFunction.run().
- * @return exception caught in AggregateFunction.run()
- */
- public Throwable[] getFunctionExceptions()
- {
- return functionExceptions;
- }
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/aggregator/AggregatorPeer.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/aggregator/AggregatorPeer.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/aggregator/AggregatorPeer.java
deleted file mode 100644
index 35f15e5..0000000
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/aggregator/AggregatorPeer.java
+++ /dev/null
@@ -1,254 +0,0 @@
-package com.gemstone.gemfire.internal.tools.gfsh.app.aggregator;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.CopyOnWriteArraySet;
-
-import com.gemstone.gemfire.cache.Cache;
-import com.gemstone.gemfire.cache.CacheFactory;
-import com.gemstone.gemfire.cache.Region;
-import com.gemstone.gemfire.cache.execute.Execution;
-import com.gemstone.gemfire.cache.execute.FunctionService;
-import com.gemstone.gemfire.internal.cache.PartitionedRegion;
-import com.gemstone.gemfire.internal.tools.gfsh.aggregator.AggregateFunction;
-import com.gemstone.gemfire.internal.tools.gfsh.aggregator.AggregatorPartitionFunction;
-
-/**
- * AggregatorPeer is experimental use only. If the application is a peer member
- * hosting the specified region, then this class may provide better performance
- * than Aggregator, which uses the client/server topology. It also does not
- * require the command region to be created unless the method
- * aggregate(AggregateFunction function, Aggregator aggregatorClient) is used.
- * In which case, the command region is created by Aggregator.
- *
- * @author dpark
- *
- */
-public class AggregatorPeer
-{
- PartitionedRegion region;
- Execution execution;
-
- // 30 sec timeout;
- private long timeout = 30000;
- private Set routingKeySet;
-
- /**
- * Creates a AggregatorPeer object with the specified region path.
- * @param regionFullPath The full path of the partitioned region on
- * which aggregation operations are to be executed.
- */
- public AggregatorPeer(String regionFullPath)
- {
- Cache cache = CacheFactory.getAnyInstance();
- region = (PartitionedRegion)cache.getRegion(regionFullPath);
- init();
- }
-
- /**
- * Creates an AggregatorPeer object with the specified partitioned region.
- * @param region The partitioned region on which aggregation operations
- * are to be executed.
- */
- public AggregatorPeer(Region region)
- {
- this.region = (PartitionedRegion)region;
- init();
- }
-
- private void init()
- {
- execution = FunctionService.onMembers(region.getCache().getDistributedSystem());
- int totalNumBuckets = region.getPartitionAttributes().getTotalNumBuckets();
- routingKeySet = new CopyOnWriteArraySet();
- for (int i = 0; i < totalNumBuckets; i++) {
- routingKeySet.add(i);
- }
- }
-
- public void setRoutingKeys(Set routingKeySet)
- {
- this.routingKeySet = routingKeySet;
- }
-
- public Set getRoutingKeys()
- {
- return routingKeySet;
- }
-
- public Region getRegion()
- {
- return region;
- }
-
- public Object aggregate(AggregateFunction function) throws AggregatorException
- {
- return aggregate(function, routingKeySet);
- }
-
- /**
- * Executes the specified function in each of the partition buckets identified
- * by the specified routingKeySet.
- * @param function aggregate function to execute.
- * @param routingKeySet A set of RoutingKey objects that identify the
- * partition buckets in which the function to be executed.
- * @return Returns aggregate results. The result type is specified by the function
- * passed in.
- * @throws AggregatorException
- */
- private Object aggregate(AggregateFunction function, Set routingKeySet) throws AggregatorException
- {
- try {
- Object obj = execution.withArgs(function).execute(AggregatorPartitionFunction.ID).getResult();
- if (obj instanceof List) {
- List list = (List)obj;
- return function.aggregate(list);
- } else if (obj instanceof Map) {
- // GFE 6.3 support
- Map map = (Map)obj;
- ArrayList list = new ArrayList();
- Collection<List> col = map.values();
- for (List list2 : col) {
- list.addAll(list2);
- }
- return function.aggregate(list);
- } else {
- throw new AggregatorException("Unsupported aggregate result type: " + obj.getClass().getName());
- }
- } catch (Exception ex) {
- throw new AggregatorException(ex);
- }
- }
-
- public synchronized Object aggregate(AggregateFunction function, Aggregator aggregatorClient) throws AggregatorException
- {
- if (aggregatorClient == null) {
- return aggregate(function);
- } else {
- ArrayList resultsList = new ArrayList();
- ArrayList exceptionList = new ArrayList();
- long count = 2;
- new Thread(new LocalAggregator(function, resultsList, exceptionList)).start();
-
- for (int i = 0; i < count - 1; i++) {
- new Thread(new DSAggregator(function, aggregatorClient, resultsList, exceptionList)).start();
- }
- boolean allResponded = false;
- long startTime = System.currentTimeMillis();
- do {
- try {
- wait(timeout);
- synchronized (resultsList) {
- allResponded = resultsList.size() == count;
- if (allResponded == false) {
- if (exceptionList.isEmpty() == false) {
- break;
- }
- }
- }
- if (allResponded == false && System.currentTimeMillis() - startTime >= timeout) {
- break;
- }
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- } while (allResponded == false);
-
- if (allResponded == false) {
- if (exceptionList.isEmpty() == false) {
-
- throw new AggregatorException("Distributed System Error. Errors from "
- + exceptionList.size()
- + " distributed system(s). See getClientExceptions()",
- (Throwable[])exceptionList.toArray(new Throwable[0]));
- } else {
- throw new AggregatorException("The aggregate operation timedout. Not all distributed systems responded within the timeout period of " + timeout + " msec.");
- }
- } else {
- Object results[] = resultsList.toArray();
- return function.aggregateDistributedSystems(results);
- }
- }
- }
-
- public long getTimeout()
- {
- return timeout;
- }
-
- public void setTimeout(long timeout)
- {
- this.timeout = timeout;
- }
-
- private synchronized void notifyResults()
- {
- notify();
- }
-
- class LocalAggregator implements Runnable
- {
- private AggregateFunction function;
- private ArrayList resultsList;
- private ArrayList exceptionList;
-
- LocalAggregator(AggregateFunction function, ArrayList resultsList, ArrayList exceptionList)
- {
- this.function = function;
- this.resultsList = resultsList;
- this.exceptionList = exceptionList;
- }
-
- public void run()
- {
- try {
- Object results = aggregate(function);
- synchronized (resultsList) {
- resultsList.add(results);
- }
- notifyResults();
- } catch (AggregatorException ex) {
- synchronized (resultsList) {
- exceptionList.add(ex);
- }
- notifyResults();
- }
- }
- }
-
- class DSAggregator implements Runnable
- {
- private AggregateFunction function;
- private Aggregator aggregatorClient;
- private ArrayList resultsList;
- private ArrayList exceptionList;
-
- DSAggregator(AggregateFunction function, Aggregator aggregatorClient, ArrayList resultsList, ArrayList exceptionList)
- {
- this.function = function;
- this.aggregatorClient = aggregatorClient;
- this.resultsList = resultsList;
- this.exceptionList = exceptionList;
- }
-
- public void run()
- {
- try {
- Object results = aggregatorClient.aggregate(function, region.getFullPath());
- synchronized (resultsList) {
- resultsList.add(results);
- }
- notifyResults();
- } catch (AggregatorException ex) {
- synchronized (resultsList) {
- exceptionList.add(ex);
- }
- notifyResults();
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/aggregator/functions/util/LocalRegionInfoFunction.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/aggregator/functions/util/LocalRegionInfoFunction.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/aggregator/functions/util/LocalRegionInfoFunction.java
deleted file mode 100644
index 8f1e1db..0000000
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/aggregator/functions/util/LocalRegionInfoFunction.java
+++ /dev/null
@@ -1,235 +0,0 @@
-package com.gemstone.gemfire.internal.tools.gfsh.app.aggregator.functions.util;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-import com.gemstone.gemfire.DataSerializable;
-import com.gemstone.gemfire.DataSerializer;
-import com.gemstone.gemfire.cache.Cache;
-import com.gemstone.gemfire.cache.CacheFactory;
-import com.gemstone.gemfire.cache.Region;
-import com.gemstone.gemfire.cache.execute.FunctionContext;
-import com.gemstone.gemfire.distributed.DistributedMember;
-import com.gemstone.gemfire.distributed.DistributedSystem;
-import com.gemstone.gemfire.internal.GemFireVersion;
-import com.gemstone.gemfire.internal.cache.BucketRegion;
-import com.gemstone.gemfire.internal.cache.ForceReattemptException;
-import com.gemstone.gemfire.internal.cache.PartitionedRegion;
-import com.gemstone.gemfire.internal.tools.gfsh.aggregator.AggregateFunction;
-import com.gemstone.gemfire.internal.tools.gfsh.aggregator.AggregateResults;
-import com.gemstone.gemfire.internal.tools.gfsh.app.cache.data.MapMessage;
-
-public class LocalRegionInfoFunction implements AggregateFunction, DataSerializable
-{
- private static final long serialVersionUID = 1L;
-
- private String regionPath;
-
- private static boolean priorTo6011 = true;
-
- static {
- priorTo6011 = isPriorTo6011();
- }
-
- static boolean isPriorTo6011()
- {
- String gemfireVersion = GemFireVersion.getGemFireVersion();
- String split[] = gemfireVersion.split("\\.");
- int major = 0;
- int minor = 0;
- int update = 0;
- int update2 = 0;
- for (int i = 0; i < split.length; i++) {
- switch (i) {
- case 0:
- major = Integer.parseInt(split[i]);
- break;
- case 1:
- try {
- minor = Integer.parseInt(split[i]);
- } catch (NumberFormatException ex) {
- minor = Integer.parseInt(split[i].substring(0, 1));
- }
- break;
- case 2:
- try {
- update = Integer.parseInt(split[i]);
- } catch (NumberFormatException ex) {
- // non-number. ignore
- }
- break;
- case 3:
- try {
- update2 = Integer.parseInt(split[i]);
- } catch (NumberFormatException ex) {
- // non-number. ignore.
- }
- break;
- }
- }
-
- if (major < 6) {
- return true; // 7
- } else if (minor > 0) {
- return false; // 6.1
- } else if (update < 1) {
- return true; // 6.0.0
- } else if (update > 1) {
- return false; // 6.0.2
- } else if (update2 <= 0) {
- return true; // 6.0.1.0
- } else {
- return false; // 6.0.1.1
- }
-
- }
-
- public LocalRegionInfoFunction()
- {
- }
-
- public LocalRegionInfoFunction(String regionPath)
- {
- this.regionPath = regionPath;
- }
-
- public String getRegionPath()
- {
- return regionPath;
- }
-
- public void setRegionPath(String regionPath)
- {
- this.regionPath = regionPath;
- }
-
- public AggregateResults run(FunctionContext context)
- {
- AggregateResults results = new AggregateResults();
- Cache cache = CacheFactory.getAnyInstance();
- DistributedSystem ds = cache.getDistributedSystem();
- DistributedMember member = ds.getDistributedMember();
-
- Region region = cache.getRegion(regionPath);
- if (region == null) {
- results.setCode(AggregateResults.CODE_ERROR);
- results.setCodeMessage("Undefined region: " + regionPath);
- return results;
- }
-
- MapMessage message = new MapMessage();
- message.put("MemberId", member.getId());
- message.put("MemberName", ds.getName());
- message.put("Host", member.getHost());
- // message.put("IpAddress",
- // dataSet.getNode().getMemberId().getIpAddress().getHostAddress());
- // message.put("Port", parent.getNode().getMemberId().getPort());
- message.put("Pid", member.getProcessId());
- message.put("RegionPath", regionPath);
-
- boolean isPR = region instanceof PartitionedRegion;
- message.put("IsPR", isPR);
- if (isPR) {
- PartitionedRegion pr = (PartitionedRegion) region;
- SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy h:mm:ss.SSS a");
- message.put("LastAccessedTime", format.format(new Date(pr.getLastAccessedTime())));
- message.put("LastModifiedTime", format.format(new Date(pr.getLastModifiedTime())));
-
- // total local primary bucket size
- int totalRegionSize = 0;
- // if (priorTo6011) { // 5.7 - 6.0.1
- // The following call is not returning the primary bucket regions.
- // totalRegionSize = PartitionRegionHelper.getLocalData(pr).size();
-
- // getDataStore() is null if peer client
- if (pr.getDataStore() == null) {
- message.put("IsPeerClient", true);
- } else {
- List<Integer> bucketIdList = pr.getDataStore().getLocalPrimaryBucketsListTestOnly();
- for (Integer bucketId : bucketIdList) {
- BucketRegion bucketRegion;
- try {
- bucketRegion = pr.getDataStore().getInitializedBucketForId(null, bucketId);
- totalRegionSize += bucketRegion.size();
- } catch (ForceReattemptException e) {
- // ignore
- }
- }
- message.put("IsPeerClient", false);
- }
-
- // } else {
- // // The following call is not returning the primary bucket
- // regions.
- // // totalRegionSize =
- // PartitionRegionHelper.getLocalData(pr).size();
- //
- // Region localRegion = new LocalDataSet(pr,
- // pr.getDataStore().getAllLocalPrimaryBucketIds());
- // totalRegionSize = localRegion.size();
- // }
- message.put("RegionSize", totalRegionSize);
-
- } else {
- message.put("IsPeerClient", false);
- message.put("RegionSize", region.size());
- message.put("Scope", region.getAttributes().getScope().toString());
- }
- message.put("DataPolicy", region.getAttributes().getDataPolicy().toString());
-
- // info.evictionPolicy =
- // region.getAttributes().getEvictionAttributes().getAlgorithm();
-
- results.setDataObject(message);
- return results;
- }
-
- /**
- * Returns a java.util.List of LocalRegionInfo objects;
- */
- public Object aggregate(List list)
- {
- ArrayList resultList = new ArrayList();
- for (int i = 0; i < list.size(); i++) {
- AggregateResults results = (AggregateResults) list.get(i);
- if (results.getCode() == AggregateResults.CODE_ERROR) {
- // MapMessage info = new MapMessage();
- // info.put("Code", results.getCode());
- // info.put("CodeMessage", results.getCodeMessage());
- // info.put("RegionPath", regionPath);
- // resultList.add(info);
- // break;
- // ignore - occurs only if undefined region
- continue;
- }
- if (results.getDataObject() != null) {
- resultList.add(results.getDataObject());
- }
- }
- return resultList;
- }
-
- public Object aggregateDistributedSystems(Object[] results)
- {
- ArrayList list = new ArrayList();
- for (int i = 0; i < results.length; i++) {
- list.add(results[i]);
- }
- return list;
- }
-
- public void fromData(DataInput input) throws IOException, ClassNotFoundException
- {
- regionPath = DataSerializer.readString(input);
- }
-
- public void toData(DataOutput output) throws IOException
- {
- DataSerializer.writeString(regionPath, output);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/aggregator/functions/util/RegionCreateFunction.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/aggregator/functions/util/RegionCreateFunction.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/aggregator/functions/util/RegionCreateFunction.java
deleted file mode 100644
index f43b356..0000000
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/aggregator/functions/util/RegionCreateFunction.java
+++ /dev/null
@@ -1,81 +0,0 @@
-package com.gemstone.gemfire.internal.tools.gfsh.app.aggregator.functions.util;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import com.gemstone.gemfire.DataSerializable;
-import com.gemstone.gemfire.DataSerializer;
-import com.gemstone.gemfire.cache.execute.FunctionContext;
-import com.gemstone.gemfire.internal.tools.gfsh.aggregator.AggregateFunction;
-import com.gemstone.gemfire.internal.tools.gfsh.aggregator.AggregateResults;
-import com.gemstone.gemfire.internal.tools.gfsh.app.command.task.RegionCreateTask;
-
-public class RegionCreateFunction implements AggregateFunction, DataSerializable
-{
- private static final long serialVersionUID = 1L;
-
- private RegionCreateTask regionCreateTask;
-
- public RegionCreateFunction()
- {
- }
-
- public RegionCreateFunction(RegionCreateTask regionCreateTask)
- {
- this.regionCreateTask = regionCreateTask;
- }
-
- public RegionCreateTask getRegionCreateAllTask()
- {
- return regionCreateTask;
- }
-
- public void setRegionCreateAllTask(RegionCreateTask regionCreateAllTask)
- {
- this.regionCreateTask = regionCreateAllTask;
- }
-
- public AggregateResults run(FunctionContext context)
- {
- AggregateResults results = new AggregateResults();
- results.setDataObject(regionCreateTask.runTask(null));
- return results;
- }
-
- /**
- * Returns a java.util.List of LocalRegionInfo objects;
- */
- public Object aggregate(List list)
- {
- ArrayList resultList = new ArrayList();
- for (int i = 0; i < list.size(); i++) {
- AggregateResults results = (AggregateResults)list.get(i);
- if (results.getDataObject() != null) {
- resultList.add(results.getDataObject());
- }
- }
- return resultList;
- }
-
- public Object aggregateDistributedSystems(Object[] results)
- {
- ArrayList list = new ArrayList();
- for (int i = 0; i < results.length; i++) {
- list.add(results[i]);
- }
- return list;
- }
-
- public void fromData(DataInput input) throws IOException, ClassNotFoundException
- {
- regionCreateTask = (RegionCreateTask)DataSerializer.readObject(input);
- }
-
- public void toData(DataOutput output) throws IOException
- {
- DataSerializer.writeObject(regionCreateTask, output);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/aggregator/functions/util/RegionDestroyFunction.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/aggregator/functions/util/RegionDestroyFunction.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/aggregator/functions/util/RegionDestroyFunction.java
deleted file mode 100644
index fc1b031..0000000
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/aggregator/functions/util/RegionDestroyFunction.java
+++ /dev/null
@@ -1,86 +0,0 @@
-package com.gemstone.gemfire.internal.tools.gfsh.app.aggregator.functions.util;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import com.gemstone.gemfire.DataSerializable;
-import com.gemstone.gemfire.DataSerializer;
-import com.gemstone.gemfire.cache.execute.FunctionContext;
-import com.gemstone.gemfire.internal.tools.gfsh.aggregator.AggregateFunction;
-import com.gemstone.gemfire.internal.tools.gfsh.aggregator.AggregateResults;
-import com.gemstone.gemfire.internal.tools.gfsh.app.command.task.RegionDestroyTask;
-
-public class RegionDestroyFunction implements AggregateFunction, DataSerializable
-{
- private static final long serialVersionUID = 1L;
-
- private RegionDestroyTask regionDestroyTask;
-
- public RegionDestroyFunction()
- {
- }
-
- public RegionDestroyFunction(String regionPath)
- {
- this.regionDestroyTask = new RegionDestroyTask(regionPath);
- }
-
- public RegionDestroyFunction(RegionDestroyTask regionDestroyTask)
- {
- this.regionDestroyTask = regionDestroyTask;
- }
-
- public RegionDestroyTask getRegionDestroyTask()
- {
- return regionDestroyTask;
- }
-
- public void setRegionCreateAllTask(RegionDestroyTask regionDestroyTask)
- {
- this.regionDestroyTask = regionDestroyTask;
- }
-
- public AggregateResults run(FunctionContext context)
- {
- AggregateResults results = new AggregateResults();
- results.setDataObject(regionDestroyTask.runTask(null));
- return results;
- }
-
- /**
- * Returns a java.util.List of LocalRegionInfo objects;
- */
- public Object aggregate(List list)
- {
- ArrayList resultList = new ArrayList();
- for (int i = 0; i < list.size(); i++) {
- AggregateResults results = (AggregateResults)list.get(i);
- if (results.getDataObject() != null) {
- resultList.add(results.getDataObject());
- }
- }
- return resultList;
- }
-
- public Object aggregateDistributedSystems(Object[] results)
- {
- ArrayList list = new ArrayList();
- for (int i = 0; i < results.length; i++) {
- list.add(results[i]);
- }
- return list;
- }
-
- public void fromData(DataInput input) throws IOException, ClassNotFoundException
- {
- regionDestroyTask = (RegionDestroyTask)DataSerializer.readObject(input);
- }
-
- public void toData(DataOutput output) throws IOException
- {
- DataSerializer.writeObject(regionDestroyTask, output);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/CacheBase.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/CacheBase.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/CacheBase.java
deleted file mode 100644
index f0dc3f6..0000000
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/CacheBase.java
+++ /dev/null
@@ -1,178 +0,0 @@
-package com.gemstone.gemfire.internal.tools.gfsh.app.cache;
-
-/*=========================================================================
- * Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved.
- * This product is protected by U.S. and international copyright
- * and intellectual property laws. Pivotal products are covered by
- * more patents listed at http://www.pivotal.io/patents.
- *========================================================================
- */
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.net.InetAddress;
-import java.text.MessageFormat;
-import java.util.Properties;
-
-import com.gemstone.gemfire.LogWriter;
-import com.gemstone.gemfire.cache.Cache;
-import com.gemstone.gemfire.cache.CacheException;
-import com.gemstone.gemfire.cache.CacheExistsException;
-import com.gemstone.gemfire.cache.CacheFactory;
-import com.gemstone.gemfire.distributed.DistributedSystem;
-import com.gemstone.gemfire.distributed.Locator;
-import com.gemstone.gemfire.internal.OSProcess;
-
-@SuppressWarnings("deprecation")
-public class CacheBase
-{
- /**
- * The system region that holds system-level data for configuration
- * and real-time state updates.
- */
- public final static String PROPERTY_SYSTEM_REGION_PATH = "systemRegionPath";
-
- protected DistributedSystem distributedSystem;
- protected Cache cache;
- protected LogWriter logger;
-
- public static void startLocator(String address, int port, String logFile)
- throws IOException
- {
- InetAddress inetAddress = InetAddress.getByName(address);
- Locator.startLocatorAndDS(port, new File(logFile), inetAddress, new Properties());
- }
-
- public CacheBase()
- {
- }
-
- protected void initializeCache() throws CacheException, IOException {
-
- try {
- InstantiatorClassLoader.loadDataSerializables();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- open();
- }
-
- protected void initializeLogStatsResources() {
- String gemfirePropertyFile = System.getProperty("gemfirePropertyFile");
- Properties props = new Properties();
- try {
- if (gemfirePropertyFile != null) {
- File propFile = new File(gemfirePropertyFile);
- if (propFile.exists()) {
- FileInputStream fis = new FileInputStream(gemfirePropertyFile);
- props.load(fis);
- fis.close();
- }
- }
- } catch (IOException e) {
- //Ignore here.
- }
-
- String pid = String.valueOf(OSProcess.getId());
-
- String logFile = System.getProperty("gemfire.log-file");
- if (logFile == null) {
- logFile = props.getProperty("log-file");
- if (logFile == null) {
- String gfshLogFileFormat = System.getProperty("gfsh.log-file-format");
- logFile = MessageFormat.format(gfshLogFileFormat, new Object[] { pid });
- System.setProperty("gemfire.log-file", logFile);
- }
- }
-
- String statArchive = System.getProperty("gemfire.statistic-archive-file");
- if (statArchive == null) {
- statArchive = props.getProperty("statistic-archive-file");
- if (statArchive == null) {
- String gfshLogFileFormat = System.getProperty("gfsh.stat-file-format");
- statArchive = MessageFormat.format(gfshLogFileFormat, new Object[] { pid });
- System.setProperty("gemfire.statistic-archive-file", statArchive);
- }
- }
- }
-
- protected void open() throws IOException {
- // Create distributed system properties
- Properties properties = new Properties();
-
- // Connect to the distributed system
- distributedSystem = DistributedSystem.connect(properties);
-
- try {
- // Create cache
- cache = CacheFactory.create(distributedSystem);
- cache.setLockLease(10); // 10 second time out
-
- int bridgeServerPort = Integer.getInteger("bridgeServerPort", 0).intValue();
- String groups = System.getProperty("serverGroups");
- String[] serverGroups = null;
- if (groups != null) {
- serverGroups = groups.split(",");
- }
- if (bridgeServerPort != 0) {
- cache.setIsServer(true);
- com.gemstone.gemfire.cache.server.CacheServer server = cache.addCacheServer();
- server.setPort(bridgeServerPort);
- server.setNotifyBySubscription(true);
- server.setGroups(serverGroups);
- server.start();
- }
- } catch (CacheExistsException ex) {
- cache = CacheFactory.getAnyInstance();
- }
- if (cache != null) {
- logger = cache.getLogger();
- }
- }
-
- protected void close()
- {
- if (cache != null) {
- cache.close();
- }
- }
-
- public DistributedSystem getDistributedSystem()
- {
- return distributedSystem;
- }
-
- public Cache getGemFireCache()
- {
- return cache;
- }
-
-// Findbugs - wait not in loop - also seems unused code
- public void waitForever() throws InterruptedException {
- Object obj = new Object();
- synchronized (obj) {
- obj.wait();
- }
- }
-
- public LogWriter getLogger()
- {
- return cache.getLogger();
- }
-
- public static void main(String[] args) throws Exception {
- CacheBase base = new CacheBase();
- base.initializeCache();
- }
-
- public Cache getCache()
- {
- return cache;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/InstantiatorClassLoader.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/InstantiatorClassLoader.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/InstantiatorClassLoader.java
deleted file mode 100644
index f5de572..0000000
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/InstantiatorClassLoader.java
+++ /dev/null
@@ -1,101 +0,0 @@
-package com.gemstone.gemfire.internal.tools.gfsh.app.cache;
-
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.LineNumberReader;
-
-public class InstantiatorClassLoader
-{
- /**
- * Loads the DataSerializable classes from the relative file path
- * specified by the system property "dataSerializableFilePath". If not
- * defined then the default relative file path, "etc/DataSerializables.txt",
- * is read. The file must contain fully-qualified class names separated
- * by a new line. Lines that begin with # or that have white spaces only
- * are ignored. For example,
- * <p>
- * <table cellpadding=0 cellspacing=0>
- * <tr># Trade objects</tr>
- * <tr>foo.data.Trade</tr>
- * <tr>foo.data.Price</tr>
- * <tr>foo.data.Order</tr>
- * <tr>#
- * <tr># Info objects</tr>
- * <tr>foo.info.Company</tr>
- * <tr>foo.info.Employee</tr>
- * <tr>foo.info.Customer</tr>
- * </table>
- *
- * @throws IOException Thrown if unable to read the file.
- * @throws ClassNotFoundException Thrown if any one of classes in the file is
- * undefined.
- * @return Returns a comma separated list of loaded class paths.
- */
- public static String loadDataSerializables() throws IOException, ClassNotFoundException
- {
- String dataSerializableFilePath = System.getProperty("dataSerializableFilePath", "etc/DataSerializables.txt");
- return loadDataSerializables(dataSerializableFilePath);
- }
-
- /**
- * Loads the DataSerializable classes from the specified relative file path.
- * The file must contain fully-qualified class names separated
- * by a new line. Lines that begin with # or that have white spaces only
- * are ignored. For example,
- * <p>
- * <table cellpadding=0 cellspacing=0>
- * <tr># Trade objects</tr>
- * <tr>foo.data.Trade</tr>
- * <tr>foo.data.Price</tr>
- * <tr>foo.data.Order</tr>
- * <tr>#
- * <tr># Info objects</tr>
- * <tr>foo.info.Company</tr>
- * <tr>foo.info.Employee</tr>
- * <tr>foo.info.Customer</tr>
- * </table>
- *
- * @param filePath The relative or absolute file path.
- * @return Returns a comma separated list of loaded class paths.
- * @throws IOException Thrown if unable to read the file.
- * @throws ClassNotFoundException Thrown if any one of classes in the file is
- * undefined.
- */
- public static String loadDataSerializables(String filePath) throws IOException, ClassNotFoundException
- {
- filePath = filePath.trim();
- File file;
- if (filePath.startsWith("/") || filePath.indexOf(':') >= 0) {
- // absolute path
- file = new File(filePath);
- } else {
- String userDir = System.getProperty("user.dir");
- file = new File(userDir, filePath);
- }
-
- LineNumberReader reader = new LineNumberReader(new FileReader(file));
- String line = reader.readLine();
- String className;
- StringBuffer buffer = new StringBuffer(1000);
- while (line != null) {
- className = line.trim();
- if (className.length() > 0 && className.startsWith("#") == false) {
- Class.forName(className);
- buffer.append(className);
- buffer.append(", ");
- }
- line = reader.readLine();
- }
- reader.close();
- String classList;
- int endIndex = buffer.lastIndexOf(", "); // 8
- if (endIndex == buffer.length() - 2) {
- classList = buffer.substring(0, endIndex);
- } else {
- classList = buffer.toString();
- }
- return classList;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/data/GenericMap.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/data/GenericMap.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/data/GenericMap.java
deleted file mode 100644
index 1e2ff5e..0000000
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/data/GenericMap.java
+++ /dev/null
@@ -1,196 +0,0 @@
-package com.gemstone.gemfire.internal.tools.gfsh.app.cache.data;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.Collection;
-
-import com.gemstone.gemfire.DataSerializable;
-import com.gemstone.gemfire.DataSerializer;
-
-public interface GenericMap extends DataSerializable
-{
- public Entry add(String key, GenericMap value);
- public Entry add(String key, Mappable value);
- public Entry add(String key, String value);
- public Entry add(String key, boolean value);
- public Entry add(String key, byte value);
- public Entry add(String key, short value);
- public Entry add(String key, int value);
- public Entry add(String key, long value);
- public Entry add(String key, float value);
- public Entry add(String key, double value);
- public Entry addEntry(Entry entry);
- public Entry getEntry(int index);
- public Entry getEntry(String key);
- public Object getValue(String key);
- public boolean getBoolean(String key) throws NoSuchFieldException, InvalidTypeException;
- public byte getByte(String key) throws NoSuchFieldException, InvalidTypeException;
- public char getChar(String key) throws NoSuchFieldException, InvalidTypeException;
- public short getShort(String key) throws NoSuchFieldException, InvalidTypeException;
- public int getInt(String key) throws NoSuchFieldException, InvalidTypeException;
- public long getLong(String key) throws NoSuchFieldException, InvalidTypeException;
- public float getFloat(String key) throws NoSuchFieldException, InvalidTypeException;
- public double getDouble(String key) throws NoSuchFieldException, InvalidTypeException;
- public String getString(String key) throws NoSuchFieldException, InvalidTypeException;
- public Entry getEntryAt(int index);
- public Object getValueAt(int index);
- public String getNameAt(int index);
- public int indexOf(String key);
- public int lastIndexOf(String key);
- public Entry getLastEntry();
- public Object getLastValue();
- public Entry getFirstEntry();
- public Object getFirstValue();
- public boolean hasGenericData();
- public boolean remove(Entry entry);
- public Entry remove(int index);
- public Collection getEntries();
- public int size();
- public Entry[] getAllEntries();
- public Entry[] getAllPrimitives();
- public int getPrimitiveCount();
- public Entry[] getAllGenericData();
- public int getGenericDataCount();
- public void clear();
- public void dump(OutputStream out);
- public Object clone();
-
- /**
- * Entry is an element that contains a (key, value) pair. This
- * class is exclusively used by GenericMessage.
- */
- public static class Entry implements DataSerializable
- {
- /**
- * The value type is TYPE_OBJECT if it is a non-primitive and non-MapMessage
- * type.
- */
- public final static byte TYPE_GENERIC_DATA = 1;
-
- /**
- * The value type is TYPE_MAPPABLE if it is Mappable type.
- */
- public final static byte TYPE_MAPPABLE = 2;
-
- public final static byte TYPE_BYTE = 3;
- public final static byte TYPE_CHAR = 4;
- public final static byte TYPE_DOUBLE = 5;
- public final static byte TYPE_FLOAT = 6;
- public final static byte TYPE_INTEGER = 7;
- public final static byte TYPE_LONG = 8;
- public final static byte TYPE_SHORT = 9;
- public final static byte TYPE_BOOLEAN = 10;
- public final static byte TYPE_STRING = 11;
-
- private byte type = TYPE_GENERIC_DATA;
- private String key;
- private Object value;
-
- public Entry()
- {
- }
-
- /**
- * Creates a new Entry object.
- * @param key The key identifying the value.
- * @param value The value.
- * @param type The value type.
- */
- public Entry(String key, Object value, byte type)
- {
- this.key = key;
- this.value = value;
- this.type = type;
- }
-
- /**
- * Creates a new Entry object. The value type is set to the default
- * type TYPE_GENERIC_DATA.
- * @param key The key identifying the value.
- * @param value The value.
- */
- public Entry(String key, GenericMap value)
- {
- this(key, value, TYPE_GENERIC_DATA);
- }
-
- /**
- * Returns the key identifying the value.
- */
- public String getKey()
- {
- return key;
- }
-
- /**
- * Returns the value.
- */
- public Object getValue()
- {
- return value;
- }
-
- /**
- * Returns the value type.
- */
- public short getType()
- {
- return type;
- }
-
- public int intValue() throws InvalidTypeException
- {
- if (type == TYPE_INTEGER) {
- return ((Integer)value).intValue();
- } else if (type == TYPE_LONG) {
- return ((Long)value).intValue();
- } else if (type == TYPE_BYTE) {
- return ((Byte)value).intValue();
- } else if (type == TYPE_CHAR) {
- return Character.getNumericValue(((Character)value).charValue());
- } else if (type == TYPE_SHORT) {
- return ((Short)value).intValue();
- } else if (type == TYPE_FLOAT) {
- return ((Float)value).intValue();
- } else if (type == TYPE_DOUBLE) {
- return ((Double)value).intValue();
- } else if (type == TYPE_BOOLEAN) {
- if (((Boolean)value).booleanValue()) {
- return 1;
- } else {
- return 0;
- }
- } else {
- throw new InvalidTypeException(value.getClass() + ": Unable to convert object to int.");
- }
- }
-
- public boolean isPrimitive()
- {
- return type == TYPE_BYTE ||
- type == TYPE_CHAR ||
- type == TYPE_DOUBLE ||
- type == TYPE_FLOAT ||
- type == TYPE_INTEGER ||
- type == TYPE_LONG ||
- type == TYPE_SHORT ||
- type == TYPE_BOOLEAN;
- }
-
- public void fromData(DataInput dataInput) throws IOException, ClassNotFoundException
- {
- type = dataInput.readByte();
- key = DataSerializer.readString(dataInput);
- value = DataSerializer.readObject(dataInput);
- }
-
- public void toData(DataOutput dataOutput) throws IOException
- {
- dataOutput.writeByte(type);
- DataSerializer.writeString(key, dataOutput);
- DataSerializer.writeObject(value, dataOutput);
- }
- }
-}