org.apache.ignite.compute.gridify

## Annotation Type Gridify

-     @Documented
       @Retention(value=RUNTIME)
       @Target(value=METHOD)
      public @interface Gridify

  `Gridify` annotation is the main way to grid-enable existing code.

  This annotation can be applied to any public method that needs to be grid-enabled, static or non-static. When this annotation is applied to a method, the method execution is considered to be grid-enabled. In general, the execution of this method can be transferred to another node in the grid, potentially splitting it into multiple subtasks to be executed in parallel on multiple grid nodes. But from the caller perspective this method still looks and behaves like a local apply. This is achieved by utilizing AOP-based interception of the annotated code and injecting all the necessary grid logic into the method execution.

  By default, when neither `taskClass()` or `taskName()` are specified a method with `@Gridify` annotation will be executed on randomly picked remote node.

  Note that when using `@Gridify` annotation with default task (without specifying explicit grid task), the state of the whole instance will be serialized and sent out to remote node. Therefore the class must implement `Serializable` interface. If you cannot make the class `Serializable`, then you must implement custom grid task which will take care of proper state initialization. In either case, Ignite must be able to serialize the state passed to remote node.

  Refer to `ComputeTask` documentation for more information on how a task can be split into multiple sub-jobs.

  # Java Example

  Here is a simple example how to grid-enable a Java method. The method `sayIt` with `@Gridify` annotation will be executed on remote node.

       ...
       @Gridify
       public static void sayIt(String arg) {
          // Simply print out the argument.
          System.out.println(arg);
       }
       ...

  Here is an example of how to grid-enable a Java method with custom task. The custom task logic will provide a way to split and aggregate the result. The method `sayIt` will be executed on remote node.

       public class GridifyHelloWorldTaskExample {
           ...
           @Gridify(taskClass = GridifyHelloWorldTask.class, timeout = 3000)
           public static integer sayIt(String arg) {
               // Simply print out the argument.
               System.out.println(">>> Printing '" + arg + "' on this node from grid-enabled method.");

               return arg.length();
           }
           ...
       }

  The custom task will actually take the String passed into `sayIt(String)` method, split it into words and execute every word on different remote node.

       public class GridifyHelloWorldTask extends GridifyTaskSplitAdapter<Integer> {
          @Override public Integer apply(String e) {
              return F.outJobs(F.yield(((String)arg.getMethodParameters()[0]).split(" "), new C1<String, Integer>() {
                  @Override public Integer apply(String e) {
                      // Note that no recursive cross-cutting will happen here.
                      return GridifyHelloWorldTaskExample.sayIt(e);
                  }
              }));
          }

          public Integer reduce(List<ComputeJobResult> results) throws IgniteCheckedException {
              return results.size() - 1 + F.sum(F.<Integer>jobResults(results));
          }
       }

  # Jboss AOP

  The following configuration needs to be applied to enable JBoss byte code weaving. Note that Ignite is not shipped with JBoss and necessary libraries will have to be downloaded separately (they come standard if you have JBoss installed already):
  - The following JVM configuration must be present:
    - `-javaagent:[path to jboss-aop-jdk50-4.x.x.jar]`
    - `-Djboss.aop.class.path=[path to ignite.jar]`
    - `-Djboss.aop.exclude=org,com -Djboss.aop.include=org.apache.ignite.examples`
  - The following JARs should be in a classpath:
    - `javassist-3.x.x.jar`
    - `jboss-aop-jdk50-4.x.x.jar`
    - `jboss-aspect-library-jdk50-4.x.x.jar`
    - `jboss-common-4.x.x.jar`
    - `trove-1.0.2.jar`

  # AspectJ AOP

  The following configuration needs to be applied to enable AspectJ byte code weaving.
  - JVM configuration should include: `-javaagent:${IGNITE_HOME}/libs/aspectjweaver-1.7.2.jar`
  - META-INF/aop.xml file should be created and specified on the classpath. The file should contain Gridify aspects and needed weaver options.

  # Spring AOP

  Spring AOP framework is based on dynamic proxy implementation and doesn't require any specific runtime parameters for online weaving.

  Note that this method of weaving is rather inconvenient and AspectJ or JBoss AOP is recommended over it. Spring AOP can be used in situation when code augmentation is undesired and cannot be used. It also allows for very fine grained control of what gets weaved.

- - ### Optional Element Summary

    Optional Elements
    Modifier and Type | Optional Element and Description
    --- | ---
    `String` | `gridName` Deprecated. Use `igniteInstanceName()`. Nonempty `igniteInstanceName()` takes precedence.
    `String` | `igniteInstanceName` Name of the Ignite instance to use.
    `Class<? extends GridifyInterceptor>` | `interceptor` Optional interceptor class.
    `Class<? extends ComputeTask<GridifyArgument,?>>` | `taskClass` Optional gridify task class.
    `String` | `taskName` Optional gridify task name.
    `long` | `timeout` Optional gridify task execution timeout.

- - ### Element Detail

    - #### taskName

          public abstract String taskName

      Optional gridify task name. Note that either this name or `taskClass()` must be specified - but not both. If neither one is specified tasks' fully qualified name will be used as a default name.
      Default:
        ""

  - - #### taskClass

          public abstract Class<? extends ComputeTask<GridifyArgument,?>> taskClass

      Optional gridify task class. Note that either this name or `taskName()` must be specified - but not both. If neither one is specified tasks' fully qualified name will be used as a default name.
      Default:
        org.apache.ignite.compute.gridify.aop.GridifyDefaultTask.class

  - - #### timeout

          public abstract long timeout

      Optional gridify task execution timeout. Default is `0` which indicates that task will not timeout.
      Default:
        0L

  - - #### interceptor

          public abstract Class<? extends GridifyInterceptor> interceptor

      Optional interceptor class. Since `null` are not supported the value of `GridifyInterceptor.class` acts as a default value.
      Default:
        org.apache.ignite.compute.gridify.GridifyInterceptor.class

  - - #### gridName

          @Deprecated
          public abstract String gridName

      Deprecated. Use `igniteInstanceName()`. Nonempty `igniteInstanceName()` takes precedence.
      Name of the grid to use. By default, no-name default grid is used. Refer to `Ignition` for information about named grids.
      Default:
        ""

  - - #### igniteInstanceName

          public abstract String igniteInstanceName

      Name of the Ignite instance to use. By default, no-name default Ignite instance is used. Refer to `Ignition` for information about named Ignite instances.
      Default:
        ""

2021 Copyright © Apache Software Foundation
| Follow @ApacheIgnite
Ignite Database and Caching Platform | : ver. 2.11.0
Release Date | : September 11 2021