GridGain™ 2.0.3
Java API Specification

org.gridgain.grid
Class GridFactory

java.lang.Object
  extended by org.gridgain.grid.GridFactory

public final class GridFactory
extends Object

This interface defines a factory for the main GridGain API. It controls Grid life cycle and allows listening for grid events. Although user can call grid factory directly to start and stop grid, grid is usually started and stopped by grid loaders. Some examples of Grid loaders are:

Note that all parameters passed in GridConfiguration to GridFactory.start(GridConfiguration) method are optional. If not provided, default values will be used. Below is the table that provides default value for every configuration parameter.

GridConfiguration Method Default Value Description
GridConfiguration.getGridName() null Grid name (null is a default value).
GridConfiguration.getUserAttributes() Empty set. Attributes to be set on local node.
GridConfiguration.getGridLogger() Log4J logger initialized to log only to console (see GridLog4jLogger.GridLog4jLogger(boolean)) Logger to use within grid.
getExecutorService() Grid thread pool with default initialization (see GridThreadPoolExecutorService). Thread pool used by grid.
GridConfiguration.getGridGainHome() Inferred (see GridConfiguration.getGridGainHome() for details). Path to GridGain installation folder.
GridConfiguration.getMBeanServer() Platform MBean server (see ManagementFactory.getPlatformMBeanServer()). MBean server used by grid.
GridConfiguration.getNodeId() Randomly generated node ID (see UUID.randomUUID()). Local node unique identifier.
GridConfiguration.isPeerClassLoadingEnabled() true Boolean flag to control peer class loading. When enabled, if a task is not deployed on a node, the system will attempt to load it from a peer node (usually from the node that initiated task execution).
GridConfiguration.getP2PLocalClassPathExclude() Empty list. List of packages to exclude from local classpath when executing grid tasks. All classes within these packages will be loaded on demand from the node that initiated task execution.
GridConfiguration.getMetricsExpireTime() Long.MAX_VALUE Maximum time until node metrics from remote nodes are considered expired. Node metrics are frequently updated (usually with every heartbeat) and provide runtime information about remote nodes (see GridNode.getMetrics()).
GridConfiguration.getMetricsHistorySize() 10,000 Maximum number of metrics to keep in the memory. The larger this number, the more precise the metrics calculations are (at the expense of more memory consumption). Node metrics are frequently updated (usually with every heartbeat) and provide runtime information about remote nodes (see GridNode.getMetrics()).
GridConfiguration.getDiscoverySpi() Multicast-based grid discovery (see GridMulticastDiscoverySpi). Fully configured SPI used for discovering remote grid nodes.
GridConfiguration.getCommunicationSpi() TCP-based communication (see GridTcpCommunicationSpi). Fully configured SPI used for communication between grid nodes.
GridConfiguration.getDeploymentSpi() Local (in-memory) deployment SPI (see GridLocalDeploymentSpi). Fully configured SPI used for deploying grid tasks.
GridConfiguration.getCheckpointSpi() Shared file system checkpoint SPI which (see GridSharedFsCheckpointSpi). Fully configured SPI used for storing intermediate job state to safeguard against failures.
GridConfiguration.getEventStorageSpi() In-memory limited event storage (see GridMemoryEventStorageSpi). Fully configured SPI used for storing grid events.
GridConfiguration.getTopologySpi() Basic topology spi that provides all discovered grid nodes (see GridBasicTopologySpi). Fully configured SPI used for determining grid task execution topology.
GridConfiguration.getFailoverSpi() Failover SPI that always fails over jobs to another node (see GridAlwaysFailoverSpi). Fully configured SPI used for failing over jobs to another node in case of node failure.
GridConfiguration.getCollisionSpi() Job collision SPI that executes all incoming jobs in FIFO order (see GridFifoQueueCollisionSpi). Fully configured SPI used for handling job collisions.
GridConfiguration.getMetricsSpi() Basic JDK-based local VM Metrics implementation (see GridJdkLocalMetricsSpi). Fully configured SPI used for providing local VM metrics.
GridConfiguration.getLoadBalancingSpi() Round-Robin implementation that will pick a random start node for every task and will iterate through all nodes starting at the start node sequentially for every grid job. (see GridRoundRobinLoadBalancingSpi). Fully configured SPI used for load balancing of jobs within grid.
GridConfiguration.getTracingSpi() If not provided, then tracing will not be performed. Fully configured SPI used for tracing public grid method invocations.
Use GridFactory.start() method to start grid with default configuration. You can also use GridConfigurationAdapter to override some default configuration. Below is an example on how to start grid with URI deployment and JGroups-based discovery SPI's.
 GridConfigurationAdapter cfg = new GridConfigurationAdapter();

 GridUriDeployment deploySpi = new GridUriDeployment();

 deploySpi.setUriList(Collections.singletonList("classes://tmp/ideoutput/classes"));

 GridJgroupsDiscovery discoSpi = new GridJgroupsDiscovery();

 discoSpi.setConfigurationFile("/config/jgroups/multicast/jgroups.xml");

 cfg.setDeploymentSpi(deploySpi);
 cfg.setDiscoverySpi(discoSpi);

 GridFactroy.start(cfg);
 

