# ignite-63
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/cc186b52 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/cc186b52 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/cc186b52 Branch: refs/heads/ignite-63 Commit: cc186b52192ef63b1c60a07bb8231354343156e7 Parents: a6f9c9e Author: sboikov <semen.boi...@inria.fr> Authored: Fri Jan 23 01:30:24 2015 +0300 Committer: sboikov <semen.boi...@inria.fr> Committed: Fri Jan 23 01:30:24 2015 +0300 ---------------------------------------------------------------------- .../aop/aspectj/GridifyAspectJAspect.java | 123 ++++ .../aspectj/GridifySetToSetAspectJAspect.java | 134 ++++ .../aspectj/GridifySetToValueAspectJAspect.java | 134 ++++ .../compute/gridify/aop/aspectj/package.html | 24 + .../aop/spring/GridifySetToSetSpringAspect.java | 129 ++++ .../spring/GridifySetToValueSpringAspect.java | 129 ++++ .../gridify/aop/spring/GridifySpringAspect.java | 118 +++ .../aop/spring/GridifySpringEnhancer.java | 81 ++ .../aop/spring/GridifySpringPointcut.java | 136 ++++ .../compute/gridify/aop/spring/package.html | 23 + .../aop/aspectj/GridifyAspectJAspect.java | 123 ---- .../aspectj/GridifySetToSetAspectJAspect.java | 134 ---- .../aspectj/GridifySetToValueAspectJAspect.java | 134 ---- .../compute/gridify/aop/aspectj/package.html | 24 - .../aop/spring/GridifySetToSetSpringAspect.java | 129 ---- .../spring/GridifySetToValueSpringAspect.java | 129 ---- .../gridify/aop/spring/GridifySpringAspect.java | 118 --- .../aop/spring/GridifySpringEnhancer.java | 82 --- .../aop/spring/GridifySpringPointcut.java | 136 ---- .../compute/gridify/aop/spring/package.html | 23 - .../test/config/aop/aspectj/META-INF/aop.xml | 6 +- .../ignite/gridify/GridAbstractAopTest.java | 734 +++++++++++++++++++ .../ignite/gridify/GridBasicAopSelfTest.java | 77 ++ .../gridify/GridNonSpringAopSelfTest.java | 57 ++ .../ignite/gridify/GridSpringAopSelfTest.java | 52 ++ .../ignite/gridify/GridTestAopTarget.java | 138 ++++ .../gridify/GridTestAopTargetInterface.java | 87 +++ .../gridify/GridTestGridifyException.java | 38 + .../ignite/gridify/GridTestGridifyJob.java | 67 ++ .../ignite/gridify/GridTestGridifyTask.java | 47 ++ .../ignite/gridify/GridifySetToSetTarget.java | 372 ++++++++++ .../gridify/GridifySetToSetTargetInterface.java | 109 +++ .../ignite/gridify/GridifySetToValueTarget.java | 199 +++++ .../GridifySetToValueTargetInterface.java | 100 +++ .../GridifySetToXXXNonSpringAopSelfTest.java | 203 +++++ .../GridifySetToXXXSpringAopSelfTest.java | 204 ++++++ .../gridify/hierarchy/GridSuperTarget.java | 53 ++ .../ignite/gridify/hierarchy/GridTarget.java | 45 ++ .../gridify/hierarchy/GridifyHierarchyTest.java | 51 ++ .../ignite/gridify/hierarchy/package.html | 23 + .../java/org/apache/ignite/gridify/package.html | 23 + .../ignite/gridify/test_resource.properties | 18 + .../GridOptimizedMarshallerAopTest.java | 105 +++ .../ignite/p2p/GridP2PGridifySelfTest.java | 242 ++++++ .../ignite/testsuites/GridAopSelfTestSuite.java | 2 +- .../GridSingleSplitTestJobTarget.java | 46 ++ .../singlesplit/GridSingleSplitTestTask.java | 94 +++ .../singlesplit/GridSingleSplitsLoadTest.java | 135 ++++ .../loadtests/direct/singlesplit/package.html | 24 + .../gridify/GridifyLoadTestJobTarget.java | 37 + .../loadtests/gridify/GridifyLoadTestTask.java | 70 ++ .../gridify/GridifySingleSplitLoadTest.java | 157 ++++ .../GridOptimizedMarshallerAopTest.java | 105 --- .../grid/p2p/GridP2PGridifySelfTest.java | 241 ------ .../GridSingleSplitTestJobTarget.java | 46 -- .../singlesplit/GridSingleSplitTestTask.java | 94 --- .../singlesplit/GridSingleSplitsLoadTest.java | 135 ---- .../loadtests/direct/singlesplit/package.html | 24 - .../gridify/GridifyLoadTestJobTarget.java | 37 - .../loadtests/gridify/GridifyLoadTestTask.java | 70 -- .../gridify/GridifySingleSplitLoadTest.java | 157 ---- .../GridExternalNonSpringAopSelfTest.java | 2 +- 62 files changed, 4643 insertions(+), 1946 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cc186b52/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/aspectj/GridifyAspectJAspect.java ---------------------------------------------------------------------- diff --git a/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/aspectj/GridifyAspectJAspect.java b/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/aspectj/GridifyAspectJAspect.java new file mode 100644 index 0000000..de26d2c --- /dev/null +++ b/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/aspectj/GridifyAspectJAspect.java @@ -0,0 +1,123 @@ +/* + * 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.compute.gridify.aop.aspectj; + +import org.apache.ignite.*; +import org.apache.ignite.compute.*; +import org.apache.ignite.compute.gridify.*; +import org.apache.ignite.compute.gridify.aop.*; +import org.aspectj.lang.*; +import org.aspectj.lang.annotation.*; +import org.aspectj.lang.reflect.*; +import org.apache.ignite.internal.util.typedef.*; +import java.lang.reflect.*; + +import static org.apache.ignite.IgniteState.*; + +/** + * AspectJ aspect that cross-cuts on all methods grid-enabled with + * {@link org.apache.ignite.compute.gridify.Gridify} annotation and potentially executes them on + * remote node. + * <p> + * See {@link org.apache.ignite.compute.gridify.Gridify} documentation for more information about execution of + * {@code gridified} methods. + * @see org.apache.ignite.compute.gridify.Gridify + */ +@Aspect +public class GridifyAspectJAspect { + /** + * Aspect implementation which executes grid-enabled methods on remote + * nodes. + * + * @param joinPnt Join point provided by AspectJ AOP. + * @return Method execution result. + * @throws Throwable If execution failed. + */ + @SuppressWarnings({"ProhibitedExceptionDeclared", "ProhibitedExceptionThrown", "CatchGenericClass", "unchecked"}) + @Around("execution(@org.apache.ignite.compute.gridify.Gridify * *(..)) && !cflow(call(* org.apache.ignite.compute.ComputeJob.*(..)))") + public Object gridify(ProceedingJoinPoint joinPnt) throws Throwable { + Method mtd = ((MethodSignature) joinPnt.getSignature()).getMethod(); + + Gridify ann = mtd.getAnnotation(Gridify.class); + + assert ann != null : "Intercepted method does not have gridify annotation."; + + // Since annotations in Java don't allow 'null' as default value + // we have accept an empty string and convert it here. + // NOTE: there's unintended behavior when user specifies an empty + // string as intended grid name. + // NOTE: the 'ann.gridName() == null' check is added to mitigate + // annotation bugs in some scripting languages (e.g. Groovy). + String gridName = F.isEmpty(ann.gridName()) ? null : ann.gridName(); + + if (G.state(gridName) != STARTED) + throw new IgniteCheckedException("Grid is not locally started: " + gridName); + + // Initialize defaults. + GridifyArgument arg = new GridifyArgumentAdapter(mtd.getDeclaringClass(), mtd.getName(), + mtd.getParameterTypes(), joinPnt.getArgs(), joinPnt.getTarget()); + + if (!ann.interceptor().equals(GridifyInterceptor.class)) { + // Check interceptor first. + if (!ann.interceptor().newInstance().isGridify(ann, arg)) + return joinPnt.proceed(); + } + + if (!ann.taskClass().equals(GridifyDefaultTask.class) && !ann.taskName().isEmpty()) { + throw new IgniteCheckedException("Gridify annotation must specify either Gridify.taskName() or " + + "Gridify.taskClass(), but not both: " + ann); + } + + try { + Ignite ignite = G.ignite(gridName); + + // If task class was specified. + if (!ann.taskClass().equals(GridifyDefaultTask.class)) { + return ignite.compute().withTimeout(ann.timeout()).execute( + (Class<? extends ComputeTask<GridifyArgument, Object>>)ann.taskClass(), arg); + } + + // If task name was not specified. + if (ann.taskName().isEmpty()) { + return ignite.compute().withTimeout(ann.timeout()).execute(new GridifyDefaultTask( + joinPnt.getSignature().getDeclaringType()), arg); + } + + // If task name was specified. + return ignite.compute().withTimeout(ann.timeout()).execute(ann.taskName(), arg); + } + catch (Throwable e) { + for (Class<?> ex : ((MethodSignature) joinPnt.getSignature()).getMethod().getExceptionTypes()) { + // Descend all levels down. + Throwable cause = e.getCause(); + + while (cause != null) { + if (ex.isAssignableFrom(cause.getClass())) + throw cause; + + cause = cause.getCause(); + } + + if (ex.isAssignableFrom(e.getClass())) + throw e; + } + + throw new GridifyRuntimeException("Undeclared exception thrown: " + e.getMessage(), e); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cc186b52/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/aspectj/GridifySetToSetAspectJAspect.java ---------------------------------------------------------------------- diff --git a/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/aspectj/GridifySetToSetAspectJAspect.java b/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/aspectj/GridifySetToSetAspectJAspect.java new file mode 100644 index 0000000..93c9faa --- /dev/null +++ b/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/aspectj/GridifySetToSetAspectJAspect.java @@ -0,0 +1,134 @@ +/* + * 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.compute.gridify.aop.aspectj; + +import org.apache.ignite.*; +import org.apache.ignite.compute.gridify.*; +import org.apache.ignite.compute.gridify.aop.*; +import org.aspectj.lang.*; +import org.aspectj.lang.annotation.*; +import org.aspectj.lang.reflect.*; +import org.apache.ignite.internal.util.typedef.*; +import org.apache.ignite.internal.util.gridify.*; +import java.lang.reflect.*; + +import static org.apache.ignite.IgniteState.*; +import static org.apache.ignite.internal.util.gridify.GridifyUtils.*; + +/** + * AspectJ aspect that cross-cuts on all methods grid-enabled with + * {@link GridifySetToSet} annotation and potentially executes them on + * remote node. + * <p> + * See {@link GridifySetToSet} documentation for more information about execution of + * {@code gridified} methods. + * @see GridifySetToSet + */ +@Aspect +public class GridifySetToSetAspectJAspect extends GridifySetToSetAbstractAspect { + /** + * Aspect implementation which executes grid-enabled methods on remote + * nodes. + * + * @param joinPnt Join point provided by AspectJ AOP. + * @return Method execution result. + * @throws Throwable If execution failed. + */ + @SuppressWarnings({"ProhibitedExceptionDeclared", "ProhibitedExceptionThrown", "CatchGenericClass"}) + @Around("execution(@org.apache.ignite.compute.gridify.GridifySetToSet * *(..)) && !cflow(call(* org.apache.ignite.compute.ComputeJob.*(..)))") + public Object gridify(ProceedingJoinPoint joinPnt) throws Throwable { + Method mtd = ((MethodSignature) joinPnt.getSignature()).getMethod(); + + GridifySetToSet ann = mtd.getAnnotation(GridifySetToSet.class); + + assert ann != null : "Intercepted method does not have gridify annotation."; + + // Since annotations in Java don't allow 'null' as default value + // we have accept an empty string and convert it here. + // NOTE: there's unintended behavior when user specifies an empty + // string as intended grid name. + // NOTE: the 'ann.gridName() == null' check is added to mitigate + // annotation bugs in some scripting languages (e.g. Groovy). + String gridName = F.isEmpty(ann.gridName()) ? null : ann.gridName(); + + if (G.state(gridName) != STARTED) + throw new IgniteCheckedException("Grid is not locally started: " + gridName); + + GridifyNodeFilter nodeFilter = null; + + if (!ann.nodeFilter().equals(GridifyNodeFilter.class)) + nodeFilter = ann.nodeFilter().newInstance(); + + // Check method return type. + checkMethodSignature(mtd); + + GridifyArgumentBuilder argBuilder = new GridifyArgumentBuilder(); + + // Creates task argument. + GridifyRangeArgument arg = argBuilder.createTaskArgument( + mtd.getDeclaringClass(), + mtd.getName(), + mtd.getReturnType(), + mtd.getParameterTypes(), + mtd.getParameterAnnotations(), + joinPnt.getArgs(), + joinPnt.getTarget()); + + if (!ann.interceptor().equals(GridifyInterceptor.class)) { + // Check interceptor first. + if (!ann.interceptor().newInstance().isGridify(ann, arg)) + return joinPnt.proceed(); + } + + // Proceed locally for negative threshold parameter. + if (ann.threshold() < 0) + return joinPnt.proceed(); + + // Analyse where to execute method (remotely or locally). + if (arg.getInputSize() != UNKNOWN_SIZE && arg.getInputSize() <= ann.threshold()) + return joinPnt.proceed(); + + // Check is split to jobs allowed for input method argument with declared splitSize. + checkIsSplitToJobsAllowed(arg, ann); + + try { + Ignite ignite = G.ignite(gridName); + + return execute(ignite.compute(), joinPnt.getSignature().getDeclaringType(), arg, nodeFilter, + ann.threshold(), ann.splitSize(), ann.timeout()); + } + catch (Throwable e) { + for (Class<?> ex : ((MethodSignature) joinPnt.getSignature()).getMethod().getExceptionTypes()) { + // Descend all levels down. + Throwable cause = e.getCause(); + + while (cause != null) { + if (ex.isAssignableFrom(cause.getClass())) + throw cause; + + cause = cause.getCause(); + } + + if (ex.isAssignableFrom(e.getClass())) + throw e; + } + + throw new GridifyRuntimeException("Undeclared exception thrown: " + e.getMessage(), e); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cc186b52/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/aspectj/GridifySetToValueAspectJAspect.java ---------------------------------------------------------------------- diff --git a/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/aspectj/GridifySetToValueAspectJAspect.java b/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/aspectj/GridifySetToValueAspectJAspect.java new file mode 100644 index 0000000..d67ef04 --- /dev/null +++ b/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/aspectj/GridifySetToValueAspectJAspect.java @@ -0,0 +1,134 @@ +/* + * 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.compute.gridify.aop.aspectj; + +import org.apache.ignite.*; +import org.apache.ignite.compute.gridify.*; +import org.apache.ignite.compute.gridify.aop.*; +import org.aspectj.lang.*; +import org.aspectj.lang.annotation.*; +import org.aspectj.lang.reflect.*; +import org.apache.ignite.internal.util.typedef.*; +import org.apache.ignite.internal.util.gridify.*; +import java.lang.reflect.*; + +import static org.apache.ignite.IgniteState.*; +import static org.apache.ignite.internal.util.gridify.GridifyUtils.*; + +/** + * AspectJ aspect that cross-cuts on all methods grid-enabled with + * {@link GridifySetToValue} annotation and potentially executes them on + * remote node. + * <p> + * See {@link GridifySetToValue} documentation for more information about execution of + * {@code gridified} methods. + * @see GridifySetToValue + */ +@Aspect +public class GridifySetToValueAspectJAspect extends GridifySetToValueAbstractAspect { + /** + * Aspect implementation which executes grid-enabled methods on remote + * nodes. + * + * @param joinPnt Join point provided by AspectJ AOP. + * @return Method execution result. + * @throws Throwable If execution failed. + */ + @SuppressWarnings({"ProhibitedExceptionDeclared", "ProhibitedExceptionThrown", "CatchGenericClass"}) + @Around("execution(@org.apache.ignite.compute.gridify.GridifySetToValue * *(..)) && !cflow(call(* org.apache.ignite.compute.ComputeJob.*(..)))") + public Object gridify(ProceedingJoinPoint joinPnt) throws Throwable { + Method mtd = ((MethodSignature) joinPnt.getSignature()).getMethod(); + + GridifySetToValue ann = mtd.getAnnotation(GridifySetToValue.class); + + assert ann != null : "Intercepted method does not have gridify annotation."; + + // Since annotations in Java don't allow 'null' as default value + // we have accept an empty string and convert it here. + // NOTE: there's unintended behavior when user specifies an empty + // string as intended grid name. + // NOTE: the 'ann.gridName() == null' check is added to mitigate + // annotation bugs in some scripting languages (e.g. Groovy). + String gridName = F.isEmpty(ann.gridName()) ? null : ann.gridName(); + + if (G.state(gridName) != STARTED) + throw new IgniteCheckedException("Grid is not locally started: " + gridName); + + GridifyNodeFilter nodeFilter = null; + + if (!ann.nodeFilter().equals(GridifyNodeFilter.class)) + nodeFilter = ann.nodeFilter().newInstance(); + + // Check is method allowed for gridify. + checkMethodSignature(mtd); + + GridifyArgumentBuilder argBuilder = new GridifyArgumentBuilder(); + + // Creates task argument. + GridifyRangeArgument arg = argBuilder.createTaskArgument( + mtd.getDeclaringClass(), + mtd.getName(), + mtd.getReturnType(), + mtd.getParameterTypes(), + mtd.getParameterAnnotations(), + joinPnt.getArgs(), + joinPnt.getTarget()); + + if (!ann.interceptor().equals(GridifyInterceptor.class)) { + // Check interceptor first. + if (!ann.interceptor().newInstance().isGridify(ann, arg)) + return joinPnt.proceed(); + } + + // Proceed locally for negative threshold parameter. + if (ann.threshold() < 0) + return joinPnt.proceed(); + + // Analyse where to execute method (remotely or locally). + if (arg.getInputSize() != UNKNOWN_SIZE && arg.getInputSize() <= ann.threshold()) + return joinPnt.proceed(); + + // Check is split to jobs allowed for input method argument with declared splitSize. + checkIsSplitToJobsAllowed(arg, ann); + + try { + Ignite ignite = G.ignite(gridName); + + return execute(mtd, ignite.compute(), joinPnt.getSignature().getDeclaringType(), arg, nodeFilter, + ann.threshold(), ann.splitSize(), ann.timeout()); + } + catch (Throwable e) { + for (Class<?> ex : ((MethodSignature) joinPnt.getSignature()).getMethod().getExceptionTypes()) { + // Descend all levels down. + Throwable cause = e.getCause(); + + while (cause != null) { + if (ex.isAssignableFrom(cause.getClass())) + throw cause; + + cause = cause.getCause(); + } + + if (ex.isAssignableFrom(e.getClass())) + throw e; + } + + throw new GridifyRuntimeException("Undeclared exception thrown: " + e.getMessage(), e); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cc186b52/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/aspectj/package.html ---------------------------------------------------------------------- diff --git a/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/aspectj/package.html b/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/aspectj/package.html new file mode 100644 index 0000000..677b0b7 --- /dev/null +++ b/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/aspectj/package.html @@ -0,0 +1,24 @@ +<!-- + 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. + --> + +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<html> +<body> + <!-- Package description. --> + Contains all classes used by AspectJ AOP implementation. +</body> +</html> http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cc186b52/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/spring/GridifySetToSetSpringAspect.java ---------------------------------------------------------------------- diff --git a/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/spring/GridifySetToSetSpringAspect.java b/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/spring/GridifySetToSetSpringAspect.java new file mode 100644 index 0000000..daec6d0 --- /dev/null +++ b/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/spring/GridifySetToSetSpringAspect.java @@ -0,0 +1,129 @@ +/* + * 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.compute.gridify.aop.spring; + +import org.aopalliance.intercept.*; +import org.apache.ignite.*; +import org.apache.ignite.compute.gridify.*; +import org.apache.ignite.compute.gridify.aop.*; +import org.apache.ignite.internal.util.typedef.*; +import org.apache.ignite.internal.util.gridify.*; +import java.lang.reflect.*; + +import static org.apache.ignite.IgniteState.*; +import static org.apache.ignite.internal.util.gridify.GridifyUtils.*; + +/** + * Spring aspect that cross-cuts on all methods grid-enabled with + * {@link GridifySetToSet} annotation and potentially executes them on + * remote node. + * <p> + * Note that Spring uses proxy-based AOP, so in order to be properly + * cross-cut, all methods need to be enhanced with {@link GridifySpringEnhancer} + * helper. + * <p> + * See {@link GridifySetToSet} documentation for more information about execution of + * {@code gridified} methods. + * @see GridifySetToSet + */ +public class GridifySetToSetSpringAspect extends GridifySetToSetAbstractAspect implements MethodInterceptor { + /** + * Aspect implementation which executes grid-enabled methods on remote + * nodes. + * + * {@inheritDoc} + */ + @SuppressWarnings({"ProhibitedExceptionDeclared", "ProhibitedExceptionThrown", "CatchGenericClass"}) + @Override public Object invoke(MethodInvocation invoc) throws Throwable { + Method mtd = invoc.getMethod(); + + GridifySetToSet ann = mtd.getAnnotation(GridifySetToSet.class); + + assert ann != null : "Intercepted method does not have gridify annotation."; + + // Since annotations in Java don't allow 'null' as default value + // we have accept an empty string and convert it here. + // NOTE: there's unintended behavior when user specifies an empty + // string as intended grid name. + // NOTE: the 'ann.gridName() == null' check is added to mitigate + // annotation bugs in some scripting languages (e.g. Groovy). + String gridName = F.isEmpty(ann.gridName()) ? null : ann.gridName(); + + if (G.state(gridName) != STARTED) + throw new IgniteCheckedException("Grid is not locally started: " + gridName); + + GridifyNodeFilter nodeFilter = null; + + if (!ann.nodeFilter().equals(GridifyNodeFilter.class)) + nodeFilter = ann.nodeFilter().newInstance(); + + GridifyArgumentBuilder argBuilder = new GridifyArgumentBuilder(); + + // Creates task argument. + GridifyRangeArgument arg = argBuilder.createTaskArgument( + mtd.getDeclaringClass(), + mtd.getName(), + mtd.getReturnType(), + mtd.getParameterTypes(), + mtd.getParameterAnnotations(), + invoc.getArguments(), + invoc.getThis()); + + if (!ann.interceptor().equals(GridifyInterceptor.class)) { + // Check interceptor first. + if (!ann.interceptor().newInstance().isGridify(ann, arg)) + return invoc.proceed(); + } + + // Proceed locally for negative threshold parameter. + if (ann.threshold() < 0) + return invoc.proceed(); + + // Analyse where to execute method (remotely or locally). + if (arg.getInputSize() != UNKNOWN_SIZE && arg.getInputSize() <= ann.threshold()) + return invoc.proceed(); + + // Check is split to jobs allowed for input method argument with declared splitSize. + checkIsSplitToJobsAllowed(arg, ann); + + try { + Ignite ignite = G.ignite(gridName); + + return execute(ignite.compute(), invoc.getMethod().getDeclaringClass(), arg, nodeFilter, + ann.threshold(), ann.splitSize(), ann.timeout()); + } + catch (Throwable e) { + for (Class<?> ex : invoc.getMethod().getExceptionTypes()) { + // Descend all levels down. + Throwable cause = e.getCause(); + + while (cause != null) { + if (ex.isAssignableFrom(cause.getClass())) + throw cause; + + cause = cause.getCause(); + } + + if (ex.isAssignableFrom(e.getClass())) + throw e; + } + + throw new GridifyRuntimeException("Undeclared exception thrown: " + e.getMessage(), e); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cc186b52/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/spring/GridifySetToValueSpringAspect.java ---------------------------------------------------------------------- diff --git a/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/spring/GridifySetToValueSpringAspect.java b/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/spring/GridifySetToValueSpringAspect.java new file mode 100644 index 0000000..37d7d1c --- /dev/null +++ b/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/spring/GridifySetToValueSpringAspect.java @@ -0,0 +1,129 @@ +/* + * 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.compute.gridify.aop.spring; + +import org.aopalliance.intercept.*; +import org.apache.ignite.*; +import org.apache.ignite.compute.gridify.*; +import org.apache.ignite.compute.gridify.aop.*; +import org.apache.ignite.internal.util.typedef.*; +import org.apache.ignite.internal.util.gridify.*; +import java.lang.reflect.*; + +import static org.apache.ignite.IgniteState.*; +import static org.apache.ignite.internal.util.gridify.GridifyUtils.*; + +/** + * Spring aspect that cross-cuts on all methods grid-enabled with + * {@link GridifySetToValue} annotation and potentially executes them on + * remote node. + * <p> + * Note that Spring uses proxy-based AOP, so in order to be properly + * cross-cut, all methods need to be enhanced with {@link GridifySpringEnhancer} + * helper. + * <p> + * See {@link GridifySetToValue} documentation for more information about execution of + * {@code gridified} methods. + * @see GridifySetToValue + */ +public class GridifySetToValueSpringAspect extends GridifySetToValueAbstractAspect implements MethodInterceptor { + /** + * Aspect implementation which executes grid-enabled methods on remote + * nodes. + * + * {@inheritDoc} + */ + @SuppressWarnings({"ProhibitedExceptionDeclared", "ProhibitedExceptionThrown", "CatchGenericClass"}) + @Override public Object invoke(MethodInvocation invoc) throws Throwable { + Method mtd = invoc.getMethod(); + + GridifySetToValue ann = mtd.getAnnotation(GridifySetToValue.class); + + assert ann != null : "Intercepted method does not have gridify annotation."; + + // Since annotations in Java don't allow 'null' as default value + // we have accept an empty string and convert it here. + // NOTE: there's unintended behavior when user specifies an empty + // string as intended grid name. + // NOTE: the 'ann.gridName() == null' check is added to mitigate + // annotation bugs in some scripting languages (e.g. Groovy). + String gridName = F.isEmpty(ann.gridName()) ? null : ann.gridName(); + + if (G.state(gridName) != STARTED) + throw new IgniteCheckedException("Grid is not locally started: " + gridName); + + GridifyNodeFilter nodeFilter = null; + + if (!ann.nodeFilter().equals(GridifyNodeFilter.class)) + nodeFilter = ann.nodeFilter().newInstance(); + + GridifyArgumentBuilder argBuilder = new GridifyArgumentBuilder(); + + // Creates task argument. + GridifyRangeArgument arg = argBuilder.createTaskArgument( + mtd.getDeclaringClass(), + mtd.getName(), + mtd.getReturnType(), + mtd.getParameterTypes(), + mtd.getParameterAnnotations(), + invoc.getArguments(), + invoc.getThis()); + + if (!ann.interceptor().equals(GridifyInterceptor.class)) { + // Check interceptor first. + if (!ann.interceptor().newInstance().isGridify(ann, arg)) + return invoc.proceed(); + } + + // Proceed locally for negative threshold parameter. + if (ann.threshold() < 0) + return invoc.proceed(); + + // Analyse where to execute method (remotely or locally). + if (arg.getInputSize() != UNKNOWN_SIZE && arg.getInputSize() <= ann.threshold()) + return invoc.proceed(); + + // Check is split to jobs allowed for input method argument with declared splitSize. + checkIsSplitToJobsAllowed(arg, ann); + + try { + Ignite ignite = G.ignite(gridName); + + return execute(mtd, ignite.compute(), invoc.getMethod().getDeclaringClass(), arg, nodeFilter, + ann.threshold(), ann.splitSize(), ann.timeout()); + } + catch (Throwable e) { + for (Class<?> ex : invoc.getMethod().getExceptionTypes()) { + // Descend all levels down. + Throwable cause = e.getCause(); + + while (cause != null) { + if (ex.isAssignableFrom(cause.getClass())) + throw cause; + + cause = cause.getCause(); + } + + if (ex.isAssignableFrom(e.getClass())) + throw e; + } + + throw new GridifyRuntimeException("Undeclared exception thrown: " + e.getMessage(), e); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cc186b52/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/spring/GridifySpringAspect.java ---------------------------------------------------------------------- diff --git a/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/spring/GridifySpringAspect.java b/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/spring/GridifySpringAspect.java new file mode 100644 index 0000000..a11e2f1 --- /dev/null +++ b/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/spring/GridifySpringAspect.java @@ -0,0 +1,118 @@ +/* + * 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.compute.gridify.aop.spring; + +import org.aopalliance.intercept.*; +import org.apache.ignite.*; +import org.apache.ignite.compute.*; +import org.apache.ignite.compute.gridify.*; +import org.apache.ignite.compute.gridify.aop.*; +import org.apache.ignite.internal.util.typedef.*; + +import java.lang.reflect.*; + +import static org.apache.ignite.IgniteState.*; + +/** + * Spring aspect that cross-cuts on all methods grid-enabled with + * {@link org.apache.ignite.compute.gridify.Gridify} annotation and potentially executes them on + * remote node. + * <p> + * Note that Spring uses proxy-based AOP, so in order to be properly + * cross-cut, all methods need to be enhanced with {@link GridifySpringEnhancer} + * helper. + * <p> + * See {@link org.apache.ignite.compute.gridify.Gridify} documentation for more information about execution of + * {@code gridified} methods. + * @see org.apache.ignite.compute.gridify.Gridify + */ +public class GridifySpringAspect implements MethodInterceptor { + /** + * Aspect implementation which executes grid-enabled methods on remote + * nodes. + * + * {@inheritDoc} + */ + @SuppressWarnings({"ProhibitedExceptionDeclared", "ProhibitedExceptionThrown", "CatchGenericClass", "unchecked"}) + @Override public Object invoke(MethodInvocation invoc) throws Throwable { + Method mtd = invoc.getMethod(); + + Gridify ann = mtd.getAnnotation(Gridify.class); + + assert ann != null : "Intercepted method does not have gridify annotation."; + + // Since annotations in Java don't allow 'null' as default value + // we have accept an empty string and convert it here. + // NOTE: there's unintended behavior when user specifies an empty + // string as intended grid name. + // NOTE: the 'ann.gridName() == null' check is added to mitigate + // annotation bugs in some scripting languages (e.g. Groovy). + String gridName = F.isEmpty(ann.gridName()) ? null : ann.gridName(); + + if (G.state(gridName) != STARTED) + throw new IgniteCheckedException("Grid is not locally started: " + gridName); + + // Initialize defaults. + GridifyArgument arg = new GridifyArgumentAdapter(mtd.getDeclaringClass(), mtd.getName(), + mtd.getParameterTypes(), invoc.getArguments(), invoc.getThis()); + + if (!ann.interceptor().equals(GridifyInterceptor.class)) { + // Check interceptor first. + if (!ann.interceptor().newInstance().isGridify(ann, arg)) + return invoc.proceed(); + } + + if (!ann.taskClass().equals(GridifyDefaultTask.class) && !ann.taskName().isEmpty()) + throw new IgniteCheckedException("Gridify annotation must specify either Gridify.taskName() or " + + "Gridify.taskClass(), but not both: " + ann); + + try { + Ignite ignite = G.ignite(gridName); + + if (!ann.taskClass().equals(GridifyDefaultTask.class)) + return ignite.compute().withTimeout(ann.timeout()).execute( + (Class<? extends ComputeTask<GridifyArgument, Object>>)ann.taskClass(), arg); + + // If task name was not specified. + if (ann.taskName().isEmpty()) + return ignite.compute().withTimeout(ann.timeout()).execute( + new GridifyDefaultTask(invoc.getMethod().getDeclaringClass()), arg); + + // If task name was specified. + return ignite.compute().withTimeout(ann.timeout()).execute(ann.taskName(), arg); + } + catch (Throwable e) { + for (Class<?> ex : invoc.getMethod().getExceptionTypes()) { + // Descend all levels down. + Throwable cause = e.getCause(); + + while (cause != null) { + if (ex.isAssignableFrom(cause.getClass())) + throw cause; + + cause = cause.getCause(); + } + + if (ex.isAssignableFrom(e.getClass())) + throw e; + } + + throw new GridifyRuntimeException("Undeclared exception thrown: " + e.getMessage(), e); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cc186b52/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/spring/GridifySpringEnhancer.java ---------------------------------------------------------------------- diff --git a/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/spring/GridifySpringEnhancer.java b/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/spring/GridifySpringEnhancer.java new file mode 100644 index 0000000..d80b24e --- /dev/null +++ b/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/spring/GridifySpringEnhancer.java @@ -0,0 +1,81 @@ +/* + * 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.compute.gridify.aop.spring; + +import org.springframework.aop.framework.*; +import org.springframework.aop.support.*; + +/** + * Spring AOP enhancer. Use it to grid-enable methods annotated with + * {@link org.apache.ignite.compute.gridify.Gridify}, {@link org.apache.ignite.compute.gridify.GridifySetToValue} and {@link org.apache.ignite.compute.gridify.GridifySetToSet} annotations. + * <p> + * Note, that Spring AOP requires that all grid-enabled methods must + * be {@code enhanced} because it is proxy-based. Other AOP implementations, + * such as JBoss or AspectJ don't require special handling. + * <p> + * See {@link org.apache.ignite.compute.gridify.Gridify} documentation for more information about execution of + * {@code gridified} methods. + * @see org.apache.ignite.compute.gridify.Gridify + * @see org.apache.ignite.compute.gridify.GridifySetToValue + * @see org.apache.ignite.compute.gridify.GridifySetToSet + */ +public final class GridifySpringEnhancer { + /** Spring aspect. */ + private static final GridifySpringAspect dfltAsp = new GridifySpringAspect(); + + /** Spring aspect. */ + private static final GridifySetToSetSpringAspect setToSetAsp = new GridifySetToSetSpringAspect(); + + /** Spring aspect. */ + private static final GridifySetToValueSpringAspect setToValAsp = new GridifySetToValueSpringAspect(); + + /** + * Enforces singleton. + */ + private GridifySpringEnhancer() { + // No-op. + } + + /** + * Enhances the object on load. + * + * @param <T> Type of the object to enhance. + * @param obj Object to augment/enhance. + * @return Enhanced object. + */ + @SuppressWarnings({"unchecked"}) + public static <T> T enhance(T obj) { + ProxyFactory proxyFac = new ProxyFactory(obj); + + proxyFac.addAdvice(dfltAsp); + proxyFac.addAdvice(setToValAsp); + proxyFac.addAdvice(setToSetAsp); + + while (proxyFac.getAdvisors().length > 0) + proxyFac.removeAdvisor(0); + + proxyFac.addAdvisor(new DefaultPointcutAdvisor( + new GridifySpringPointcut(GridifySpringPointcutType.DFLT), dfltAsp)); + proxyFac.addAdvisor(new DefaultPointcutAdvisor( + new GridifySpringPointcut(GridifySpringPointcutType.SET_TO_VALUE), setToValAsp)); + proxyFac.addAdvisor(new DefaultPointcutAdvisor( + new GridifySpringPointcut(GridifySpringPointcutType.SET_TO_SET), setToSetAsp)); + + return (T)proxyFac.getProxy(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cc186b52/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/spring/GridifySpringPointcut.java ---------------------------------------------------------------------- diff --git a/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/spring/GridifySpringPointcut.java b/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/spring/GridifySpringPointcut.java new file mode 100644 index 0000000..dd462a2 --- /dev/null +++ b/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/spring/GridifySpringPointcut.java @@ -0,0 +1,136 @@ +/* + * 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.compute.gridify.aop.spring; + +import org.apache.ignite.compute.gridify.*; +import org.springframework.aop.*; +import java.lang.reflect.*; + +/** + * Pointcut used by gridified aspects to find methods + * annotated with {@link org.apache.ignite.compute.gridify.Gridify}, {@link GridifySetToValue} and + * {@link GridifySetToSet} annotations. + */ +public class GridifySpringPointcut implements Pointcut { + /** + * Class filter. + */ + private static final ClassFilter filter = new ClassFilter() { + @SuppressWarnings({"unchecked", "RawUseOfParameterizedType"}) + @Override public boolean matches(Class cls) { + return true; + } + }; + + /** Method matcher. */ + private static final MethodMatcher dfltMatcher = new GridifyMethodMatcher() { + // Warning suppression is due to Spring... + @SuppressWarnings("unchecked") + @Override public boolean matches(Method method, Class cls) { + return cls.isAnnotationPresent(Gridify.class) || method.isAnnotationPresent(Gridify.class); + } + }; + + /** Method matcher. */ + private static final MethodMatcher setToValueMatcher = new GridifyMethodMatcher() { + // Warning suppression is due to Spring... + @SuppressWarnings("unchecked") + @Override public boolean matches(Method method, Class cls) { + return cls.isAnnotationPresent(GridifySetToValue.class) || method.isAnnotationPresent(GridifySetToValue.class); + } + }; + + /** Method matcher. */ + private static final MethodMatcher setToSetMatcher = new GridifyMethodMatcher() { + // Warning suppression is due to Spring... + @SuppressWarnings("unchecked") + @Override public boolean matches(Method method, Class cls) { + return cls.isAnnotationPresent(GridifySetToSet.class) || method.isAnnotationPresent(GridifySetToSet.class); + } + }; + + /** */ + private final GridifySpringPointcutType type; + + /** + * Creates pointcut associated with specific aspect. + * + * @param type Type. + */ + public GridifySpringPointcut(GridifySpringPointcutType type) { + assert type != null; + + this.type = type; + } + + /** {@inheritDoc} */ + @Override public ClassFilter getClassFilter() { + return filter; + } + + /** {@inheritDoc} */ + @Override public MethodMatcher getMethodMatcher() { + switch (type) { + case DFLT: return dfltMatcher; + case SET_TO_VALUE: return setToValueMatcher; + case SET_TO_SET: return setToSetMatcher; + + default: + assert false : "Unknown pointcut type: " + type; + } + + return null; + } + + /** + * Method matcher. + */ + private abstract static class GridifyMethodMatcher implements MethodMatcher { + /** {@inheritDoc} */ + @SuppressWarnings("unchecked") + @Override public abstract boolean matches(Method method, Class cls); + + /** {@inheritDoc} */ + @Override public boolean isRuntime() { + return false; + } + + /** {@inheritDoc} */ + // Warning suppression is due to Spring... + @SuppressWarnings({"unchecked", "RawUseOfParameterizedType"}) + @Override public boolean matches(Method method, Class aClass, Object[] objs) { + // No-op. + return false; + } + } + + /** + * Pointcut type. + */ + @SuppressWarnings({"PublicInnerClass"}) + public enum GridifySpringPointcutType { + /** */ + DFLT, + + /** */ + SET_TO_VALUE, + + /** */ + SET_TO_SET + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cc186b52/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/spring/package.html ---------------------------------------------------------------------- diff --git a/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/spring/package.html b/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/spring/package.html new file mode 100644 index 0000000..3162446 --- /dev/null +++ b/modules/aop/src/main/java/org/apache/ignite/compute/gridify/aop/spring/package.html @@ -0,0 +1,23 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<!-- + 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. + --> +<html> +<body> + <!-- Package description. --> + Contains all classes used by Spring AOP implementation. +</body> +</html> http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cc186b52/modules/aop/src/main/java/org/gridgain/grid/compute/gridify/aop/aspectj/GridifyAspectJAspect.java ---------------------------------------------------------------------- diff --git a/modules/aop/src/main/java/org/gridgain/grid/compute/gridify/aop/aspectj/GridifyAspectJAspect.java b/modules/aop/src/main/java/org/gridgain/grid/compute/gridify/aop/aspectj/GridifyAspectJAspect.java deleted file mode 100644 index e73814c..0000000 --- a/modules/aop/src/main/java/org/gridgain/grid/compute/gridify/aop/aspectj/GridifyAspectJAspect.java +++ /dev/null @@ -1,123 +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.gridgain.grid.compute.gridify.aop.aspectj; - -import org.apache.ignite.*; -import org.apache.ignite.compute.*; -import org.apache.ignite.compute.gridify.*; -import org.apache.ignite.compute.gridify.aop.*; -import org.aspectj.lang.*; -import org.aspectj.lang.annotation.*; -import org.aspectj.lang.reflect.*; -import org.apache.ignite.internal.util.typedef.*; -import java.lang.reflect.*; - -import static org.apache.ignite.IgniteState.*; - -/** - * AspectJ aspect that cross-cuts on all methods grid-enabled with - * {@link org.apache.ignite.compute.gridify.Gridify} annotation and potentially executes them on - * remote node. - * <p> - * See {@link org.apache.ignite.compute.gridify.Gridify} documentation for more information about execution of - * {@code gridified} methods. - * @see org.apache.ignite.compute.gridify.Gridify - */ -@Aspect -public class GridifyAspectJAspect { - /** - * Aspect implementation which executes grid-enabled methods on remote - * nodes. - * - * @param joinPnt Join point provided by AspectJ AOP. - * @return Method execution result. - * @throws Throwable If execution failed. - */ - @SuppressWarnings({"ProhibitedExceptionDeclared", "ProhibitedExceptionThrown", "CatchGenericClass", "unchecked"}) - @Around("execution(@org.apache.ignite.compute.gridify.Gridify * *(..)) && !cflow(call(* org.apache.ignite.compute.ComputeJob.*(..)))") - public Object gridify(ProceedingJoinPoint joinPnt) throws Throwable { - Method mtd = ((MethodSignature) joinPnt.getSignature()).getMethod(); - - Gridify ann = mtd.getAnnotation(Gridify.class); - - assert ann != null : "Intercepted method does not have gridify annotation."; - - // Since annotations in Java don't allow 'null' as default value - // we have accept an empty string and convert it here. - // NOTE: there's unintended behavior when user specifies an empty - // string as intended grid name. - // NOTE: the 'ann.gridName() == null' check is added to mitigate - // annotation bugs in some scripting languages (e.g. Groovy). - String gridName = F.isEmpty(ann.gridName()) ? null : ann.gridName(); - - if (G.state(gridName) != STARTED) - throw new IgniteCheckedException("Grid is not locally started: " + gridName); - - // Initialize defaults. - GridifyArgument arg = new GridifyArgumentAdapter(mtd.getDeclaringClass(), mtd.getName(), - mtd.getParameterTypes(), joinPnt.getArgs(), joinPnt.getTarget()); - - if (!ann.interceptor().equals(GridifyInterceptor.class)) { - // Check interceptor first. - if (!ann.interceptor().newInstance().isGridify(ann, arg)) - return joinPnt.proceed(); - } - - if (!ann.taskClass().equals(GridifyDefaultTask.class) && !ann.taskName().isEmpty()) { - throw new IgniteCheckedException("Gridify annotation must specify either Gridify.taskName() or " + - "Gridify.taskClass(), but not both: " + ann); - } - - try { - Ignite ignite = G.ignite(gridName); - - // If task class was specified. - if (!ann.taskClass().equals(GridifyDefaultTask.class)) { - return ignite.compute().withTimeout(ann.timeout()).execute( - (Class<? extends ComputeTask<GridifyArgument, Object>>)ann.taskClass(), arg); - } - - // If task name was not specified. - if (ann.taskName().isEmpty()) { - return ignite.compute().withTimeout(ann.timeout()).execute(new GridifyDefaultTask( - joinPnt.getSignature().getDeclaringType()), arg); - } - - // If task name was specified. - return ignite.compute().withTimeout(ann.timeout()).execute(ann.taskName(), arg); - } - catch (Throwable e) { - for (Class<?> ex : ((MethodSignature) joinPnt.getSignature()).getMethod().getExceptionTypes()) { - // Descend all levels down. - Throwable cause = e.getCause(); - - while (cause != null) { - if (ex.isAssignableFrom(cause.getClass())) - throw cause; - - cause = cause.getCause(); - } - - if (ex.isAssignableFrom(e.getClass())) - throw e; - } - - throw new GridifyRuntimeException("Undeclared exception thrown: " + e.getMessage(), e); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cc186b52/modules/aop/src/main/java/org/gridgain/grid/compute/gridify/aop/aspectj/GridifySetToSetAspectJAspect.java ---------------------------------------------------------------------- diff --git a/modules/aop/src/main/java/org/gridgain/grid/compute/gridify/aop/aspectj/GridifySetToSetAspectJAspect.java b/modules/aop/src/main/java/org/gridgain/grid/compute/gridify/aop/aspectj/GridifySetToSetAspectJAspect.java deleted file mode 100644 index 76c4b1e..0000000 --- a/modules/aop/src/main/java/org/gridgain/grid/compute/gridify/aop/aspectj/GridifySetToSetAspectJAspect.java +++ /dev/null @@ -1,134 +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.gridgain.grid.compute.gridify.aop.aspectj; - -import org.apache.ignite.*; -import org.apache.ignite.compute.gridify.*; -import org.apache.ignite.compute.gridify.aop.*; -import org.aspectj.lang.*; -import org.aspectj.lang.annotation.*; -import org.aspectj.lang.reflect.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.internal.util.gridify.*; -import java.lang.reflect.*; - -import static org.apache.ignite.IgniteState.*; -import static org.apache.ignite.internal.util.gridify.GridifyUtils.*; - -/** - * AspectJ aspect that cross-cuts on all methods grid-enabled with - * {@link GridifySetToSet} annotation and potentially executes them on - * remote node. - * <p> - * See {@link GridifySetToSet} documentation for more information about execution of - * {@code gridified} methods. - * @see GridifySetToSet - */ -@Aspect -public class GridifySetToSetAspectJAspect extends GridifySetToSetAbstractAspect { - /** - * Aspect implementation which executes grid-enabled methods on remote - * nodes. - * - * @param joinPnt Join point provided by AspectJ AOP. - * @return Method execution result. - * @throws Throwable If execution failed. - */ - @SuppressWarnings({"ProhibitedExceptionDeclared", "ProhibitedExceptionThrown", "CatchGenericClass"}) - @Around("execution(@org.apache.ignite.compute.gridify.GridifySetToSet * *(..)) && !cflow(call(* org.apache.ignite.compute.ComputeJob.*(..)))") - public Object gridify(ProceedingJoinPoint joinPnt) throws Throwable { - Method mtd = ((MethodSignature) joinPnt.getSignature()).getMethod(); - - GridifySetToSet ann = mtd.getAnnotation(GridifySetToSet.class); - - assert ann != null : "Intercepted method does not have gridify annotation."; - - // Since annotations in Java don't allow 'null' as default value - // we have accept an empty string and convert it here. - // NOTE: there's unintended behavior when user specifies an empty - // string as intended grid name. - // NOTE: the 'ann.gridName() == null' check is added to mitigate - // annotation bugs in some scripting languages (e.g. Groovy). - String gridName = F.isEmpty(ann.gridName()) ? null : ann.gridName(); - - if (G.state(gridName) != STARTED) - throw new IgniteCheckedException("Grid is not locally started: " + gridName); - - GridifyNodeFilter nodeFilter = null; - - if (!ann.nodeFilter().equals(GridifyNodeFilter.class)) - nodeFilter = ann.nodeFilter().newInstance(); - - // Check method return type. - checkMethodSignature(mtd); - - GridifyArgumentBuilder argBuilder = new GridifyArgumentBuilder(); - - // Creates task argument. - GridifyRangeArgument arg = argBuilder.createTaskArgument( - mtd.getDeclaringClass(), - mtd.getName(), - mtd.getReturnType(), - mtd.getParameterTypes(), - mtd.getParameterAnnotations(), - joinPnt.getArgs(), - joinPnt.getTarget()); - - if (!ann.interceptor().equals(GridifyInterceptor.class)) { - // Check interceptor first. - if (!ann.interceptor().newInstance().isGridify(ann, arg)) - return joinPnt.proceed(); - } - - // Proceed locally for negative threshold parameter. - if (ann.threshold() < 0) - return joinPnt.proceed(); - - // Analyse where to execute method (remotely or locally). - if (arg.getInputSize() != UNKNOWN_SIZE && arg.getInputSize() <= ann.threshold()) - return joinPnt.proceed(); - - // Check is split to jobs allowed for input method argument with declared splitSize. - checkIsSplitToJobsAllowed(arg, ann); - - try { - Ignite ignite = G.ignite(gridName); - - return execute(ignite.compute(), joinPnt.getSignature().getDeclaringType(), arg, nodeFilter, - ann.threshold(), ann.splitSize(), ann.timeout()); - } - catch (Throwable e) { - for (Class<?> ex : ((MethodSignature) joinPnt.getSignature()).getMethod().getExceptionTypes()) { - // Descend all levels down. - Throwable cause = e.getCause(); - - while (cause != null) { - if (ex.isAssignableFrom(cause.getClass())) - throw cause; - - cause = cause.getCause(); - } - - if (ex.isAssignableFrom(e.getClass())) - throw e; - } - - throw new GridifyRuntimeException("Undeclared exception thrown: " + e.getMessage(), e); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cc186b52/modules/aop/src/main/java/org/gridgain/grid/compute/gridify/aop/aspectj/GridifySetToValueAspectJAspect.java ---------------------------------------------------------------------- diff --git a/modules/aop/src/main/java/org/gridgain/grid/compute/gridify/aop/aspectj/GridifySetToValueAspectJAspect.java b/modules/aop/src/main/java/org/gridgain/grid/compute/gridify/aop/aspectj/GridifySetToValueAspectJAspect.java deleted file mode 100644 index 952b782..0000000 --- a/modules/aop/src/main/java/org/gridgain/grid/compute/gridify/aop/aspectj/GridifySetToValueAspectJAspect.java +++ /dev/null @@ -1,134 +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.gridgain.grid.compute.gridify.aop.aspectj; - -import org.apache.ignite.*; -import org.apache.ignite.compute.gridify.*; -import org.apache.ignite.compute.gridify.aop.*; -import org.aspectj.lang.*; -import org.aspectj.lang.annotation.*; -import org.aspectj.lang.reflect.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.internal.util.gridify.*; -import java.lang.reflect.*; - -import static org.apache.ignite.IgniteState.*; -import static org.apache.ignite.internal.util.gridify.GridifyUtils.*; - -/** - * AspectJ aspect that cross-cuts on all methods grid-enabled with - * {@link GridifySetToValue} annotation and potentially executes them on - * remote node. - * <p> - * See {@link GridifySetToValue} documentation for more information about execution of - * {@code gridified} methods. - * @see GridifySetToValue - */ -@Aspect -public class GridifySetToValueAspectJAspect extends GridifySetToValueAbstractAspect { - /** - * Aspect implementation which executes grid-enabled methods on remote - * nodes. - * - * @param joinPnt Join point provided by AspectJ AOP. - * @return Method execution result. - * @throws Throwable If execution failed. - */ - @SuppressWarnings({"ProhibitedExceptionDeclared", "ProhibitedExceptionThrown", "CatchGenericClass"}) - @Around("execution(@org.apache.ignite.compute.gridify.GridifySetToValue * *(..)) && !cflow(call(* org.apache.ignite.compute.ComputeJob.*(..)))") - public Object gridify(ProceedingJoinPoint joinPnt) throws Throwable { - Method mtd = ((MethodSignature) joinPnt.getSignature()).getMethod(); - - GridifySetToValue ann = mtd.getAnnotation(GridifySetToValue.class); - - assert ann != null : "Intercepted method does not have gridify annotation."; - - // Since annotations in Java don't allow 'null' as default value - // we have accept an empty string and convert it here. - // NOTE: there's unintended behavior when user specifies an empty - // string as intended grid name. - // NOTE: the 'ann.gridName() == null' check is added to mitigate - // annotation bugs in some scripting languages (e.g. Groovy). - String gridName = F.isEmpty(ann.gridName()) ? null : ann.gridName(); - - if (G.state(gridName) != STARTED) - throw new IgniteCheckedException("Grid is not locally started: " + gridName); - - GridifyNodeFilter nodeFilter = null; - - if (!ann.nodeFilter().equals(GridifyNodeFilter.class)) - nodeFilter = ann.nodeFilter().newInstance(); - - // Check is method allowed for gridify. - checkMethodSignature(mtd); - - GridifyArgumentBuilder argBuilder = new GridifyArgumentBuilder(); - - // Creates task argument. - GridifyRangeArgument arg = argBuilder.createTaskArgument( - mtd.getDeclaringClass(), - mtd.getName(), - mtd.getReturnType(), - mtd.getParameterTypes(), - mtd.getParameterAnnotations(), - joinPnt.getArgs(), - joinPnt.getTarget()); - - if (!ann.interceptor().equals(GridifyInterceptor.class)) { - // Check interceptor first. - if (!ann.interceptor().newInstance().isGridify(ann, arg)) - return joinPnt.proceed(); - } - - // Proceed locally for negative threshold parameter. - if (ann.threshold() < 0) - return joinPnt.proceed(); - - // Analyse where to execute method (remotely or locally). - if (arg.getInputSize() != UNKNOWN_SIZE && arg.getInputSize() <= ann.threshold()) - return joinPnt.proceed(); - - // Check is split to jobs allowed for input method argument with declared splitSize. - checkIsSplitToJobsAllowed(arg, ann); - - try { - Ignite ignite = G.ignite(gridName); - - return execute(mtd, ignite.compute(), joinPnt.getSignature().getDeclaringType(), arg, nodeFilter, - ann.threshold(), ann.splitSize(), ann.timeout()); - } - catch (Throwable e) { - for (Class<?> ex : ((MethodSignature) joinPnt.getSignature()).getMethod().getExceptionTypes()) { - // Descend all levels down. - Throwable cause = e.getCause(); - - while (cause != null) { - if (ex.isAssignableFrom(cause.getClass())) - throw cause; - - cause = cause.getCause(); - } - - if (ex.isAssignableFrom(e.getClass())) - throw e; - } - - throw new GridifyRuntimeException("Undeclared exception thrown: " + e.getMessage(), e); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cc186b52/modules/aop/src/main/java/org/gridgain/grid/compute/gridify/aop/aspectj/package.html ---------------------------------------------------------------------- diff --git a/modules/aop/src/main/java/org/gridgain/grid/compute/gridify/aop/aspectj/package.html b/modules/aop/src/main/java/org/gridgain/grid/compute/gridify/aop/aspectj/package.html deleted file mode 100644 index 677b0b7..0000000 --- a/modules/aop/src/main/java/org/gridgain/grid/compute/gridify/aop/aspectj/package.html +++ /dev/null @@ -1,24 +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. - --> - -<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> -<html> -<body> - <!-- Package description. --> - Contains all classes used by AspectJ AOP implementation. -</body> -</html> http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cc186b52/modules/aop/src/main/java/org/gridgain/grid/compute/gridify/aop/spring/GridifySetToSetSpringAspect.java ---------------------------------------------------------------------- diff --git a/modules/aop/src/main/java/org/gridgain/grid/compute/gridify/aop/spring/GridifySetToSetSpringAspect.java b/modules/aop/src/main/java/org/gridgain/grid/compute/gridify/aop/spring/GridifySetToSetSpringAspect.java deleted file mode 100644 index 813adf2..0000000 --- a/modules/aop/src/main/java/org/gridgain/grid/compute/gridify/aop/spring/GridifySetToSetSpringAspect.java +++ /dev/null @@ -1,129 +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.gridgain.grid.compute.gridify.aop.spring; - -import org.aopalliance.intercept.*; -import org.apache.ignite.*; -import org.apache.ignite.compute.gridify.*; -import org.apache.ignite.compute.gridify.aop.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.internal.util.gridify.*; -import java.lang.reflect.*; - -import static org.apache.ignite.IgniteState.*; -import static org.apache.ignite.internal.util.gridify.GridifyUtils.*; - -/** - * Spring aspect that cross-cuts on all methods grid-enabled with - * {@link GridifySetToSet} annotation and potentially executes them on - * remote node. - * <p> - * Note that Spring uses proxy-based AOP, so in order to be properly - * cross-cut, all methods need to be enhanced with {@link GridifySpringEnhancer} - * helper. - * <p> - * See {@link GridifySetToSet} documentation for more information about execution of - * {@code gridified} methods. - * @see GridifySetToSet - */ -public class GridifySetToSetSpringAspect extends GridifySetToSetAbstractAspect implements MethodInterceptor { - /** - * Aspect implementation which executes grid-enabled methods on remote - * nodes. - * - * {@inheritDoc} - */ - @SuppressWarnings({"ProhibitedExceptionDeclared", "ProhibitedExceptionThrown", "CatchGenericClass"}) - @Override public Object invoke(MethodInvocation invoc) throws Throwable { - Method mtd = invoc.getMethod(); - - GridifySetToSet ann = mtd.getAnnotation(GridifySetToSet.class); - - assert ann != null : "Intercepted method does not have gridify annotation."; - - // Since annotations in Java don't allow 'null' as default value - // we have accept an empty string and convert it here. - // NOTE: there's unintended behavior when user specifies an empty - // string as intended grid name. - // NOTE: the 'ann.gridName() == null' check is added to mitigate - // annotation bugs in some scripting languages (e.g. Groovy). - String gridName = F.isEmpty(ann.gridName()) ? null : ann.gridName(); - - if (G.state(gridName) != STARTED) - throw new IgniteCheckedException("Grid is not locally started: " + gridName); - - GridifyNodeFilter nodeFilter = null; - - if (!ann.nodeFilter().equals(GridifyNodeFilter.class)) - nodeFilter = ann.nodeFilter().newInstance(); - - GridifyArgumentBuilder argBuilder = new GridifyArgumentBuilder(); - - // Creates task argument. - GridifyRangeArgument arg = argBuilder.createTaskArgument( - mtd.getDeclaringClass(), - mtd.getName(), - mtd.getReturnType(), - mtd.getParameterTypes(), - mtd.getParameterAnnotations(), - invoc.getArguments(), - invoc.getThis()); - - if (!ann.interceptor().equals(GridifyInterceptor.class)) { - // Check interceptor first. - if (!ann.interceptor().newInstance().isGridify(ann, arg)) - return invoc.proceed(); - } - - // Proceed locally for negative threshold parameter. - if (ann.threshold() < 0) - return invoc.proceed(); - - // Analyse where to execute method (remotely or locally). - if (arg.getInputSize() != UNKNOWN_SIZE && arg.getInputSize() <= ann.threshold()) - return invoc.proceed(); - - // Check is split to jobs allowed for input method argument with declared splitSize. - checkIsSplitToJobsAllowed(arg, ann); - - try { - Ignite ignite = G.ignite(gridName); - - return execute(ignite.compute(), invoc.getMethod().getDeclaringClass(), arg, nodeFilter, - ann.threshold(), ann.splitSize(), ann.timeout()); - } - catch (Throwable e) { - for (Class<?> ex : invoc.getMethod().getExceptionTypes()) { - // Descend all levels down. - Throwable cause = e.getCause(); - - while (cause != null) { - if (ex.isAssignableFrom(cause.getClass())) - throw cause; - - cause = cause.getCause(); - } - - if (ex.isAssignableFrom(e.getClass())) - throw e; - } - - throw new GridifyRuntimeException("Undeclared exception thrown: " + e.getMessage(), e); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cc186b52/modules/aop/src/main/java/org/gridgain/grid/compute/gridify/aop/spring/GridifySetToValueSpringAspect.java ---------------------------------------------------------------------- diff --git a/modules/aop/src/main/java/org/gridgain/grid/compute/gridify/aop/spring/GridifySetToValueSpringAspect.java b/modules/aop/src/main/java/org/gridgain/grid/compute/gridify/aop/spring/GridifySetToValueSpringAspect.java deleted file mode 100644 index e1354b2..0000000 --- a/modules/aop/src/main/java/org/gridgain/grid/compute/gridify/aop/spring/GridifySetToValueSpringAspect.java +++ /dev/null @@ -1,129 +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.gridgain.grid.compute.gridify.aop.spring; - -import org.aopalliance.intercept.*; -import org.apache.ignite.*; -import org.apache.ignite.compute.gridify.*; -import org.apache.ignite.compute.gridify.aop.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.internal.util.gridify.*; -import java.lang.reflect.*; - -import static org.apache.ignite.IgniteState.*; -import static org.apache.ignite.internal.util.gridify.GridifyUtils.*; - -/** - * Spring aspect that cross-cuts on all methods grid-enabled with - * {@link GridifySetToValue} annotation and potentially executes them on - * remote node. - * <p> - * Note that Spring uses proxy-based AOP, so in order to be properly - * cross-cut, all methods need to be enhanced with {@link GridifySpringEnhancer} - * helper. - * <p> - * See {@link GridifySetToValue} documentation for more information about execution of - * {@code gridified} methods. - * @see GridifySetToValue - */ -public class GridifySetToValueSpringAspect extends GridifySetToValueAbstractAspect implements MethodInterceptor { - /** - * Aspect implementation which executes grid-enabled methods on remote - * nodes. - * - * {@inheritDoc} - */ - @SuppressWarnings({"ProhibitedExceptionDeclared", "ProhibitedExceptionThrown", "CatchGenericClass"}) - @Override public Object invoke(MethodInvocation invoc) throws Throwable { - Method mtd = invoc.getMethod(); - - GridifySetToValue ann = mtd.getAnnotation(GridifySetToValue.class); - - assert ann != null : "Intercepted method does not have gridify annotation."; - - // Since annotations in Java don't allow 'null' as default value - // we have accept an empty string and convert it here. - // NOTE: there's unintended behavior when user specifies an empty - // string as intended grid name. - // NOTE: the 'ann.gridName() == null' check is added to mitigate - // annotation bugs in some scripting languages (e.g. Groovy). - String gridName = F.isEmpty(ann.gridName()) ? null : ann.gridName(); - - if (G.state(gridName) != STARTED) - throw new IgniteCheckedException("Grid is not locally started: " + gridName); - - GridifyNodeFilter nodeFilter = null; - - if (!ann.nodeFilter().equals(GridifyNodeFilter.class)) - nodeFilter = ann.nodeFilter().newInstance(); - - GridifyArgumentBuilder argBuilder = new GridifyArgumentBuilder(); - - // Creates task argument. - GridifyRangeArgument arg = argBuilder.createTaskArgument( - mtd.getDeclaringClass(), - mtd.getName(), - mtd.getReturnType(), - mtd.getParameterTypes(), - mtd.getParameterAnnotations(), - invoc.getArguments(), - invoc.getThis()); - - if (!ann.interceptor().equals(GridifyInterceptor.class)) { - // Check interceptor first. - if (!ann.interceptor().newInstance().isGridify(ann, arg)) - return invoc.proceed(); - } - - // Proceed locally for negative threshold parameter. - if (ann.threshold() < 0) - return invoc.proceed(); - - // Analyse where to execute method (remotely or locally). - if (arg.getInputSize() != UNKNOWN_SIZE && arg.getInputSize() <= ann.threshold()) - return invoc.proceed(); - - // Check is split to jobs allowed for input method argument with declared splitSize. - checkIsSplitToJobsAllowed(arg, ann); - - try { - Ignite ignite = G.ignite(gridName); - - return execute(mtd, ignite.compute(), invoc.getMethod().getDeclaringClass(), arg, nodeFilter, - ann.threshold(), ann.splitSize(), ann.timeout()); - } - catch (Throwable e) { - for (Class<?> ex : invoc.getMethod().getExceptionTypes()) { - // Descend all levels down. - Throwable cause = e.getCause(); - - while (cause != null) { - if (ex.isAssignableFrom(cause.getClass())) - throw cause; - - cause = cause.getCause(); - } - - if (ex.isAssignableFrom(e.getClass())) - throw e; - } - - throw new GridifyRuntimeException("Undeclared exception thrown: " + e.getMessage(), e); - } - } -}