Skip to content

Commit

Permalink
# ignite-47 Disable unnecessary injection.
Browse files Browse the repository at this point in the history
(cherry picked from commit 2c29387)
  • Loading branch information
sevdokimov-gg committed Mar 11, 2015
1 parent 330a705 commit 6717796
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 22 deletions.
Expand Up @@ -22,6 +22,7 @@
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.*;
Expand Down Expand Up @@ -1092,7 +1093,7 @@ protected TaskNoReduceAdapter(@Nullable GridPeerDeployAware pda) {
* 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;

Expand Down Expand Up @@ -1126,7 +1127,7 @@ private T1(GridClosureCallMode mode, Collection<? extends Runnable> jobs) {
* 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;

Expand Down Expand Up @@ -1157,7 +1158,7 @@ private T2(GridClosureCallMode mode, Runnable job) {
* 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;

Expand Down Expand Up @@ -1210,7 +1211,7 @@ private T3(GridClosureCallMode mode, Collection<? extends Callable<R1>> jobs, Ig

/**
*/
private static class T4 extends TaskNoReduceAdapter<Void> {
private static class T4 extends TaskNoReduceAdapter<Void> implements GridNoImplicitInjection {
/** */
private static final long serialVersionUID = 0L;

Expand Down Expand Up @@ -1241,7 +1242,7 @@ private T4(ClusterNode node, Runnable job) {

/**
*/
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;

Expand Down Expand Up @@ -1284,7 +1285,7 @@ private T5(ClusterNode node, Callable<R> job) {
* 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;

Expand Down Expand Up @@ -1327,7 +1328,7 @@ private T6(
* 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;

Expand Down Expand Up @@ -1365,7 +1366,7 @@ private T7(GridClosureCallMode mode, Callable<R> job) {

/**
*/
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;

Expand Down Expand Up @@ -1409,7 +1410,8 @@ private T8(IgniteClosure<T, R> job, @Nullable T arg) {

/**
*/
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;

Expand Down Expand Up @@ -1460,7 +1462,7 @@ private T9(IgniteClosure<T, R> job, Collection<? extends T> args) {

/**
*/
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;

Expand Down Expand Up @@ -1526,7 +1528,8 @@ private T10(IgniteClosure<T, R1> job, Collection<? extends T> args, IgniteReduce

/**
*/
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;

Expand Down Expand Up @@ -1574,7 +1577,8 @@ private T11(IgniteClosure<T, R> job, @Nullable T arg) {
/**
*
*/
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;

Expand Down Expand Up @@ -1623,6 +1627,11 @@ public C1(){
arg = (T)in.readObject();
}

/** {@inheritDoc} */
@Override public IgniteClosure userObject() {
return job;
}

/** {@inheritDoc} */
@Override public String toString() {
return S.toString(C1.class, this);
Expand Down Expand Up @@ -1665,7 +1674,7 @@ private C1MLA(IgniteClosure<T, R> job, T arg) {
/**
*
*/
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;

Expand Down Expand Up @@ -1711,6 +1720,11 @@ private C2(Callable<R> c) {
c = (Callable<R>)in.readObject();
}

/** {@inheritDoc} */
@Override public Callable userObject() {
return c;
}

/** {@inheritDoc} */
@Override public String toString() {
return S.toString(C2.class, this);
Expand Down Expand Up @@ -1751,7 +1765,7 @@ private C2MLA(Callable<R> c) {

/**
*/
private static class C4 implements ComputeJob, Externalizable {
private static class C4 implements ComputeJob, Externalizable, GridNoImplicitInjection, GridInternalWrapper<Runnable> {
/** */
private static final long serialVersionUID = 0L;

Expand Down Expand Up @@ -1794,6 +1808,11 @@ private C4(Runnable r) {
r = (Runnable)in.readObject();
}

/** {@inheritDoc} */
@Override public Runnable userObject() {
return r;
}

/** {@inheritDoc} */
@Override public String toString() {
return S.toString(C4.class, this);
Expand All @@ -1803,7 +1822,7 @@ private C4(Runnable r) {
/**
*
*/
private static class C4MLA extends C4 implements ComputeJobMasterLeaveAware{
private static class C4MLA extends C4 implements ComputeJobMasterLeaveAware {
/** */
private static final long serialVersionUID = 0L;

Expand Down
@@ -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 {

}
Expand Up @@ -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.*;
Expand All @@ -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);
}

/**
Expand All @@ -68,6 +71,13 @@ public Annotation getAnnotation() {
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);
Expand Down
Expand Up @@ -158,10 +158,8 @@ private boolean injectInternal(Object target,
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);
Expand Down Expand Up @@ -361,13 +359,18 @@ private GridResourceField[] getFieldsWithAnnotation(@Nullable GridDeployment dep
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));
}
}
}

Expand Down

0 comments on commit 6717796

Please sign in to comment.