You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2015/12/29 14:56:00 UTC
[3/3] ignite git commit: IGNITE-2263: Further simplification of
GridFunc.
IGNITE-2263: Further simplification of GridFunc.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/597ef1d6
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/597ef1d6
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/597ef1d6
Branch: refs/heads/ignite-2263
Commit: 597ef1d6edd6650a8975b079549d6dc2d06a3a33
Parents: e91d6e6
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Tue Dec 29 16:56:53 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Tue Dec 29 16:56:53 2015 +0300
----------------------------------------------------------------------
.../GridCachePartitionExchangeManager.java | 12 +-
.../ignite/internal/util/lang/GridFunc.java | 131 -------------------
.../ignite/lang/GridBasicPerformanceTest.java | 10 +-
3 files changed, 18 insertions(+), 135 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/597ef1d6/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java
index a0f7f93..4732597 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java
@@ -80,6 +80,7 @@ import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.internal.util.worker.GridWorker;
import org.apache.ignite.lang.IgniteBiInClosure;
+import org.apache.ignite.lang.IgnitePredicate;
import org.apache.ignite.lang.IgniteProductVersion;
import org.apache.ignite.lang.IgniteUuid;
import org.apache.ignite.thread.IgniteThread;
@@ -1270,9 +1271,16 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
}
// After workers line up and before preloading starts we initialize all futures.
- if (log.isDebugEnabled())
+ if (log.isDebugEnabled()) {
+ IgnitePredicate p = new IgnitePredicate<IgniteInternalFuture<?>>() {
+ @Override public boolean apply(IgniteInternalFuture<?> f) {
+ return !f.isDone();
+ }
+ };
+
log.debug("Before waiting for exchange futures [futs" +
- F.view(exchFuts.values(), F.unfinishedFutures()) + ", worker=" + this + ']');
+ F.view(exchFuts.values(), p) + ", worker=" + this + ']');
+ }
// Take next exchange future.
exchFut = poll(futQ, timeout, this);
http://git-wip-us.apache.org/repos/asf/ignite/blob/597ef1d6/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
index 3e7b122..4cba715 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
@@ -38,12 +38,9 @@ import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
-import java.util.concurrent.atomic.AtomicReference;
import javax.cache.Cache;
-import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.compute.ComputeJobResult;
-import org.apache.ignite.internal.IgniteFutureTimeoutCheckedException;
import org.apache.ignite.internal.IgniteInternalFuture;
import org.apache.ignite.internal.util.F0;
import org.apache.ignite.internal.util.GridConcurrentHashSet;
@@ -333,13 +330,6 @@ public class GridFunc {
}
};
- /** */
- private static final IgnitePredicate<IgniteInternalFuture<?>> UNFINISHED_FUTURE = new IgnitePredicate<IgniteInternalFuture<?>>() {
- @Override public boolean apply(IgniteInternalFuture<?> f) {
- return !f.isDone();
- }
- };
-
/**
* Gets predicate that evaluates to {@code true} only for given local node ID.
*
@@ -1409,21 +1399,6 @@ public class GridFunc {
}
/**
- * Converts given runnable to an absolute closure.
- *
- * @param r Runnable to convert to closure. If {@code null} - no-op closure is returned.
- * @return Closure that wraps given runnable. Note that wrapping closure always returns {@code null}.
- */
- public static GridAbsClosure as(@Nullable final Runnable r) {
- return new CA() {
- @Override public void apply() {
- if (r != null)
- r.run();
- }
- };
- }
-
- /**
* Gets size of the given collection with provided optional predicates.
*
* @param c Collection to size.
@@ -3817,35 +3792,6 @@ public class GridFunc {
}
/**
- * @param arr Array.
- * @param val Value to find.
- * @return {@code True} if array contains given value.
- */
- public static boolean contains(Integer[] arr, int val) {
- for (Integer el : arr) {
- if (el == val)
- return true;
- }
-
- return false;
- }
-
- /**
- * @param arr Array.
- * @param val Value to find.
- * @return {@code True} if array contains given value.
- */
- @SuppressWarnings("ForLoopReplaceableByForEach")
- public static boolean contains(long[] arr, long val) {
- for (int i = 0; i < arr.length; i++) {
- if (arr[i] == val)
- return true;
- }
-
- return false;
- }
-
- /**
* Tests whether specified arguments are equal, or both {@code null}.
*
* @param o1 Object to compare.
@@ -4017,74 +3963,6 @@ public class GridFunc {
}
/**
- * Compares two arrays. Unlike {@code Arrays#equals(...)} method this implementation
- * checks two arrays as sets allowing the same elements to be in different indexes.
- *
- * @param a1 First array to check.
- * @param a2 Second array to check.
- * @param sorted Tells whether or not both arrays are pre-sorted so that binary
- * search could be used instead of iteration.
- * @param dups Tells whether or not arrays can contain duplicates. If arrays contain
- * duplicate the implementation will have to do double work.
- * @return {@code True} if arrays are equal, {@code false} otherwise.
- */
- public static boolean eqArray(Object[] a1, Object[] a2, boolean sorted, boolean dups) {
- if (a1 == a2)
- return true;
-
- if (a1 == null || a2 == null || a1.length != a2.length)
- return false;
-
- // Short circuit.
- if (a1.length == 1)
- return eq(a1[0], a2[0]);
-
- for (Object o1 : a1) {
- boolean found = false;
-
- if (sorted)
- found = Arrays.binarySearch(a2, o1) >= 0;
- else {
- for (Object o2 : a2) {
- if (eq(o1, o2)) {
- found = true;
-
- break;
- }
- }
- }
-
- if (!found)
- return false;
- }
-
- // If there are no dups - we can't skip checking seconds array
- // against first one.
- if (dups) {
- for (Object o2 : a2) {
- boolean found = false;
-
- if (sorted)
- found = Arrays.binarySearch(a1, o2) >= 0;
- else {
- for (Object o1 : a1) {
- if (eq(o2, o1)) {
- found = true;
-
- break;
- }
- }
- }
-
- if (!found)
- return false;
- }
- }
-
- return true;
- }
-
- /**
* Compares two {@link org.apache.ignite.cluster.ClusterNode} instances for equality.
* <p>
* Since introduction of {@link org.apache.ignite.cluster.ClusterNode} in Apache Ignite 3.0 the semantic of equality between
@@ -4152,13 +4030,4 @@ public class GridFunc {
public static GridClosureException wrap(Throwable e) {
return new GridClosureException(e);
}
-
- /**
- * Returns predicate for filtering unfinished futures.
- *
- * @return Predicate for filtering unfinished futures.
- */
- public static IgnitePredicate<IgniteInternalFuture<?>> unfinishedFutures() {
- return UNFINISHED_FUTURE;
- }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/597ef1d6/modules/core/src/test/java/org/apache/ignite/lang/GridBasicPerformanceTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/lang/GridBasicPerformanceTest.java b/modules/core/src/test/java/org/apache/ignite/lang/GridBasicPerformanceTest.java
index 37e7afe..353367e 100644
--- a/modules/core/src/test/java/org/apache/ignite/lang/GridBasicPerformanceTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/lang/GridBasicPerformanceTest.java
@@ -748,8 +748,14 @@ public class GridBasicPerformanceTest {
for (int i = 0; i < MAX; i++) {
if (sort)
Arrays.binarySearch(arr, ThreadLocalRandom8.current().nextInt(lim));
- else
- F.contains(arr, ThreadLocalRandom8.current().nextInt(lim));
+ else {
+ int val = ThreadLocalRandom8.current().nextInt(lim);
+
+ for (long arrItem : arr) {
+ if (arrItem == val)
+ break;
+ }
+ }
}
long time = System.currentTimeMillis() - start;