Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 43366200CAA for ; Tue, 9 May 2017 19:39:49 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 4211C160BB6; Tue, 9 May 2017 17:39:49 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D68E4160BEB for ; Tue, 9 May 2017 19:39:41 +0200 (CEST) Received: (qmail 67454 invoked by uid 500); 9 May 2017 17:39:38 -0000 Mailing-List: contact commits-help@geode.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.apache.org Delivered-To: mailing list commits@geode.apache.org Received: (qmail 66391 invoked by uid 99); 9 May 2017 17:39:37 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 May 2017 17:39:37 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 984ECE0FE7; Tue, 9 May 2017 17:39:37 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: klund@apache.org To: commits@geode.apache.org Date: Tue, 09 May 2017 17:40:11 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [36/49] geode git commit: GEODE-2632: change dependencies on GemFireCacheImpl to InternalCache archived-at: Tue, 09 May 2017 17:39:49 -0000 http://git-wip-us.apache.org/repos/asf/geode/blob/4b489e56/geode-core/src/main/java/org/apache/geode/internal/InternalInstantiator.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/InternalInstantiator.java b/geode-core/src/main/java/org/apache/geode/internal/InternalInstantiator.java index d292ca9..1c1a73e 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/InternalInstantiator.java +++ b/geode-core/src/main/java/org/apache/geode/internal/InternalInstantiator.java @@ -33,9 +33,11 @@ import org.apache.geode.cache.Cache; import org.apache.geode.distributed.internal.DistributionManager; import org.apache.geode.distributed.internal.InternalDistributedSystem; import org.apache.geode.distributed.internal.SerialDistributionMessage; +import org.apache.geode.i18n.StringId; import org.apache.geode.internal.cache.EnumListenerEvent; import org.apache.geode.internal.cache.EventID; import org.apache.geode.internal.cache.GemFireCacheImpl; +import org.apache.geode.internal.cache.InternalCache; import org.apache.geode.internal.cache.PoolManagerImpl; import org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier; import org.apache.geode.internal.cache.tier.sockets.CacheClientUpdater; @@ -46,7 +48,6 @@ import org.apache.geode.internal.cache.tier.sockets.Part; import org.apache.geode.internal.i18n.LocalizedStrings; import org.apache.geode.internal.logging.LogService; import org.apache.geode.internal.logging.log4j.LocalizedMessage; -import org.apache.geode.i18n.StringId; /** * Contains the implementation of {@link org.apache.geode.Instantiator} registration and @@ -84,7 +85,7 @@ public class InternalInstantiator { /////////////////////// Static Methods /////////////////////// /** - * Registers an Instantiator with the data serialization framework. + * Registers an {@code Instantiator} with the data serialization framework. */ public static void register(Instantiator instantiator, boolean distribute) { // [sumedh] Skip the checkForThread() check if the instantiation has not @@ -99,7 +100,7 @@ public class InternalInstantiator { } /** - * Actually registers an Instantiator with the data serialization framework. + * Actually registers an {@code Instantiator} with the data serialization framework. * * @param instantiator * @param distribute @@ -161,7 +162,7 @@ public class InternalInstantiator { // if instantiator is getting registered for first time // its EventID will be null, so generate a new event id // the the distributed system is connected - GemFireCacheImpl cache = GemFireCacheImpl.getInstance(); + InternalCache cache = GemFireCacheImpl.getInstance(); if (cache != null && instantiator.getEventId() == null) { instantiator.setEventId(new EventID(cache.getDistributedSystem())); } @@ -204,7 +205,7 @@ public class InternalInstantiator { * Sets the EventID to the instantiator if distributed system is created */ public static EventID generateEventId() { - GemFireCacheImpl cache = GemFireCacheImpl.getInstance(); + InternalCache cache = GemFireCacheImpl.getInstance(); if (cache == null) { // A cache has not yet created return null; @@ -232,8 +233,6 @@ public class InternalInstantiator { /** * Sends Instantiator registration message to all cache clients - * - * @param instantiator */ private static void sendRegistrationMessageToClients(Instantiator instantiator) { Cache cache = GemFireCacheImpl.getInstance(); @@ -267,7 +266,7 @@ public class InternalInstantiator { } /** - * Creates a new Instantiator with the given class and id and + * Creates a new {@code Instantiator} with the given class and id and * {@linkplain #register(Instantiator, boolean) registers} it with the data serialization * framework. * @@ -284,7 +283,7 @@ public class InternalInstantiator { } /** - * Creates a new Instantiator with the given class and id and + * Creates a new {@code Instantiator} with the given class and id and * {@linkplain #register(Instantiator, boolean) registers} it with the data serialization * framework. * @@ -303,7 +302,7 @@ public class InternalInstantiator { } /** - * Lazily creates a new Instantiator with the given class and id. + * Lazily creates a new {@code Instantiator} with the given class and id. * * @throws IllegalArgumentException The instantiator cannot be created * @throws IllegalStateException The instantiator cannot be registered @@ -318,7 +317,7 @@ public class InternalInstantiator { } /** - * Lazily creates a new Instantiator with the given class and id. + * Lazily creates a new {@code Instantiator} with the given class and id. * * This method is only called when server connection and CacheClientUpdaterThread * @@ -377,7 +376,7 @@ public class InternalInstantiator { instantiatedClass = InternalDataSerializer.getCachedClass(holder.getInstantiatedClassName()); } catch (ClassNotFoundException cnfe) { - GemFireCacheImpl cache = GemFireCacheImpl.getInstance(); + InternalCache cache = GemFireCacheImpl.getInstance(); if (cache != null && cache.getLoggerI18n() != null && cache.getLoggerI18n().infoEnabled()) { cache.getLoggerI18n().info( LocalizedStrings.InternalInstantiator_COULD_NOT_LOAD_INSTANTIATOR_CLASS_0, @@ -454,11 +453,11 @@ public class InternalInstantiator { } /** - * Unregisters the given class with the given class id with the Instantiator. + * Unregisters the given class with the given class id with the {@code Instantiator}. * - * @throws IllegalArgumentException If c was not previously registered with id - * classId. - * @throws NullPointerException If c is null + * @throws IllegalArgumentException If {@code c} was not previously registered with id + * {@code classId}. + * @throws NullPointerException If {@code c} is {@code null} */ public static synchronized void unregister(Class c, int classId) { if (c == null) { @@ -489,7 +488,7 @@ public class InternalInstantiator { /** * Returns the class id for the given class. * - * @return 0 if the class has not be registered + * @return {@code 0} if the class has not be registered * * @see DataSerializer#writeObject(Object, DataOutput) */ @@ -554,7 +553,7 @@ public class InternalInstantiator { instantiator = (Instantiator) idsToInstantiators.get(classId); } } catch (ClassNotFoundException cnfe) { - GemFireCacheImpl cache = GemFireCacheImpl.getInstance(); + InternalCache cache = GemFireCacheImpl.getInstance(); if (cache != null && cache.getLoggerI18n() != null && cache.getLoggerI18n().infoEnabled()) { cache.getLoggerI18n().info( @@ -585,11 +584,11 @@ public class InternalInstantiator { } /** - * Reflectively instantiates an instance of Instantiator. + * Reflectively instantiates an instance of {@code Instantiator}. * - * @param instantiatorClass The implementation of Instantiator to instantiate - * @param instantiatedClass The implementation of DataSerialization that will be - * produced by the Instantiator + * @param instantiatorClass The implementation of {@code Instantiator} to instantiate + * @param instantiatedClass The implementation of {@code DataSerialization} that will be produced + * by the {@code Instantiator} * * @throws IllegalArgumentException If the class can't be instantiated */ @@ -680,7 +679,7 @@ public class InternalInstantiator { idsToHolders.remove(holder.getId()); } } catch (ClassNotFoundException cnfe) { - GemFireCacheImpl cache = GemFireCacheImpl.getInstance(); + InternalCache cache = GemFireCacheImpl.getInstance(); if (cache != null && cache.getLoggerI18n() != null && cache.getLoggerI18n().infoEnabled()) { cache.getLoggerI18n().info( @@ -716,8 +715,8 @@ public class InternalInstantiator { /////////////////////// Inner Classes /////////////////////// /** - * A marker object for Instantiators that have not been registered. Using this marker - * object allows us to asynchronously send Instantiator registration updates. If the + * A marker object for {@code Instantiator}s that have not been registered. Using this marker + * object allows us to asynchronously send {@code Instantiator} registration updates. If the * serialized bytes arrive at a VM before the registration message does, the deserializer will * wait an amount of time for the registration message to arrive. */ @@ -727,7 +726,7 @@ public class InternalInstantiator { private volatile Instantiator instantiator = null; /** - * Creates a new Marker whose {@link #getInstantiator} method will wait for the + * Creates a new {@code Marker} whose {@link #getInstantiator} method will wait for the * instantiator to be registered. */ Marker() { @@ -737,7 +736,7 @@ public class InternalInstantiator { /** * Returns the instantiator associated with this marker. If the instantiator has not been * registered yet, then this method will wait until the instantiator is registered. If this - * method has to wait for too long, then null is returned. + * method has to wait for too long, then {@code null} is returned. */ Instantiator getInstantiator() { synchronized (this) { @@ -811,11 +810,11 @@ public class InternalInstantiator { /** * A distribution message that alerts other members of the distributed cache of a new - * Instantiator being registered. + * {@code Instantiator} being registered. */ public static class RegistrationMessage extends SerialDistributionMessage { /** - * The Instantiator class that was registered + * The {@code Instantiator} class that was registered */ protected Class instantiatorClass; @@ -823,12 +822,12 @@ public class InternalInstantiator { protected Class instantiatedClass; /** - * The id of the Instantiator that was registered + * The id of the {@code Instantiator} that was registered */ protected int id; /** - * The eventId of the Instantiator that was registered + * The eventId of the {@code Instantiator} that was registered */ protected EventID eventId; @@ -838,7 +837,7 @@ public class InternalInstantiator { protected transient StringBuffer fromDataProblems; /** - * The name of the Instantiator class that was registered + * The name of the {@code Instantiator} class that was registered */ protected String instantiatorClassName; @@ -846,15 +845,15 @@ public class InternalInstantiator { protected String instantiatedClassName; /** - * Constructor for DataSerializable + * Constructor for {@code DataSerializable} */ public RegistrationMessage() { } /** - * Creates a new RegistrationMessage that broadcasts that the given - * Instantiator was registered. + * Creates a new {@code RegistrationMessage} that broadcasts that the given {@code Instantiator} + * was registered. */ public RegistrationMessage(Instantiator s) { this.instantiatorClass = s.getClass(); @@ -951,7 +950,7 @@ public class InternalInstantiator { } /** * A distribution message that alerts other members of the distributed cache of a new - * Instantiator being registered. + * {@code Instantiator} being registered. * * * @since GemFire 5.0 @@ -961,15 +960,15 @@ public class InternalInstantiator { private transient ClientProxyMembershipID context; /** - * Constructor for RegistrationConetxtMessage + * Constructor for {@code RegistrationConetxtMessage} */ public RegistrationContextMessage() { } /** - * Creates a new RegistrationContextMessage that broadcasts that the given - * Instantiator was registered. + * Creates a new {@code RegistrationContextMessage} that broadcasts that the given + * {@code Instantiator} was registered. */ public RegistrationContextMessage(Instantiator s) { this.instantiatorClass = s.getClass(); http://git-wip-us.apache.org/repos/asf/geode/blob/4b489e56/geode-core/src/main/java/org/apache/geode/internal/MigrationClient.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/MigrationClient.java b/geode-core/src/main/java/org/apache/geode/internal/MigrationClient.java index 4cc99d9..1f3ef2a 100755 --- a/geode-core/src/main/java/org/apache/geode/internal/MigrationClient.java +++ b/geode-core/src/main/java/org/apache/geode/internal/MigrationClient.java @@ -16,6 +16,18 @@ package org.apache.geode.internal; import static org.apache.geode.distributed.ConfigurationProperties.*; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.EOFException; +import java.io.File; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.net.SocketAddress; +import java.util.Properties; + import org.apache.geode.cache.Cache; import org.apache.geode.cache.CacheFactory; import org.apache.geode.cache.Region; @@ -25,16 +37,6 @@ import org.apache.geode.distributed.internal.InternalDistributedSystem; import org.apache.geode.internal.cache.GemFireCacheImpl; import org.apache.geode.internal.net.SocketCreator; -import java.io.*; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.Socket; -import java.net.SocketAddress; -import java.util.Properties; - -import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS; -import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT; - /** * MigrationClient is used to retrieve all of the data for a region from a MigrationServer. First * start a MigrationServer using one version of GemFire, then connect to it using a MigrationClient @@ -49,30 +51,29 @@ import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT; * The region should be defined in the cache-xml file, and must also be defined in the server's * cache-xml file. *

