use of org.apache.ignite.internal.util.gridify.GridifyRangeArgument in project ignite by apache.
the class GridifySetToValueAspectJAspect method gridify.
/**
* 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 Igninte 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);
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(igniteInstanceName);
return execute(mtd, ignite.compute(), joinPnt.getSignature().getDeclaringType(), arg, nodeFilter, ann.threshold(), ann.splitSize(), ann.timeout());
} 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);
}
}
use of org.apache.ignite.internal.util.gridify.GridifyRangeArgument in project ignite by apache.
the class GridifySetToSetSpringAspect method invoke.
/**
* 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 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);
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(igniteInstanceName);
return execute(ignite.compute(), invoc.getMethod().getDeclaringClass(), arg, nodeFilter, ann.threshold(), ann.splitSize(), ann.timeout());
} catch (Exception 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);
}
}
use of org.apache.ignite.internal.util.gridify.GridifyRangeArgument in project ignite by apache.
the class GridifySetToValueAbstractAspect method execute.
/**
* Execute method on grid.
*
* @param mtd Method.
* @param compute {@link org.apache.ignite.IgniteCompute} instance.
* @param cls Joint point signature class.
* @param arg GridifyArgument with all method signature parameters.
* @param nodeFilter Node filter.
* @param threshold Parameter that defines the minimal value below which the
* execution will NOT be grid-enabled.
* @param splitSize Size of elements to send in job argument.
* @param timeout Execution timeout.
* @return Result.
* @throws IgniteCheckedException If execution failed.
*/
protected Object execute(Method mtd, IgniteCompute compute, Class<?> cls, GridifyRangeArgument arg, GridifyNodeFilter nodeFilter, int threshold, int splitSize, long timeout) throws IgniteCheckedException {
long now = U.currentTimeMillis();
long end = timeout == 0 ? Long.MAX_VALUE : timeout + now;
// Prevent overflow.
if (end < 0)
end = Long.MAX_VALUE;
Collection<?> res = null;
while (true) {
if (now > end)
throw new ComputeTaskTimeoutCheckedException("Timeout occurred while waiting for completion.");
GridifyRangeArgument taskArg = createGridifyArgument(arg, res);
if (taskArg == null)
return result(res);
else if (taskArg.getInputSize() != UNKNOWN_SIZE && taskArg.getInputSize() <= threshold) {
// Note, that we can't cancel by timeout locally started method.
try {
mtd.setAccessible(true);
return mtd.invoke(arg.getTarget(), taskArg.getMethodParameters());
} catch (IllegalAccessException | InvocationTargetException e) {
throw new IgniteCheckedException("Failed to execute method locally.", e);
}
} else {
res = compute.withTimeout(timeout == 0 ? 0L : (end - now)).execute(new GridifyDefaultRangeTask(cls, nodeFilter, threshold, splitSize, true), taskArg);
}
now = U.currentTimeMillis();
}
}
use of org.apache.ignite.internal.util.gridify.GridifyRangeArgument in project ignite by apache.
the class GridifySetToSetAspectJAspect method gridify.
/**
* 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 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);
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(igniteInstanceName);
return execute(ignite.compute(), joinPnt.getSignature().getDeclaringType(), arg, nodeFilter, ann.threshold(), ann.splitSize(), ann.timeout());
} 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);
}
}
use of org.apache.ignite.internal.util.gridify.GridifyRangeArgument in project ignite by apache.
the class GridifySetToValueSpringAspect method invoke.
/**
* 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 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);
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(igniteInstanceName);
return execute(mtd, ignite.compute(), invoc.getMethod().getDeclaringClass(), arg, nodeFilter, ann.threshold(), ann.splitSize(), ann.timeout());
} catch (Exception 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);
}
}
Aggregations