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/23 14:52:12 UTC
[1/5] ignite git commit: IGNITE-2236: Removed several unused methods.
Repository: ignite
Updated Branches:
refs/heads/ignite-2236 [created] 48d8f8d61
IGNITE-2236: Removed several unused methods.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/0e591446
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/0e591446
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/0e591446
Branch: refs/heads/ignite-2236
Commit: 0e591446e3533bf3901cfdb90e9bc9fe6464913a
Parents: 34eaf5a
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Wed Dec 23 15:52:43 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Wed Dec 23 15:52:43 2015 +0300
----------------------------------------------------------------------
.../service/GridServiceProcessor.java | 17 ++++++--
.../util/future/GridCompoundFuture.java | 46 --------------------
.../ignite/testframework/GridTestUtils.java | 4 +-
3 files changed, 16 insertions(+), 51 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/0e591446/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java
index 6b05edd..2841083 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java
@@ -515,10 +515,10 @@ public class GridServiceProcessor extends GridProcessorAdapter {
*/
@SuppressWarnings("unchecked")
public IgniteInternalFuture<?> cancelAll() {
- Collection<IgniteInternalFuture<?>> futs = new ArrayList<>();
-
Iterator<Cache.Entry<Object, Object>> it = serviceEntries(ServiceDeploymentPredicate.INSTANCE);
+ GridCompoundFuture res = null;
+
while (it.hasNext()) {
Cache.Entry<Object, Object> e = it.next();
@@ -527,11 +527,20 @@ public class GridServiceProcessor extends GridProcessorAdapter {
GridServiceDeployment dep = (GridServiceDeployment)e.getValue();
+ if (res == null)
+ res = new GridCompoundFuture<>();
+
// Cancel each service separately.
- futs.add(cancel(dep.configuration().getName()));
+ res.add(cancel(dep.configuration().getName()));
}
- return futs.isEmpty() ? new GridFinishedFuture<>() : new GridCompoundFuture(null, futs);
+ if (res != null) {
+ res.markInitialized();
+
+ return res;
+ }
+ else
+ return new GridFinishedFuture<>();
}
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/0e591446/modules/core/src/main/java/org/apache/ignite/internal/util/future/GridCompoundFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/future/GridCompoundFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/util/future/GridCompoundFuture.java
index 4b2461e..6812aec 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/future/GridCompoundFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/future/GridCompoundFuture.java
@@ -93,21 +93,6 @@ public class GridCompoundFuture<T, R> extends GridFutureAdapter<R> {
this.rdc = rdc;
}
- /**
- * @param rdc Reducer to add.
- * @param futs Futures to add.
- */
- public GridCompoundFuture(
- @Nullable IgniteReducer<T, R> rdc,
- @Nullable Iterable<IgniteInternalFuture<T>> futs
- ) {
- this.rdc = rdc;
-
- addAll(futs);
-
- markInitialized();
- }
-
/** {@inheritDoc} */
@Override public boolean cancel() throws IgniteCheckedException {
if (onCancelled()) {
@@ -219,37 +204,6 @@ public class GridCompoundFuture<T, R> extends GridFutureAdapter<R> {
}
/**
- * Adds futures to this compound future.
- *
- * @param futs Futures to add.
- */
- @SafeVarargs
- public final void addAll(@Nullable IgniteInternalFuture<T>... futs) {
- addAll(F.asList(futs));
- }
-
- /**
- * Adds futures to this compound future.
- *
- * @param futs Futures to add.
- */
- public void addAll(@Nullable Iterable<IgniteInternalFuture<T>> futs) {
- if (futs != null) {
- for (IgniteInternalFuture<T> fut : futs)
- add(fut);
- }
- }
-
- /**
- * Gets optional reducer.
- *
- * @return Optional reducer.
- */
- @Nullable public IgniteReducer<T, R> reducer() {
- return rdc;
- }
-
- /**
* Sets optional reducer.
*
* @param rdc Optional reducer.
http://git-wip-us.apache.org/repos/asf/ignite/blob/0e591446/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java b/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
index 7116227..2b01e4f 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
@@ -623,7 +623,9 @@ public final class GridTestUtils {
// Compound future, that adds cancel() support to execution future.
GridCompoundFuture<Long, Long> compFut = new GridCompoundFuture<>();
- compFut.addAll(cancelFut, runFut);
+ compFut.add(cancelFut);
+ compFut.add(runFut);
+
compFut.reducer(F.sumLongReducer());
compFut.markInitialized();
[4/5] ignite git commit: IGNITE-2236: Removed dedicated listener.
Posted by vo...@apache.org.
IGNITE-2236: Removed dedicated listener.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/2fe1a0dd
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/2fe1a0dd
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/2fe1a0dd
Branch: refs/heads/ignite-2236
Commit: 2fe1a0dd95d4eeb0049afc87e7833fe9dec63c32
Parents: 702c4f4
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Wed Dec 23 16:31:25 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Wed Dec 23 16:31:25 2015 +0300
----------------------------------------------------------------------
.../util/future/GridCompoundFuture.java | 175 +++++++++----------
1 file changed, 79 insertions(+), 96 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/2fe1a0dd/modules/core/src/main/java/org/apache/ignite/internal/util/future/GridCompoundFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/future/GridCompoundFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/util/future/GridCompoundFuture.java
index feabbf5..f15617f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/future/GridCompoundFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/future/GridCompoundFuture.java
@@ -17,15 +17,11 @@
package org.apache.ignite.internal.util.future;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.internal.IgniteFutureCancelledCheckedException;
import org.apache.ignite.internal.IgniteInternalFuture;
import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
import org.apache.ignite.internal.transactions.IgniteTxOptimisticCheckedException;
-import org.apache.ignite.internal.util.tostring.GridToStringExclude;
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
import org.apache.ignite.internal.util.typedef.C1;
import org.apache.ignite.internal.util.typedef.F;
@@ -35,10 +31,14 @@ import org.apache.ignite.lang.IgniteInClosure;
import org.apache.ignite.lang.IgniteReducer;
import org.jetbrains.annotations.Nullable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
+
/**
* Future composed of multiple inner futures.
*/
-public class GridCompoundFuture<T, R> extends GridFutureAdapter<R> {
+public class GridCompoundFuture<T, R> extends GridFutureAdapter<R> implements IgniteInClosure<IgniteInternalFuture<T>> {
/** */
private static final long serialVersionUID = 0L;
@@ -56,10 +56,6 @@ public class GridCompoundFuture<T, R> extends GridFutureAdapter<R> {
/** Futures. */
protected final ArrayList<IgniteInternalFuture<T>> futs = new ArrayList<>();
- /** */
- @GridToStringExclude
- private final Listener lsnr = new Listener();
-
/** Reducer. */
@GridToStringInclude
private final IgniteReducer<T, R> rdc;
@@ -91,6 +87,61 @@ public class GridCompoundFuture<T, R> extends GridFutureAdapter<R> {
}
/** {@inheritDoc} */
+ @Override public void apply(IgniteInternalFuture<T> fut) {
+ try {
+ T t = fut.get();
+
+ try {
+ if (rdc != null && !rdc.collect(t))
+ onDone(rdc.reduce());
+ }
+ catch (RuntimeException e) {
+ U.error(null, "Failed to execute compound future reducer: " + this, e);
+
+ // Exception in reducer is a bug, so we bypass checkComplete here.
+ onDone(e);
+ }
+ catch (AssertionError e) {
+ U.error(null, "Failed to execute compound future reducer: " + this, e);
+
+ // Bypass checkComplete because need to rethrow.
+ onDone(e);
+
+ throw e;
+ }
+ }
+ catch (IgniteTxOptimisticCheckedException | IgniteFutureCancelledCheckedException |
+ ClusterTopologyCheckedException e) {
+ if (!ignoreFailure(e))
+ onDone(e);
+ }
+ catch (IgniteCheckedException e) {
+ if (!ignoreFailure(e)) {
+ U.error(null, "Failed to execute compound future reducer: " + this, e);
+
+ onDone(e);
+ }
+ }
+ catch (RuntimeException e) {
+ U.error(null, "Failed to execute compound future reducer: " + this, e);
+
+ onDone(e);
+ }
+ catch (AssertionError e) {
+ U.error(null, "Failed to execute compound future reducer: " + this, e);
+
+ // Bypass checkComplete because need to rethrow.
+ onDone(e);
+
+ throw e;
+ }
+
+ lsnrCallsUpd.incrementAndGet(GridCompoundFuture.this);
+
+ checkComplete();
+ }
+
+ /** {@inheritDoc} */
@Override public boolean cancel() throws IgniteCheckedException {
if (onCancelled()) {
for (IgniteInternalFuture<T> fut : futures())
@@ -107,24 +158,6 @@ public class GridCompoundFuture<T, R> extends GridFutureAdapter<R> {
*
* @return Collection of futures.
*/
- private Collection<IgniteInternalFuture<T>> futures(boolean pending) {
- synchronized (futs) {
- Collection<IgniteInternalFuture<T>> res = new ArrayList<>(futs.size());
-
- for (IgniteInternalFuture<T> fut : futs) {
- if (!pending || !fut.isDone())
- res.add(fut);
- }
-
- return res;
- }
- }
-
- /**
- * Gets collection of futures.
- *
- * @return Collection of futures.
- */
public Collection<IgniteInternalFuture<T>> futures() {
return futures(false);
}
@@ -139,6 +172,24 @@ public class GridCompoundFuture<T, R> extends GridFutureAdapter<R> {
}
/**
+ * Gets collection of futures.
+ *
+ * @return Collection of futures.
+ */
+ private Collection<IgniteInternalFuture<T>> futures(boolean pending) {
+ synchronized (futs) {
+ Collection<IgniteInternalFuture<T>> res = new ArrayList<>(futs.size());
+
+ for (IgniteInternalFuture<T> fut : futs) {
+ if (!pending || !fut.isDone())
+ res.add(fut);
+ }
+
+ return res;
+ }
+ }
+
+ /**
* Checks if this compound future should ignore this particular exception.
*
* @param err Exception to check.
@@ -190,7 +241,7 @@ public class GridCompoundFuture<T, R> extends GridFutureAdapter<R> {
futs.add(fut);
}
- fut.listen(lsnr);
+ fut.listen(this);
if (isCancelled()) {
try {
@@ -282,72 +333,4 @@ public class GridCompoundFuture<T, R> extends GridFutureAdapter<R> {
})
);
}
-
- /**
- * Listener for futures.
- */
- private class Listener implements IgniteInClosure<IgniteInternalFuture<T>> {
- /** */
- private static final long serialVersionUID = 0L;
-
- /** {@inheritDoc} */
- @Override public void apply(IgniteInternalFuture<T> fut) {
- try {
- T t = fut.get();
-
- try {
- if (rdc != null && !rdc.collect(t))
- onDone(rdc.reduce());
- }
- catch (RuntimeException e) {
- U.error(null, "Failed to execute compound future reducer: " + this, e);
-
- // Exception in reducer is a bug, so we bypass checkComplete here.
- onDone(e);
- }
- catch (AssertionError e) {
- U.error(null, "Failed to execute compound future reducer: " + this, e);
-
- // Bypass checkComplete because need to rethrow.
- onDone(e);
-
- throw e;
- }
- }
- catch (IgniteTxOptimisticCheckedException | IgniteFutureCancelledCheckedException |
- ClusterTopologyCheckedException e) {
- if (!ignoreFailure(e))
- onDone(e);
- }
- catch (IgniteCheckedException e) {
- if (!ignoreFailure(e)) {
- U.error(null, "Failed to execute compound future reducer: " + this, e);
-
- onDone(e);
- }
- }
- catch (RuntimeException e) {
- U.error(null, "Failed to execute compound future reducer: " + this, e);
-
- onDone(e);
- }
- catch (AssertionError e) {
- U.error(null, "Failed to execute compound future reducer: " + this, e);
-
- // Bypass checkComplete because need to rethrow.
- onDone(e);
-
- throw e;
- }
-
- lsnrCallsUpd.incrementAndGet(GridCompoundFuture.this);
-
- checkComplete();
- }
-
- /** {@inheritDoc} */
- @Override public String toString() {
- return "Compound future listener []";
- }
- }
}
[2/5] ignite git commit: IGNITE-2236: Reworked "ignoreChildFailures"
- it is removed.
Posted by vo...@apache.org.
IGNITE-2236: Reworked "ignoreChildFailures" - it is removed.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/f688f10e
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/f688f10e
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/f688f10e
Branch: refs/heads/ignite-2236
Commit: f688f10e68d453094d5b20657c7f39ad4e4bb505
Parents: 0e59144
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Wed Dec 23 16:02:41 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Wed Dec 23 16:02:41 2015 +0300
----------------------------------------------------------------------
.../processors/cache/GridCacheMvccManager.java | 17 ++++++++--
...arOptimisticSerializableTxPrepareFuture.java | 6 ++--
.../GridNearPessimisticTxPrepareFuture.java | 6 ++--
.../util/future/GridCompoundFuture.java | 33 ++++----------------
4 files changed, 28 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/f688f10e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMvccManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMvccManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMvccManager.java
index a297773..c30bcb4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMvccManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMvccManager.java
@@ -978,9 +978,7 @@ public class GridCacheMvccManager extends GridCacheSharedManagerAdapter {
*/
@SuppressWarnings("unchecked")
public IgniteInternalFuture<?> finishAtomicUpdates(AffinityTopologyVersion topVer) {
- GridCompoundFuture<Object, Object> res = new GridCompoundFuture<>();
-
- res.ignoreChildFailures(ClusterTopologyCheckedException.class, CachePartialUpdateCheckedException.class);
+ GridCompoundFuture<Object, Object> res = new FinishAtomicUpdateFuture();
for (GridCacheAtomicFuture<?> fut : atomicFuts.values()) {
IgniteInternalFuture<Void> complete = fut.completeFuture(topVer);
@@ -1219,6 +1217,19 @@ public class GridCacheMvccManager extends GridCacheSharedManagerAdapter {
}
/**
+ * Finish atomic update future.
+ */
+ private static class FinishAtomicUpdateFuture extends GridCompoundFuture<Object, Object> {
+ /** {@inheritDoc} */
+ @Override protected boolean ignoreFailure(Throwable err) {
+ Class cls = err.getClass();
+
+ return ClusterTopologyCheckedException.class.isAssignableFrom(cls) ||
+ CachePartialUpdateCheckedException.class.isAssignableFrom(cls);
+ }
+ }
+
+ /**
* Thread local for pending MVCC candidates.
*/
private static class MvccCandidateThreadLocal extends ThreadLocal<ArrayList<GridCacheMvccCandidate>> {
http://git-wip-us.apache.org/repos/asf/ignite/blob/f688f10e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticSerializableTxPrepareFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticSerializableTxPrepareFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticSerializableTxPrepareFuture.java
index f52b3fc..a2b5520 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticSerializableTxPrepareFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticSerializableTxPrepareFuture.java
@@ -88,9 +88,11 @@ public class GridNearOptimisticSerializableTxPrepareFuture extends GridNearOptim
super(cctx, tx);
assert tx.optimistic() && tx.serializable() : tx;
+ }
- // Should wait for all mini futures completion before finishing tx.
- ignoreChildFailures(IgniteCheckedException.class);
+ /** {@inheritDoc} */
+ @Override protected boolean ignoreFailure(Throwable err) {
+ return IgniteCheckedException.class.isAssignableFrom(err.getClass());
}
/** {@inheritDoc} */
http://git-wip-us.apache.org/repos/asf/ignite/blob/f688f10e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearPessimisticTxPrepareFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearPessimisticTxPrepareFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearPessimisticTxPrepareFuture.java
index ffe5373..0f0121c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearPessimisticTxPrepareFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearPessimisticTxPrepareFuture.java
@@ -63,9 +63,11 @@ public class GridNearPessimisticTxPrepareFuture extends GridNearTxPrepareFutureA
super(cctx, tx);
assert tx.pessimistic() : tx;
+ }
- // Should wait for all mini futures completion before finishing tx.
- ignoreChildFailures(IgniteCheckedException.class);
+ /** {@inheritDoc} */
+ @Override protected boolean ignoreFailure(Throwable err) {
+ return IgniteCheckedException.class.isAssignableFrom(err.getClass());
}
/** {@inheritDoc} */
http://git-wip-us.apache.org/repos/asf/ignite/blob/f688f10e/modules/core/src/main/java/org/apache/ignite/internal/util/future/GridCompoundFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/future/GridCompoundFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/util/future/GridCompoundFuture.java
index 6812aec..4d9029f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/future/GridCompoundFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/future/GridCompoundFuture.java
@@ -64,9 +64,6 @@ public class GridCompoundFuture<T, R> extends GridFutureAdapter<R> {
@GridToStringInclude
private IgniteReducer<T, R> rdc;
- /** Exceptions to ignore. */
- private Class<? extends Throwable>[] ignoreChildFailures;
-
/**
* Updated via {@link #flagsUpd}.
*
@@ -142,11 +139,13 @@ public class GridCompoundFuture<T, R> extends GridFutureAdapter<R> {
}
/**
- * @param ignoreChildFailures Flag indicating whether compound future should ignore child futures failures.
+ * Checks if this compound future should ignore this particular exception.
+ *
+ * @param err Exception to check.
+ * @return {@code True} if this error should be ignored.
*/
- @SafeVarargs
- public final void ignoreChildFailures(Class<? extends Throwable>... ignoreChildFailures) {
- this.ignoreChildFailures = ignoreChildFailures;
+ protected boolean ignoreFailure(Throwable err) {
+ return false;
}
/**
@@ -278,26 +277,6 @@ public class GridCompoundFuture<T, R> extends GridFutureAdapter<R> {
}
}
- /**
- * Checks if this compound future should ignore this particular exception.
- *
- * @param err Exception to check.
- * @return {@code True} if this error should be ignored.
- */
- private boolean ignoreFailure(@Nullable Throwable err) {
- if (err == null)
- return true;
-
- if (ignoreChildFailures != null) {
- for (Class<? extends Throwable> ignoreCls : ignoreChildFailures) {
- if (ignoreCls.isAssignableFrom(err.getClass()))
- return true;
- }
- }
-
- return false;
- }
-
/** {@inheritDoc} */
@Override public String toString() {
return S.toString(GridCompoundFuture.class, this,
[3/5] ignite git commit: IGNITE-2236: Simplified reducer logic.
Posted by vo...@apache.org.
IGNITE-2236: Simplified reducer logic.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/702c4f42
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/702c4f42
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/702c4f42
Branch: refs/heads/ignite-2236
Commit: 702c4f4239515da9ea2d6d4542d0728bbfba0424
Parents: f688f10
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Wed Dec 23 16:24:50 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Wed Dec 23 16:24:50 2015 +0300
----------------------------------------------------------------------
...arOptimisticSerializableTxPrepareFuture.java | 39 +++++++++++---------
.../util/future/GridCompoundFuture.java | 15 ++------
.../ignite/testframework/GridTestUtils.java | 3 +-
3 files changed, 26 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/702c4f42/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticSerializableTxPrepareFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticSerializableTxPrepareFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticSerializableTxPrepareFuture.java
index a2b5520..cd03bc3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticSerializableTxPrepareFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticSerializableTxPrepareFuture.java
@@ -629,32 +629,37 @@ public class GridNearOptimisticSerializableTxPrepareFuture extends GridNearOptim
}
/**
- *
+ * Client remap future.
*/
private class ClientRemapFuture extends GridCompoundFuture<GridNearTxPrepareResponse, Boolean> {
- /** */
- private boolean remap = true;
-
/**
- *
+ * Constructor.
*/
public ClientRemapFuture() {
- super();
+ super(new ClientRemapFutureReducer());
+ }
+ }
- reducer(new IgniteReducer<GridNearTxPrepareResponse, Boolean>() {
- @Override public boolean collect(GridNearTxPrepareResponse res) {
- assert res != null;
+ /**
+ * Client remap future reducer.
+ */
+ private class ClientRemapFutureReducer implements IgniteReducer<GridNearTxPrepareResponse, Boolean> {
+ /** Remap flag. */
+ private boolean remap = true;
- if (res.clientRemapVersion() == null)
- remap = false;
+ /** {@inheritDoc} */
+ @Override public boolean collect(@Nullable GridNearTxPrepareResponse res) {
+ assert res != null;
- return true;
- }
+ if (res.clientRemapVersion() == null)
+ remap = false;
- @Override public Boolean reduce() {
- return remap;
- }
- });
+ return true;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Boolean reduce() {
+ return remap;
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/702c4f42/modules/core/src/main/java/org/apache/ignite/internal/util/future/GridCompoundFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/future/GridCompoundFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/util/future/GridCompoundFuture.java
index 4d9029f..feabbf5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/future/GridCompoundFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/future/GridCompoundFuture.java
@@ -62,7 +62,7 @@ public class GridCompoundFuture<T, R> extends GridFutureAdapter<R> {
/** Reducer. */
@GridToStringInclude
- private IgniteReducer<T, R> rdc;
+ private final IgniteReducer<T, R> rdc;
/**
* Updated via {@link #flagsUpd}.
@@ -77,10 +77,10 @@ public class GridCompoundFuture<T, R> extends GridFutureAdapter<R> {
private volatile int lsnrCalls;
/**
- *
+ * Default constructor.
*/
public GridCompoundFuture() {
- // No-op.
+ this(null);
}
/**
@@ -203,15 +203,6 @@ public class GridCompoundFuture<T, R> extends GridFutureAdapter<R> {
}
/**
- * Sets optional reducer.
- *
- * @param rdc Optional reducer.
- */
- public void reducer(@Nullable IgniteReducer<T, R> rdc) {
- this.rdc = rdc;
- }
-
- /**
* @param flag Flag to CAS.
* @return {@code True} if CAS succeeds.
*/
http://git-wip-us.apache.org/repos/asf/ignite/blob/702c4f42/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java b/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
index 2b01e4f..568e4b8 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
@@ -621,12 +621,11 @@ public final class GridTestUtils {
});
// Compound future, that adds cancel() support to execution future.
- GridCompoundFuture<Long, Long> compFut = new GridCompoundFuture<>();
+ GridCompoundFuture<Long, Long> compFut = new GridCompoundFuture<>(F.sumLongReducer());
compFut.add(cancelFut);
compFut.add(runFut);
- compFut.reducer(F.sumLongReducer());
compFut.markInitialized();
cancelFut.onDone();
[5/5] ignite git commit: IGNITE-2236: Simplified "future(pending)"
methods and INIT flag handling.
Posted by vo...@apache.org.
IGNITE-2236: Simplified "future(pending)" methods and INIT flag handling.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/48d8f8d6
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/48d8f8d6
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/48d8f8d6
Branch: refs/heads/ignite-2236
Commit: 48d8f8d618fb8ae5f22a91a7b324dfec1b54c3a9
Parents: 2fe1a0d
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Wed Dec 23 16:53:01 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Wed Dec 23 16:53:01 2015 +0300
----------------------------------------------------------------------
.../util/future/GridCompoundFuture.java | 71 +++-----------------
1 file changed, 10 insertions(+), 61 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/48d8f8d6/modules/core/src/main/java/org/apache/ignite/internal/util/future/GridCompoundFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/future/GridCompoundFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/util/future/GridCompoundFuture.java
index f15617f..8a56160 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/future/GridCompoundFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/future/GridCompoundFuture.java
@@ -42,8 +42,8 @@ public class GridCompoundFuture<T, R> extends GridFutureAdapter<R> implements Ig
/** */
private static final long serialVersionUID = 0L;
- /** */
- private static final int INITED = 0b1;
+ /** Initialization flag. */
+ private static final int INIT_FLAG = 0x1;
/** */
private static final AtomicIntegerFieldUpdater<GridCompoundFuture> flagsUpd =
@@ -63,7 +63,7 @@ public class GridCompoundFuture<T, R> extends GridFutureAdapter<R> implements Ig
/**
* Updated via {@link #flagsUpd}.
*
- * @see #INITED
+ * @see #INIT_FLAG
*/
@SuppressWarnings("unused")
private volatile int flags;
@@ -159,33 +159,8 @@ public class GridCompoundFuture<T, R> extends GridFutureAdapter<R> implements Ig
* @return Collection of futures.
*/
public Collection<IgniteInternalFuture<T>> futures() {
- return futures(false);
- }
-
- /**
- * Gets pending (unfinished) futures.
- *
- * @return Pending futures.
- */
- public Collection<IgniteInternalFuture<T>> pending() {
- return futures(true);
- }
-
- /**
- * Gets collection of futures.
- *
- * @return Collection of futures.
- */
- private Collection<IgniteInternalFuture<T>> futures(boolean pending) {
synchronized (futs) {
- Collection<IgniteInternalFuture<T>> res = new ArrayList<>(futs.size());
-
- for (IgniteInternalFuture<T> fut : futs) {
- if (!pending || !fut.isDone())
- res.add(fut);
- }
-
- return res;
+ return new ArrayList<>(futs);
}
}
@@ -222,14 +197,6 @@ public class GridCompoundFuture<T, R> extends GridFutureAdapter<R> implements Ig
}
/**
- * @return {@code True} if this future was initialized. Initialization happens when
- * {@link #markInitialized()} method is called on future.
- */
- public boolean initialized() {
- return flagSet(INITED);
- }
-
- /**
* Adds a future to this compound future.
*
* @param fut Future to add.
@@ -254,36 +221,18 @@ public class GridCompoundFuture<T, R> extends GridFutureAdapter<R> implements Ig
}
/**
- * @param flag Flag to CAS.
- * @return {@code True} if CAS succeeds.
- */
- private boolean casFlag(int flag) {
- for (;;) {
- int flags0 = flags;
-
- if ((flags0 & flag) != 0)
- return false;
-
- if (flagsUpd.compareAndSet(this, flags0, flags0 | flag))
- return true;
- }
- }
-
- /**
- * @param flag Flag to check.
- * @return {@code True} if set.
+ * @return {@code True} if this future was initialized. Initialization happens when
+ * {@link #markInitialized()} method is called on future.
*/
- private boolean flagSet(int flag) {
- return (flags & flag) != 0;
+ public boolean initialized() {
+ return flags == INIT_FLAG;
}
/**
* Mark this future as initialized.
*/
public void markInitialized() {
- if (casFlag(INITED))
- // Check complete to make sure that we take care
- // of all the ignored callbacks.
+ if (flagsUpd.compareAndSet(this, 0, INIT_FLAG))
checkComplete();
}
@@ -291,7 +240,7 @@ public class GridCompoundFuture<T, R> extends GridFutureAdapter<R> implements Ig
* Check completeness of the future.
*/
private void checkComplete() {
- if (flagSet(INITED) && !isDone() && lsnrCalls == futuresSize()) {
+ if (initialized() && !isDone() && lsnrCalls == futuresSize()) {
try {
onDone(rdc != null ? rdc.reduce() : null);
}