You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by se...@apache.org on 2015/05/14 16:40:32 UTC
[05/26] 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-709_2
Commit: a1ce1ce4b749f2fc12a803052bf0df21eb42f675
Parents: 96ad5a8
Author: sevdokimov <se...@gridgain.com>
Authored: Tue May 12 19:15:56 2015 +0300
Committer: sevdokimov <se...@gridgain.com>
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<T> {
- /**
- * 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<T, R> implements ComputeJob, Externalizable, GridNoImplicitInjection,
- GridInternalWrapper<IgniteClosure> {
+ private static class C1<T, R> implements ComputeJob, Externalizable {
/** */
private static final long serialVersionUID = 0L;
/** */
+ @InjectRecursively
protected IgniteClosure<T, R> 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<R> implements ComputeJob, Externalizable, GridNoImplicitInjection, GridInternalWrapper<Callable> {
+ private static class C2<R> implements ComputeJob, Externalizable {
/** */
private static final long serialVersionUID = 0L;
/** */
+ @InjectRecursively
protected Callable<R> 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<Runnable> {
+ 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<IgfsJob> {
+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<IgfsJob> {
@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<GridResourceField>, List<GridResourceMethod>> t2 = annMap.get(ann.annotationType());
-
- if (t2 == null) {
- t2 = new T2<List<GridResourceField>, List<GridResourceMethod>>(
- new ArrayList<GridResourceField>(),
- new ArrayList<GridResourceMethod>());
+ if (injectRecursively != null
+ || (allowImplicitInjection && field.getName().startsWith("this$")
+ || field.getName().startsWith("val$")))
+ recursiveFieldsList.add(field);
+ else {
+ for (Annotation ann : field.getAnnotations()) {
+ T2<List<GridResourceField>, List<GridResourceMethod>> t2 = annMap.get(ann.annotationType());
- annMap.put(ann.annotationType(), t2);
- }
+ if (t2 == null) {
+ t2 = new T2<List<GridResourceField>, List<GridResourceMethod>>(
+ new ArrayList<GridResourceField>(),
+ new ArrayList<GridResourceMethod>());
- 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<Object>,
- 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.
+}