- *

* Typically, the cache-xml file will be exactly the same as the one used by the MigrationServer - * with different disk-dirs settings. When Region entries are transfered from the server to the + * with different disk-dirs settings. When Region entries are transferred from the server to the * client, they are then stored in new files in these directories. * * @since GemFire 6.0.1 - * */ public class MigrationClient { - final static boolean VERBOSE = MigrationServer.VERBOSE; + private static final boolean VERBOSE = MigrationServer.VERBOSE; + + // version for backward communications compatibility + private static final int VERSION = 551; - final static int VERSION = 551; // version for backward communications compatibility + private static final int CODE_ERROR = MigrationServer.CODE_ERROR; - protected static final int CODE_ERROR = MigrationServer.CODE_ERROR; - protected static final int CODE_ENTRY = - MigrationServer.CODE_ENTRY; /* serialized key, serialized value */ - protected static final int CODE_COMPLETED = MigrationServer.CODE_COMPLETED; + /* serialized key, serialized value */ + private static final int CODE_ENTRY = MigrationServer.CODE_ENTRY; + + private static final int CODE_COMPLETED = MigrationServer.CODE_COMPLETED; public static void main(String[] args) throws Exception { int argIdx = 0; - String cacheXmlFileName = null; - String regionName = null; - String bindAddressName = null; - int serverPort = 10533; + String cacheXmlFileName; + String regionName; if (args.length > argIdx + 1) { regionName = args[argIdx++]; @@ -82,9 +83,11 @@ public class MigrationClient { .println("MigrationClient regionName [cache-xml-file] [server-port] [server-address]"); return; } + int serverPort = 10533; if (args.length > argIdx) { serverPort = Integer.parseInt(args[argIdx++]); } + String bindAddressName = null; if (args.length > argIdx) { bindAddressName = args[argIdx++]; } @@ -101,19 +104,16 @@ public class MigrationClient { instance.getRegion(regionName); } - - private InetAddress serverAddress; - private int port; + private final InetAddress serverAddress; + private final int port; private DistributedSystem distributedSystem; private File cacheXmlFile; private Cache cache; - private Socket server; private int serverVersion; private DataInputStream dis; private DataOutputStream dos; - /** * Create a MigrationClient to be used with a DistributedSystem and Cache that are created using * GemFire APIs @@ -121,13 +121,13 @@ public class MigrationClient { * @param bindAddressName the server's address * @param serverPort the server's port */ - public MigrationClient(String bindAddressName, int serverPort) { + private MigrationClient(String bindAddressName, int serverPort) { this.port = serverPort; try { this.serverAddress = InetAddress.getByName(bindAddressName); - } catch (IOException e) { + } catch (IOException ignore) { throw new IllegalArgumentException( - "Error - bind address cannot be resolved: '" + bindAddressName + "'"); + "Error - bind address cannot be resolved: '" + bindAddressName + '\''); } } @@ -143,7 +143,8 @@ public class MigrationClient { this.cacheXmlFile = new File(cacheXmlFileName); if (!this.cacheXmlFile.exists()) { // in 6.x this should be localizable - System.err.println("Warning - file not found in local directory: '" + cacheXmlFileName + "'"); + System.err + .println("Warning - file not found in local directory: '" + cacheXmlFileName + '\''); } } @@ -167,7 +168,6 @@ public class MigrationClient { this.distributedSystem = DistributedSystem.connect(dsProps); } - /** * create the cache to be used by this migration server * @@ -191,8 +191,7 @@ public class MigrationClient { public Region getRegion(String regionName) throws IOException, ClassNotFoundException { initDSAndCache(); - Region region = null; - region = this.cache.getRegion(regionName); + Region region = this.cache.getRegion(regionName); try { connectToServer(); if (this.serverVersion != VERSION) { @@ -209,7 +208,7 @@ public class MigrationClient { int responseCode = -1; try { responseCode = this.dis.readShort(); - } catch (EOFException e) { + } catch (EOFException ignore) { } switch (responseCode) { case -1: @@ -219,11 +218,11 @@ public class MigrationClient { break; case CODE_ERROR: String errorString = this.dis.readUTF(); - System.err.println("Server responded with error: '" + errorString + "'"); + System.err.println("Server responded with error: '" + errorString + '\''); throw new IOException(errorString); case CODE_ENTRY: - Object key = (new ObjectInputStream(server.getInputStream())).readObject(); - Object value = (new ObjectInputStream(server.getInputStream())).readObject(); + Object key = new ObjectInputStream(this.server.getInputStream()).readObject(); + Object value = new ObjectInputStream(this.server.getInputStream()).readObject(); if (VERBOSE) { System.out.println("received " + key); } @@ -232,14 +231,13 @@ public class MigrationClient { } } } finally { - if (server != null && !server.isClosed()) { - server.close(); + if (this.server != null && !this.server.isClosed()) { + this.server.close(); } } return region; } - private void connectToServer() throws IOException { this.server = new Socket(); SocketAddress addr; http://git-wip-us.apache.org/repos/asf/geode/blob/4b489e56/geode-core/src/main/java/org/apache/geode/internal/MigrationServer.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/MigrationServer.java b/geode-core/src/main/java/org/apache/geode/internal/MigrationServer.java index 3cb3e61..1252eb0 100755 --- a/geode-core/src/main/java/org/apache/geode/internal/MigrationServer.java +++ b/geode-core/src/main/java/org/apache/geode/internal/MigrationServer.java @@ -16,24 +16,36 @@ package org.apache.geode.internal; import static org.apache.geode.distributed.ConfigurationProperties.*; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.NetworkInterface; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.SocketAddress; +import java.net.SocketException; +import java.net.UnknownHostException; +import java.util.Enumeration; +import java.util.Properties; + +import org.apache.logging.log4j.Logger; + import org.apache.geode.admin.internal.InetAddressUtil; import org.apache.geode.cache.Cache; import org.apache.geode.cache.CacheFactory; import org.apache.geode.cache.Region; +import org.apache.geode.cache.Region.Entry; import org.apache.geode.distributed.DistributedSystem; import org.apache.geode.distributed.internal.DistributionConfig; import org.apache.geode.distributed.internal.InternalDistributedSystem; import org.apache.geode.internal.cache.GemFireCacheImpl; import org.apache.geode.internal.i18n.LocalizedStrings; - -import java.io.*; -import java.net.*; -import java.util.Enumeration; -import java.util.Iterator; -import java.util.Properties; - -import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS; -import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT; +import org.apache.geode.internal.logging.LogService; /** * MigrationServer creates a cache using a supplied cache.xml and then opens a server socket that a @@ -98,28 +110,34 @@ import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT; * @since GemFire 6.0.1 */ public class MigrationServer { - final static boolean VERBOSE = Boolean.getBoolean("Migration.VERBOSE"); + private static final Logger logger = LogService.getLogger(); + + static final boolean VERBOSE = Boolean.getBoolean("Migration.VERBOSE"); + + // version for backward communications compatibility + private static final int VERSION = 551; - final static int VERSION = 551; // version for backward communications compatibility + static final int CODE_ERROR = 0; - protected static final int CODE_ERROR = 0; - protected static final int CODE_ENTRY = 1; /* serialized key, serialized value */ - protected static final int CODE_COMPLETED = 2; + /* serialized key, serialized value */ + static final int CODE_ENTRY = 1; + + static final int CODE_COMPLETED = 2; public static void main(String[] args) throws Exception { int argIdx = 0; String cacheXmlFileName = "cache.xml"; - String bindAddressName = null; - int listenPort = 10533; if (args.length > 0) { cacheXmlFileName = args[argIdx++]; } else { System.err.println("MigrationServer cache-xml-file [server-address] [server-port]"); } + int listenPort = 10533; if (args.length > argIdx) { listenPort = Integer.parseInt(args[argIdx++]); } + String bindAddressName = null; if (args.length > argIdx) { bindAddressName = args[argIdx++]; } @@ -136,15 +154,13 @@ public class MigrationServer { instance.serve(); } - private InetAddress bindAddress; - private int listenPort; + private final int listenPort; private ServerSocket serverSocket; private DistributedSystem distributedSystem; private File cacheXmlFile; private Cache cache; - /** * Create a MigrationServer to be used with a DistributedSystem and Cache that are created using * GemFire APIs @@ -152,18 +168,18 @@ public class MigrationServer { * @param bindAddressName the NIC to bind to, or null to use all interfaces * @param listenPort the port to listen on */ - public MigrationServer(String bindAddressName, int listenPort) { + private MigrationServer(String bindAddressName, int listenPort) { this.listenPort = listenPort; if (bindAddressName != null) { if (!isLocalHost(bindAddressName)) { throw new IllegalArgumentException( - "Error - bind address is not an address of this machine: '" + bindAddressName + "'"); + "Error - bind address is not an address of this machine: '" + bindAddressName + '\''); } try { this.bindAddress = InetAddress.getByName(bindAddressName); - } catch (IOException e) { + } catch (IOException ignore) { throw new IllegalArgumentException( - "Error - bind address cannot be resolved: '" + bindAddressName + "'"); + "Error - bind address cannot be resolved: '" + bindAddressName + '\''); } } try { @@ -175,7 +191,7 @@ public class MigrationServer { this.serverSocket = new ServerSocket(listenPort); } if (VERBOSE) { - System.out.println("created server socket " + serverSocket); + System.out.println("created server socket " + this.serverSocket); } } catch (IOException e) { throw new IllegalArgumentException("Port is already in use", e); @@ -194,7 +210,8 @@ public class MigrationServer { this.cacheXmlFile = new File(cacheXmlFileName); if (!this.cacheXmlFile.exists()) { // in 6.x this should be localizable - System.err.println("Warning - file not found in local directory: '" + cacheXmlFileName + "'"); + System.err + .println("Warning - file not found in local directory: '" + cacheXmlFileName + '\''); } } @@ -221,7 +238,6 @@ public class MigrationServer { } } - /** * create the cache to be used by this migration server * @@ -237,7 +253,6 @@ public class MigrationServer { } } - /** * This locates the distributed system and cache, if they have not been created by this server, * and then listens for requests from MigrationClient processes. @@ -269,16 +284,16 @@ public class MigrationServer { Socket clientSocket; try { clientSocket = this.serverSocket.accept(); - } catch (java.net.SocketException e) { + } catch (SocketException ignored) { return; } - (new RequestHandler(clientSocket)).serveClientRequest(); + new RequestHandler(clientSocket).serveClientRequest(); } } finally { System.out.println("Closing migration server"); try { this.serverSocket.close(); - } catch (Exception e) { + } catch (Exception ignore) { this.serverSocket = null; } } @@ -315,8 +330,6 @@ public class MigrationServer { return this.distributedSystem; } - - // copied from 6.0 SocketCreator public static boolean isLocalHost(Object host) { if (host instanceof InetAddress) { @@ -324,11 +337,11 @@ public class MigrationServer { return true; } else { try { - Enumeration en = NetworkInterface.getNetworkInterfaces(); + Enumeration en = NetworkInterface.getNetworkInterfaces(); while (en.hasMoreElements()) { - NetworkInterface i = (NetworkInterface) en.nextElement(); - for (Enumeration en2 = i.getInetAddresses(); en2.hasMoreElements();) { - InetAddress addr = (InetAddress) en2.nextElement(); + NetworkInterface i = en.nextElement(); + for (Enumeration en2 = i.getInetAddresses(); en2.hasMoreElements();) { + InetAddress addr = en2.nextElement(); if (host.equals(addr)) { return true; } @@ -353,21 +366,16 @@ public class MigrationServer { return null; } try { - if (host.indexOf("/") > -1) { - return InetAddress.getByName(host.substring(host.indexOf("/") + 1)); + if (host.contains("/")) { + return InetAddress.getByName(host.substring(host.indexOf('/') + 1)); } else { return InetAddress.getByName(host); } - } catch (java.net.UnknownHostException e) { + } catch (UnknownHostException e) { throw new IllegalArgumentException(e.getMessage()); } } - - - // R E Q U E S T H A N D L E R - - class RequestHandler implements Runnable { Socket clientSocket; DataInputStream dis; @@ -375,11 +383,10 @@ public class MigrationServer { RequestHandler(Socket clientSocket) throws IOException { this.clientSocket = clientSocket; - dos = new DataOutputStream(this.clientSocket.getOutputStream()); - dis = new DataInputStream(this.clientSocket.getInputStream()); + this.dos = new DataOutputStream(this.clientSocket.getOutputStream()); + this.dis = new DataInputStream(this.clientSocket.getInputStream()); } - // for now this is a blocking operation - multithread later if necessary void serveClientRequest() { try { @@ -389,65 +396,57 @@ public class MigrationServer { try { this.clientSocket.close(); } catch (IOException e) { - e.printStackTrace(); + logger.debug(e); } } } } + @Override public void run() { try { // first exchange version information so we can communicate correctly - dos.writeShort(VERSION); - int version = dis.readShort(); + this.dos.writeShort(VERSION); + int version = this.dis.readShort(); handleRequest(version); } catch (IOException e) { System.err.println("Trouble dispatching request: " + e.getMessage()); - return; } finally { try { this.clientSocket.close(); } catch (IOException e) { - System.err.println("Trouble closing client socket: " + e.getMessage()); + logger.debug("Trouble closing client socket", e); } } } /** * read and dispatch a single request on client socket - * - * @param clientVersion */ private void handleRequest(int clientVersion) { // for now we ignore the client version in the server. The client // is typically of a later release than the server, and this information // is given to the server in case a situation arises where it's needed try { - ClientRequest req = ClientRequest.readRequest(this.clientSocket, dis, dos); + ClientRequest req = ClientRequest.readRequest(this.clientSocket, this.dis, this.dos); if (req != null) { System.out.println( "Processing " + req + " from " + this.clientSocket.getInetAddress().getHostAddress()); req.process(MigrationServer.this); - dos.flush(); + this.dos.flush(); } } catch (IOException e) { - e.printStackTrace(); + logger.debug(e); } } - } - - // R E Q U E S T C L A S S E S - - - - static abstract class ClientRequest { + abstract static class ClientRequest { Socket clientSocket; DataInputStream dsi; DataOutputStream dso; - final static int REGION_REQUEST = 1; + static final int REGION_REQUEST = 1; /** * Use readRequest to create a new request object, not this constructor. Subclasses may refine @@ -467,11 +466,9 @@ public class MigrationServer { /** * Read and return a request from a client * - * @param clientSocket * @param dsi socket input stream * @param dso socket output stream * @return the new request - * @throws IOException */ static ClientRequest readRequest(Socket clientSocket, DataInputStream dsi, DataOutputStream dso) throws IOException { @@ -480,8 +477,8 @@ public class MigrationServer { case REGION_REQUEST: return new RegionRequest(clientSocket, dsi, dso); } - String errorMessage = "Type of request is not implemented in this server"; dso.writeShort(CODE_ERROR); + String errorMessage = "Type of request is not implemented in this server"; dso.writeUTF(errorMessage); System.err.println("Migration server received unknown type of request (" + requestType + ") from " + clientSocket.getInetAddress().getHostAddress()); @@ -494,7 +491,6 @@ public class MigrationServer { } abstract void process(MigrationServer server) throws IOException; - } /** @@ -506,12 +502,12 @@ public class MigrationServer { RegionRequest(Socket clientSocket, DataInputStream dsi, DataOutputStream dso) throws IOException { super(clientSocket, dsi, dso); - regionName = dsi.readUTF(); + this.regionName = dsi.readUTF(); } @Override public String toString() { - return "request for contents of region '" + this.regionName + "'"; + return "request for contents of region '" + this.regionName + '\''; } @Override @@ -519,7 +515,7 @@ public class MigrationServer { Cache cache = server.getCache(); Region region = null; try { - region = cache.getRegion(regionName); + region = cache.getRegion(this.regionName); if (region == null) { String errorMessage = "Error: region " + this.regionName + " not found in cache"; System.err.println(errorMessage); @@ -527,12 +523,12 @@ public class MigrationServer { } } catch (IllegalArgumentException e) { String errorMessage = "Error: malformed region name"; - System.err.println(errorMessage); + logger.warn(errorMessage, e); writeErrorResponse(errorMessage); } try { - for (Iterator it = region.entrySet().iterator(); it.hasNext();) { - sendEntry((Region.Entry) it.next()); + for (Object o : region.entrySet()) { + sendEntry((Entry) o); } this.dso.writeShort(CODE_COMPLETED); } catch (Exception e) { @@ -540,22 +536,21 @@ public class MigrationServer { } } - private void sendEntry(Region.Entry entry) throws Exception { + private void sendEntry(Region.Entry entry) throws IOException { Object key = entry.getKey(); Object value = entry.getValue(); if (!(key instanceof Serializable)) { - throw new IOException("Could not serialize entry for '" + key + "'"); + throw new IOException("Could not serialize entry for '" + key + '\''); } if (!(value instanceof Serializable)) { - throw new IOException("Could not serialize entry for '" + key + "'"); + throw new IOException("Could not serialize entry for '" + key + '\''); } if (VERBOSE) { System.out.println("Sending " + key); } - dso.writeShort(CODE_ENTRY); - (new ObjectOutputStream(clientSocket.getOutputStream())).writeObject(key); - (new ObjectOutputStream(clientSocket.getOutputStream())).writeObject(value); + this.dso.writeShort(CODE_ENTRY); + new ObjectOutputStream(clientSocket.getOutputStream()).writeObject(key); + new ObjectOutputStream(clientSocket.getOutputStream()).writeObject(value); } } - } http://git-wip-us.apache.org/repos/asf/geode/blob/4b489e56/geode-core/src/main/java/org/apache/geode/internal/PdxSerializerObject.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/PdxSerializerObject.java b/geode-core/src/main/java/org/apache/geode/internal/PdxSerializerObject.java index bbb3d4c..e299fbc 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/PdxSerializerObject.java +++ b/geode-core/src/main/java/org/apache/geode/internal/PdxSerializerObject.java @@ -20,7 +20,7 @@ package org.apache.geode.internal; * org.apache package. * * This is necessary because we exclude all other objects from the org.apache package. See - * {@link InternalDataSerializer#writePdx(java.io.DataOutput, org.apache.geode.internal.cache.GemFireCacheImpl, Object, org.apache.geode.pdx.PdxSerializer)} + * {@link InternalDataSerializer#writePdx(java.io.DataOutput, org.apache.geode.internal.cache.InternalCache, Object, org.apache.geode.pdx.PdxSerializer)} * * */ http://git-wip-us.apache.org/repos/asf/geode/blob/4b489e56/geode-core/src/main/java/org/apache/geode/internal/admin/ClientHealthMonitoringRegion.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/admin/ClientHealthMonitoringRegion.java b/geode-core/src/main/java/org/apache/geode/internal/admin/ClientHealthMonitoringRegion.java index ad33588..b1ae54d 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/admin/ClientHealthMonitoringRegion.java +++ b/geode-core/src/main/java/org/apache/geode/internal/admin/ClientHealthMonitoringRegion.java @@ -22,53 +22,53 @@ import org.apache.geode.cache.Region; import org.apache.geode.cache.RegionAttributes; import org.apache.geode.cache.Scope; import org.apache.geode.cache.util.CacheListenerAdapter; -import org.apache.geode.internal.cache.GemFireCacheImpl; +import org.apache.geode.internal.cache.InternalCache; import org.apache.geode.internal.cache.InternalRegionArguments; import org.apache.geode.internal.i18n.LocalizedStrings; /** * This is an admin (meta) region used by the client health monitoring service to publish the client * health details to the cache-server. - * */ - public class ClientHealthMonitoringRegion { - public final static String ADMIN_REGION_NAME = "__ADMIN_CLIENT_HEALTH_MONITORING__"; - public final static int ADMIN_REGION_EXPIRY_INTERVAL = 20; + static final String ADMIN_REGION_NAME = "__ADMIN_CLIENT_HEALTH_MONITORING__"; + + static final int ADMIN_REGION_EXPIRY_INTERVAL = 20; /** * Instance for current cache - * - * @guarded.By ClientHealthMonitoringRegion.class + *

+ * GuardedBy ClientHealthMonitoringRegion.class */ - static Region currentInstance; + private static Region currentInstance; /** * This is an accessor method used to get the reference of this region. If this region is not yet * initialized, then it attempts to create it. * - * @param c the Cache we are currently using + * @param cache the Cache we are currently using * @return ClientHealthMonitoringRegion reference. */ - public static synchronized Region getInstance(GemFireCacheImpl c) { - if (currentInstance != null && currentInstance.getCache() == c && !c.isClosed()) { + public static synchronized Region getInstance(InternalCache cache) { + if (currentInstance != null && currentInstance.getCache() == cache && !cache.isClosed()) { return currentInstance; } - if (c == null || c.isClosed()) { + if (cache == null || cache.isClosed()) { return null; // give up } - initialize(c); + initialize(cache); return currentInstance; } /** * This method creates the client health monitoring region. - * + *

+ * GuardedBy ClientHealthMonitoringRegion.class + * * @param cache The current GemFire Cache - * @guarded.By ClientHealthMonitoringRegion.class */ - private static void initialize(GemFireCacheImpl cache) { + private static void initialize(InternalCache cache) { try { AttributesFactory factory = new AttributesFactory(); factory.setScope(Scope.LOCAL); http://git-wip-us.apache.org/repos/asf/geode/blob/4b489e56/geode-core/src/main/java/org/apache/geode/internal/admin/ClientStatsManager.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/admin/ClientStatsManager.java b/geode-core/src/main/java/org/apache/geode/internal/admin/ClientStatsManager.java index de6a43a..4276500 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/admin/ClientStatsManager.java +++ b/geode-core/src/main/java/org/apache/geode/internal/admin/ClientStatsManager.java @@ -15,7 +15,6 @@ package org.apache.geode.internal.admin; import java.util.Date; -import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; @@ -25,7 +24,6 @@ import org.apache.geode.cache.CacheWriterException; import org.apache.geode.cache.Region; import org.apache.geode.cache.client.internal.PoolImpl; import org.apache.geode.cache.client.internal.ServerRegionProxy; -import org.apache.geode.cache.query.CqQuery; import org.apache.geode.distributed.DistributedSystemDisconnectedException; import org.apache.geode.distributed.internal.InternalDistributedSystem; import org.apache.geode.i18n.LogWriterI18n; @@ -33,30 +31,30 @@ import org.apache.geode.internal.admin.remote.ClientHealthStats; import org.apache.geode.internal.cache.EntryEventImpl; import org.apache.geode.internal.cache.EventID; import org.apache.geode.internal.cache.GemFireCacheImpl; +import org.apache.geode.internal.cache.InternalCache; import org.apache.geode.internal.i18n.LocalizedStrings; import org.apache.geode.internal.offheap.annotations.Released; import org.apache.geode.management.internal.cli.CliUtil; /** * This class publishes the client statistics using the admin region. - * */ public class ClientStatsManager { /** * Last cache that was initialized * - * @guarded.By ClientStatsManager.class + * GuardedBy ClientStatsManager.class */ - static GemFireCacheImpl lastInitializedCache = null; + private static InternalCache lastInitializedCache = null; /** - * @guarded.By ClientStatsManager.class + * GuardedBy ClientStatsManager.class */ private static Statistics cachePerfStats = null; /** - * @guarded.By ClientStatsManager.class + * GuardedBy ClientStatsManager.class */ private static Statistics vmStats = null; @@ -66,7 +64,7 @@ public class ClientStatsManager { * @param pool Connection pool which may be used for admin region. */ public static synchronized void publishClientStats(PoolImpl pool) { - GemFireCacheImpl currentCache = GemFireCacheImpl.getInstance(); + InternalCache currentCache = GemFireCacheImpl.getInstance(); if (!initializeStatistics(currentCache)) { return; // handles null case too } @@ -106,9 +104,9 @@ public class ClientStatsManager { logger.info(LocalizedStrings.ClientStatsManager_FAILED_TO_PUBLISH_CLIENT_STATISTICS, e); } - if (logger.fineEnabled()) + if (logger.fineEnabled()) { logger.fine("Exiting ClientStatsManager#publishClientStats."); - + } } public static void cleanupForTests() { @@ -117,12 +115,12 @@ public class ClientStatsManager { /** * This method initializes the client statistics to be queried. - * + * + * GuardedBy ClientStatsManager.class + * * @return true if statistics correctly initialized - * @guarded.By ClientStatsManager.class */ - private static boolean initializeStatistics(GemFireCacheImpl currentCache) { - + private static boolean initializeStatistics(InternalCache currentCache) { if (currentCache == null) { return false; } @@ -176,7 +174,6 @@ public class ClientStatsManager { "VMStats"); } - return true; } @@ -186,86 +183,81 @@ public class ClientStatsManager { * * @return the client health stats object to be published to the server. */ - private static ClientHealthStats getClientHealthStats(GemFireCacheImpl currentCache, - PoolImpl pool) { + private static ClientHealthStats getClientHealthStats(InternalCache currentCache, PoolImpl pool) { if (currentCache == null) { return null; } ClientHealthStats stats = new ClientHealthStats(); LogWriterI18n logger = currentCache.getLoggerI18n(); - { - int gets = -1; - int puts = -1; - int misses = -1; - long processCpuTime = -1; - int threads = -1; - int cacheListenerCalls = -1; - int cpus = -1; - String poolName = ""; - - if (cachePerfStats != null) { - gets = cachePerfStats.getInt("gets"); - puts = cachePerfStats.getInt("puts"); - misses = cachePerfStats.getInt("misses"); - cacheListenerCalls = cachePerfStats.getInt("cacheListenerCallsCompleted"); - } - - if (vmStats != null) { - processCpuTime = vmStats.getLong("processCpuTime"); - threads = vmStats.getInt("threads"); - cpus = vmStats.getInt("cpus"); - } - stats.setNumOfGets(gets); - stats.setNumOfPuts(puts); - stats.setNumOfMisses(misses); - stats.setNumOfCacheListenerCalls(cacheListenerCalls); - stats.setProcessCpuTime(processCpuTime); - stats.setNumOfThreads(threads); - stats.setCpus(cpus); + int gets = -1; + int puts = -1; + int misses = -1; + int cacheListenerCalls = -1; - poolName = pool.getName(); - try { - Map newPoolStats = stats.getPoolStats(); - String poolStatsStr = "MinConnections=" + pool.getMinConnections() + ";MaxConnections=" - + pool.getMaxConnections() + ";Redudancy=" + pool.getSubscriptionRedundancy() + ";CQS=" - + pool.getQueryService().getCqs().length; - logger.info(LocalizedStrings.DEBUG, - "ClientHealthStats for poolname " + poolName + " poolStatsStr=" + poolStatsStr); + if (cachePerfStats != null) { + gets = cachePerfStats.getInt("gets"); + puts = cachePerfStats.getInt("puts"); + misses = cachePerfStats.getInt("misses"); + cacheListenerCalls = cachePerfStats.getInt("cacheListenerCallsCompleted"); + } - newPoolStats.put(poolName, poolStatsStr); + long processCpuTime = -1; + int threads = -1; + int cpus = -1; + if (vmStats != null) { + processCpuTime = vmStats.getLong("processCpuTime"); + threads = vmStats.getInt("threads"); + cpus = vmStats.getInt("cpus"); + } - // consider old stats - Region clientHealthMonitoringRegion = - ClientHealthMonitoringRegion.getInstance(currentCache); + stats.setNumOfGets(gets); + stats.setNumOfPuts(puts); + stats.setNumOfMisses(misses); + stats.setNumOfCacheListenerCalls(cacheListenerCalls); + stats.setProcessCpuTime(processCpuTime); + stats.setNumOfThreads(threads); + stats.setCpus(cpus); - if (clientHealthMonitoringRegion != null) { - InternalDistributedSystem ds = - (InternalDistributedSystem) currentCache.getDistributedSystem(); - ClientHealthStats oldStats = - (ClientHealthStats) clientHealthMonitoringRegion.get(ds.getMemberId()); - logger.info(LocalizedStrings.DEBUG, "getClientHealthStats got oldStats " + oldStats); - if (oldStats != null) { - Map oldPoolStats = oldStats.getPoolStats(); - logger.info(LocalizedStrings.DEBUG, - "getClientHealthStats got oldPoolStats " + oldPoolStats); - if (oldPoolStats != null) { - Iterator> it = oldPoolStats.entrySet().iterator(); - while (it.hasNext()) { - Entry entry = it.next(); - if (!poolName.equals(entry.getKey())) { - stats.getPoolStats().put(entry.getKey(), entry.getValue()); - } + String poolName = pool.getName(); + try { + Map newPoolStats = stats.getPoolStats(); + String poolStatsStr = "MinConnections=" + pool.getMinConnections() + ";MaxConnections=" + + pool.getMaxConnections() + ";Redundancy=" + pool.getSubscriptionRedundancy() + ";CQS=" + + pool.getQueryService().getCqs().length; + logger.info(LocalizedStrings.DEBUG, + "ClientHealthStats for poolName " + poolName + " poolStatsStr=" + poolStatsStr); + + newPoolStats.put(poolName, poolStatsStr); + + // consider old stats + Region clientHealthMonitoringRegion = ClientHealthMonitoringRegion.getInstance(currentCache); + + if (clientHealthMonitoringRegion != null) { + InternalDistributedSystem ds = + (InternalDistributedSystem) currentCache.getDistributedSystem(); + ClientHealthStats oldStats = + (ClientHealthStats) clientHealthMonitoringRegion.get(ds.getMemberId()); + logger.info(LocalizedStrings.DEBUG, "getClientHealthStats got oldStats " + oldStats); + if (oldStats != null) { + Map oldPoolStats = oldStats.getPoolStats(); + logger.info(LocalizedStrings.DEBUG, + "getClientHealthStats got oldPoolStats " + oldPoolStats); + if (oldPoolStats != null) { + for (Entry entry : oldPoolStats.entrySet()) { + if (!poolName.equals(entry.getKey())) { + stats.getPoolStats().put(entry.getKey(), entry.getValue()); } } } } - - } catch (Exception e) { - logger.fine("Exception in getting pool stats in getClientHealthStats " - + CliUtil.stackTraceAsString(e)); } + + } catch (Exception e) { + logger.fine("Exception in getting pool stats in getClientHealthStats " + + CliUtil.stackTraceAsString(e)); } + stats.setUpdateTime(new Date()); return stats; } http://git-wip-us.apache.org/repos/asf/geode/blob/4b489e56/geode-core/src/main/java/org/apache/geode/internal/admin/remote/BridgeServerResponse.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/admin/remote/BridgeServerResponse.java b/geode-core/src/main/java/org/apache/geode/internal/admin/remote/BridgeServerResponse.java index aeb5e95..4e915d6 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/admin/remote/BridgeServerResponse.java +++ b/geode-core/src/main/java/org/apache/geode/internal/admin/remote/BridgeServerResponse.java @@ -14,15 +14,18 @@ */ package org.apache.geode.internal.admin.remote; +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; + import org.apache.geode.CancelException; import org.apache.geode.DataSerializer; import org.apache.geode.cache.CacheFactory; +import org.apache.geode.cache.server.CacheServer; import org.apache.geode.distributed.internal.DistributionManager; import org.apache.geode.internal.Assert; import org.apache.geode.internal.cache.CacheServerImpl; -import org.apache.geode.internal.cache.GemFireCacheImpl; -import java.io.*; -import java.util.*; +import org.apache.geode.internal.cache.InternalCache; /** * A message that is sent in response to a {@link BridgeServerResponse}. It perform an operation on @@ -38,17 +41,15 @@ public final class BridgeServerResponse extends AdminResponse { /** An exception thrown while performing the operation */ private Exception exception; - ////////////////////// Static Methods ////////////////////// - /** - * Creates a BridgeServerResponse in response to the given request. + * Creates a {@code BridgeServerResponse} in response to the given request. */ static BridgeServerResponse create(DistributionManager dm, BridgeServerRequest request) { BridgeServerResponse m = new BridgeServerResponse(); m.setRecipient(request.getSender()); try { - GemFireCacheImpl cache = (GemFireCacheImpl) CacheFactory.getInstanceCloseOk(dm.getSystem()); + InternalCache cache = (InternalCache) CacheFactory.getInstanceCloseOk(dm.getSystem()); if (request.getCacheId() != System.identityHashCode(cache)) { m.bridgeInfo = null; @@ -66,8 +67,8 @@ public final class BridgeServerResponse extends AdminResponse { int id = request.getBridgeId(); // Note that since this is only an informational request // it is not necessary to synchronize on allBridgeServersLock - for (Iterator iter = cache.getCacheServers().iterator(); iter.hasNext();) { - CacheServerImpl bridge = (CacheServerImpl) iter.next(); + for (CacheServer cacheServer : cache.getCacheServers()) { + CacheServerImpl bridge = (CacheServerImpl) cacheServer; if (System.identityHashCode(bridge) == id) { m.bridgeInfo = new RemoteBridgeServer(bridge); break; @@ -81,8 +82,8 @@ public final class BridgeServerResponse extends AdminResponse { case BridgeServerRequest.START_OPERATION: { RemoteBridgeServer config = request.getBridgeInfo(); - for (Iterator iter = cache.getCacheServers().iterator(); iter.hasNext();) { - CacheServerImpl bridge = (CacheServerImpl) iter.next(); + for (CacheServer cacheServer : cache.getCacheServers()) { + CacheServerImpl bridge = (CacheServerImpl) cacheServer; if (System.identityHashCode(bridge) == config.getId()) { bridge.configureFrom(config); bridge.start(); @@ -98,8 +99,8 @@ public final class BridgeServerResponse extends AdminResponse { case BridgeServerRequest.STOP_OPERATION: { RemoteBridgeServer config = request.getBridgeInfo(); - for (Iterator iter = cache.getCacheServers().iterator(); iter.hasNext();) { - CacheServerImpl bridge = (CacheServerImpl) iter.next(); + for (CacheServer cacheServer : cache.getCacheServers()) { + CacheServerImpl bridge = (CacheServerImpl) cacheServer; if (System.identityHashCode(bridge) == config.getId()) { bridge.stop(); m.bridgeInfo = new RemoteBridgeServer(bridge); @@ -115,10 +116,9 @@ public final class BridgeServerResponse extends AdminResponse { default: Assert.assertTrue(false, "Unknown bridge server operation: " + operation); } - } - } catch (CancelException ex) { + } catch (CancelException ignore) { m.bridgeInfo = null; } catch (Exception ex) { @@ -128,12 +128,10 @@ public final class BridgeServerResponse extends AdminResponse { return m; } - ////////////////////// Instance Methods ////////////////////// - /** * Returns information about the bridge operated on */ - public RemoteBridgeServer getBridgeInfo() { + RemoteBridgeServer getBridgeInfo() { return this.bridgeInfo; } @@ -144,6 +142,7 @@ public final class BridgeServerResponse extends AdminResponse { return this.exception; } + @Override public int getDSFID() { return BRIDGE_SERVER_RESPONSE; } @@ -158,8 +157,7 @@ public final class BridgeServerResponse extends AdminResponse { @Override public void fromData(DataInput in) throws IOException, ClassNotFoundException { super.fromData(in); - this.bridgeInfo = (RemoteBridgeServer) DataSerializer.readObject(in); - this.exception = (Exception) DataSerializer.readObject(in); + this.bridgeInfo = DataSerializer.readObject(in); + this.exception = DataSerializer.readObject(in); } - } http://git-wip-us.apache.org/repos/asf/geode/blob/4b489e56/geode-core/src/main/java/org/apache/geode/internal/admin/remote/CacheConfigResponse.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/admin/remote/CacheConfigResponse.java b/geode-core/src/main/java/org/apache/geode/internal/admin/remote/CacheConfigResponse.java index b806405..aedf67e 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/admin/remote/CacheConfigResponse.java +++ b/geode-core/src/main/java/org/apache/geode/internal/admin/remote/CacheConfigResponse.java @@ -12,20 +12,19 @@ * or implied. See the License for the specific language governing permissions and limitations under * the License. */ - - package org.apache.geode.internal.admin.remote; -// import org.apache.geode.internal.admin.*; -import org.apache.geode.distributed.internal.*; -import org.apache.geode.*; -import org.apache.geode.cache.*; -import org.apache.geode.internal.*; -import org.apache.geode.internal.cache.*; -import java.io.*; -// import java.net.*; -// import java.util.*; -import org.apache.geode.distributed.internal.membership.*; +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; + +import org.apache.geode.CancelException; +import org.apache.geode.DataSerializer; +import org.apache.geode.cache.CacheFactory; +import org.apache.geode.distributed.internal.DistributionManager; +import org.apache.geode.distributed.internal.membership.InternalDistributedMember; +import org.apache.geode.internal.Assert; +import org.apache.geode.internal.cache.InternalCache; /** * A message that is sent in response to a {@link CacheConfigRequest}. @@ -33,7 +32,7 @@ import org.apache.geode.distributed.internal.membership.*; * @since GemFire 3.5 */ public final class CacheConfigResponse extends AdminResponse { - // instance variables + private RemoteCacheInfo info; /** @@ -44,14 +43,14 @@ public final class CacheConfigResponse extends AdminResponse { private Exception exception; /** - * Returns a CacheConfigResponse that will be returned to the specified recipient. + * Returns a {@code CacheConfigResponse} that will be returned to the specified recipient. */ public static CacheConfigResponse create(DistributionManager dm, InternalDistributedMember recipient, int cacheId, byte attributeCode, int newValue) { CacheConfigResponse m = new CacheConfigResponse(); m.setRecipient(recipient); try { - GemFireCacheImpl c = (GemFireCacheImpl) CacheFactory.getInstanceCloseOk(dm.getSystem()); + InternalCache c = (InternalCache) CacheFactory.getInstanceCloseOk(dm.getSystem()); if (cacheId != System.identityHashCode(c)) { m.info = null; } else { @@ -70,7 +69,7 @@ public final class CacheConfigResponse extends AdminResponse { } } m.info = new RemoteCacheInfo(c); - } catch (CancelException ex) { + } catch (CancelException ignore) { m.info = null; } catch (Exception ex) { @@ -80,7 +79,7 @@ public final class CacheConfigResponse extends AdminResponse { return m; } - public RemoteCacheInfo getCacheInfo() { + RemoteCacheInfo getCacheInfo() { return this.info; } @@ -91,6 +90,7 @@ public final class CacheConfigResponse extends AdminResponse { return this.exception; } + @Override public int getDSFID() { return CACHE_CONFIG_RESPONSE; } @@ -105,8 +105,8 @@ public final class CacheConfigResponse extends AdminResponse { @Override public void fromData(DataInput in) throws IOException, ClassNotFoundException { super.fromData(in); - this.info = (RemoteCacheInfo) DataSerializer.readObject(in); - this.exception = (Exception) DataSerializer.readObject(in); + this.info = DataSerializer.readObject(in); + this.exception = DataSerializer.readObject(in); } @Override http://git-wip-us.apache.org/repos/asf/geode/blob/4b489e56/geode-core/src/main/java/org/apache/geode/internal/admin/remote/CacheInfoResponse.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/admin/remote/CacheInfoResponse.java b/geode-core/src/main/java/org/apache/geode/internal/admin/remote/CacheInfoResponse.java index ffa6f09..5a5c36c 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/admin/remote/CacheInfoResponse.java +++ b/geode-core/src/main/java/org/apache/geode/internal/admin/remote/CacheInfoResponse.java @@ -12,20 +12,18 @@ * or implied. See the License for the specific language governing permissions and limitations under * the License. */ - - package org.apache.geode.internal.admin.remote; -// import org.apache.geode.internal.admin.*; -import org.apache.geode.distributed.internal.*; -import org.apache.geode.*; -import org.apache.geode.cache.*; -// import org.apache.geode.internal.*; -import org.apache.geode.internal.cache.*; -import java.io.*; -// import java.net.*; -// import java.util.*; -import org.apache.geode.distributed.internal.membership.*; +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; + +import org.apache.geode.CancelException; +import org.apache.geode.DataSerializer; +import org.apache.geode.cache.CacheFactory; +import org.apache.geode.distributed.internal.DistributionManager; +import org.apache.geode.distributed.internal.membership.InternalDistributedMember; +import org.apache.geode.internal.cache.InternalCache; /** * A message that is sent in response to a {@link CacheInfoRequest}. @@ -33,30 +31,30 @@ import org.apache.geode.distributed.internal.membership.*; * @since GemFire 3.5 */ public final class CacheInfoResponse extends AdminResponse { - // instance variables - private RemoteCacheInfo info; + private RemoteCacheInfo info; /** - * Returns a CacheInfoResponse that will be returned to the specified recipient. + * Returns a {@code CacheInfoResponse} that will be returned to the specified recipient. */ public static CacheInfoResponse create(DistributionManager dm, InternalDistributedMember recipient) { CacheInfoResponse m = new CacheInfoResponse(); m.setRecipient(recipient); try { - GemFireCacheImpl c = (GemFireCacheImpl) CacheFactory.getInstanceCloseOk(dm.getSystem()); + InternalCache c = (InternalCache) CacheFactory.getInstanceCloseOk(dm.getSystem()); m.info = new RemoteCacheInfo(c); - } catch (CancelException ex) { + } catch (CancelException ignore) { m.info = null; } return m; } - public RemoteCacheInfo getCacheInfo() { + RemoteCacheInfo getCacheInfo() { return this.info; } + @Override public int getDSFID() { return CACHE_INFO_RESPONSE; } http://git-wip-us.apache.org/repos/asf/geode/blob/4b489e56/geode-core/src/main/java/org/apache/geode/internal/admin/remote/CompactRequest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/admin/remote/CompactRequest.java b/geode-core/src/main/java/org/apache/geode/internal/admin/remote/CompactRequest.java index 6894903..de0e301 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/admin/remote/CompactRequest.java +++ b/geode-core/src/main/java/org/apache/geode/internal/admin/remote/CompactRequest.java @@ -24,7 +24,10 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; +import org.apache.logging.log4j.Logger; + import org.apache.geode.CancelException; +import org.apache.geode.cache.DiskStore; import org.apache.geode.cache.persistence.PersistentID; import org.apache.geode.distributed.DistributedMember; import org.apache.geode.distributed.internal.DM; @@ -33,14 +36,19 @@ import org.apache.geode.distributed.internal.DistributionMessage; import org.apache.geode.distributed.internal.ReplyException; import org.apache.geode.internal.cache.DiskStoreImpl; import org.apache.geode.internal.cache.GemFireCacheImpl; +import org.apache.geode.internal.cache.InternalCache; +import org.apache.geode.internal.logging.LogService; import org.apache.geode.internal.util.ArrayUtils; /** * An instruction to all members with cache that they should compact their disk stores. - * */ public class CompactRequest extends CliLegacyMessage { - public CompactRequest() {} + private static final Logger logger = LogService.getLogger(); + + public CompactRequest() { + // do nothing + } public static Map> send(DM dm) { Set recipients = dm.getOtherDistributionManagerIds(); @@ -61,7 +69,7 @@ public class CompactRequest extends CliLegacyMessage { throw e; } } catch (InterruptedException e) { - e.printStackTrace(); + logger.warn(e); } return replyProcessor.results; @@ -74,12 +82,12 @@ public class CompactRequest extends CliLegacyMessage { @Override protected AdminResponse createResponse(DistributionManager dm) { - GemFireCacheImpl cache = GemFireCacheImpl.getInstance(); - HashSet compactedStores = new HashSet(); + InternalCache cache = GemFireCacheImpl.getInstance(); + HashSet compactedStores = new HashSet<>(); if (cache != null && !cache.isClosed()) { - for (DiskStoreImpl store : cache.listDiskStoresIncludingRegionOwned()) { + for (DiskStore store : cache.listDiskStoresIncludingRegionOwned()) { if (store.forceCompaction()) { - compactedStores.add(store.getPersistentID()); + compactedStores.add(((DiskStoreImpl) store).getPersistentID()); } } } @@ -87,6 +95,7 @@ public class CompactRequest extends CliLegacyMessage { return new CompactResponse(this.getSender(), compactedStores); } + @Override public int getDSFID() { return COMPACT_REQUEST; } @@ -111,7 +120,7 @@ public class CompactRequest extends CliLegacyMessage { Map> results = Collections.synchronizedMap(new HashMap>()); - public CompactReplyProcessor(DM dm, Collection initMembers) { + CompactReplyProcessor(DM dm, Collection initMembers) { super(dm, initMembers); } @@ -128,14 +137,12 @@ public class CompactRequest extends CliLegacyMessage { @Override protected void process(DistributionMessage msg, boolean warn) { if (msg instanceof CompactResponse) { - final HashSet persistentIds = ((CompactResponse) msg).getPersistentIds(); + final Set persistentIds = ((CompactResponse) msg).getPersistentIds(); if (persistentIds != null && !persistentIds.isEmpty()) { - results.put(msg.getSender(), persistentIds); + this.results.put(msg.getSender(), persistentIds); } } super.process(msg, warn); } - - } } http://git-wip-us.apache.org/repos/asf/geode/blob/4b489e56/geode-core/src/main/java/org/apache/geode/internal/admin/remote/DurableClientInfoResponse.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/admin/remote/DurableClientInfoResponse.java b/geode-core/src/main/java/org/apache/geode/internal/admin/remote/DurableClientInfoResponse.java index ff62b50..6cc6f2f 100755 --- a/geode-core/src/main/java/org/apache/geode/internal/admin/remote/DurableClientInfoResponse.java +++ b/geode-core/src/main/java/org/apache/geode/internal/admin/remote/DurableClientInfoResponse.java @@ -12,18 +12,18 @@ * or implied. See the License for the specific language governing permissions and limitations under * the License. */ - package org.apache.geode.internal.admin.remote; -// import org.apache.geode.internal.admin.*; -import org.apache.geode.distributed.internal.*; -import org.apache.geode.*; -import org.apache.geode.cache.*; // import org.apache.geode.internal.*; -import org.apache.geode.internal.cache.*; +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; -import java.io.*; // import java.net.*; -// import java.util.*; -import org.apache.geode.distributed.internal.membership.*; +import org.apache.geode.cache.CacheClosedException; +import org.apache.geode.cache.CacheFactory; +import org.apache.geode.distributed.internal.DistributionManager; +import org.apache.geode.distributed.internal.membership.InternalDistributedMember; +import org.apache.geode.internal.cache.CacheServerImpl; +import org.apache.geode.internal.cache.InternalCache; /** * A message that is sent in response to a {@link DurableClientInfoRequest}. @@ -38,16 +38,15 @@ public class DurableClientInfoResponse extends AdminResponse { private boolean returnVal = false; /** - * Returns a DurableClientInfoResponse that will be returned to the specified - * recipient. + * Returns a {@code DurableClientInfoResponse} that will be returned to the specified recipient. */ public static DurableClientInfoResponse create(DistributionManager dm, InternalDistributedMember recipient, DurableClientInfoRequest request) { DurableClientInfoResponse m = new DurableClientInfoResponse(); m.setRecipient(recipient); try { - GemFireCacheImpl c = (GemFireCacheImpl) CacheFactory.getInstanceCloseOk(dm.getSystem()); - if (c.getCacheServers().size() > 0) { + InternalCache c = (InternalCache) CacheFactory.getInstanceCloseOk(dm.getSystem()); + if (!c.getCacheServers().isEmpty()) { CacheServerImpl server = (CacheServerImpl) c.getCacheServers().iterator().next(); switch (request.action) { @@ -63,35 +62,34 @@ public class DurableClientInfoResponse extends AdminResponse { } } } - } catch (CacheClosedException ex) { + } catch (CacheClosedException ignore) { // do nothing } return m; } - public boolean getResultBoolean() { + boolean getResultBoolean() { return this.returnVal; } + @Override public void toData(DataOutput out) throws IOException { super.toData(out); out.writeBoolean(this.returnVal); } + @Override public void fromData(DataInput in) throws IOException, ClassNotFoundException { super.fromData(in); this.returnVal = in.readBoolean(); } + @Override public String toString() { return "DurableClientInfoResponse from " + this.getSender(); } - /* - * (non-Javadoc) - * - * @see org.apache.geode.internal.DataSerializableFixedID#getDSFID() - */ + @Override public int getDSFID() { return DURABLE_CLIENT_INFO_RESPONSE; } http://git-wip-us.apache.org/repos/asf/geode/blob/4b489e56/geode-core/src/main/java/org/apache/geode/internal/admin/remote/MissingPersistentIDsRequest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/admin/remote/MissingPersistentIDsRequest.java b/geode-core/src/main/java/org/apache/geode/internal/admin/remote/MissingPersistentIDsRequest.java index f5d9b4f..0e5686b 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/admin/remote/MissingPersistentIDsRequest.java +++ b/geode-core/src/main/java/org/apache/geode/internal/admin/remote/MissingPersistentIDsRequest.java @@ -22,18 +22,20 @@ import java.util.Map; import java.util.Set; import java.util.TreeSet; +import org.apache.logging.log4j.Logger; + import org.apache.geode.CancelException; -import org.apache.geode.cache.CacheFactory; import org.apache.geode.cache.persistence.PersistentID; import org.apache.geode.distributed.internal.DM; import org.apache.geode.distributed.internal.DistributionManager; import org.apache.geode.distributed.internal.DistributionMessage; import org.apache.geode.distributed.internal.ReplyException; -import org.apache.geode.distributed.internal.ReplyProcessor21; import org.apache.geode.internal.cache.GemFireCacheImpl; +import org.apache.geode.internal.cache.InternalCache; import org.apache.geode.internal.cache.persistence.PersistentMemberID; import org.apache.geode.internal.cache.persistence.PersistentMemberManager; import org.apache.geode.internal.cache.persistence.PersistentMemberPattern; +import org.apache.geode.internal.logging.LogService; /** * A request to all members for any persistent members that they are waiting for. TODO prpersist - @@ -41,6 +43,7 @@ import org.apache.geode.internal.cache.persistence.PersistentMemberPattern; * request response to a single member. Maybe we need to a new base class. */ public class MissingPersistentIDsRequest extends CliLegacyMessage { + private static final Logger logger = LogService.getLogger(); public static Set send(DM dm) { Set recipients = dm.getOtherDistributionManagerIds(); @@ -59,12 +62,12 @@ public class MissingPersistentIDsRequest extends CliLegacyMessage { throw e; } } catch (InterruptedException e) { - e.printStackTrace(); + logger.warn(e); } + Set results = replyProcessor.missing; Set existing = replyProcessor.existing; - MissingPersistentIDsResponse localResponse = (MissingPersistentIDsResponse) request.createResponse((DistributionManager) dm); results.addAll(localResponse.getMissingIds()); @@ -76,9 +79,9 @@ public class MissingPersistentIDsRequest extends CliLegacyMessage { @Override protected AdminResponse createResponse(DistributionManager dm) { - Set missingIds = new HashSet(); - Set localPatterns = new HashSet(); - GemFireCacheImpl cache = GemFireCacheImpl.getInstance(); + Set missingIds = new HashSet<>(); + Set localPatterns = new HashSet<>(); + InternalCache cache = GemFireCacheImpl.getInstance(); if (cache != null && !cache.isClosed()) { PersistentMemberManager mm = cache.getPersistentMemberManager(); Map> waitingRegions = mm.getWaitingRegions(); @@ -96,8 +99,6 @@ public class MissingPersistentIDsRequest extends CliLegacyMessage { return new MissingPersistentIDsResponse(missingIds, localPatterns, this.getSender()); } - - @Override public void fromData(DataInput in) throws IOException, ClassNotFoundException { super.fromData(in); @@ -105,10 +106,11 @@ public class MissingPersistentIDsRequest extends CliLegacyMessage { @Override protected Object clone() throws CloneNotSupportedException { - // TODO Auto-generated method stub + // TODO: delete this clone method? return super.clone(); } + @Override public int getDSFID() { return MISSING_PERSISTENT_IDS_REQUEST; } @@ -117,19 +119,15 @@ public class MissingPersistentIDsRequest extends CliLegacyMessage { Set missing = Collections.synchronizedSet(new TreeSet()); Set existing = Collections.synchronizedSet(new TreeSet()); - /** - * @param dm - * @param recipients - */ - public MissingPersistentIDProcessor(DM dm, Set recipients) { + MissingPersistentIDProcessor(DM dm, Set recipients) { super(dm, recipients); } @Override protected void process(DistributionMessage msg, boolean warn) { if (msg instanceof MissingPersistentIDsResponse) { - missing.addAll(((MissingPersistentIDsResponse) msg).getMissingIds()); - existing.addAll(((MissingPersistentIDsResponse) msg).getLocalIds()); + this.missing.addAll(((MissingPersistentIDsResponse) msg).getMissingIds()); + this.existing.addAll(((MissingPersistentIDsResponse) msg).getLocalIds()); } super.process(msg, warn); } http://git-wip-us.apache.org/repos/asf/geode/blob/4b489e56/geode-core/src/main/java/org/apache/geode/internal/admin/remote/PrepareRevokePersistentIDRequest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/admin/remote/PrepareRevokePersistentIDRequest.java b/geode-core/src/main/java/org/apache/geode/internal/admin/remote/PrepareRevokePersistentIDRequest.java index 2f187ef..227fd06 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/admin/remote/PrepareRevokePersistentIDRequest.java +++ b/geode-core/src/main/java/org/apache/geode/internal/admin/remote/PrepareRevokePersistentIDRequest.java @@ -19,6 +19,8 @@ import java.io.DataOutput; import java.io.IOException; import java.util.Set; +import org.apache.logging.log4j.Logger; + import org.apache.geode.CancelException; import org.apache.geode.cache.persistence.RevokeFailedException; import org.apache.geode.distributed.internal.DM; @@ -26,23 +28,27 @@ import org.apache.geode.distributed.internal.DistributionManager; import org.apache.geode.distributed.internal.ReplyException; import org.apache.geode.internal.InternalDataSerializer; import org.apache.geode.internal.cache.GemFireCacheImpl; +import org.apache.geode.internal.cache.InternalCache; import org.apache.geode.internal.cache.persistence.PersistentMemberManager; import org.apache.geode.internal.cache.persistence.PersistentMemberPattern; import org.apache.geode.internal.i18n.LocalizedStrings; +import org.apache.geode.internal.logging.LogService; /** * An instruction to all members that they should forget about the persistent member described by * this pattern. TODO prpersist - This extends AdminRequest, but it doesn't work with most of the * admin paradigm, which is a request response to a single member. Maybe we need to a new base * class. - * */ public class PrepareRevokePersistentIDRequest extends CliLegacyMessage { - PersistentMemberPattern pattern; + private static final Logger logger = LogService.getLogger(); + + private PersistentMemberPattern pattern; + private boolean cancel; public PrepareRevokePersistentIDRequest() { - + // do nothing } public PrepareRevokePersistentIDRequest(PersistentMemberPattern pattern, boolean cancel) { @@ -77,7 +83,7 @@ public class PrepareRevokePersistentIDRequest extends CliLegacyMessage { } throw e; } catch (InterruptedException e) { - e.printStackTrace(); + logger.warn(e); } request.setSender(dm.getId()); request.createResponse((DistributionManager) dm); @@ -85,16 +91,16 @@ public class PrepareRevokePersistentIDRequest extends CliLegacyMessage { @Override protected AdminResponse createResponse(DistributionManager dm) { - GemFireCacheImpl cache = GemFireCacheImpl.getInstance(); + InternalCache cache = GemFireCacheImpl.getInstance(); if (cache != null && !cache.isClosed()) { PersistentMemberManager mm = cache.getPersistentMemberManager(); - if (cancel) { - mm.cancelRevoke(pattern); + if (this.cancel) { + mm.cancelRevoke(this.pattern); } else { - if (!mm.prepareRevoke(pattern, dm, getSender())) { + if (!mm.prepareRevoke(this.pattern, dm, getSender())) { throw new RevokeFailedException( LocalizedStrings.RevokeFailedException_Member_0_is_already_running_1 - .toLocalizedString(dm.getId(), pattern)); + .toLocalizedString(dm.getId(), this.pattern)); } } } @@ -102,6 +108,7 @@ public class PrepareRevokePersistentIDRequest extends CliLegacyMessage { return new RevokePersistentIDResponse(this.getSender()); } + @Override public int getDSFID() { return PREPARE_REVOKE_PERSISTENT_ID_REQUEST; } @@ -109,16 +116,15 @@ public class PrepareRevokePersistentIDRequest extends CliLegacyMessage { @Override public void fromData(DataInput in) throws IOException, ClassNotFoundException { super.fromData(in); - pattern = new PersistentMemberPattern(); - InternalDataSerializer.invokeFromData(pattern, in); - cancel = in.readBoolean(); + this.pattern = new PersistentMemberPattern(); + InternalDataSerializer.invokeFromData(this.pattern, in); + this.cancel = in.readBoolean(); } @Override public void toData(DataOutput out) throws IOException { super.toData(out); - InternalDataSerializer.invokeToData(pattern, out); - out.writeBoolean(cancel); + InternalDataSerializer.invokeToData(this.pattern, out); + out.writeBoolean(this.cancel); } - } http://git-wip-us.apache.org/repos/asf/geode/blob/4b489e56/geode-core/src/main/java/org/apache/geode/internal/admin/remote/RefreshMemberSnapshotResponse.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/admin/remote/RefreshMemberSnapshotResponse.java b/geode-core/src/main/java/org/apache/geode/internal/admin/remote/RefreshMemberSnapshotResponse.java index d7a910b..9e973f9 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/admin/remote/RefreshMemberSnapshotResponse.java +++ b/geode-core/src/main/java/org/apache/geode/internal/admin/remote/RefreshMemberSnapshotResponse.java @@ -12,7 +12,6 @@ * or implied. See the License for the specific language governing permissions and limitations under * the License. */ - package org.apache.geode.internal.admin.remote; import java.io.DataInput; @@ -25,20 +24,19 @@ import org.apache.geode.cache.CacheFactory; import org.apache.geode.distributed.DistributedSystem; import org.apache.geode.distributed.internal.DistributionManager; import org.apache.geode.distributed.internal.membership.InternalDistributedMember; -import org.apache.geode.internal.cache.GemFireCacheImpl; +import org.apache.geode.internal.cache.InternalCache; /** * A message that is sent to a particular distribution manager to get its current * {@link org.apache.geode.admin.GemFireMemberStatus}. - * */ public class RefreshMemberSnapshotResponse extends AdminResponse { - // instance variables + GemFireMemberStatus snapshot; /** - * Returns a FetchSysCfgResponse that will be returned to the specified recipient. - * The message will contains a copy of the local manager's config. + * Returns a {@code FetchSysCfgResponse} that will be returned to the specified recipient. The + * message will contains a copy of the local manager's config. */ public static RefreshMemberSnapshotResponse create(DistributionManager dm, InternalDistributedMember recipient) { @@ -47,9 +45,9 @@ public class RefreshMemberSnapshotResponse extends AdminResponse { try { DistributedSystem sys = dm.getSystem(); - GemFireCacheImpl c = (GemFireCacheImpl) CacheFactory.getInstance(sys); + InternalCache c = (InternalCache) CacheFactory.getInstance(sys); m.snapshot = new GemFireMemberStatus(c); - } catch (Exception ex) { + } catch (Exception ignore) { m.snapshot = null; } return m; @@ -71,17 +69,17 @@ public class RefreshMemberSnapshotResponse extends AdminResponse { @Override public void fromData(DataInput in) throws IOException, ClassNotFoundException { super.fromData(in); - this.snapshot = (GemFireMemberStatus) DataSerializer.readObject(in); + this.snapshot = DataSerializer.readObject(in); } /** * Returns the DataSerializer fixed id for the class that implements this method. */ + @Override public int getDSFID() { return REFRESH_MEMBER_SNAP_RESPONSE; } - @Override public String toString() { return "RefreshMemberSnapshotResponse from " + this.getRecipient() + " snapshot=" http://git-wip-us.apache.org/repos/asf/geode/blob/4b489e56/geode-core/src/main/java/org/apache/geode/internal/admin/remote/RegionSubRegionsSizeResponse.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/admin/remote/RegionSubRegionsSizeResponse.java b/geode-core/src/main/java/org/apache/geode/internal/admin/remote/RegionSubRegionsSizeResponse.java index ba4d848..1ce35ad 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/admin/remote/RegionSubRegionsSizeResponse.java +++ b/geode-core/src/main/java/org/apache/geode/internal/admin/remote/RegionSubRegionsSizeResponse.java @@ -17,7 +17,6 @@ package org.apache.geode.internal.admin.remote; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; -import java.util.Iterator; import java.util.Set; import org.apache.logging.log4j.Logger; @@ -29,25 +28,30 @@ import org.apache.geode.cache.Region; import org.apache.geode.distributed.DistributedSystem; import org.apache.geode.distributed.internal.DistributionManager; import org.apache.geode.distributed.internal.membership.InternalDistributedMember; -import org.apache.geode.internal.cache.GemFireCacheImpl; +import org.apache.geode.internal.cache.InternalCache; import org.apache.geode.internal.logging.LogService; /** * Admin response carrying region info for a member - * */ public class RegionSubRegionsSizeResponse extends AdminResponse implements Cancellable { private static final Logger logger = LogService.getLogger(); - public RegionSubRegionsSizeResponse() {} + private RegionSubRegionSnapshot snapshot; + + private boolean cancelled; + + public RegionSubRegionsSizeResponse() { + // do nothing + } public RegionSubRegionSnapshot getSnapshot() { return this.snapshot; } /** - * Returns a RegionSubRegionsSizeResponse that will be returned to the specified + * Returns a {@code RegionSubRegionsSizeResponse} that will be returned to the specified * recipient. The message will contains a copy of the region snapshot */ public static RegionSubRegionsSizeResponse create(DistributionManager dm, @@ -60,15 +64,17 @@ public class RegionSubRegionsSizeResponse extends AdminResponse implements Cance return m; } - public void populateSnapshot(DistributionManager dm) { - if (cancelled) + void populateSnapshot(DistributionManager dm) { + if (this.cancelled) { return; + } DistributedSystem sys = dm.getSystem(); - GemFireCacheImpl cache = (GemFireCacheImpl) CacheFactory.getInstance(sys); + InternalCache cache = (InternalCache) CacheFactory.getInstance(sys); - if (cancelled) + if (this.cancelled) { return; + } RegionSubRegionSnapshot root = new RegionSubRegionSnapshot(); /* @@ -93,19 +99,17 @@ public class RegionSubRegionsSizeResponse extends AdminResponse implements Cance * @param regions collection of sub-regions of the region represented by parentSnapShot * @param cache cache instance is used for to get the LogWriter instance to log exceptions if any */ - // Re-factored to fix #41060 - void populateRegionSubRegions(RegionSubRegionSnapshot parentSnapShot, Set regions, - GemFireCacheImpl cache) { - if (cancelled) + private void populateRegionSubRegions(RegionSubRegionSnapshot parentSnapShot, Set regions, + InternalCache cache) { + if (this.cancelled) { return; + } - Region subRegion = null; - RegionSubRegionSnapshot subRegionSnapShot = null; - for (Iterator iter = regions.iterator(); iter.hasNext();) { - subRegion = (Region) iter.next(); + for (Object region : regions) { + Region subRegion = (Region) region; try { - subRegionSnapShot = new RegionSubRegionSnapshot(subRegion); + RegionSubRegionSnapshot subRegionSnapShot = new RegionSubRegionSnapshot(subRegion); parentSnapShot.addSubRegion(subRegionSnapShot); Set subRegions = subRegion.subregions(false); @@ -117,15 +121,15 @@ public class RegionSubRegionsSizeResponse extends AdminResponse implements Cance } } - + @Override public synchronized void cancel() { - cancelled = true; + this.cancelled = true; } @Override public void toData(DataOutput out) throws IOException { super.toData(out); - out.writeBoolean(cancelled); + out.writeBoolean(this.cancelled); DataSerializer.writeObject(this.snapshot, out); } @@ -133,23 +137,20 @@ public class RegionSubRegionsSizeResponse extends AdminResponse implements Cance public void fromData(DataInput in) throws IOException, ClassNotFoundException { super.fromData(in); this.cancelled = in.readBoolean(); - this.snapshot = (RegionSubRegionSnapshot) DataSerializer.readObject(in); + this.snapshot = DataSerializer.readObject(in); } /** * Returns the DataSerializer fixed id for the class that implements this method. */ + @Override public int getDSFID() { return REGION_SUB_SIZE_RESPONSE; } @Override public String toString() { - return "RegionSubRegionsSizeResponse [from=" + this.getRecipient() + " " - + (snapshot == null ? "null" : snapshot.toString()); + return "RegionSubRegionsSizeResponse [from=" + this.getRecipient() + ' ' + + (this.snapshot == null ? "null" : this.snapshot.toString()); } - - private RegionSubRegionSnapshot snapshot; - - private boolean cancelled; }