Note that you can start multiple grid nodes within same VM by specifying grid name (see GridFactory.start(GridConfiguration)). This may be useful for testing whenever it is needed to check internal job parameters when jobs are running on different nodes. In most cases, however, you should use default no-name grid.



See Also:

  Documentation
  Email Support
  Online Forums
  Issue Tracking

Author:   2005-2008 Copyright © GridGain Systems. All Rights Reserved. ver. 2.0.3

 

Method Summary
static void addListener(GridFactoryListener listener)
          Adds a listener for grid life cycle events.
static List<Grid> getAllGrids()
          Gets a list of all grids started so far.
static Grid getGrid()
          Gets an instance of default no-name grid.
static Grid getGrid(String name)
          Gets an instance named grid.
static GridFactoryState getState()
          Gets state of grid default grid.
static GridFactoryState getState(String name)
          Gets states of named grid.
static boolean removeListener(GridFactoryListener listener)
          Removes listener added by GridFactory.addListener(GridFactoryListener) method.
static Grid start()
          Starts grid with default configuration.
static Grid start(GridConfiguration cfg)
          Starts grid with given configuration.
static Grid start(GridConfiguration cfg, org.springframework.context.ApplicationContext springCtx)
          Starts grid with given configuration.
static Grid start(String springCfgPath)
          Starts all grids specified within given Spring XML configuration file.
static boolean stop(boolean cancel)
          Stops default grid.
static boolean stop(String name, boolean cancel)
          Stops named grid.
static void stopAll(boolean cancel)
          Stops all started grids.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getState

public static GridFactoryState getState()
Gets state of grid default grid.

Returns:
Default grid state.

getState

public static GridFactoryState getState(String name)
Gets states of named grid. If name is null, then state of default no-name grid is returned.

Parameters:
name - Grid name. If name is null, then state of default no-name grid is returned.
Returns:
Grid state.

stop

public static boolean stop(boolean cancel)
Stops default grid. This method is identical to GridFactory.stop(null, cancel) call.

Parameters:
cancel - If true then all jobs currently executing on default grid will be cancelled by calling GridJob.cancel() method. Note that just like with Thread.interrupt(), it is up to the actual job to exit from execution
Returns:
true if default grid instance was indeed stopped, false otherwise (if it was not started).

stop

public static boolean stop(String name,
                           boolean cancel)
Stops named grid. If cancel flag is set to true then all jobs currently executing on local node will be interrupted. If grid name is null, then default no-name grid will be stopped.

Parameters:
name - Grid name. If null, then default no-name grid will be stopped.
cancel - If true then all jobs currently will be cancelled by calling GridJob.cancel() method. Note that just like with Thread.interrupt(), it is up to the actual job to exit from execution. If false, then jobs currently running will not be canceled. In either case, grid node will wait for completion of all jobs running on it before stopping.
Returns:
true if named grid instance was indeed found and stopped, false otherwise (the instance with given name was not found).

