Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8670D17604 for ; Thu, 9 Apr 2015 12:14:14 +0000 (UTC) Received: (qmail 51064 invoked by uid 500); 9 Apr 2015 12:14:14 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 51037 invoked by uid 500); 9 Apr 2015 12:14:14 -0000 Mailing-List: contact commits-help@ignite.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.incubator.apache.org Delivered-To: mailing list commits@ignite.incubator.apache.org Received: (qmail 51028 invoked by uid 99); 9 Apr 2015 12:14:14 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Apr 2015 12:14:14 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 09 Apr 2015 12:13:44 +0000 Received: (qmail 48545 invoked by uid 99); 9 Apr 2015 12:13:37 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Apr 2015 12:13:37 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 6365BDFF8B; Thu, 9 Apr 2015 12:13:37 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sboikov@apache.org To: commits@ignite.incubator.apache.org Date: Thu, 09 Apr 2015 12:14:23 -0000 Message-Id: <4fe4bebf58a0425292d07372a0c566d3@git.apache.org> In-Reply-To: <54cd8259643248ceba93144c04ce82cd@git.apache.org> References: <54cd8259643248ceba93144c04ce82cd@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [48/50] [abbrv] incubator-ignite git commit: ignite-688 Age related cluster group doesn't refresh dynamically X-Virus-Checked: Checked by ClamAV on apache.org ignite-688 Age related cluster group doesn't refresh dynamically Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/ee1afe19 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/ee1afe19 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/ee1afe19 Branch: refs/heads/ignite-688 Commit: ee1afe1928409d8f8a306cce51ff252a2e1736d1 Parents: 4b37b93 Author: Andrey Gura Authored: Tue Apr 7 14:54:09 2015 +0300 Committer: Andrey Gura Committed: Thu Apr 9 15:03:42 2015 +0300 ---------------------------------------------------------------------- .../internal/cluster/ClusterGroupAdapter.java | 86 ++++++++++++++++++-- 1 file changed, 80 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ee1afe19/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 40462c3..b93a920 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 @@ -60,10 +60,10 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { private String gridName; /** Subject ID. */ - private UUID subjId; + protected UUID subjId; /** Cluster group predicate. */ - protected IgnitePredicate p; + protected volatile IgnitePredicate p; /** Node IDs. */ private Set ids; @@ -114,6 +114,28 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { } /** + * @param subjId Subject ID. + * @param ctx Grid kernal context. + * @param p Predicate. + * @param ids Node IDs. + */ + private ClusterGroupAdapter(@Nullable GridKernalContext ctx, + @Nullable UUID subjId, + @Nullable IgnitePredicate p, + Set ids) + { + if (ctx != null) + setKernalContext(ctx); + + this.subjId = subjId; + this.p = p; + this.ids = ids; + + if (p == null && ids != null) + this.p = F.nodeForNodeIds(ids); + } + + /** * ctx.gateway().readLock() */ protected void guard() { @@ -303,7 +325,7 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { } /** {@inheritDoc} */ - @Override public final ClusterGroup forPredicate(IgnitePredicate p) { + @Override public ClusterGroup forPredicate(IgnitePredicate p) { A.notNull(p, "p"); guard(); @@ -769,6 +791,9 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { /** Selected node. */ private volatile ClusterNode node; + /** Node predicate. */ + private IgnitePredicate parentP; + /** Last topology version. */ private volatile long lastTopVer; @@ -784,8 +809,9 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { * @param isOldest Oldest flag. */ private AgeClusterGroup(ClusterGroupAdapter parent, boolean isOldest) { - super(parent.ctx, parent.subjId, (IgnitePredicate)null); + super(parent.ctx, parent.subjId, parent.p, parent.ids); + this.parentP = parent.p; this.isOldest = isOldest; reset(); @@ -800,9 +826,9 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { try { lastTopVer = ctx.discovery().topologyVersion(); - Collection nodes = ctx.discovery().allNodes(); + this.p = parentP; - this.node = isOldest ? U.oldest(nodes, null) : U.youngest(nodes, null); + this.node = isOldest ? U.oldest(super.nodes(), null) : U.youngest(super.nodes(), null); this.p = F.nodeForNodes(node); } @@ -828,5 +854,53 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable { return node == null ? Collections.emptyList() : Collections.singletonList(node); } + + /** {@inheritDoc} */ + @Override public ClusterGroup forPredicate(IgnitePredicate p) { + A.notNull(p, "p"); + + guard(); + + try { + if (p != null) + ctx.resource().injectGeneric(p); + + return new ClusterGroupAdapter(ctx, this.subjId, new GroupPredicate(this, p)); + } + catch (IgniteCheckedException e) { + throw U.convertException(e); + } + finally { + unguard(); + } + } + } + + /** + * Dynamic cluster group based predicate. + */ + private static class GroupPredicate implements IgnitePredicate { + /** */ + private static final long serialVersionUID = 0L; + + /** Target cluster group. */ + private final ClusterGroup grp; + + /** Predicate. */ + private final IgnitePredicate p; + + /** + * @param grp Cluster group. + * @param p Predicate. + */ + public GroupPredicate(ClusterGroup grp, IgnitePredicate p) { + this.grp = grp; + this.p = p; + } + + /** {@inheritDoc} */ + @Override public boolean apply(ClusterNode node) { + return grp.predicate().apply(node) && p.apply(node); + } } }