ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sevdoki...@apache.org
Subject [1/2] incubator-ignite git commit: # IGNITE-45 Minor code changes: Create GridNodeOrderComparator.INSTANCE to avoid unnecessary static fields and unnecessary GridNodeOrderComparator instatiation.
Date Tue, 17 Mar 2015 14:40:28 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-45 4b55cc3d2 -> 1108b4571


# IGNITE-45 Minor code changes: Create GridNodeOrderComparator.INSTANCE to avoid unnecessary
static fields and unnecessary GridNodeOrderComparator instatiation.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/3a22db9d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/3a22db9d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/3a22db9d

Branch: refs/heads/ignite-45
Commit: 3a22db9db21c25e2ea421f4a411a06533e8cc9e5
Parents: 4b55cc3
Author: sevdokimov <sevdokimov@gridgain.com>
Authored: Tue Mar 17 16:40:59 2015 +0300
Committer: sevdokimov <sevdokimov@gridgain.com>
Committed: Tue Mar 17 16:40:59 2015 +0300

----------------------------------------------------------------------
 .../internal/GridNodeOrderComparator.java       | 10 +++++++++
 .../affinity/GridAffinityAssignmentCache.java   | 23 ++------------------
 .../dht/GridDhtAssignmentFetchFuture.java       |  5 +----
 3 files changed, 13 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a22db9d/modules/core/src/main/java/org/apache/ignite/internal/GridNodeOrderComparator.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridNodeOrderComparator.java
b/modules/core/src/main/java/org/apache/ignite/internal/GridNodeOrderComparator.java
index 422abae..10f6ff1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/GridNodeOrderComparator.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/GridNodeOrderComparator.java
@@ -29,6 +29,16 @@ public class GridNodeOrderComparator implements Comparator<ClusterNode>,
Seriali
     /** */
     private static final long serialVersionUID = 0L;
 
+    /** */
+    public static final Comparator<ClusterNode> INSTANCE = new GridNodeOrderComparator();
+
+    /**
+     * Private constructor. Don't create this class, use {@link #INSTANCE}.
+     */
+    private GridNodeOrderComparator() {
+
+    }
+
     /** {@inheritDoc} */
     @Override public int compare(ClusterNode n1, ClusterNode n2) {
         return n1.order() < n2.order() ? -1 : n1.order() > n2.order() ? 1 : n1.id().compareTo(n2.id());

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a22db9d/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java
index a008315..2ff00db 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java
@@ -36,9 +36,6 @@ import java.util.concurrent.atomic.*;
  * Affinity cached function.
  */
 public class GridAffinityAssignmentCache {
-    /** Node order comparator. */
-    private static final Comparator<ClusterNode> nodeCmp = new GridNodeOrderComparator();
-
     /** Cache name. */
     private final String cacheName;
 
@@ -166,9 +163,9 @@ public class GridAffinityAssignmentCache {
             sorted = Collections.singletonList(ctx.localNode());
         else {
             // Resolve nodes snapshot for specified topology version.
-            Collection<ClusterNode> nodes = ctx.discovery().cacheAffinityNodes(cacheName,
topVer);
+            sorted = new ArrayList<>(ctx.discovery().cacheAffinityNodes(cacheName,
topVer));
 
-            sorted = sort(nodes);
+            Collections.sort(sorted, GridNodeOrderComparator.INSTANCE);
         }
 
         List<List<ClusterNode>> prevAssignment = prev == null ? null : prev.assignment();
@@ -409,22 +406,6 @@ public class GridAffinityAssignmentCache {
     }
 
     /**
-     * Sorts nodes according to order.
-     *
-     * @param nodes Nodes to sort.
-     * @return Sorted list of nodes.
-     */
-    private List<ClusterNode> sort(Collection<ClusterNode> nodes) {
-        List<ClusterNode> sorted = new ArrayList<>(nodes.size());
-
-        sorted.addAll(nodes);
-
-        Collections.sort(sorted, nodeCmp);
-
-        return sorted;
-    }
-
-    /**
      * Affinity ready future. Will remove itself from ready futures map.
      */
     private class AffinityReadyFuture extends GridFutureAdapter<AffinityTopologyVersion>
{

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a22db9d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtAssignmentFetchFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtAssignmentFetchFuture.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtAssignmentFetchFuture.java
index 645d590..79628cc 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtAssignmentFetchFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtAssignmentFetchFuture.java
@@ -40,9 +40,6 @@ public class GridDhtAssignmentFetchFuture extends GridFutureAdapter<List<List<Cl
     /** */
     private static final long serialVersionUID = 0L;
 
-    /** Nodes order comparator. */
-    private static final Comparator<ClusterNode> CMP = new GridNodeOrderComparator();
-
     /** Logger reference. */
     private static final AtomicReference<IgniteLogger> logRef = new AtomicReference<>();
 
@@ -75,7 +72,7 @@ public class GridDhtAssignmentFetchFuture extends GridFutureAdapter<List<List<Cl
 
         LinkedList<ClusterNode> tmp = new LinkedList<>();
         tmp.addAll(availableNodes);
-        Collections.sort(tmp, CMP);
+        Collections.sort(tmp, GridNodeOrderComparator.INSTANCE);
 
         this.availableNodes = tmp;
 


Mime
View raw message