in modules/aop-ext/src/main/java/org/apache/ignite/compute/gridify/aop/aspectj/GridifyAspectJAspect.java [60:132]
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 Ignite instance name.
// NOTE: the 'ann.igniteInstanceName() == null' check is added to mitigate
// annotation bugs in some scripting languages (e.g. Groovy).
String igniteInstanceName = F.isEmpty(ann.igniteInstanceName()) ? ann.gridName() : ann.igniteInstanceName();
if (F.isEmpty(igniteInstanceName))
igniteInstanceName = null;
if (G.state(igniteInstanceName) != STARTED)
throw new IgniteCheckedException("Grid is not locally started: " + igniteInstanceName);
// 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(igniteInstanceName);
// 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 (Exception 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);
}
}