ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sevdoki...@apache.org
Subject [4/5] incubator-ignite git commit: # ignite-47 Disable unnecessary injection.
Date Sat, 07 Mar 2015 19:16:52 GMT
# ignite-47 Disable unnecessary injection.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/2c29387a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/2c29387a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/2c29387a

Branch: refs/heads/ignite-47
Commit: 2c29387acc497cef63ac291003a31c67154f198b
Parents: 4d816eb
Author: sevdokimov <sergey.evdokimov@jetbrains.com>
Authored: Sat Mar 7 21:14:48 2015 +0300
Committer: sevdokimov <sergey.evdokimov@jetbrains.com>
Committed: Sat Mar 7 21:14:48 2015 +0300

----------------------------------------------------------------------
 .../closure/GridClosureProcessor.java           | 49 ++++++++++++++------
 .../resource/GridNoImplicitInjection.java       | 25 ++++++++++
 .../processors/resource/GridResourceField.java  | 12 ++++-
 .../processors/resource/GridResourceIoc.java    | 15 +++---
 4 files changed, 79 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2c29387a/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 aa170ab..f6103e3 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
@@ -22,6 +22,7 @@ import org.apache.ignite.cluster.*;
 import org.apache.ignite.compute.*;
 import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.processors.*;
+import org.apache.ignite.internal.processors.resource.*;
 import org.apache.ignite.internal.util.*;
 import org.apache.ignite.internal.util.future.*;
 import org.apache.ignite.internal.util.lang.*;
