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 BEEB818A64 for ; Wed, 13 May 2015 16:10:35 +0000 (UTC) Received: (qmail 92828 invoked by uid 500); 13 May 2015 16:10:35 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 92797 invoked by uid 500); 13 May 2015 16:10:35 -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 92788 invoked by uid 99); 13 May 2015 16:10:35 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 May 2015 16:10:35 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 39A0DC209E for ; Wed, 13 May 2015 16:10:35 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.771 X-Spam-Level: X-Spam-Status: No, score=0.771 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, 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-east.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id GtrLOKCyN_mv for ; Wed, 13 May 2015 16:10:28 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with SMTP id 8216243DB7 for ; Wed, 13 May 2015 16:10:27 +0000 (UTC) Received: (qmail 92442 invoked by uid 99); 13 May 2015 16:10:27 -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; Wed, 13 May 2015 16:10:27 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id D121FE32BD; Wed, 13 May 2015 16:10:26 +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: Wed, 13 May 2015 16:10:27 -0000 Message-Id: <4d057c60286249e5a291ecdb9b83843c@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [2/7] incubator-ignite git commit: IGNITE-894 Add @InjectRecursively. IGNITE-894 Add @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/a1ce1ce4 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/a1ce1ce4 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/a1ce1ce4 Branch: refs/heads/ignite-sprint-5 Commit: a1ce1ce4b749f2fc12a803052bf0df21eb42f675 Parents: 96ad5a8 Author: sevdokimov Authored: Tue May 12 19:15:56 2015 +0300 Committer: sevdokimov Committed: Tue May 12 19:15:56 2015 +0300 ---------------------------------------------------------------------- .../ignite/internal/GridInternalWrapper.java | 30 ------ .../closure/GridClosureProcessor.java | 25 ++--- .../internal/processors/igfs/IgfsJobImpl.java | 9 +- .../processors/resource/GridResourceIoc.java | 34 +++---- .../resource/GridResourceProcessor.java | 22 +---- .../processors/resource/GridResourceUtils.java | 15 --- .../util/lang/GridComputeJobWrapper.java | 96 -------------------- .../ignite/resources/InjectRecursively.java | 22 +++++ 8 files changed, 48 insertions(+), 205 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a1ce1ce4/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 deleted file mode 100644 index 76563e7..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/GridInternalWrapper.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; - -/** - * 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/a1ce1ce4/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 658557e..8f5afbf 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, GridNoImplicitInjection, - GridInternalWrapper { + private static class C1 implements ComputeJob, Externalizable { /** */ private static final long serialVersionUID = 0L; /** */ + @InjectRecursively protected IgniteClosure job; /** */ @@ -1635,11 +1635,6 @@ public class GridClosureProcessor extends GridProcessorAdapter { } /** {@inheritDoc} */ - @Override public IgniteClosure userObject() { - return job; - } - - /** {@inheritDoc} */ @Override public String toString() { return S.toString(C1.class, this); } @@ -1681,11 +1676,12 @@ public class GridClosureProcessor extends GridProcessorAdapter { /** * */ - private static class C2 implements ComputeJob, Externalizable, GridNoImplicitInjection, GridInternalWrapper { + private static class C2 implements ComputeJob, Externalizable { /** */ private static final long serialVersionUID = 0L; /** */ + @InjectRecursively protected Callable c; /** @@ -1728,11 +1724,6 @@ public class GridClosureProcessor extends GridProcessorAdapter { } /** {@inheritDoc} */ - @Override public Callable userObject() { - return c; - } - - /** {@inheritDoc} */ @Override public String toString() { return S.toString(C2.class, this); } @@ -1772,11 +1763,12 @@ public class GridClosureProcessor extends GridProcessorAdapter { /** */ - private static class C4 implements ComputeJob, Externalizable, GridNoImplicitInjection, GridInternalWrapper { + private static class C4 implements ComputeJob, Externalizable { /** */ private static final long serialVersionUID = 0L; /** */ + @InjectRecursively protected Runnable r; /** @@ -1816,11 +1808,6 @@ 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/a1ce1ce4/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 fa90e21..b5a336e 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,6 @@ 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.*; import org.apache.ignite.resources.*; import java.io.*; @@ -29,11 +28,12 @@ import java.io.*; /** * IGFS job implementation. */ -public class IgfsJobImpl implements ComputeJob, GridInternalWrapper { +public class IgfsJobImpl implements ComputeJob { /** */ private static final long serialVersionUID = 0L; /** IGFS job. */ + @InjectRecursively private IgfsJob job; /** IGFS name. */ @@ -109,9 +109,4 @@ public class IgfsJobImpl implements ComputeJob, GridInternalWrapper { @Override public void cancel() { job.cancel(); } - - /** {@inheritDoc} */ - @Override public IgfsJob userObject() { - return job; - } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a1ce1ce4/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 3d853d6..a2ffa55 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 @@ -22,6 +22,7 @@ import org.apache.ignite.internal.managers.deployment.*; import org.apache.ignite.internal.util.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.resources.*; import org.jetbrains.annotations.*; import org.jsr166.*; @@ -272,27 +273,26 @@ class GridResourceIoc { for (Class cls0 = cls; !cls0.equals(Object.class); cls0 = cls0.getSuperclass()) { for (Field field : cls0.getDeclaredFields()) { - Annotation[] fieldAnns = field.getAnnotations(); + InjectRecursively injectRecursively = field.getAnnotation(InjectRecursively.class); - for (Annotation ann : fieldAnns) { - T2, List> t2 = annMap.get(ann.annotationType()); - - if (t2 == null) { - t2 = new T2, List>( - new ArrayList(), - new ArrayList()); + if (injectRecursively != null + || (allowImplicitInjection && field.getName().startsWith("this$") + || field.getName().startsWith("val$"))) + recursiveFieldsList.add(field); + else { + for (Annotation ann : field.getAnnotations()) { + T2, List> t2 = annMap.get(ann.annotationType()); - annMap.put(ann.annotationType(), t2); - } + if (t2 == null) { + t2 = new T2, List>( + new ArrayList(), + new ArrayList()); - t2.get1().add(new GridResourceField(field, ann)); - } + annMap.put(ann.annotationType(), t2); + } - if (allowImplicitInjection - && fieldAnns.length == 0 - && GridResourceUtils.mayRequireResources(field)) { - // Account for anonymous inner classes. - recursiveFieldsList.add(field); + t2.get1().add(new GridResourceField(field, ann)); + } } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a1ce1ce4/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 cb4149b..5b51592 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 @@ -278,16 +278,9 @@ public class GridResourceProcessor extends GridProcessorAdapter { log.debug("Injecting resources: " + job); // Unwrap Proxy object. - Object obj = unwrapTarget(unwrapJob(job)); + 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); - } } /** @@ -329,19 +322,6 @@ public class GridResourceProcessor extends GridProcessorAdapter { } /** - * Gets rid of job wrapper, if any. - * - * @param job Job to unwrap. - * @return Unwrapped job. - */ - private ComputeJob unwrapJob(ComputeJob job) { - if (job instanceof GridComputeJobWrapper) - return ((GridComputeJobWrapper)job).wrappedJob(); - - return job; - } - - /** * Injects held resources into given grid task. * * @param dep Deployed class. http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a1ce1ce4/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 660d6ba..254f171 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,19 +88,4 @@ 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/a1ce1ce4/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridComputeJobWrapper.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridComputeJobWrapper.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridComputeJobWrapper.java deleted file mode 100644 index 82c0078..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridComputeJobWrapper.java +++ /dev/null @@ -1,96 +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.util.lang; - -import org.apache.ignite.compute.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.jetbrains.annotations.*; - -import java.util.concurrent.*; - -/** - * Convenient wrapper for grid job. It allows to create a job clone in cases when the same - * job needs to be cloned to multiple grid nodes during mapping phase of task execution. - */ -public class GridComputeJobWrapper implements ComputeJob, Callable, - GridPeerDeployAware { - /** */ - private static final long serialVersionUID = 0L; - - /** */ - private final ComputeJob job; - - /** Peer deploy aware class. */ - private transient volatile GridPeerDeployAware p; - - /** - * Creates a wrapper with given grid {@code job}. - * - * @param job Job to wrap. - */ - public GridComputeJobWrapper(ComputeJob job) { - A.notNull(job, "job"); - - this.job = job; - } - - /** - * Gets wrapped job. - * - * @return Wrapped job. - */ - public ComputeJob wrappedJob() { - return job; - } - - /** {@inheritDoc} */ - @Nullable @Override public final Object call() throws Exception { - return execute(); - } - - /** {@inheritDoc} */ - @Override public Class deployClass() { - if (p == null) - p = U.detectPeerDeployAware(this); - - return p.deployClass(); - } - - /** {@inheritDoc} */ - @Override public ClassLoader classLoader() { - if (p == null) - p = U.detectPeerDeployAware(this); - - return p.classLoader(); - } - - /** {@inheritDoc} */ - @Override public void cancel() { - job.cancel(); - } - - /** {@inheritDoc} */ - @Override public Object execute() { - return job.execute(); - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(GridComputeJobWrapper.class, this); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a1ce1ce4/modules/core/src/main/java/org/apache/ignite/resources/InjectRecursively.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/resources/InjectRecursively.java b/modules/core/src/main/java/org/apache/ignite/resources/InjectRecursively.java new file mode 100644 index 0000000..6cf8c8a --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/resources/InjectRecursively.java @@ -0,0 +1,22 @@ +/* @java.file.header */ + +/* _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.resources; + +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. +}