http://git-wip-us.apache.org/repos/asf/geode/blob/d16d192b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/HandShake.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/HandShake.java b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/HandShake.java index 0b11bf1..388f838 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/HandShake.java +++ b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/HandShake.java @@ -14,7 +14,49 @@ */ package org.apache.geode.internal.cache.tier.sockets; -import static org.apache.geode.distributed.ConfigurationProperties.*; +import static org.apache.geode.distributed.ConfigurationProperties.CONFLATE_EVENTS; +import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_CLIENT_AUTHENTICATOR; +import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_CLIENT_AUTH_INIT; + +import org.apache.commons.lang.StringUtils; +import org.apache.geode.CancelCriterion; +import org.apache.geode.DataSerializer; +import org.apache.geode.GemFireConfigException; +import org.apache.geode.InternalGemFireException; +import org.apache.geode.cache.GatewayConfigurationException; +import org.apache.geode.cache.client.PoolFactory; +import org.apache.geode.cache.client.ServerRefusedConnectionException; +import org.apache.geode.cache.client.internal.Connection; +import org.apache.geode.distributed.DistributedMember; +import org.apache.geode.distributed.DistributedSystem; +import org.apache.geode.distributed.internal.DM; +import org.apache.geode.distributed.internal.DistributionConfig; +import org.apache.geode.distributed.internal.InternalDistributedSystem; +import org.apache.geode.distributed.internal.LonerDistributionManager; +import org.apache.geode.distributed.internal.ServerLocation; +import org.apache.geode.distributed.internal.membership.InternalDistributedMember; +import org.apache.geode.internal.ClassLoadUtil; +import org.apache.geode.internal.HeapDataOutputStream; +import org.apache.geode.internal.InternalDataSerializer; +import org.apache.geode.internal.InternalInstantiator; +import org.apache.geode.internal.Version; +import org.apache.geode.internal.VersionedDataInputStream; +import org.apache.geode.internal.VersionedDataOutputStream; +import org.apache.geode.internal.cache.tier.Acceptor; +import org.apache.geode.internal.cache.tier.ClientHandShake; +import org.apache.geode.internal.cache.tier.ConnectionProxy; +import org.apache.geode.internal.i18n.LocalizedStrings; +import org.apache.geode.internal.logging.InternalLogWriter; +import org.apache.geode.internal.logging.LogService; +import org.apache.geode.internal.security.IntegratedSecurityService; +import org.apache.geode.internal.security.SecurityService; +import org.apache.geode.pdx.internal.PeerTypeRegistration; +import org.apache.geode.security.AuthInitialize; +import org.apache.geode.security.AuthenticationFailedException; +import org.apache.geode.security.AuthenticationRequiredException; +import org.apache.geode.security.Authenticator; +import org.apache.geode.security.GemFireSecurityException; +import org.apache.logging.log4j.Logger; import java.io.ByteArrayInputStream; import java.io.DataInputStream; @@ -49,7 +91,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Properties; - import javax.crypto.Cipher; import javax.crypto.KeyAgreement; import javax.crypto.SecretKey; @@ -58,46 +99,6 @@ import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import javax.net.ssl.SSLSocket; -import org.apache.geode.CancelCriterion; -import org.apache.geode.DataSerializer; -import org.apache.geode.GemFireConfigException; -import org.apache.geode.InternalGemFireException; -import org.apache.geode.cache.GatewayConfigurationException; -import org.apache.geode.cache.client.PoolFactory; -import org.apache.geode.cache.client.ServerRefusedConnectionException; -import org.apache.geode.cache.client.internal.Connection; -import org.apache.geode.distributed.DistributedMember; -import org.apache.geode.distributed.DistributedSystem; -import org.apache.geode.distributed.internal.DM; -import org.apache.geode.distributed.internal.DistributionConfig; -import org.apache.geode.distributed.internal.InternalDistributedSystem; -import org.apache.geode.distributed.internal.LonerDistributionManager; -import org.apache.geode.distributed.internal.ServerLocation; -import org.apache.geode.distributed.internal.membership.InternalDistributedMember; -import org.apache.geode.internal.ClassLoadUtil; -import org.apache.geode.internal.HeapDataOutputStream; -import org.apache.geode.internal.InternalDataSerializer; -import org.apache.geode.internal.InternalInstantiator; -import org.apache.geode.internal.Version; -import org.apache.geode.internal.VersionedDataInputStream; -import org.apache.geode.internal.VersionedDataOutputStream; -import org.apache.geode.internal.cache.tier.Acceptor; -import org.apache.geode.internal.cache.tier.ClientHandShake; -import org.apache.geode.internal.cache.tier.ConnectionProxy; -import org.apache.geode.internal.i18n.LocalizedStrings; -import org.apache.geode.internal.lang.StringUtils; -import org.apache.geode.internal.logging.InternalLogWriter; -import org.apache.geode.internal.logging.LogService; -import org.apache.geode.internal.security.IntegratedSecurityService; -import org.apache.geode.internal.security.SecurityService; -import org.apache.geode.pdx.internal.PeerTypeRegistration; -import org.apache.geode.security.AuthInitialize; -import org.apache.geode.security.AuthenticationFailedException; -import org.apache.geode.security.AuthenticationRequiredException; -import org.apache.geode.security.Authenticator; -import org.apache.geode.security.GemFireSecurityException; -import org.apache.logging.log4j.Logger; - public class HandShake implements ClientHandShake { private static final Logger logger = LogService.getLogger();
http://git-wip-us.apache.org/repos/asf/geode/blob/d16d192b/geode-core/src/main/java/org/apache/geode/internal/lang/StringUtils.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/lang/StringUtils.java b/geode-core/src/main/java/org/apache/geode/internal/lang/StringUtils.java index 499d546..8a44564 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/lang/StringUtils.java +++ b/geode-core/src/main/java/org/apache/geode/internal/lang/StringUtils.java @@ -22,91 +22,30 @@ import org.apache.geode.internal.cache.Token; * The StringUtils is an abstract utility class for working with and invoking operations on String * literals. * <p/> - * + * * @see java.lang.String * @since GemFire 7.0 */ @SuppressWarnings("unused") -public abstract class StringUtils { +@Deprecated +public class StringUtils extends org.apache.commons.lang.StringUtils { public static final String COMMA_DELIMITER = ","; - public static final String EMPTY_STRING = ""; public static final String LINE_SEPARATOR = System.getProperty("line.separator"); public static final String SPACE = " "; - public static final String UTF_8 = "UTF-8"; - - public static final String[] EMPTY_STRING_ARRAY = new String[0]; - public static final String[] SPACES = {"", " ", " ", " ", " ", " ", " ", " ", - " ", " ", " "}; - - /** - * Concatenates all Objects in the array into a single String by calling toString on the Object. - * </p> - * - * @param values the Object elements of the array to be concatenated into the String. - * @return a single String with all the individual Objects in the array concatenated. - * @see #concat(Object[], String) - */ - public static String concat(final Object... values) { - return concat(values, EMPTY_STRING); - } - - /** - * Concatenates all Objects in the array into a single String using the Object's toString method, - * delimited by the specified delimiter. - * </p> - * - * @param values an array of Objects to concatenate into a single String value. - * @param delimiter the String value to use as a separator between the individual Object values. - * If delimiter is null, then a empty String is used. - * @return a single String with all the individual Objects of the array concatenated together, - * separated by the specified delimiter. - * @see java.lang.Object#toString() - * @see java.lang.StringBuilder - */ - public static String concat(final Object[] values, String delimiter) { - delimiter = ObjectUtils.defaultIfNull(delimiter, EMPTY_STRING); - - final StringBuilder buffer = new StringBuilder(); - int count = 0; - - if (values != null) { - for (Object value : values) { - buffer.append(count++ > 0 ? delimiter : EMPTY_STRING); - buffer.append(value); - } - } - - return buffer.toString(); - } + private static final int MAX_ARRAY_ELEMENTS_TO_CONVERT = + Integer.getInteger("StringUtils.MAX_ARRAY_ELEMENTS_TO_CONVERT", 16); - /** - * Returns the first non-null, non-empty and non-blank String value in the array of String values. - * </p> - * - * @param values an array of String values, usually consisting of the preferred value followed by - * default values if any value in the array of String values is null, empty or blank. - * @return the first non-null, non-empty and non-blank String value in the array of Strings. If - * all values are either null, empty or blank then null is returned. - * @see #isBlank(String) - */ - public static String defaultIfBlank(final String... values) { - if (values != null) { - for (final String value : values) { - if (!isBlank(value)) { - return value; - } - } - } - return null; + public static String nullifyIfBlank(final String value) { + return isBlank(value) ? null : value; } /** * Returns only the digits (0..9) from the specified String value. * </p> - * + * * @param value the String value from which to extract digits. * @return only the digits from the specified String value. If the String is null or contains no * digits, then this method returns an empty String. @@ -126,156 +65,7 @@ public abstract class StringUtils { return buffer.toString(); } - /** - * Returns only the letters (a..zA..Z) from the specified String value. - * </p> - * - * @param value the String value from which to extract letters. - * @return only the letters from the specified String value. If the String is null or contains no - * letters, then this method returns an empty String. - * @see java.lang.Character#isLetter(char) - */ - public static String getLettersOnly(final String value) { - final StringBuilder buffer = new StringBuilder(); - - if (value != null) { - for (final char chr : value.toCharArray()) { - if (Character.isLetter(chr)) { - buffer.append(chr); - } - } - } - - return buffer.toString(); - } - - /** - * Gets a number of spaces determined by number. - * </p> - * - * @param number an integer value indicating the number of spaces to return. - * @return a String value containing a number of spaces given by number. - */ - public static String getSpaces(int number) { - final StringBuilder spaces = new StringBuilder(SPACES[Math.min(number, SPACES.length - 1)]); - - do { - number -= (SPACES.length - 1); - number = Math.max(number, 0); - spaces.append(SPACES[Math.min(number, SPACES.length - 1)]); - } while (number > 0); - - return spaces.toString(); - } - - /** - * Determines whether the specified String value is blank, which is true if it is null, an empty - * String or a String containing only spaces (blanks). - * </p> - * - * @param value the String value used in the determination for the "blank" check. - * @return a boolean value indicating whether the specified String is blank. - * @see #isEmpty(String) - */ - public static boolean isBlank(final String value) { - return (value == null || EMPTY_STRING.equals(value.trim())); - } - - /** - * Determines whether the specified String value is empty, which is true if and only if the value - * is the empty String. - * </p> - * - * @param value the String value used in the determination of the "empty" check. - * @return a boolean value indicating if the specified String is empty. - * @see #isBlank(String) - */ - public static boolean isEmpty(final String value) { - return EMPTY_STRING.equals(value); - } - - /** - * Pads the specified String value by appending the specified character up to the given length. - * </p> - * - * @param value the String value to pad by appending 'paddingCharacter' to the end. - * @param paddingCharacter the character used to pad the end of the String value. - * @param length an int value indicating the final length of the String value with padding of the - * 'paddingCharacter'. - * @return the String value padded with the specified character by appending 'paddingCharacter' to - * the end of the String value up to the given length. - * @throws NullPointerException if the String value is null. - */ - public static String padEnding(final String value, final char paddingCharacter, - final int length) { - if (value == null) { - throw new NullPointerException("The String value to pad cannot be null!"); - } - - final StringBuilder buffer = new StringBuilder(value); - - for (int valueLength = value.length(); valueLength < length; valueLength++) { - buffer.append(paddingCharacter); - } - - return buffer.toString(); - } - - /** - * A null-safe implementation of the String.toLowerCase method. - * </p> - * - * @param value a String value to convert to lower case. - * @return a lower case representation of the specified String value. - * @see java.lang.String#toLowerCase() - */ - public static String toLowerCase(final String value) { - return (value == null ? null : value.toLowerCase()); - } - - /** - * A null-safe implementation of the String.toUpperCase method. - * </p> - * - * @param value a String value to convert to upper case. - * @return an upper case representation of the specified String value. - * @see java.lang.String#toUpperCase() - */ - public static String toUpperCase(final String value) { - return (value == null ? null : value.toUpperCase()); - } - /** - * A method to trim the value of a String and guard against null values. - * <p/> - * - * @param value the String value that will be trimmed if not null. - * @return null if the String value is null or the trimmed version of the String value if String - * value is not null. - * @see java.lang.String#trim() - */ - public static String trim(final String value) { - return (value == null ? null : value.trim()); - } - - /** - * Null-safe implementation of String truncate using substring. Truncates the specified String - * value to the specified length. Returns null if the String value is null. - * </p> - * - * @param value the String value to truncate. - * @param length an int value indicating the length to truncate the String value to. - * @return the String value truncated to specified length, or null if the String value is null. - * @throws IllegalArgumentException if the value of length is less than 0. - * @see java.lang.String#substring(int, int) - */ - public static String truncate(final String value, final int length) { - if (length < 0) { - throw new IllegalArgumentException("Length must be greater than equal to 0!"); - } - - return (value == null ? null : value.substring(0, Math.min(value.length(), length))); - } /** * Gets the value of the specified Object as a String. If the Object is null then the first @@ -283,9 +73,9 @@ public abstract class StringUtils { * String values is null or all the elements in the default String values array are null, then the * value of String.valueOf(value) is returned. * </p> - * + * * @param value the Object who's String representation is being evaluated. - * @param defaultValues an array of default String values to assess if the specified Object value + * @param defaultValue an array of default String values to assess if the specified Object value * is null. * @return a String representation of the specified Object value or one of the default String * values from the array if the Object value is null. If either the default String array @@ -293,20 +83,12 @@ public abstract class StringUtils { * returned. * @see java.lang.String#valueOf(Object) */ - public static String valueOf(final Object value, final String... defaultValues) { - if (value != null) { - return value.toString(); - } else { - if (defaultValues != null) { - for (String defaultValue : defaultValues) { - if (defaultValue != null) { - return defaultValue; - } - } - } + public static String defaultString(final Object value, final String defaultValue) { + return value == null ? defaultValue : value.toString(); + } - return String.valueOf(value); - } + public static String defaultString(final Object value) { + return value == null ? EMPTY : value.toString(); } /** @@ -314,7 +96,7 @@ public abstract class StringUtils { * characters in each line, indenting all subsequent lines with the indent. If the indent is null, * then an empty String is used. * </p> - * + * * @param line a String containing the line of text to wrap. * @param widthInCharacters an integer value indicating the width of each line measured by the * number of characters. @@ -324,18 +106,19 @@ public abstract class StringUtils { * boundaries within the given width on any given split. * @throws NullPointerException if the line of text is null. */ + // Can be removed when commons is updated. public static String wrap(String line, final int widthInCharacters, String indent) { final StringBuilder buffer = new StringBuilder(); int lineCount = 1; - int spaceIndex = -1; + int spaceIndex; // if indent is null, then do not indent the wrapped lines - indent = valueOf(indent, EMPTY_STRING); + indent = StringUtils.defaultString(indent); while (line.length() > widthInCharacters) { spaceIndex = line.substring(0, widthInCharacters).lastIndexOf(SPACE); - buffer.append(lineCount++ > 1 ? indent : EMPTY_STRING); + buffer.append(lineCount++ > 1 ? indent : EMPTY); // throws IndexOutOfBoundsException if spaceIndex is -1, implying no word boundary was found // within // the given width; this also avoids the infinite loop @@ -351,13 +134,10 @@ public abstract class StringUtils { return buffer.toString(); } - private static final int MAX_ARRAY_ELEMENTS_TO_CONVERT = - Integer.getInteger("StringUtils.MAX_ARRAY_ELEMENTS_TO_CONVERT", 16); - /** * Used to convert the given object to a String. If anything goes wrong in this conversion put * some info about what went wrong on the result string but do not throw an exception. - * + * * @param o the object to convert to a string * @return the string from of the given object. */ @@ -373,7 +153,7 @@ public abstract class StringUtils { * Convert an object to a string and return it. Handled CacheDeserializables without having them * change the form they store. If deserialization is needed and fails then the string contains a * message saying so instead of throwing an exception. - * + * * @param o the object to convert to a string * @param convertArrayContents if true then the contents of the array will be in the string; * otherwise just the array identity @@ -414,13 +194,15 @@ public abstract class StringUtils { } } - private static String arrayToString(Object[] a, int maxArrayElements) { + + private static <T> String arrayToString(T[] a, int maxArrayElements) { if (maxArrayElements < 0) { maxArrayElements = 0; } if (a == null) { return "null"; } + String className = a.getClass().getSimpleName(); int iMax = a.length; if (iMax > maxArrayElements) { iMax = maxArrayElements; http://git-wip-us.apache.org/repos/asf/geode/blob/d16d192b/geode-core/src/main/java/org/apache/geode/internal/lang/SystemUtils.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/lang/SystemUtils.java b/geode-core/src/main/java/org/apache/geode/internal/lang/SystemUtils.java index 2e47556..4c50851 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/lang/SystemUtils.java +++ b/geode-core/src/main/java/org/apache/geode/internal/lang/SystemUtils.java @@ -80,8 +80,8 @@ public class SystemUtils { actualVersionDigits = StringUtils.getDigitsOnly(System.getProperty("java.version")); } - String expectedVersionDigits = StringUtils.padEnding(StringUtils.getDigitsOnly(expectedVersion), - '0', actualVersionDigits.length()); + String expectedVersionDigits = StringUtils.rightPad(StringUtils.getDigitsOnly(expectedVersion), + actualVersionDigits.length(), '0'); try { return Long.parseLong(actualVersionDigits) >= Long.parseLong(expectedVersionDigits); http://git-wip-us.apache.org/repos/asf/geode/blob/d16d192b/geode-core/src/main/java/org/apache/geode/internal/process/FileProcessController.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/process/FileProcessController.java b/geode-core/src/main/java/org/apache/geode/internal/process/FileProcessController.java index 629740c..c8ec49d 100755 --- a/geode-core/src/main/java/org/apache/geode/internal/process/FileProcessController.java +++ b/geode-core/src/main/java/org/apache/geode/internal/process/FileProcessController.java @@ -14,6 +14,7 @@ */ package org.apache.geode.internal.process; +import org.apache.commons.lang.StringUtils; import org.apache.geode.distributed.internal.DistributionConfig; import org.apache.geode.internal.i18n.LocalizedStrings; import org.apache.geode.internal.logging.LogService; @@ -101,8 +102,7 @@ public class FileProcessController implements ProcessController { LocalizedStrings.Launcher_ATTACH_API_NOT_FOUND_ERROR_MESSAGE.toLocalizedString()); } - private void stop(final File workingDir, final String stopRequestFileName) - throws UnableToControlProcessException, IOException { + private void stop(final File workingDir, final String stopRequestFileName) throws IOException { final File stopRequestFile = new File(workingDir, stopRequestFileName); if (!stopRequestFile.exists()) { stopRequestFile.createNewFile(); @@ -110,11 +110,10 @@ public class FileProcessController implements ProcessController { } private String status(final File workingDir, final String statusRequestFileName, - final String statusFileName) - throws UnableToControlProcessException, IOException, InterruptedException, TimeoutException { + final String statusFileName) throws IOException, InterruptedException, TimeoutException { // monitor for statusFile final File statusFile = new File(workingDir, statusFileName); - final AtomicReference<String> statusRef = new AtomicReference<String>(); + final AtomicReference<String> statusRef = new AtomicReference<>(); final ControlRequestHandler statusHandler = new ControlRequestHandler() { @Override @@ -162,7 +161,7 @@ public class FileProcessController implements ProcessController { } final String lines = statusRef.get(); - if (null == lines || lines.trim().isEmpty()) { + if (StringUtils.isBlank(lines)) { throw new IllegalStateException("Failed to read status file"); } return lines; http://git-wip-us.apache.org/repos/asf/geode/blob/d16d192b/geode-core/src/main/java/org/apache/geode/internal/process/signal/Signal.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/process/signal/Signal.java b/geode-core/src/main/java/org/apache/geode/internal/process/signal/Signal.java index faab4ed..78b19db 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/process/signal/Signal.java +++ b/geode-core/src/main/java/org/apache/geode/internal/process/signal/Signal.java @@ -15,7 +15,7 @@ package org.apache.geode.internal.process.signal; -import org.apache.geode.internal.lang.StringUtils; +import org.apache.commons.lang.StringUtils; /** * Signals defined in the enumerated type were based on Open BSD and the IBM JVM... @@ -78,7 +78,7 @@ public enum Signal { private final String name; Signal(final int number, final String name, final SignalType type, final String description) { - assertValidArgument(!StringUtils.isBlank(name), "The name of the signal must be specified!"); + assertValidArgument(StringUtils.isNotBlank(name), "The name of the signal must be specified!"); this.number = number; this.name = name; this.type = type; http://git-wip-us.apache.org/repos/asf/geode/blob/d16d192b/geode-core/src/main/java/org/apache/geode/internal/security/IntegratedSecurityService.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/security/IntegratedSecurityService.java b/geode-core/src/main/java/org/apache/geode/internal/security/IntegratedSecurityService.java index 8366930..600d546 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/security/IntegratedSecurityService.java +++ b/geode-core/src/main/java/org/apache/geode/internal/security/IntegratedSecurityService.java @@ -293,7 +293,7 @@ public class IntegratedSecurityService implements SecurityService { String clientAuthenticatorConfig = securityProps.getProperty(SECURITY_CLIENT_AUTHENTICATOR); String peerAuthenticatorConfig = securityProps.getProperty(SECURITY_PEER_AUTHENTICATOR); - if (!StringUtils.isBlank(shiroConfig)) { + if (StringUtils.isNotBlank(shiroConfig)) { IniSecurityManagerFactory factory = new IniSecurityManagerFactory("classpath:" + shiroConfig); // we will need to make sure that shiro uses a case sensitive permission resolver @@ -311,20 +311,20 @@ public class IntegratedSecurityService implements SecurityService { isPeerAuthenticator = false; } // only set up shiro realm if user has implemented SecurityManager - else if (!StringUtils.isBlank(securityManagerConfig)) { + else if (StringUtils.isNotBlank(securityManagerConfig)) { SecurityManager securityManager = SecurityService .getObjectOfTypeFromClassName(securityManagerConfig, SecurityManager.class); securityManager.init(securityProps); this.setSecurityManager(securityManager); } else { isIntegratedSecurity = null; - isClientAuthenticator = !StringUtils.isBlank(clientAuthenticatorConfig); - isPeerAuthenticator = !StringUtils.isBlank(peerAuthenticatorConfig); + isClientAuthenticator = StringUtils.isNotBlank(clientAuthenticatorConfig); + isPeerAuthenticator = StringUtils.isNotBlank(peerAuthenticatorConfig); } // this initializes the post processor String customPostProcessor = securityProps.getProperty(SECURITY_POST_PROCESSOR); - if (!StringUtils.isBlank(customPostProcessor)) { + if (StringUtils.isNotBlank(customPostProcessor)) { postProcessor = SecurityService.getObjectOfTypeFromClassName(customPostProcessor, PostProcessor.class); postProcessor.init(securityProps); http://git-wip-us.apache.org/repos/asf/geode/blob/d16d192b/geode-core/src/main/java/org/apache/geode/internal/util/ArrayUtils.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/util/ArrayUtils.java b/geode-core/src/main/java/org/apache/geode/internal/util/ArrayUtils.java index 6f1c7cc..6f1292a 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/util/ArrayUtils.java +++ b/geode-core/src/main/java/org/apache/geode/internal/util/ArrayUtils.java @@ -15,15 +15,12 @@ package org.apache.geode.internal.util; +import org.apache.commons.lang.StringUtils; +import org.apache.geode.internal.offheap.annotations.Unretained; + import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.List; -import java.util.Objects; -import java.util.RandomAccess; - -import org.apache.geode.internal.lang.StringUtils; -import org.apache.geode.internal.offheap.annotations.Unretained; /** * @@ -82,7 +79,7 @@ public abstract class ArrayUtils { if (array != null) { for (final Object element : array) { - buffer.append(count++ > 0 ? ", " : StringUtils.EMPTY_STRING).append(element); + buffer.append(count++ > 0 ? ", " : StringUtils.EMPTY).append(element); } } http://git-wip-us.apache.org/repos/asf/geode/blob/d16d192b/geode-core/src/main/java/org/apache/geode/internal/util/IOUtils.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/util/IOUtils.java b/geode-core/src/main/java/org/apache/geode/internal/util/IOUtils.java index c1a1952..031f827 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/util/IOUtils.java +++ b/geode-core/src/main/java/org/apache/geode/internal/util/IOUtils.java @@ -14,8 +14,8 @@ */ package org.apache.geode.internal.util; +import org.apache.commons.lang.StringUtils; import org.apache.geode.internal.lang.ObjectUtils; -import org.apache.geode.internal.lang.StringUtils; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -186,7 +186,7 @@ public abstract class IOUtils { public static String getFilename(final String pathname) { String filename = pathname; - if (!StringUtils.isBlank(filename)) { + if (StringUtils.isNotBlank(filename)) { final int index = filename.lastIndexOf(File.separator); filename = (index == -1 ? filename : filename.substring(index + 1)); } @@ -205,7 +205,7 @@ public abstract class IOUtils { * @see java.io.File#exists() */ public static boolean isExistingPathname(final String pathname) { - return (!StringUtils.isBlank(pathname) && new File(pathname).exists()); + return (StringUtils.isNotBlank(pathname) && new File(pathname).exists()); } /** http://git-wip-us.apache.org/repos/asf/geode/blob/d16d192b/geode-core/src/main/java/org/apache/geode/management/internal/AgentUtil.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/AgentUtil.java b/geode-core/src/main/java/org/apache/geode/management/internal/AgentUtil.java index ba15508..3bd442a 100755 --- a/geode-core/src/main/java/org/apache/geode/management/internal/AgentUtil.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/AgentUtil.java @@ -15,8 +15,8 @@ package org.apache.geode.management.internal; +import org.apache.commons.lang.StringUtils; import org.apache.geode.distributed.internal.DistributionConfig; -import org.apache.geode.internal.lang.StringUtils; import org.apache.geode.internal.logging.LogService; import org.apache.logging.log4j.Logger; @@ -53,7 +53,7 @@ public class AgentUtil { */ public String findWarLocation(String warFilePrefix) { String geodeHome = getGeodeHome(); - if (!StringUtils.isBlank(geodeHome)) { + if (StringUtils.isNotBlank(geodeHome)) { String[] possibleFiles = {geodeHome + "/tools/Extensions/" + warFilePrefix + "-" + gemfireVersion + ".war", geodeHome + "/tools/Pulse/" + warFilePrefix + "-" + gemfireVersion + ".war", @@ -91,7 +91,7 @@ public class AgentUtil { } public boolean isWebApplicationAvailable(final String warFileLocation) { - return !StringUtils.isBlank(warFileLocation); + return StringUtils.isNotBlank(warFileLocation); } public boolean isWebApplicationAvailable(final String... warFileLocations) { @@ -124,6 +124,6 @@ public class AgentUtil { public boolean isGemfireHomeDefined() { String gemfireHome = getGeodeHome(); - return !StringUtils.isBlank(gemfireHome); + return StringUtils.isNotBlank(gemfireHome); } } http://git-wip-us.apache.org/repos/asf/geode/blob/d16d192b/geode-core/src/main/java/org/apache/geode/management/internal/JettyHelper.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/JettyHelper.java b/geode-core/src/main/java/org/apache/geode/management/internal/JettyHelper.java index 7c26297..92987cb 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/JettyHelper.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/JettyHelper.java @@ -14,9 +14,10 @@ */ package org.apache.geode.management.internal; -import java.io.File; -import java.util.concurrent.CountDownLatch; - +import org.apache.commons.lang.StringUtils; +import org.apache.geode.GemFireConfigException; +import org.apache.geode.internal.admin.SSLConfig; +import org.apache.geode.internal.logging.LogService; import org.apache.logging.log4j.Logger; import org.eclipse.jetty.http.HttpVersion; import org.eclipse.jetty.server.Connector; @@ -30,10 +31,8 @@ import org.eclipse.jetty.server.handler.HandlerCollection; import org.eclipse.jetty.util.ssl.SslContextFactory; import org.eclipse.jetty.webapp.WebAppContext; -import org.apache.geode.GemFireConfigException; -import org.apache.geode.internal.admin.SSLConfig; -import org.apache.geode.internal.lang.StringUtils; -import org.apache.geode.internal.logging.LogService; +import java.io.File; +import java.util.concurrent.CountDownLatch; /** * @since GemFire 8.1 @@ -70,13 +69,13 @@ public class JettyHelper { if (sslConfig.isEnabled()) { SslContextFactory sslContextFactory = new SslContextFactory(); - if (!StringUtils.isBlank(sslConfig.getAlias())) { + if (StringUtils.isNotBlank(sslConfig.getAlias())) { sslContextFactory.setCertAlias(sslConfig.getAlias()); } sslContextFactory.setNeedClientAuth(sslConfig.isRequireAuth()); - if (!StringUtils.isBlank(sslConfig.getCiphers()) + if (StringUtils.isNotBlank(sslConfig.getCiphers()) && !"any".equalsIgnoreCase(sslConfig.getCiphers())) { // If use has mentioned "any" let the SSL layer decide on the ciphers sslContextFactory.setIncludeCipherSuites(SSLUtil.readArray(sslConfig.getCiphers())); @@ -97,19 +96,19 @@ public class JettyHelper { sslContextFactory.setKeyStorePath(sslConfig.getKeystore()); - if (!StringUtils.isBlank(sslConfig.getKeystoreType())) { + if (StringUtils.isNotBlank(sslConfig.getKeystoreType())) { sslContextFactory.setKeyStoreType(sslConfig.getKeystoreType()); } - if (!StringUtils.isBlank(sslConfig.getKeystorePassword())) { + if (StringUtils.isNotBlank(sslConfig.getKeystorePassword())) { sslContextFactory.setKeyStorePassword(sslConfig.getKeystorePassword()); } - if (!StringUtils.isBlank(sslConfig.getTruststore())) { + if (StringUtils.isNotBlank(sslConfig.getTruststore())) { sslContextFactory.setTrustStorePath(sslConfig.getTruststore()); } - if (!StringUtils.isBlank(sslConfig.getTruststorePassword())) { + if (StringUtils.isNotBlank(sslConfig.getTruststorePassword())) { sslContextFactory.setTrustStorePassword(sslConfig.getTruststorePassword()); } @@ -131,7 +130,7 @@ public class JettyHelper { jettyServer.setConnectors(new Connector[] {connector}); - if (!StringUtils.isBlank(bindAddress)) { + if (StringUtils.isNotBlank(bindAddress)) { connector.setHost(bindAddress); } http://git-wip-us.apache.org/repos/asf/geode/blob/d16d192b/geode-core/src/main/java/org/apache/geode/management/internal/ManagementAgent.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/ManagementAgent.java b/geode-core/src/main/java/org/apache/geode/management/internal/ManagementAgent.java index bf0b99c..3e6e4484 100755 --- a/geode-core/src/main/java/org/apache/geode/management/internal/ManagementAgent.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/ManagementAgent.java @@ -14,6 +14,32 @@ */ package org.apache.geode.management.internal; +import org.apache.commons.lang.StringUtils; +import org.apache.geode.GemFireConfigException; +import org.apache.geode.cache.CacheFactory; +import org.apache.geode.distributed.internal.DistributionConfig; +import org.apache.geode.distributed.internal.DistributionManager; +import org.apache.geode.internal.GemFireVersion; +import org.apache.geode.internal.cache.InternalCache; +import org.apache.geode.internal.logging.LogService; +import org.apache.geode.internal.net.SSLConfigurationFactory; +import org.apache.geode.internal.net.SocketCreator; +import org.apache.geode.internal.net.SocketCreatorFactory; +import org.apache.geode.internal.security.SecurableCommunicationChannel; +import org.apache.geode.internal.security.SecurityService; +import org.apache.geode.internal.security.shiro.JMXShiroAuthenticator; +import org.apache.geode.internal.tcp.TCPConduit; +import org.apache.geode.management.ManagementException; +import org.apache.geode.management.ManagementService; +import org.apache.geode.management.ManagerMXBean; +import org.apache.geode.management.internal.security.AccessControlMBean; +import org.apache.geode.management.internal.security.MBeanServerWrapper; +import org.apache.geode.management.internal.security.ResourceConstants; +import org.apache.geode.management.internal.unsafe.ReadOpFileAccessController; +import org.apache.logging.log4j.Logger; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; + import java.io.IOException; import java.io.Serializable; import java.lang.management.ManagementFactory; @@ -29,7 +55,6 @@ import java.rmi.server.RMIServerSocketFactory; import java.rmi.server.UnicastRemoteObject; import java.util.HashMap; import java.util.Set; - import javax.management.InstanceAlreadyExistsException; import javax.management.MBeanRegistrationException; import javax.management.MBeanServer; @@ -43,33 +68,6 @@ import javax.management.remote.rmi.RMIJRMPServerImpl; import javax.management.remote.rmi.RMIServerImpl; import javax.rmi.ssl.SslRMIClientSocketFactory; -import org.apache.logging.log4j.Logger; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.ServerConnector; - -import org.apache.geode.GemFireConfigException; -import org.apache.geode.cache.CacheFactory; -import org.apache.geode.distributed.internal.DistributionConfig; -import org.apache.geode.distributed.internal.DistributionManager; -import org.apache.geode.internal.GemFireVersion; -import org.apache.geode.internal.cache.InternalCache; -import org.apache.geode.internal.lang.StringUtils; -import org.apache.geode.internal.logging.LogService; -import org.apache.geode.internal.net.SSLConfigurationFactory; -import org.apache.geode.internal.net.SocketCreator; -import org.apache.geode.internal.net.SocketCreatorFactory; -import org.apache.geode.internal.security.SecurableCommunicationChannel; -import org.apache.geode.internal.security.SecurityService; -import org.apache.geode.internal.security.shiro.JMXShiroAuthenticator; -import org.apache.geode.internal.tcp.TCPConduit; -import org.apache.geode.management.ManagementException; -import org.apache.geode.management.ManagementService; -import org.apache.geode.management.ManagerMXBean; -import org.apache.geode.management.internal.security.AccessControlMBean; -import org.apache.geode.management.internal.security.MBeanServerWrapper; -import org.apache.geode.management.internal.security.ResourceConstants; -import org.apache.geode.management.internal.unsafe.ReadOpFileAccessController; - /** * Agent implementation that controls the JMX server end points for JMX clients to connect, such as * an RMI server. @@ -317,9 +315,9 @@ public class ManagementAgent { } private String getHost(final String bindAddress) throws UnknownHostException { - if (!StringUtils.isBlank(this.config.getJmxManagerHostnameForClients())) { + if (StringUtils.isNotBlank(this.config.getJmxManagerHostnameForClients())) { return this.config.getJmxManagerHostnameForClients(); - } else if (!StringUtils.isBlank(bindAddress)) { + } else if (StringUtils.isNotBlank(bindAddress)) { return InetAddress.getByName(bindAddress).getHostAddress(); } else { return SocketCreator.getLocalHost().getHostAddress(); @@ -376,7 +374,7 @@ public class ManagementAgent { } String jmxManagerHostnameForClients = this.config.getJmxManagerHostnameForClients(); - if (!StringUtils.isBlank(jmxManagerHostnameForClients)) { + if (StringUtils.isNotBlank(jmxManagerHostnameForClients)) { System.setProperty("java.rmi.server.hostname", jmxManagerHostnameForClients); } http://git-wip-us.apache.org/repos/asf/geode/blob/d16d192b/geode-core/src/main/java/org/apache/geode/management/internal/RestAgent.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/RestAgent.java b/geode-core/src/main/java/org/apache/geode/management/internal/RestAgent.java index 837e815..7c9256d 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/RestAgent.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/RestAgent.java @@ -14,13 +14,7 @@ */ package org.apache.geode.management.internal; -import java.net.UnknownHostException; - import org.apache.commons.lang.StringUtils; -import org.apache.logging.log4j.Logger; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.ServerConnector; - import org.apache.geode.cache.AttributesFactory; import org.apache.geode.cache.CacheFactory; import org.apache.geode.cache.DataPolicy; @@ -29,12 +23,17 @@ import org.apache.geode.cache.Scope; import org.apache.geode.distributed.internal.DistributionConfig; import org.apache.geode.internal.GemFireVersion; import org.apache.geode.internal.cache.InternalCache; -import org.apache.geode.internal.net.SSLConfigurationFactory; -import org.apache.geode.internal.net.SocketCreator; import org.apache.geode.internal.cache.InternalRegionArguments; import org.apache.geode.internal.logging.LogService; +import org.apache.geode.internal.net.SSLConfigurationFactory; +import org.apache.geode.internal.net.SocketCreator; import org.apache.geode.internal.security.SecurableCommunicationChannel; import org.apache.geode.management.ManagementService; +import org.apache.logging.log4j.Logger; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; + +import java.net.UnknownHostException; /** * Agent implementation that controls the HTTP server end points used for REST clients to connect @@ -156,15 +155,15 @@ public class RestAgent { public static String getBindAddressForHttpService(DistributionConfig config) { String bindAddress = config.getHttpServiceBindAddress(); - if (!StringUtils.isBlank(bindAddress)) + if (StringUtils.isNotBlank(bindAddress)) return bindAddress; bindAddress = config.getServerBindAddress(); - if (!StringUtils.isBlank(bindAddress)) + if (StringUtils.isNotBlank(bindAddress)) return bindAddress; bindAddress = config.getBindAddress(); - if (!StringUtils.isBlank(bindAddress)) + if (StringUtils.isNotBlank(bindAddress)) return bindAddress; try { http://git-wip-us.apache.org/repos/asf/geode/blob/d16d192b/geode-core/src/main/java/org/apache/geode/management/internal/SSLUtil.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/SSLUtil.java b/geode-core/src/main/java/org/apache/geode/management/internal/SSLUtil.java index 1b39b73..820e8a5 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/SSLUtil.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/SSLUtil.java @@ -14,15 +14,14 @@ */ package org.apache.geode.management.internal; +import org.apache.commons.lang.StringUtils; + import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; - import javax.net.ssl.SSLContext; -import org.apache.geode.internal.lang.StringUtils; - /** * * @since GemFire 8.1 http://git-wip-us.apache.org/repos/asf/geode/blob/d16d192b/geode-core/src/main/java/org/apache/geode/management/internal/beans/DistributedSystemBridge.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/beans/DistributedSystemBridge.java b/geode-core/src/main/java/org/apache/geode/management/internal/beans/DistributedSystemBridge.java index ef643ac..770695a 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/beans/DistributedSystemBridge.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/beans/DistributedSystemBridge.java @@ -14,34 +14,7 @@ */ package org.apache.geode.management.internal.beans; -import java.io.File; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; - -import javax.management.InstanceNotFoundException; -import javax.management.ListenerNotFoundException; -import javax.management.MBeanServer; -import javax.management.Notification; -import javax.management.NotificationBroadcasterSupport; -import javax.management.NotificationListener; -import javax.management.ObjectName; - -import org.apache.logging.log4j.Logger; - +import org.apache.commons.lang.StringUtils; import org.apache.geode.admin.internal.BackupDataStoreHelper; import org.apache.geode.admin.internal.BackupDataStoreResult; import org.apache.geode.cache.persistence.PersistentID; @@ -89,6 +62,32 @@ import org.apache.geode.management.internal.beans.stats.GatewaySenderClusterStat import org.apache.geode.management.internal.beans.stats.MemberClusterStatsMonitor; import org.apache.geode.management.internal.beans.stats.ServerClusterStatsMonitor; import org.apache.geode.management.internal.cli.json.TypedJson; +import org.apache.logging.log4j.Logger; + +import java.io.File; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import javax.management.InstanceNotFoundException; +import javax.management.ListenerNotFoundException; +import javax.management.MBeanServer; +import javax.management.Notification; +import javax.management.NotificationBroadcasterSupport; +import javax.management.NotificationListener; +import javax.management.ObjectName; /** * This is the gateway to distributed system as a whole. Aggregated metrics and stats are shown @@ -134,12 +133,12 @@ public class DistributedSystemBridge { private volatile int serverSetSize; /** - * Gatway Sender Proxy set size + * Gateway Sender Proxy set size */ private volatile int gatewaySenderSetSize; /** - * Gatway Receiver Proxy set size + * Gateway Receiver Proxy set size */ private volatile int gatewayReceiverSetSize; @@ -238,12 +237,12 @@ public class DistributedSystemBridge { * @param service Management service */ public DistributedSystemBridge(SystemManagementService service) { - this.distrLockServiceMap = new ConcurrentHashMap<ObjectName, DistributedLockServiceBridge>(); - this.distrRegionMap = new ConcurrentHashMap<ObjectName, DistributedRegionBridge>(); - this.mapOfMembers = new ConcurrentHashMap<ObjectName, MemberMXBean>(); - this.mapOfServers = new ConcurrentHashMap<ObjectName, CacheServerMXBean>(); - this.mapOfGatewayReceivers = new ConcurrentHashMap<ObjectName, GatewayReceiverMXBean>(); - this.mapOfGatewaySenders = new ConcurrentHashMap<ObjectName, GatewaySenderMXBean>(); + this.distrLockServiceMap = new ConcurrentHashMap<>(); + this.distrRegionMap = new ConcurrentHashMap<>(); + this.mapOfMembers = new ConcurrentHashMap<>(); + this.mapOfServers = new ConcurrentHashMap<>(); + this.mapOfGatewayReceivers = new ConcurrentHashMap<>(); + this.mapOfGatewaySenders = new ConcurrentHashMap<>(); this.service = service; this.cache = GemFireCacheImpl.getInstance(); this.system = cache.getInternalDistributedSystem(); @@ -506,7 +505,7 @@ public class DistributedSystemBridge { Iterator<DistributedMember> it = result.getSuccessfulMembers().keySet().iterator(); - Map<String, String[]> backedUpDiskStores = new HashMap<String, String[]>(); + Map<String, String[]> backedUpDiskStores = new HashMap<>(); while (it.hasNext()) { DistributedMember member = it.next(); Set<PersistentID> setOfDisk = result.getSuccessfulMembers().get(member); @@ -573,7 +572,7 @@ public class DistributedSystemBridge { Iterator<GatewayReceiverMXBean> gatewayReceiverIterator = mapOfGatewayReceivers.values().iterator(); if (gatewayReceiverIterator != null) { - List<String> listOfReceivers = new ArrayList<String>(); + List<String> listOfReceivers = new ArrayList<>(); while (gatewayReceiverIterator.hasNext()) { listOfReceivers.add(gatewayReceiverIterator.next().getBindAddress()); } @@ -606,7 +605,7 @@ public class DistributedSystemBridge { Iterator<MemberMXBean> memberIterator = mapOfMembers.values().iterator(); if (memberIterator != null) { - List<String> listOfServer = new ArrayList<String>(); + List<String> listOfServer = new ArrayList<>(); while (memberIterator.hasNext()) { MemberMXBean bean = memberIterator.next(); if (bean.isCacheServer()) { @@ -626,7 +625,7 @@ public class DistributedSystemBridge { Iterator<MemberMXBean> memberIterator = mapOfMembers.values().iterator(); if (memberIterator != null) { - List<String> listOfServer = new ArrayList<String>(); + List<String> listOfServer = new ArrayList<>(); while (memberIterator.hasNext()) { MemberMXBean bean = memberIterator.next(); if (bean.isServer()) { @@ -657,10 +656,10 @@ public class DistributedSystemBridge { /** * @return a list of Gateway Senders */ - public String[] listGatwaySenders() { + public String[] listGatewaySenders() { Iterator<GatewaySenderMXBean> gatewaySenderIterator = mapOfGatewaySenders.values().iterator(); if (gatewaySenderIterator != null) { - List<String> listOfSenders = new ArrayList<String>(); + List<String> listOfSenders = new ArrayList<>(); while (gatewaySenderIterator.hasNext()) { listOfSenders.add(gatewaySenderIterator.next().getSenderId()); } @@ -709,18 +708,15 @@ public class DistributedSystemBridge { public String[] listLocators() { if (cache != null) { // each locator is a string of the form host[port] or bind-addr[port] - Set<String> set = new HashSet<String>(); + Set<String> set = new HashSet<>(); Map<InternalDistributedMember, Collection<String>> map = cache.getDistributionManager().getAllHostedLocators(); for (Collection<String> hostedLocators : map.values()) { - for (String locator : hostedLocators) { - set.add(locator); - } + set.addAll(hostedLocators); } - String[] locators = set.toArray(new String[set.size()]); - return locators; + return set.toArray(new String[set.size()]); } return ManagementConstants.NO_DATA_STRING; } @@ -755,7 +751,7 @@ public class DistributedSystemBridge { Iterator<MemberMXBean> memberIterator = mapOfMembers.values().iterator(); if (memberIterator != null) { - Map<String, String[]> mapOfDisks = new HashMap<String, String[]>(); + Map<String, String[]> mapOfDisks = new HashMap<>(); while (memberIterator.hasNext()) { MemberMXBean bean = memberIterator.next(); mapOfDisks.put(bean.getMember(), bean.getDiskStores()); @@ -803,7 +799,7 @@ public class DistributedSystemBridge { Iterator<MemberMXBean> memberIterator = mapOfMembers.values().iterator(); if (memberIterator != null) { - Set<String> locatorMemberSet = new TreeSet<String>(); + Set<String> locatorMemberSet = new TreeSet<>(); while (memberIterator.hasNext()) { MemberMXBean memberMxBean = memberIterator.next(); if (memberMxBean.isLocator()) { @@ -822,17 +818,17 @@ public class DistributedSystemBridge { private String[] listStandAloneLocatorMembers() { String[] locatorMembers = ManagementConstants.NO_DATA_STRING; - Set<DistributedMember> members = new HashSet<DistributedMember>(); + Set<DistributedMember> members = new HashSet<>(); members.add(system.getDistributedMember()); members.addAll(system.getAllOtherMembers()); if (!members.isEmpty()) { - Set<String> locatorMemberSet = new TreeSet<String>(); + Set<String> locatorMemberSet = new TreeSet<>(); for (DistributedMember member : members) { if (DistributionManager.LOCATOR_DM_TYPE == ((InternalDistributedMember) member) .getVmKind()) { String name = member.getName(); - name = name != null && !name.trim().isEmpty() ? name : member.getId(); + name = StringUtils.isNotBlank(name) ? name : member.getId(); locatorMemberSet.add(name); } } @@ -852,7 +848,7 @@ public class DistributedSystemBridge { Collection<MemberMXBean> values = mapOfMembers.values(); if (values != null) { - Set<String> groupSet = new TreeSet<String>(); + Set<String> groupSet = new TreeSet<>(); for (MemberMXBean memberMXBean : values) { String[] memberGroups = memberMXBean.getGroups(); if (memberGroups != null && memberGroups.length != 0) { @@ -878,7 +874,7 @@ public class DistributedSystemBridge { /** * @param member name or id of the member - * @return basic Opertaing metrics for a given member. + * @return basic Operating metrics for a given member. */ public OSMetrics showOSMetrics(String member) throws Exception { MemberMXBean bean = validateMember(member); @@ -911,7 +907,7 @@ public class DistributedSystemBridge { return ManagementConstants.NO_DATA_STRING; } // Sort region paths - SortedSet<String> regionPathsSet = new TreeSet<String>(); + SortedSet<String> regionPathsSet = new TreeSet<>(); for (DistributedRegionBridge bridge : distrRegionMap.values()) { regionPathsSet.add(bridge.getFullPath()); } @@ -933,9 +929,8 @@ public class DistributedSystemBridge { Set<InternalDistributedMember> members = ShutdownAllRequest.send(dm, 0); String[] shutDownMembers = new String[members.size()]; int j = 0; - Iterator<InternalDistributedMember> it = members.iterator(); - while (it.hasNext()) { - shutDownMembers[j] = it.next().getId(); + for (InternalDistributedMember member : members) { + shutDownMembers[j] = member.getId(); j++; } return shutDownMembers; @@ -949,16 +944,16 @@ public class DistributedSystemBridge { * replicated region member are up and running so that the recovered data from the disk will be in * sync; * - * @return Array of PeristentMemberDetails (which contains host, directory and disk store id) + * @return Array of PersistentMemberDetails (which contains host, directory and disk store id) */ public PersistentMemberDetails[] listMissingDiskStores() { PersistentMemberDetails[] missingDiskStores = null; - Set<PersistentID> persitentMemberSet = MissingPersistentIDsRequest.send(dm); - if (persitentMemberSet != null && persitentMemberSet.size() > 0) { - missingDiskStores = new PersistentMemberDetails[persitentMemberSet.size()]; + Set<PersistentID> persistentMemberSet = MissingPersistentIDsRequest.send(dm); + if (persistentMemberSet != null && persistentMemberSet.size() > 0) { + missingDiskStores = new PersistentMemberDetails[persistentMemberSet.size()]; int j = 0; - for (PersistentID id : persitentMemberSet) { + for (PersistentID id : persistentMemberSet) { missingDiskStores[j] = new PersistentMemberDetails(id.getHost().getCanonicalHostName(), id.getDirectory(), id.getUUID().toString()); j++; @@ -974,7 +969,7 @@ public class DistributedSystemBridge { * @param diskStoreId UUID of the disk store to revoke * @return successful or failure */ - public boolean revokeMissingDiskStores(final String diskStoreId) throws Exception { + public boolean revokeMissingDiskStores(final String diskStoreId) { // make sure that the disk store we're revoking is actually missing boolean found = false; PersistentMemberDetails[] details = listMissingDiskStores(); @@ -1018,8 +1013,7 @@ public class DistributedSystemBridge { public ObjectName fetchMemberObjectName(String member) throws Exception { validateMember(member); - ObjectName memberName = MBeanJMXAdapter.getMemberMBeanName(member); - return memberName; + return MBeanJMXAdapter.getMemberMBeanName(member); } public ObjectName[] listMemberObjectNames() { @@ -1062,7 +1056,7 @@ public class DistributedSystemBridge { } public ObjectName[] fetchRegionObjectNames(ObjectName memberMBeanName) throws Exception { - List<ObjectName> list = new ArrayList<ObjectName>(); + List<ObjectName> list = new ArrayList<>(); if (mapOfMembers.get(memberMBeanName) != null) { MemberMXBean bean = mapOfMembers.get(memberMBeanName); String member = @@ -1080,11 +1074,8 @@ public class DistributedSystemBridge { } public ObjectName[] listDistributedRegionObjectNames() { - List<ObjectName> list = new ArrayList<ObjectName>(); - Iterator<ObjectName> it = distrRegionMap.keySet().iterator(); - while (it.hasNext()) { - list.add(it.next()); - } + List<ObjectName> list = new ArrayList<>(); + list.addAll(distrRegionMap.keySet()); ObjectName[] objNames = new ObjectName[list.size()]; return list.toArray(objNames); } @@ -1127,8 +1118,7 @@ public class DistributedSystemBridge { public ObjectName fetchDistributedLockServiceObjectName(String lockServiceName) throws Exception { DistributedLockServiceMXBean bean = service.getDistributedLockServiceMXBean(lockServiceName); if (bean != null) { - ObjectName lockSerName = service.getDistributedLockServiceMBeanName(lockServiceName); - return lockSerName; + return service.getDistributedLockServiceMBeanName(lockServiceName); } else { throw new Exception( ManagementStrings.DISTRIBUTED_LOCK_SERVICE_MBEAN_NOT_FOUND_IN_SYSTEM.toString()); @@ -1217,7 +1207,7 @@ public class DistributedSystemBridge { Set<ObjectName> mbeanSet = service.queryMBeanNames(distributedMember); if (mbeanSet != null && mbeanSet.size() > 0) { - listName = new ArrayList<ObjectName>(); + listName = new ArrayList<>(); for (ObjectName name : mbeanSet) { if (pattern.apply(name)) { listName.add(name); @@ -1226,8 +1216,8 @@ public class DistributedSystemBridge { } if (listName != null && listName.size() > 0) { - ObjectName[] arry = new ObjectName[listName.size()]; - return listName.toArray(arry); + ObjectName[] array = new ObjectName[listName.size()]; + return listName.toArray(array); } return ManagementConstants.NO_DATA_OBJECTNAME; } @@ -1240,21 +1230,18 @@ public class DistributedSystemBridge { */ public int getNumClients() { if (mapOfServers.keySet().size() > 0) { - Set<String> uniqueClientSet = new HashSet<String>(); - Iterator<CacheServerMXBean> it = mapOfServers.values().iterator(); - while (it.hasNext()) { - String[] clients = null; + Set<String> uniqueClientSet = new HashSet<>(); + for (CacheServerMXBean cacheServerMXBean : mapOfServers.values()) { + String[] clients; try { - clients = it.next().getClientIds(); + clients = cacheServerMXBean.getClientIds(); } catch (Exception e) { // Mostly due to condition where member is departed and proxy is still // with Manager. clients = null; } if (clients != null) { - for (String client : clients) { - uniqueClientSet.add(client); - } + Collections.addAll(uniqueClientSet, clients); } } return uniqueClientSet.size(); @@ -1477,10 +1464,8 @@ public class DistributedSystemBridge { public Map<String, Boolean> viewRemoteClusterStatus() { if (mapOfGatewaySenders.values().size() > 0) { - Map<String, Boolean> senderMap = new HashMap<String, Boolean>(); - Iterator<GatewaySenderMXBean> it = mapOfGatewaySenders.values().iterator(); - while (it.hasNext()) { - GatewaySenderMXBean bean = it.next(); + Map<String, Boolean> senderMap = new HashMap<>(); + for (GatewaySenderMXBean bean : mapOfGatewaySenders.values()) { Integer dsId = bean.getRemoteDSId(); if (dsId != null) { senderMap.merge(dsId.toString(), bean.isRunning(), Boolean::logicalAnd); @@ -1548,10 +1533,10 @@ public class DistributedSystemBridge { synchronized (distrRegionMap) { DistributedRegionBridge bridge = distrRegionMap.get(distributedRegionObjectName); if (bridge != null) { - FederationComponent newObj = (FederationComponent) (fedComp); + FederationComponent newObj = fedComp; bridge.addProxyToMap(proxyName, regionProxy, newObj); } else { - FederationComponent newObj = (FederationComponent) (fedComp); + FederationComponent newObj = fedComp; bridge = new DistributedRegionBridge(proxyName, regionProxy, newObj); DistributedRegionMXBean mbean = new DistributedRegionMBean(bridge); @@ -1591,10 +1576,10 @@ public class DistributedSystemBridge { DistributedRegionBridge bridge = distrRegionMap.get(distributedRegionObjectName); if (bridge != null) { - FederationComponent newProxy = (FederationComponent) (newValue); + FederationComponent newProxy = newValue; FederationComponent oldProxy = null; if (oldValue != null) { - oldProxy = (FederationComponent) oldValue; + oldProxy = oldValue; } bridge.updateRegion(newProxy, oldProxy); } @@ -1651,7 +1636,7 @@ public class DistributedSystemBridge { FederationComponent newValue) { // No body is calling this method right now. // If aggregate stats are added in Distributed Lock Service it will be - // neeeded. + // needed. } public void memberDeparted(InternalDistributedMember id, boolean crashed) { http://git-wip-us.apache.org/repos/asf/geode/blob/d16d192b/geode-core/src/main/java/org/apache/geode/management/internal/beans/DistributedSystemMBean.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/beans/DistributedSystemMBean.java b/geode-core/src/main/java/org/apache/geode/management/internal/beans/DistributedSystemMBean.java index a87b366..c45da73 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/beans/DistributedSystemMBean.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/beans/DistributedSystemMBean.java @@ -14,11 +14,6 @@ */ package org.apache.geode.management.internal.beans; -import java.util.Map; - -import javax.management.NotificationBroadcasterSupport; -import javax.management.ObjectName; - import org.apache.geode.management.DiskBackupStatus; import org.apache.geode.management.DiskMetrics; import org.apache.geode.management.DistributedSystemMXBean; @@ -28,6 +23,10 @@ import org.apache.geode.management.NetworkMetrics; import org.apache.geode.management.OSMetrics; import org.apache.geode.management.PersistentMemberDetails; +import java.util.Map; +import javax.management.NotificationBroadcasterSupport; +import javax.management.ObjectName; + /** * Distributed System MBean * @@ -103,7 +102,7 @@ public class DistributedSystemMBean extends NotificationBroadcasterSupport @Override public String[] listGatewaySenders() { - return bridge.listGatwaySenders(); + return bridge.listGatewaySenders(); } @Override http://git-wip-us.apache.org/repos/asf/geode/blob/d16d192b/geode-core/src/main/java/org/apache/geode/management/internal/beans/ManagementAdapter.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/beans/ManagementAdapter.java b/geode-core/src/main/java/org/apache/geode/management/internal/beans/ManagementAdapter.java index 7dce602..003a8f3 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/beans/ManagementAdapter.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/beans/ManagementAdapter.java @@ -14,26 +14,7 @@ */ package org.apache.geode.management.internal.beans; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import javax.management.InstanceNotFoundException; -import javax.management.MBeanServer; -import javax.management.MalformedObjectNameException; -import javax.management.Notification; -import javax.management.NotificationBroadcasterSupport; -import javax.management.ObjectInstance; -import javax.management.ObjectName; - -import org.apache.geode.distributed.internal.DistributionManager; -import org.apache.geode.internal.cache.CacheService; -import org.apache.logging.log4j.Logger; - +import org.apache.commons.lang.StringUtils; import org.apache.geode.cache.Cache; import org.apache.geode.cache.DiskStore; import org.apache.geode.cache.Region; @@ -42,11 +23,13 @@ import org.apache.geode.cache.server.CacheServer; import org.apache.geode.cache.wan.GatewayReceiver; import org.apache.geode.cache.wan.GatewaySender; import org.apache.geode.distributed.Locator; +import org.apache.geode.distributed.internal.DistributionManager; import org.apache.geode.distributed.internal.InternalDistributedSystem; import org.apache.geode.distributed.internal.InternalLocator; import org.apache.geode.distributed.internal.locks.DLockService; import org.apache.geode.distributed.internal.membership.InternalDistributedMember; import org.apache.geode.internal.ClassLoadUtil; +import org.apache.geode.internal.cache.CacheService; import org.apache.geode.internal.cache.InternalCache; import org.apache.geode.internal.cache.LocalRegion; import org.apache.geode.internal.cache.PartitionedRegionHelper; @@ -75,6 +58,21 @@ import org.apache.geode.management.membership.ClientMembershipEvent; import org.apache.geode.management.membership.ClientMembershipListener; import org.apache.geode.management.membership.ClientMembershipListenerAdapter; import org.apache.geode.pdx.internal.PeerTypeRegistration; +import org.apache.logging.log4j.Logger; + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import javax.management.InstanceNotFoundException; +import javax.management.MBeanServer; +import javax.management.MalformedObjectNameException; +import javax.management.Notification; +import javax.management.NotificationBroadcasterSupport; +import javax.management.ObjectInstance; +import javax.management.ObjectName; /** * Acts as an intermediate between MBean layer and Federation Layer. Handles all Call backs from @@ -111,9 +109,9 @@ public class ManagementAdapter { private MBeanAggregator aggregator; - public static final List<Class> refreshOnInit = new ArrayList<Class>(); + public static final List<Class> refreshOnInit = new ArrayList<>(); - public static final List<String> internalLocks = new ArrayList<String>(); + public static final List<String> internalLocks = new ArrayList<>(); static { refreshOnInit.add(RegionMXBean.class); @@ -219,9 +217,7 @@ public class ManagementAdapter { service.afterCreateProxy(memberObjectName, MemberMXBean.class, localMember, addedComp); - Iterator<ObjectName> it = registeredMBeans.keySet().iterator(); - while (it.hasNext()) { - ObjectName objectName = it.next(); + for (ObjectName objectName : registeredMBeans.keySet()) { if (objectName.equals(memberObjectName)) { continue; } @@ -235,8 +231,8 @@ public class ManagementAdapter { FederationComponent newObj = service.getLocalManager().getFedComponents().get(objectName); - for (int i = 0; i < intfTyps.length; i++) { - Class intfTyp = (Class) intfTyps[i]; + for (Type intfTyp1 : intfTyps) { + Class intfTyp = (Class) intfTyp1; service.afterCreateProxy(objectName, intfTyp, object, newObj); } @@ -265,12 +261,10 @@ public class ManagementAdapter { MBeanJMXAdapter jmxAdapter = service.getJMXAdapter(); Map<ObjectName, Object> registeredMBeans = jmxAdapter.getLocalGemFireMBean(); - ObjectName aggregatemMBeanPattern = null; + ObjectName aggregatemMBeanPattern; try { aggregatemMBeanPattern = new ObjectName(ManagementConstants.AGGREGATE_MBEAN_PATTERN); - } catch (MalformedObjectNameException e1) { - throw new ManagementException(e1); - } catch (NullPointerException e1) { + } catch (MalformedObjectNameException | NullPointerException e1) { throw new ManagementException(e1); } @@ -284,10 +278,7 @@ public class ManagementAdapter { service.afterRemoveProxy(memberObjectName, MemberMXBean.class, localMember, removedComp); - Iterator<ObjectName> it = registeredMBeans.keySet().iterator(); - - while (it.hasNext()) { - ObjectName objectName = it.next(); + for (ObjectName objectName : registeredMBeans.keySet()) { if (objectName.equals(memberObjectName)) { continue; } @@ -304,14 +295,11 @@ public class ManagementAdapter { FederationComponent oldObj = service.getLocalManager().getFedComponents().get(objectName); - for (int i = 0; i < intfTyps.length; i++) { - Class intfTyp = (Class) intfTyps[i]; + for (Type intfTyp1 : intfTyps) { + Class intfTyp = (Class) intfTyp1; service.afterRemoveProxy(objectName, intfTyp, object, oldObj); } - } catch (InstanceNotFoundException e) { - logger.warn("Failed to invoke aggregator for {} with exception {}", objectName, - e.getMessage(), e); - } catch (ClassNotFoundException e) { + } catch (InstanceNotFoundException | ClassNotFoundException e) { logger.warn("Failed to invoke aggregator for {} with exception {}", objectName, e.getMessage(), e); } @@ -359,7 +347,7 @@ public class ManagementAdapter { // Bridge is responsible for extracting data from GemFire Layer RegionMBeanBridge<K, V> bridge = RegionMBeanBridge.getInstance(region); - RegionMXBean regionMBean = new RegionMBean<K, V>(bridge); + RegionMXBean regionMBean = new RegionMBean<>(bridge); ObjectName regionMBeanName = MBeanJMXAdapter.getRegionMBeanName( internalCache.getDistributedSystem().getDistributedMember(), region.getFullPath()); ObjectName changedMBeanName = service.registerInternalMBean(regionMBean, regionMBeanName); @@ -567,7 +555,7 @@ public class ManagementAdapter { ObjectName asycnEventQueueMBeanName = MBeanJMXAdapter.getAsycnEventQueueMBeanName( internalCache.getDistributedSystem().getDistributedMember(), queue.getId()); - AsyncEventQueueMBean bean = null; + AsyncEventQueueMBean bean; try { bean = (AsyncEventQueueMBean) service.getLocalAsyncEventQueueMXBean(queue.getId()); if (bean == null) { @@ -616,7 +604,7 @@ public class ManagementAdapter { } private Map<String, String> prepareUserData(AlertDetails details) { - Map<String, String> userData = new HashMap<String, String>(); + Map<String, String> userData = new HashMap<>(); userData.put(JMXNotificationUserData.ALERT_LEVEL, AlertDetails.getAlertLevelAsString(details.getAlertLevel())); @@ -627,7 +615,7 @@ public class ManagementAdapter { String nameOrId = memberSource; // TODO: what if sender is null? if (sender != null) { nameOrId = sender.getName(); - nameOrId = nameOrId != null && !nameOrId.trim().isEmpty() ? nameOrId : sender.getId(); + nameOrId = StringUtils.isNotBlank(nameOrId) ? nameOrId : sender.getId(); } userData.put(JMXNotificationUserData.MEMBER, nameOrId); @@ -799,7 +787,7 @@ public class ManagementAdapter { synchronized (regionOpLock) { ObjectName regionMBeanName = MBeanJMXAdapter.getRegionMBeanName( internalCache.getDistributedSystem().getDistributedMember(), region.getFullPath()); - RegionMBean bean = null; + RegionMBean bean; try { bean = (RegionMBean) service.getLocalRegionMBean(region.getFullPath()); } catch (ManagementException e) { @@ -838,7 +826,7 @@ public class ManagementAdapter { ObjectName diskStoreMBeanName = MBeanJMXAdapter.getDiskStoreMBeanName( internalCache.getDistributedSystem().getDistributedMember(), disk.getName()); - DiskStoreMBean bean = null; + DiskStoreMBean bean; try { bean = (DiskStoreMBean) service.getLocalDiskStoreMBean(disk.getName()); if (bean == null) { http://git-wip-us.apache.org/repos/asf/geode/blob/d16d192b/geode-core/src/main/java/org/apache/geode/management/internal/beans/QueryDataFunction.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/beans/QueryDataFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/beans/QueryDataFunction.java index f701d29..9829df3 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/beans/QueryDataFunction.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/beans/QueryDataFunction.java @@ -14,21 +14,7 @@ */ package org.apache.geode.management.internal.beans; -import java.io.IOException; -import java.io.Serializable; -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import java.util.StringTokenizer; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.apache.logging.log4j.Logger; - +import org.apache.commons.lang.StringUtils; import org.apache.geode.SystemFailure; import org.apache.geode.cache.CacheFactory; import org.apache.geode.cache.DataPolicy; @@ -64,6 +50,19 @@ import org.apache.geode.management.internal.cli.commands.DataCommands; import org.apache.geode.management.internal.cli.json.GfJsonException; import org.apache.geode.management.internal.cli.json.GfJsonObject; import org.apache.geode.management.internal.cli.json.TypedJson; +import org.apache.logging.log4j.Logger; + +import java.io.Serializable; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.StringTokenizer; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * This function is executed on one or multiple members based on the member input to @@ -128,7 +127,7 @@ public class QueryDataFunction extends FunctionAdapter implements InternalEntity final boolean showMember, final String regionName, final int limit, final int queryResultSetLimit, final int queryCollectionsDepth) throws Exception { InternalCache cache = getCache(); - Function loclQueryFunc = new LocalQueryFunction("LocalQueryFunction", regionName, showMember) + Function localQueryFunc = new LocalQueryFunction("LocalQueryFunction", regionName, showMember) .setOptimizeForWrite(true); queryString = applyLimitClause(queryString, limit, queryResultSetLimit); @@ -154,7 +153,7 @@ public class QueryDataFunction extends FunctionAdapter implements InternalEntity results = query.execute(); } else { - ResultCollector rcollector = null; + ResultCollector rcollector; PartitionedRegion parRegion = PartitionedRegionHelper.getPartitionedRegion(regionName, cache); @@ -169,13 +168,11 @@ public class QueryDataFunction extends FunctionAdapter implements InternalEntity } LocalDataSet lds = new LocalDataSet(parRegion, localPrimaryBucketSet); DefaultQuery query = (DefaultQuery) cache.getQueryService().newQuery(queryString); - SelectResults selectResults = - (SelectResults) lds.executeQuery(query, null, localPrimaryBucketSet); - results = selectResults; + results = (SelectResults) lds.executeQuery(query, null, localPrimaryBucketSet); } } else { rcollector = FunctionService.onRegion(cache.getRegion(regionName)) - .setArguments(queryString).execute(loclQueryFunc); + .setArguments(queryString).execute(localQueryFunc); results = rcollector.getResult(); } } @@ -183,8 +180,7 @@ public class QueryDataFunction extends FunctionAdapter implements InternalEntity if (results != null && results instanceof SelectResults) { SelectResults selectResults = (SelectResults) results; - for (Iterator iter = selectResults.iterator(); iter.hasNext();) { - Object object = iter.next(); + for (Object object : selectResults) { result.add(RESULT_KEY, object); noDataFound = false; } @@ -203,7 +199,7 @@ public class QueryDataFunction extends FunctionAdapter implements InternalEntity if (noDataFound) { return new QueryDataFunctionResult(QUERY_EXEC_SUCCESS, - BeanUtilFuncs.compress(new JsonisedErroMessage(NO_DATA_FOUND).toString())); + BeanUtilFuncs.compress(new JsonisedErrorMessage(NO_DATA_FOUND).toString())); } return new QueryDataFunctionResult(QUERY_EXEC_SUCCESS, BeanUtilFuncs.compress(result.toString())); @@ -272,7 +268,7 @@ public class QueryDataFunction extends FunctionAdapter implements InternalEntity // member. // Note , if no member is selected this is the code path executed. A // random associated member is chosen. - List<String> decompressedList = new ArrayList<String>(); + List<String> decompressedList = new ArrayList<>(); decompressedList.add(BeanUtilFuncs.decompress(result.compressedBytes)); return wrapResult(decompressedList.toString()); } @@ -290,10 +286,10 @@ public class QueryDataFunction extends FunctionAdapter implements InternalEntity } Iterator<QueryDataFunctionResult> it = list.iterator(); - List<String> decompressedList = new ArrayList<String>(); + List<String> decompressedList = new ArrayList<>(); while (it.hasNext()) { - String decompressedStr = null; + String decompressedStr; decompressedStr = BeanUtilFuncs.decompress(it.next().compressedBytes); decompressedList.add(decompressedStr); } @@ -308,12 +304,6 @@ public class QueryDataFunction extends FunctionAdapter implements InternalEntity } catch (FunctionException fe) { throw new Exception( ManagementStrings.QUERY__MSG__QUERY_EXEC.toLocalizedString(fe.getMessage())); - } catch (IOException e) { - throw new Exception( - ManagementStrings.QUERY__MSG__QUERY_EXEC.toLocalizedString(e.getMessage())); - } catch (Exception e) { - throw new Exception( - ManagementStrings.QUERY__MSG__QUERY_EXEC.toLocalizedString(e.getMessage())); } catch (VirtualMachineError e) { SystemFailure.initiateFailure(e); throw e; @@ -339,20 +329,20 @@ public class QueryDataFunction extends FunctionAdapter implements InternalEntity throws Exception { if (query == null || query.isEmpty()) { - return new JsonisedErroMessage(ManagementStrings.QUERY__MSG__QUERY_EMPTY.toLocalizedString()) + return new JsonisedErrorMessage(ManagementStrings.QUERY__MSG__QUERY_EMPTY.toLocalizedString()) .toString(); } Set<DistributedMember> inputMembers = null; - if (members != null && !members.trim().isEmpty()) { - inputMembers = new HashSet<DistributedMember>(); + if (StringUtils.isNotBlank(members)) { + inputMembers = new HashSet<>(); StringTokenizer st = new StringTokenizer(members, ","); while (st.hasMoreTokens()) { String member = st.nextToken(); DistributedMember distributedMember = BeanUtilFuncs.getDistributedMemberByNameOrId(member); inputMembers.add(distributedMember); if (distributedMember == null) { - return new JsonisedErroMessage( + return new JsonisedErrorMessage( ManagementStrings.QUERY__MSG__INVALID_MEMBER.toLocalizedString(member)).toString(); } } @@ -370,7 +360,7 @@ public class QueryDataFunction extends FunctionAdapter implements InternalEntity for (String regionPath : regionsInQuery) { DistributedRegionMXBean regionMBean = service.getDistributedRegionMXBean(regionPath); if (regionMBean == null) { - return new JsonisedErroMessage( + return new JsonisedErrorMessage( ManagementStrings.QUERY__MSG__REGIONS_NOT_FOUND.toLocalizedString(regionPath)) .toString(); } else { @@ -379,7 +369,7 @@ public class QueryDataFunction extends FunctionAdapter implements InternalEntity if (inputMembers != null && inputMembers.size() > 0) { if (!associatedMembers.containsAll(inputMembers)) { - return new JsonisedErroMessage( + return new JsonisedErrorMessage( ManagementStrings.QUERY__MSG__REGIONS_NOT_FOUND_ON_MEMBERS .toLocalizedString(regionPath)).toString(); } @@ -387,7 +377,7 @@ public class QueryDataFunction extends FunctionAdapter implements InternalEntity } } } else { - return new JsonisedErroMessage(ManagementStrings.QUERY__MSG__INVALID_QUERY + return new JsonisedErrorMessage(ManagementStrings.QUERY__MSG__INVALID_QUERY .toLocalizedString("Region mentioned in query probably missing /")).toString(); } @@ -398,7 +388,7 @@ public class QueryDataFunction extends FunctionAdapter implements InternalEntity if (regionMBean.getRegionType().equals(DataPolicy.PARTITION.toString()) || regionMBean.getRegionType().equals(DataPolicy.PERSISTENT_PARTITION.toString())) { - return new JsonisedErroMessage( + return new JsonisedErrorMessage( ManagementStrings.QUERY__MSG__JOIN_OP_EX.toLocalizedString()).toString(); } } @@ -422,8 +412,7 @@ public class QueryDataFunction extends FunctionAdapter implements InternalEntity functionArgs[LIMIT] = limit; functionArgs[QUERY_RESULTSET_LIMIT] = queryResultSetLimit; functionArgs[QUERY_COLLECTIONS_DEPTH] = queryCollectionsDepth; - Object result = callFunction(functionArgs, inputMembers, zipResult); - return result; + return callFunction(functionArgs, inputMembers, zipResult); } else { // Query on any random member functionArgs[DISPLAY_MEMBERWISE] = false; functionArgs[QUERY] = query; @@ -431,17 +420,16 @@ public class QueryDataFunction extends FunctionAdapter implements InternalEntity functionArgs[LIMIT] = limit; functionArgs[QUERY_RESULTSET_LIMIT] = queryResultSetLimit; functionArgs[QUERY_COLLECTIONS_DEPTH] = queryCollectionsDepth; - Object result = callFunction(functionArgs, associatedMembers, zipResult); - return result; + return callFunction(functionArgs, associatedMembers, zipResult); } } else { - return new JsonisedErroMessage(ManagementStrings.QUERY__MSG__REGIONS_NOT_FOUND + return new JsonisedErrorMessage(ManagementStrings.QUERY__MSG__REGIONS_NOT_FOUND .toLocalizedString(regionsInQuery.toString())).toString(); } } catch (QueryInvalidException qe) { - return new JsonisedErroMessage( + return new JsonisedErrorMessage( ManagementStrings.QUERY__MSG__INVALID_QUERY.toLocalizedString(qe.getMessage())) .toString(); } @@ -451,13 +439,13 @@ public class QueryDataFunction extends FunctionAdapter implements InternalEntity return (InternalCache) CacheFactory.getAnyInstance(); } - private static class JsonisedErroMessage { + private static class JsonisedErrorMessage { private static String message = "message"; private GfJsonObject gFJsonObject = new GfJsonObject(); - public JsonisedErroMessage(final String errorMessage) throws Exception { + public JsonisedErrorMessage(final String errorMessage) throws Exception { try { gFJsonObject.put(message, errorMessage); } catch (GfJsonException e) { @@ -483,10 +471,10 @@ public class QueryDataFunction extends FunctionAdapter implements InternalEntity private static Set<String> compileQuery(final InternalCache cache, final String query) throws QueryInvalidException { QCompiler compiler = new QCompiler(); - Set<String> regionsInQuery = null; + Set<String> regionsInQuery; try { CompiledValue compiledQuery = compiler.compileQuery(query); - Set<String> regions = new HashSet<String>(); + Set<String> regions = new HashSet<>(); compiledQuery.getRegionsInQuery(regions, null); regionsInQuery = Collections.unmodifiableSet(regions); return regionsInQuery;