This is a quick up-and-running tutorial for GridGain examples.
Examples Configuration
GridGain comes with a set of examples. Examples' source code, necessary configuration and Javadoc are located in ${GRIDGAIN_HOME}/examples folder. All examples come with fully documented source code.
All examples can be easily imported into Java IDE such as IDEA, Eclipse or NetBeans on any supported OS. Following short instruction will guide you through a setup for IDEA on Windows OS (as an example):
- Create the new single-module project, name it "Examples" (name can be anything)
- Specify source code directory as %GRIDGAIN_HOME%\examples\src
- Add necessary libraries:
- Add all libraries from %GRIDGAIN_HOME%\libs
- Add main GridGain JAR located at %GRIDGAIN_HOME%\gridgain-x.x.x.jar
- Make sure to select Java 6 JDK


Once you have setup the project, follow the instructions in Javadoc on how to run example. In order to use annotation based @Gridify ![]()
| Library Versions Note that latest supported library versions shipped with GridGain (indicated in the name if the JAR file) can change from release to release. If such library is required for your configuration - make sure to pick the latest supported one. |
Scala
To run Scala examples you need to configure Scala support in IDE (if you use IDE). We highly recommend to upgrade to the latest version of IDE (IDEA 9, for example) to run Scala example as Scala support is dramatically improving with each release of IDEs.
For convenience, GridGain is shipped with a specific version of Scala libraries the GridGain was tested with. Under the libs folder you will find two JARs:
- scala-compiler_x.x.x.jar
- scala-library_x.x.x.jar
These are the only JARs needed to configure Scala support in any IDE. You can use Scala version younger than the one shipped with GridGain we do not recommend running with older versions of Scala.
Note that as of GridGain 3.0.1 - only Scala 2.8 and higher is supported. Scala 2.7 and older are not supported.
JBoss AOP
Note that GridGain is not shipped with JBoss and doesn't include necessary JBoss libraries. We assume that if you choose to use JBoss AOP you would have these libraries anyways. The following configuration needs to be applied to enable JBoss byte code weaving:
- The following JVM configuration must be present:
- -javaagent:[path to jboss-aop-jdk50-4.x.x.jar]
- -Djboss.aop.class.path=[path to gridgain.jar]
- -Djboss.aop.exclude=org,com -Djboss.aop.include=org.gridgain.examples
- The following JARs should be in a classpath:
- javassist-4.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.x.jar
AspectJ AOP
The following configuration needs to be applied to enable AspectJ byte code weaving.
- VM parameters should include: -javaagent:[GRIDGAIN_HOME]/libs/aspectjweaver-1.5.3.jar
- Classpath should contain the [GRIDGAIN_HOME]/config/aop/aspectj folder.
Note that configuring these settings vary greatly from one IDE to another. For IDEA - you set VP parameters in Run/Debug Configurations, and classpath entries can be added under Project Structure -> Modules -> Dependencies.
Spring AOP
Spring AOP framework is based on dynamic proxy implementation and doesn't require any specific runtime parameters for online weaving. All weaving is on-demand and should be performed by calling method GridifySpringEnhancer.enhance(Object) ![]()
Note that since this method of weaving requires manual enhancing of participating classes, it is rather inconvenient in most cases, and AspectJ or JbossAOP are recommended over it. Spring AOP can be used in situations when code augmentation is undesired and cannot be used. It also allows for very fine grained control of what gets weaved.
Getting Started
We recommend starting with these example as a starting point in discovering GridGain:
Java
- Package org.gridgain.examples.helloworld
- Package org.gridgain.examples.cache
Scala
- Package org.gridgain.scalar.examples
Both packages contain several examples that demonstrate some of the basic functionality of GridGain. As you are getting familiar with these examples you can look around for other functionality.
Starting Grid Node
All examples will need some (one or more) remote nodes to be running. To start a remote node open the terminal window on Linux/Mac OS X or Command Prompt on Windows, change directory to ${GRIDGAIN_HOME}/bin and run the ggstart.{sh|bat} script. It takes 2-3 seconds for grid node to start and if everything worked fine you should see starting log ending with successful start acknowledgment:

Note that you can start as many nodes on a single computer this way as you like. You don't need to change any configuration as long as you use default GridGain configuration.
IP-Multicast
Note that default configuration for discovery SPI uses IP-multicast. Depending on operating system IP-multicast can be disabled. Check your firewall settings to make sure that IP-multicast is enabled.
| IP-multicast IP-multicast should be enabled in order for default configuration to work properly. Refer to Troubleshooting section for help with IP multicast. We also advise you to Google |