stopAll

public static void stopAll(boolean cancel)
Stops all started grids. If cancel flag is set to true then all jobs currently executing on local node will be interrupted.

Note: it is usually safer and more appropriate to stop grid instances individually instead of blanket operation. In most cases, the party that started the grid instance should be responsible for stopping it.

Parameters:
cancel - If true then all jobs currently executing on all grids will be cancelled by calling GridJob.cancel() method. Note that just like with Thread.interrupt(), it is up to the actual job to exit from execution

start

public static Grid start()
                  throws GridException
Starts grid with default configuration. By default this method will use grid configuration defined in GRIDGAIN_HOME/config/default-spring.xml configuration file. If such file is not found, then all system defaults will be used.

Throws:
GridException - If default grid could not be started. This exception will be thrown also if default grid has already been started.
Returns:
Started grid.

start

public static Grid start(GridConfiguration cfg)
                  throws GridException
Starts grid with given configuration. Note that this method is no-op if grid with the name provided in given configuration is already started.

Throws:
GridException - If grid could not be started. This exception will be thrown also if named grid has already been started.
Parameters:
cfg - Grid configuration. This cannot be null.
Returns:
Started grid.

start

public static Grid start(GridConfiguration cfg,
                         org.springframework.context.ApplicationContext springCtx)
                  throws GridException
Starts grid with given configuration. Note that this method is no-op if grid with the name provided in given configuration is already started.

Throws:
GridException - If grid could not be started. This exception will be thrown also if named grid has already been started.
Parameters:
cfg - Grid configuration. This cannot be null.
springCtx - Spring application context, possibly null. If provided, this context can be injected into grid tasks and grid jobs using @GridSpringApplicationContextResource annotation.
Returns:
Started grid.

start

public static Grid start(String springCfgPath)
                  throws GridException
Starts all grids specified within given Spring XML configuration file. If grid with given name is started already, then exception is thrown. In this case all instances that may have been started so far will be stopped too.

Most commonly, Spring XML configuration file will contain only one Grid definition. Note that Grid configuration bean(s) is retrieved form configuration file by type, so the name of the Grid configuration bean is ignored.

Throws:
GridException - If grid could not be started or configuration read. This exception will be thrown also if grid with given name has already been started or Spring XML configuration file is invalid.
Parameters:
springCfgPath - Spring XML configuration file path. This cannot be null.
Returns:
Started grid. If Spring configuration contains multiple grid instances, then the 1st found instance is returned.

getGrid

public static Grid getGrid()
                    throws IllegalStateException
Gets an instance of default no-name grid. Note that caller of this method should not assume that it will return the same instance every time.

This method is identical to GridFactory.stop(null) call.

Throws:
IllegalStateException - Thrown if default grid was not properly initialized or grid instance was stopped or was not started.
Returns:
An instance of default no-name grid. This method never returns null.

getAllGrids

public static List<Grid> getAllGrids()
Gets a list of all grids started so far.

Returns:
List of all grids started so far.

getGrid

public static Grid getGrid(String name)
                    throws IllegalStateException
Gets an instance named grid. If grid name is null or empty string, then default no-name grid will be returned. Note that caller of this method should not assume that it will return the same instance every time.

Throws:
IllegalStateException - Thrown if default grid was not properly initialized or grid instance was stopped or was not started.
Parameters:
name - Grid name. If null, then default no-name grid will be returned.
Returns:
An instance of named grid. This method never returns null.

addListener

public static void addListener(GridFactoryListener listener)
Adds a listener for grid life cycle events.

Parameters:
listener - Listener for grid life cycle events.

removeListener

public static boolean removeListener(GridFactoryListener listener)
Removes listener added by GridFactory.addListener(GridFactoryListener) method.

Parameters:
listener - Listener to remove.
Returns:
true if listener was added before, false otherwise.

GridGain™ 2.0.3
Java API Specification

GridGain™ - Grid Computing Made Simple, ver. 2.0.3.20052008
2005-2008 Copyright © GridGain Systems. All Rights Reserved.