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 DA57C10B49 for ; Thu, 14 May 2015 14:40:40 +0000 (UTC) Received: (qmail 7827 invoked by uid 500); 14 May 2015 14:40:40 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 7757 invoked by uid 500); 14 May 2015 14:40:40 -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 7741 invoked by uid 99); 14 May 2015 14:40:40 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 May 2015 14:40:40 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 3D1461A2C3A for ; Thu, 14 May 2015 14:40:40 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.771 X-Spam-Level: * X-Spam-Status: No, score=1.771 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, T_RP_MATCHES_RCVD=-0.01, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id hRXEUIXVFkDr for ; Thu, 14 May 2015 14:40:37 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with SMTP id B6A15262C3 for ; Thu, 14 May 2015 14:40:28 +0000 (UTC) Received: (qmail 7334 invoked by uid 99); 14 May 2015 14:40:28 -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, 14 May 2015 14:40:28 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 6FE78E3A5D; Thu, 14 May 2015 14:40:28 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sevdokimov@apache.org To: commits@ignite.incubator.apache.org Date: Thu, 14 May 2015 14:40:52 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [25/26] incubator-ignite git commit: # IGNITE-894 Revert adding @InjectRecursively. # IGNITE-894 Revert adding @InjectRecursively. Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/56e67e8f Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/56e67e8f Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/56e67e8f Branch: refs/heads/ignite-709_2 Commit: 56e67e8f7ce808c190346d9228987f25b54b4e6f Parents: 593e3ee Author: sevdokimov Authored: Thu May 14 16:38:45 2015 +0300 Committer: sevdokimov Committed: Thu May 14 16:40:00 2015 +0300 ---------------------------------------------------------------------- .../ignite/internal/GridInternalWrapper.java | 30 ++++++++++++++++ .../closure/GridClosureProcessor.java | 25 ++++++++++---- .../internal/processors/igfs/IgfsJobImpl.java | 10 ++++-- .../processors/resource/GridResourceIoc.java | 36 ++++++++++---------- .../resource/GridResourceProcessor.java | 8 ++++- .../processors/resource/GridResourceUtils.java | 15 ++++++++ .../processors/resource/InjectRecursively.java | 30 ---------------- .../resources/META-INF/classnames.properties | 1 - 8 files changed, 96 insertions(+), 59 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/56e67e8f/modules/core/src/main/java/org/apache/ignite/internal/GridInternalWrapper.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridInternalWrapper.java b/modules/core/src/main/java/org/apache/ignite/internal/GridInternalWrapper.java new file mode 100644 index 0000000..76563e7 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/GridInternalWrapper.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal; + +/** + * Internal wrapper interface for custom resource injection logic. + */ +public interface GridInternalWrapper { + /** + * Get user object where resources must be injected. + * + * @return User object. + */ + public T userObject(); +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/56e67e8f/modules/core/src/main/java/org/apache/ignite/internal/processors/closure/GridClosureProcessor.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/closure/GridClosureProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/closure/GridClosureProcessor.java index 8f5afbf..658557e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/closure/GridClosureProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/closure/GridClosureProcessor.java @@ -1584,12 +1584,12 @@ public class GridClosureProcessor extends GridProcessorAdapter { /** * */ - private static class C1 implements ComputeJob, Externalizable { + private static class C1 implements ComputeJob, Externalizable, GridNoImplicitInjection, + GridInternalWrapper { /** */ private static final long serialVersionUID = 0L; /** */ - @InjectRecursively protected IgniteClosure job; /** */ @@ -1635,6 +1635,11 @@ public class GridClosureProcessor extends GridProcessorAdapter { } /** {@inheritDoc} */ + @Override public IgniteClosure userObject() { + return job; + } + + /** {@inheritDoc} */ @Override public String toString() { return S.toString(C1.class, this); } @@ -1676,12 +1681,11 @@ public class GridClosureProcessor extends GridProcessorAdapter { /** * */ - private static class C2 implements ComputeJob, Externalizable { + private static class C2 implements ComputeJob, Externalizable, GridNoImplicitInjection, GridInternalWrapper { /** */ private static final long serialVersionUID = 0L; /** */ - @InjectRecursively protected Callable c; /** @@ -1724,6 +1728,11 @@ public class GridClosureProcessor extends GridProcessorAdapter { } /** {@inheritDoc} */ + @Override public Callable userObject() { + return c; + } + + /** {@inheritDoc} */ @Override public String toString() { return S.toString(C2.class, this); } @@ -1763,12 +1772,11 @@ public class GridClosureProcessor extends GridProcessorAdapter { /** */ - private static class C4 implements ComputeJob, Externalizable { + private static class C4 implements ComputeJob, Externalizable, GridNoImplicitInjection, GridInternalWrapper { /** */ private static final long serialVersionUID = 0L; /** */ - @InjectRecursively protected Runnable r; /** @@ -1808,6 +1816,11 @@ public class GridClosureProcessor extends GridProcessorAdapter { } /** {@inheritDoc} */ + @Override public Runnable userObject() { + return r; + } + + /** {@inheritDoc} */ @Override public String toString() { return S.toString(C4.class, this); } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/56e67e8f/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsJobImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsJobImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsJobImpl.java index 8f2cfd2..fa90e21 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsJobImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsJobImpl.java @@ -21,7 +21,7 @@ import org.apache.ignite.*; import org.apache.ignite.compute.*; import org.apache.ignite.igfs.*; import org.apache.ignite.igfs.mapreduce.*; -import org.apache.ignite.internal.processors.resource.*; +import org.apache.ignite.internal.*; import org.apache.ignite.resources.*; import java.io.*; @@ -29,12 +29,11 @@ import java.io.*; /** * IGFS job implementation. */ -public class IgfsJobImpl implements ComputeJob { +public class IgfsJobImpl implements ComputeJob, GridInternalWrapper { /** */ private static final long serialVersionUID = 0L; /** IGFS job. */ - @InjectRecursively private IgfsJob job; /** IGFS name. */ @@ -110,4 +109,9 @@ public class IgfsJobImpl implements ComputeJob { @Override public void cancel() { job.cancel(); } + + /** {@inheritDoc} */ + @Override public IgfsJob userObject() { + return job; + } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/56e67e8f/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceIoc.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceIoc.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceIoc.java index ce19664..1e85ecd 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceIoc.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceIoc.java @@ -272,29 +272,29 @@ class GridResourceIoc { for (Class cls0 = cls; !cls0.equals(Object.class); cls0 = cls0.getSuperclass()) { for (Field field : cls0.getDeclaredFields()) { - InjectRecursively injectRecursively = field.getAnnotation(InjectRecursively.class); + Annotation[] fieldAnns = field.getAnnotations(); - if (injectRecursively != null - || (allowImplicitInjection && field.getName().startsWith("this$") - || field.getName().startsWith("val$"))) { - field.setAccessible(true); + for (Annotation ann : fieldAnns) { + T2, List> t2 = annMap.get(ann.annotationType()); - recursiveFieldsList.add(field); - } - else { - for (Annotation ann : field.getAnnotations()) { - T2, List> t2 = annMap.get(ann.annotationType()); + if (t2 == null) { + t2 = new T2, List>( + new ArrayList(), + new ArrayList()); - if (t2 == null) { - t2 = new T2, List>( - new ArrayList(), - new ArrayList()); + annMap.put(ann.annotationType(), t2); + } - annMap.put(ann.annotationType(), t2); - } + t2.get1().add(new GridResourceField(field, ann)); + } - t2.get1().add(new GridResourceField(field, ann)); - } + if (allowImplicitInjection + && fieldAnns.length == 0 + && GridResourceUtils.mayRequireResources(field)) { + field.setAccessible(true); + + // Account for anonymous inner classes. + recursiveFieldsList.add(field); } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/56e67e8f/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceProcessor.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceProcessor.java index 5b51592..f5ba492 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceProcessor.java @@ -23,7 +23,6 @@ import org.apache.ignite.compute.*; import org.apache.ignite.internal.*; import org.apache.ignite.internal.managers.deployment.*; import org.apache.ignite.internal.processors.*; -import org.apache.ignite.internal.util.lang.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.lifecycle.*; import org.apache.ignite.resources.*; @@ -281,6 +280,13 @@ public class GridResourceProcessor extends GridProcessorAdapter { Object obj = unwrapTarget(job); injectToJob(dep, taskCls, obj, ses, jobCtx); + + if (obj instanceof GridInternalWrapper) { + Object usrObj = ((GridInternalWrapper)obj).userObject(); + + if (usrObj != null) + injectToJob(dep, taskCls, usrObj, ses, jobCtx); + } } /** http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/56e67e8f/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceUtils.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceUtils.java index 254f171..660d6ba 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceUtils.java @@ -88,4 +88,19 @@ final class GridResourceUtils { ", target=" + target + ", rsrc=" + rsrc + ']', e); } } + + /** + * Checks if specified field requires recursive inspection to find resource annotations. + * + * @param f Field. + * @return {@code true} if requires, {@code false} if doesn't. + */ + static boolean mayRequireResources(Field f) { + assert f != null; + + // Need to inspect anonymous classes, callable and runnable instances. + return f.getName().startsWith("this$") || f.getName().startsWith("val$") || + Callable.class.isAssignableFrom(f.getType()) || Runnable.class.isAssignableFrom(f.getType()) || + IgniteClosure.class.isAssignableFrom(f.getType()); + } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/56e67e8f/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/InjectRecursively.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/InjectRecursively.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/InjectRecursively.java deleted file mode 100644 index 383ee03..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/InjectRecursively.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.resource; - -import java.lang.annotation.*; - -/** - * Indicates that resource injection should be performed for field value too. - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface InjectRecursively { - // No-op. -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/56e67e8f/modules/core/src/main/resources/META-INF/classnames.properties ---------------------------------------------------------------------- diff --git a/modules/core/src/main/resources/META-INF/classnames.properties b/modules/core/src/main/resources/META-INF/classnames.properties index f130840..b3eed46 100644 --- a/modules/core/src/main/resources/META-INF/classnames.properties +++ b/modules/core/src/main/resources/META-INF/classnames.properties @@ -1140,7 +1140,6 @@ org.apache.ignite.internal.util.lang.GridAbsClosure org.apache.ignite.internal.util.lang.GridAbsClosureX org.apache.ignite.internal.util.lang.GridCloseableIterator org.apache.ignite.internal.util.lang.GridClosureException -org.apache.ignite.internal.util.lang.GridComputeJobWrapper org.apache.ignite.internal.util.lang.GridFunc$1 org.apache.ignite.internal.util.lang.GridFunc$10 org.apache.ignite.internal.util.lang.GridFunc$100