You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by se...@apache.org on 2019/07/12 19:05:33 UTC

[flink] 06/10: [hotfix][core] Minor cleanups to the ResourceSpec class

This is an automated email from the ASF dual-hosted git repository.

sewen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git

commit 5654e0f4750cd9fbe7cba2bdebd16ea3cb4011d6
Author: Stephan Ewen <se...@apache.org>
AuthorDate: Thu Jul 11 17:40:41 2019 +0200

    [hotfix][core] Minor cleanups to the ResourceSpec class
    
      - Some JavaDoc comments
      - Make the class final, because several methods are not designed to handle inheritence well.
      - Avoid repeated string concatenation/building
---
 .../apache/flink/api/common/operators/ResourceSpec.java   | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/flink-core/src/main/java/org/apache/flink/api/common/operators/ResourceSpec.java b/flink-core/src/main/java/org/apache/flink/api/common/operators/ResourceSpec.java
index dc6a611..2d56746 100755
--- a/flink-core/src/main/java/org/apache/flink/api/common/operators/ResourceSpec.java
+++ b/flink-core/src/main/java/org/apache/flink/api/common/operators/ResourceSpec.java
@@ -50,12 +50,19 @@ import static org.apache.flink.util.Preconditions.checkArgument;
  * </ol>
  */
 @Internal
-public class ResourceSpec implements Serializable {
+public final class ResourceSpec implements Serializable {
 
 	private static final long serialVersionUID = 1L;
 
+	/**
+	 * A ResourceSpec that indicates an unknown set of resources.
+	 */
 	public static final ResourceSpec UNKNOWN = new ResourceSpec();
 
+	/**
+	 * The default ResourceSpec used for operators and transformation functions.
+	 * Currently equal to {@link #UNKNOWN}.
+	 */
 	public static final ResourceSpec DEFAULT = UNKNOWN;
 
 	public static final String GPU_NAME = "GPU";
@@ -91,7 +98,7 @@ public class ResourceSpec implements Serializable {
 	 * @param managedMemoryInMB The size of managed memory, in megabytes.
 	 * @param extendedResources The extended resources, associated with the resource manager used
 	 */
-	protected ResourceSpec(
+	private ResourceSpec(
 			double cpuCores,
 			int heapMemoryInMB,
 			int directMemoryInMB,
@@ -273,9 +280,9 @@ public class ResourceSpec implements Serializable {
 
 	@Override
 	public String toString() {
-		String extend = "";
+		StringBuilder extend = new StringBuilder();
 		for (Resource resource : extendedResources.values()) {
-			extend += ", " + resource.getName() + "=" + resource.getValue();
+			extend.append(", ").append(resource.getName()).append("=").append(resource.getValue());
 		}
 		return "ResourceSpec{" +
 				"cpuCores=" + cpuCores +