# sprint-2
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/d591ae81 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/d591ae81 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/d591ae81 Branch: refs/heads/ignite-185 Commit: d591ae812fb2dc2427c1911413b914ee9959e5cf Parents: 413143a Author: sboikov <sboi...@gridgain.com> Authored: Thu Feb 19 16:44:44 2015 +0300 Committer: sboikov <sboi...@gridgain.com> Committed: Thu Feb 19 16:44:44 2015 +0300 ---------------------------------------------------------------------- .../apache/ignite/internal/IgniteKernal.java | 4 +- .../internal/cluster/ClusterGroupAdapter.java | 94 ++++++++------------ .../internal/cluster/IgniteClusterImpl.java | 20 ++++- .../internal/GridProjectionAbstractTest.java | 2 +- 4 files changed, 58 insertions(+), 62 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d591ae81/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java index e0953bf..8f1179f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java @@ -673,9 +673,7 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable { igfsExecSvc, restExecSvc); - cluster = new IgniteClusterImpl(); - - cluster.setKernalContext(ctx); + cluster = new IgniteClusterImpl(ctx); U.onGridStart(); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d591ae81/modules/core/src/main/java/org/apache/ignite/internal/cluster/ClusterGroupAdapter.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/cluster/ClusterGroupAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/cluster/ClusterGroupAdapter.java index 9c736cf..178c604 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/cluster/ClusterGroupAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/cluster/ClusterGroupAdapter.java @@ -44,9 +44,6 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { /** Kernal context. */ protected transient GridKernalContext ctx; - /** Parent projection. */ - private transient ClusterGroup parent; - /** Compute. */ private transient IgniteComputeImpl compute; @@ -65,7 +62,7 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { /** Subject ID. */ private UUID subjId; - /** Projection predicate. */ + /** Cluster group predicate. */ protected IgnitePredicate<ClusterNode> p; /** Node IDs. */ @@ -80,17 +77,13 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { /** * @param subjId Subject ID. - * @param parent Parent of this projection. - * @param ctx Grid kernal context. + * @param ctx Kernal context. * @param p Predicate. */ - protected ClusterGroupAdapter(@Nullable ClusterGroup parent, - @Nullable GridKernalContext ctx, + protected ClusterGroupAdapter(@Nullable GridKernalContext ctx, @Nullable UUID subjId, @Nullable IgnitePredicate<ClusterNode> p) { - this.parent = parent; - if (ctx != null) setKernalContext(ctx); @@ -101,18 +94,14 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { } /** - * @param parent Parent of this projection. - * @param ctx Grid kernal context. + * @param ctx Kernal context. * @param subjId Subject ID. * @param ids Node IDs. */ - protected ClusterGroupAdapter(@Nullable ClusterGroup parent, - @Nullable GridKernalContext ctx, + protected ClusterGroupAdapter(@Nullable GridKernalContext ctx, @Nullable UUID subjId, Set<UUID> ids) { - this.parent = parent; - if (ctx != null) setKernalContext(ctx); @@ -126,19 +115,15 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { /** * @param subjId Subject ID. - * @param parent Parent of this projection. * @param ctx Grid kernal context. * @param p Predicate. * @param ids Node IDs. */ - private ClusterGroupAdapter(@Nullable ClusterGroup parent, - @Nullable GridKernalContext ctx, + private ClusterGroupAdapter(@Nullable GridKernalContext ctx, @Nullable UUID subjId, @Nullable IgnitePredicate<ClusterNode> p, Set<UUID> ids) { - this.parent = parent; - if (ctx != null) setKernalContext(ctx); @@ -179,9 +164,6 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { this.ctx = ctx; - if (parent == null) - parent = ctx.grid().cluster(); - gridName = ctx.gridName(); } @@ -200,7 +182,7 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { } /** - * @return {@link org.apache.ignite.IgniteCompute} for this projection. + * @return {@link org.apache.ignite.IgniteCompute} for this cluster group. */ public final IgniteCompute compute() { if (compute == null) { @@ -213,7 +195,7 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { } /** - * @return {@link org.apache.ignite.IgniteMessaging} for this projection. + * @return {@link org.apache.ignite.IgniteMessaging} for this cluster group. */ public final IgniteMessaging message() { if (messaging == null) { @@ -226,7 +208,7 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { } /** - * @return {@link org.apache.ignite.IgniteEvents} for this projection. + * @return {@link org.apache.ignite.IgniteEvents} for this cluster group. */ public final IgniteEvents events() { if (evts == null) { @@ -239,7 +221,7 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { } /** - * @return {@link org.apache.ignite.IgniteServices} for this projection. + * @return {@link org.apache.ignite.IgniteServices} for this cluster group. */ public IgniteServices services() { if (svcs == null) { @@ -252,7 +234,7 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { } /** - * @return {@link ExecutorService} for this projection. + * @return {@link ExecutorService} for this cluster group. */ public ExecutorService executorService() { assert ctx != null; @@ -349,7 +331,7 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { guard(); try { - return new ClusterGroupAdapter(this, ctx, subjId, this.p != null ? F.and(p, this.p) : p); + return new ClusterGroupAdapter(ctx, subjId, this.p != null ? F.and(p, this.p) : p); } finally { unguard(); @@ -385,7 +367,7 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { nodeIds.add(node.id()); } - return new ClusterGroupAdapter(this, ctx, subjId, nodeIds); + return new ClusterGroupAdapter(ctx, subjId, nodeIds); } finally { unguard(); @@ -405,7 +387,7 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { if (contains(n)) nodeIds.add(n.id()); - return new ClusterGroupAdapter(this, ctx, subjId, nodeIds); + return new ClusterGroupAdapter(ctx, subjId, nodeIds); } finally { unguard(); @@ -435,7 +417,7 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { nodeIds.add(id); } - return new ClusterGroupAdapter(this, ctx, subjId, nodeIds); + return new ClusterGroupAdapter(ctx, subjId, nodeIds); } finally { unguard(); @@ -456,7 +438,7 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { nodeIds.add(id); } - return new ClusterGroupAdapter(this, ctx, subjId, nodeIds); + return new ClusterGroupAdapter(ctx, subjId, nodeIds); } finally { unguard(); @@ -471,8 +453,8 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { } /** {@inheritDoc} */ - @Override public ClusterGroup forOthers(ClusterGroup prj) { - A.notNull(prj, "prj"); + @Override public ClusterGroup forOthers(ClusterGroup grp) { + A.notNull(grp, "grp"); if (ids != null) { guard(); @@ -483,18 +465,18 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { for (UUID id : ids) { ClusterNode n = node(id); - if (n != null && !prj.predicate().apply(n)) + if (n != null && !grp.predicate().apply(n)) nodeIds.add(id); } - return new ClusterGroupAdapter(this, ctx, subjId, nodeIds); + return new ClusterGroupAdapter(ctx, subjId, nodeIds); } finally { unguard(); } } else - return forPredicate(F.not(prj.predicate())); + return forPredicate(F.not(grp.predicate())); } /** {@inheritDoc} */ @@ -504,7 +486,7 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { /** * @param excludeIds Node IDs. - * @return New projection. + * @return New cluster group. */ private ClusterGroup forOthers(Collection<UUID> excludeIds) { assert excludeIds != null; @@ -520,7 +502,7 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { nodeIds.add(id); } - return new ClusterGroupAdapter(this, ctx, subjId, nodeIds); + return new ClusterGroupAdapter(ctx, subjId, nodeIds); } finally { unguard(); @@ -579,12 +561,12 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { /** {@inheritDoc} */ @Override public ClusterGroup forOldest() { - return new AgeProjection(this, true); + return new AgeClusterGroup(this, true); } /** {@inheritDoc} */ @Override public ClusterGroup forYoungest() { - return new AgeProjection(this, false); + return new AgeClusterGroup(this, false); } /** {@inheritDoc} */ @@ -595,8 +577,8 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { guard(); try { - return ids != null ? new ClusterGroupAdapter(this, ctx, subjId, ids) : - new ClusterGroupAdapter(this, ctx, subjId, p); + return ids != null ? new ClusterGroupAdapter(ctx, subjId, ids) : + new ClusterGroupAdapter(ctx, subjId, p); } finally { unguard(); @@ -605,7 +587,7 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { /** * @param n Node. - * @return Whether node belongs to this projection. + * @return Whether node belongs to this cluster group. */ private boolean contains(ClusterNode n) { assert n != null; @@ -615,7 +597,7 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { /** * @param id Node ID. - * @return Whether node belongs to this projection. + * @return Whether node belongs to this cluster group. */ private boolean contains(UUID id) { assert id != null; @@ -663,10 +645,8 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { try { IgniteKernal g = IgnitionEx.gridx(gridName); - ClusterGroup grp = g.cluster(); - - return ids != null ? new ClusterGroupAdapter(grp, g.context(), subjId, ids) : - p != null ? new ClusterGroupAdapter(grp, g.context(), subjId, p) : g; + return ids != null ? new ClusterGroupAdapter(g.context(), subjId, ids) : + p != null ? new ClusterGroupAdapter(g.context(), subjId, p) : g; } catch (IllegalStateException e) { throw U.withCause(new InvalidObjectException(e.getMessage()), e); @@ -815,9 +795,9 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { } /** - * Age-based projection. + * Age-based cluster group. */ - private static class AgeProjection extends ClusterGroupAdapter { + private static class AgeClusterGroup extends ClusterGroupAdapter { /** Serialization version. */ private static final long serialVersionUID = 0L; @@ -833,16 +813,16 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { /** * Required for {@link Externalizable}. */ - public AgeProjection() { + public AgeClusterGroup() { // No-op. } /** - * @param prj Parent projection. + * @param parent Parent cluster group. * @param isOldest Oldest flag. */ - private AgeProjection(ClusterGroupAdapter prj, boolean isOldest) { - super(prj.parent, prj.ctx, prj.subjId, prj.p, prj.ids); + private AgeClusterGroup(ClusterGroupAdapter parent, boolean isOldest) { + super(parent.ctx, parent.subjId, parent.p, parent.ids); this.isOldest = isOldest; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d591ae81/modules/core/src/main/java/org/apache/ignite/internal/cluster/IgniteClusterImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/cluster/IgniteClusterImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/cluster/IgniteClusterImpl.java index f23a6d4..1482784 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/cluster/IgniteClusterImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/cluster/IgniteClusterImpl.java @@ -53,6 +53,24 @@ public class IgniteClusterImpl extends ClusterGroupAdapter implements IgniteClus @GridToStringExclude private ClusterNodeLocalMap nodeLoc; + /** + * Required by {@link Externalizable}. + */ + public IgniteClusterImpl() { + // No-op. + } + + /** + * @param ctx Kernal context. + */ + public IgniteClusterImpl(GridKernalContext ctx) { + super(ctx, null, (IgnitePredicate<ClusterNode>)null); + + cfg = ctx.config(); + + nodeLoc = new ClusterNodeLocalMapImpl(ctx); + } + /** {@inheritDoc} */ @Override public void setKernalContext(GridKernalContext ctx) { super.setKernalContext(ctx); @@ -67,7 +85,7 @@ public class IgniteClusterImpl extends ClusterGroupAdapter implements IgniteClus guard(); try { - return new ClusterGroupAdapter(this, ctx, null, Collections.singleton(cfg.getNodeId())); + return new ClusterGroupAdapter(ctx, null, Collections.singleton(cfg.getNodeId())); } finally { unguard(); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d591ae81/modules/core/src/test/java/org/apache/ignite/internal/GridProjectionAbstractTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridProjectionAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/GridProjectionAbstractTest.java index 49ea259..0171290 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/GridProjectionAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/GridProjectionAbstractTest.java @@ -257,7 +257,7 @@ public abstract class GridProjectionAbstractTest extends GridCommonAbstractTest IgnitePredicate<Event> lsnr; - if (!Ignite.class.isAssignableFrom(projection().getClass())) { + if (!IgniteCluster.class.isAssignableFrom(projection().getClass())) { g.events().localListen(lsnr = new IgnitePredicate<Event>() { @Override public boolean apply(Event evt) { assert evt.type() == EVT_JOB_STARTED;