@@ -1104,7 +1105,7 @@ public class GridClosureProcessor extends GridProcessorAdapter {
      * Task that is free of dragged in enclosing context for the method
      * {@link GridClosureProcessor#runAsync(GridClosureCallMode, Collection, Collection)}.
      */
-    private class T1 extends TaskNoReduceAdapter<Void> {
+    private class T1 extends TaskNoReduceAdapter<Void> implements GridNoImplicitInjection
{
         /** */
         private static final long serialVersionUID = 0L;
 
@@ -1138,7 +1139,7 @@ public class GridClosureProcessor extends GridProcessorAdapter {
      * Task that is free of dragged in enclosing context for the method
      * {@link GridClosureProcessor#runAsync(GridClosureCallMode, Runnable, Collection)}.
      */
-    private class T2 extends TaskNoReduceAdapter<Void> {
+    private class T2 extends TaskNoReduceAdapter<Void> implements GridNoImplicitInjection
{
         /** */
         private static final long serialVersionUID = 0L;
 
@@ -1169,7 +1170,7 @@ public class GridClosureProcessor extends GridProcessorAdapter {
      * Task that is free of dragged in enclosing context for the method
      * {@link GridClosureProcessor#forkjoinAsync(GridClosureCallMode, Collection, org.apache.ignite.lang.IgniteReducer,
Collection)}
      */
-    private class T3<R1, R2> extends GridPeerDeployAwareTaskAdapter<Void, R2>
{
+    private class T3<R1, R2> extends GridPeerDeployAwareTaskAdapter<Void, R2>
implements GridNoImplicitInjection {
         /** */
         private static final long serialVersionUID = 0L;
 
@@ -1222,7 +1223,7 @@ public class GridClosureProcessor extends GridProcessorAdapter {
 
     /**
      */
-    private static class T4 extends TaskNoReduceAdapter<Void> {
+    private static class T4 extends TaskNoReduceAdapter<Void> implements GridNoImplicitInjection
{
         /** */
         private static final long serialVersionUID = 0L;
 
@@ -1253,7 +1254,7 @@ public class GridClosureProcessor extends GridProcessorAdapter {
 
     /**
      */
-    private static class T5<R> extends GridPeerDeployAwareTaskAdapter<Void, R>
{
+    private static class T5<R> extends GridPeerDeployAwareTaskAdapter<Void, R>
implements GridNoImplicitInjection {
         /** */
         private static final long serialVersionUID = 0L;
 
@@ -1296,7 +1297,7 @@ public class GridClosureProcessor extends GridProcessorAdapter {
      * Task that is free of dragged in enclosing context for the method
      * {@link GridClosureProcessor#callAsync(GridClosureCallMode, Collection, Collection)}
      */
-    private class T6<R> extends GridPeerDeployAwareTaskAdapter<Void, Collection<R>>
{
+    private class T6<R> extends GridPeerDeployAwareTaskAdapter<Void, Collection<R>>
implements GridNoImplicitInjection {
         /** */
         private static final long serialVersionUID = 0L;
 
@@ -1339,7 +1340,7 @@ public class GridClosureProcessor extends GridProcessorAdapter {
      * Task that is free of dragged in enclosing context for the method
      * {@link GridClosureProcessor#callAsync(GridClosureCallMode, Callable, Collection)}
      */
-    private class T7<R> extends GridPeerDeployAwareTaskAdapter<Void, R> {
+    private class T7<R> extends GridPeerDeployAwareTaskAdapter<Void, R> implements
GridNoImplicitInjection {
         /** */
         private static final long serialVersionUID = 0L;
 
@@ -1377,7 +1378,7 @@ public class GridClosureProcessor extends GridProcessorAdapter {
 
     /**
      */
-    private static class T8<T, R> extends GridPeerDeployAwareTaskAdapter<Void, R>
{
+    private static class T8<T, R> extends GridPeerDeployAwareTaskAdapter<Void, R>
implements GridNoImplicitInjection {
         /** */
         private static final long serialVersionUID = 0L;
 
@@ -1421,7 +1422,8 @@ public class GridClosureProcessor extends GridProcessorAdapter {
 
     /**
      */
-    private class T9<T, R> extends GridPeerDeployAwareTaskAdapter<Void, Collection<R>>
{
+    private class T9<T, R> extends GridPeerDeployAwareTaskAdapter<Void, Collection<R>>
+        implements GridNoImplicitInjection {
         /** */
         private static final long serialVersionUID = 0L;
 
@@ -1472,7 +1474,7 @@ public class GridClosureProcessor extends GridProcessorAdapter {
 
     /**
      */
-    private class T10<T, R1, R2> extends GridPeerDeployAwareTaskAdapter<Void, R2>
{
+    private class T10<T, R1, R2> extends GridPeerDeployAwareTaskAdapter<Void, R2>
implements GridNoImplicitInjection {
         /** */
         private static final long serialVersionUID = 0L;
 
@@ -1538,7 +1540,8 @@ public class GridClosureProcessor extends GridProcessorAdapter {
 
     /**
      */
-    private class T11<T, R> extends GridPeerDeployAwareTaskAdapter<Void, Collection<R>>
{
+    private class T11<T, R> extends GridPeerDeployAwareTaskAdapter<Void, Collection<R>>
+        implements GridNoImplicitInjection {
         /** */
         private static final long serialVersionUID = 0L;
 
@@ -1586,7 +1589,8 @@ public class GridClosureProcessor extends GridProcessorAdapter {
     /**
      *
      */
-    private static class C1<T, R> implements ComputeJob, Externalizable {
+    private static class C1<T, R> implements ComputeJob, Externalizable, GridNoImplicitInjection,
+        GridInternalWrapper<IgniteClosure> {
         /** */
         private static final long serialVersionUID = 0L;
 
@@ -1636,6 +1640,11 @@ public class GridClosureProcessor extends GridProcessorAdapter {
         }
 
         /** {@inheritDoc} */
+        @Override public IgniteClosure userObject() {
+            return job;
+        }
+
+        /** {@inheritDoc} */
         @Override public String toString() {
             return S.toString(C1.class, this);
         }
@@ -1677,7 +1686,7 @@ public class GridClosureProcessor extends GridProcessorAdapter {
     /**
      *
      */
-    private static class C2<R> implements ComputeJob, Externalizable {
+    private static class C2<R> implements ComputeJob, Externalizable, GridNoImplicitInjection,
GridInternalWrapper<Callable> {
         /** */
         private static final long serialVersionUID = 0L;
 
@@ -1724,6 +1733,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,7 +1777,7 @@ public class GridClosureProcessor extends GridProcessorAdapter {
 
     /**
      */
-    private static class C4 implements ComputeJob, Externalizable {
+    private static class C4 implements ComputeJob, Externalizable, GridNoImplicitInjection,
GridInternalWrapper<Runnable> {
         /** */
         private static final long serialVersionUID = 0L;
 
@@ -1807,6 +1821,11 @@ public class GridClosureProcessor extends GridProcessorAdapter {
         }
 
         /** {@inheritDoc} */
+        @Override public Runnable userObject() {
+            return r;
+        }
+
+        /** {@inheritDoc} */
         @Override public String toString() {
             return S.toString(C4.class, this);
         }
@@ -1815,7 +1834,7 @@ public class GridClosureProcessor extends GridProcessorAdapter {
     /**
      *
      */
-    private static class C4MLA extends C4 implements ComputeJobMasterLeaveAware{
+    private static class C4MLA extends C4 implements ComputeJobMasterLeaveAware {
         /** */
         private static final long serialVersionUID = 0L;
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2c29387a/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridNoImplicitInjection.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridNoImplicitInjection.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridNoImplicitInjection.java
new file mode 100644
index 0000000..93b833d
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridNoImplicitInjection.java
@@ -0,0 +1,25 @@
+/*
+ * 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;
+
+/**
+ * Disables injection.
+ */
+public interface GridNoImplicitInjection {
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2c29387a/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceField.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceField.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceField.java
index 04f750f..6b921f4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceField.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceField.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.internal.processors.resource;
 
 import org.apache.ignite.internal.util.typedef.internal.*;
+import org.jetbrains.annotations.*;
 
 import java.lang.annotation.*;
 import java.lang.reflect.*;
@@ -42,12 +43,14 @@ class GridResourceField {
      * @param field Field where resource should be injected.
      * @param ann Resource annotation.
      */
-    GridResourceField(Field field, Annotation ann) {
+    GridResourceField(Field field, @Nullable Annotation ann) {
         assert field != null;
         assert ann != null || GridResourceUtils.mayRequireResources(field);
 
         this.field = field;
         this.ann = ann;
+
+        field.setAccessible(true);
     }
 
     /**
@@ -68,6 +71,13 @@ class GridResourceField {
         return ann;
     }
 
+    /**
+     * Return {@code true} if field contains object that should be process too.
+     */
+    public boolean processFieldValue() {
+        return ann == null;
+    }
+
     /** {@inheritDoc} */
     @Override public String toString() {
         return S.toString(GridResourceField.class, this);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2c29387a/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 de1ce60..10e0884 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
@@ -158,10 +158,8 @@ class GridResourceIoc {
         boolean injected = false;
 
         for (GridResourceField field : getFieldsWithAnnotation(dep, targetCls, annCls)) {
-            Field f = field.getField();
-
-            if (GridResourceUtils.mayRequireResources(f)) {
-                f.setAccessible(true);
+            if (field.processFieldValue()) {
+                Field f = field.getField();
 
                 try {
                     Object obj = f.get(target);
@@ -361,13 +359,18 @@ class GridResourceIoc {
         if (fields == null) {
             List<GridResourceField> fieldsList = new ArrayList<>();
 
+            boolean allowImplicitInjection = !GridNoImplicitInjection.class.isAssignableFrom(cls);
+
             for (Class cls0 = cls; !cls0.equals(Object.class); cls0 = cls0.getSuperclass())
{
                 for (Field field : cls0.getDeclaredFields()) {
                     Annotation ann = field.getAnnotation(annCls);
 
-                    if (ann != null || GridResourceUtils.mayRequireResources(field))
-                        // Account for anonymous inner classes.
+                    if (ann != null)
                         fieldsList.add(new GridResourceField(field, ann));
+                    else if (allowImplicitInjection && GridResourceUtils.mayRequireResources(field))
{
+                        // Account for anonymous inner classes.
+                        fieldsList.add(new GridResourceField(field, null));
+                    }
                 }
             }
 


Mime
View raw message