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 <voze...@gridgain.com> Authored: Wed Dec 23 16:53:01 2015 +0300 Committer: vozerov-gridgain <voze...@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); }