|
GridGain 2.1.0
Java API Specification |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.gridgain.grid.GridFactory
public final class GridFactory
This interface defines a factory for the main GridGain API. It controls Grid life cycle and allows listening for grid events.
GridCommandLineLoaderGridJbossLoaderGridWeblogicStartup and GridWeblogicShutdownGridWebsphereLoaderGridGlassfishLoaderGridServletLoader
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. |
GridConfiguration.getExecutorService() |
Grid thread pool with default initialization (see GridThreadPoolExecutorService).
The size of the thread pool is 100 by default.
|
Executor service used by grid to handle GridTask and GridJob execution.
|
GridConfiguration.getSystemExecutorService() |
Default thread pool size is 5. |
This executor service is in charge of processing GridTaskSession
requests and user messages sent via Grid.sendMessage(GridNode, Serializable) method.
|
GridConfiguration.getPeerClassLoadingExecutorService() |
Default thread pool size is 20. | This executor service is in charge of handling peer class loading requests/responses. |
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.getPeerClassLoadingMissedResourcesCacheSize() |
true | Size of internal missed resources cache. Grid will cache all missed resources and all subsequent call for the same resource on the same class loader will return null immediately. If class was missed then subsequent call for the same class on the class loader will throw corresponding exception. But if cache size is less than needed redundant peer resources/classes requests can be sent. |
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() |
GridConfiguration.DFLT_METRICS_EXPIRE_TIME |
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() |
GridConfiguration.DFLT_METRICS_HISTORY_SIZE |
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.getPeerClassLoadingTimeout() |
GridConfiguration.DFLT_PEER_CLASS_LOADING_TIMEOUT |
Maximum timeout in milliseconds to wait for class-loading responses from
remote nodes. After reaching this timeout ClassNotFoundException
will be thrown.
|
GridConfiguration.getLifecycleBeans() |
The default is null. |
Collection of GridLifecycleBean beans. Use these beans whenever you need to
plug some cusom logic before or after grid startup or stopping routines.
|
GridConfiguration.getDiscoveryStartupDelay() |
The default value is 60,000ms specified by
GridConfiguration.DFLT_DISCOVERY_STARTUP_DELAY. This should be good enough for
vast majority of configurations. However, if you do anticipate an even larger
delay, you should increase this value.
|
This value is used to expire messages from waiting list whenever node discovery discrepancies happen. During startup, it is possible for some SPI's, such as GridMuleDiscoverySpi or GridJmsDiscoverySpi, to have a small time window when Node A has discovered Node B, but Node B has not discovered Node A yet. Such time window is usually very small, a matter of milliseconds, but certain JMS providers or some Mule messaging protocols may be very slow and hence have larger discovery delay window. |
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. |
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.
Runtime.addShutdownHook(Thread)) to stop
all started grids when VM is exiting but it is recommended to stop all started grid
instances in your code where you started them.
Defining GRIDGAIN_NO_SHUTDOWN_HOOK system property or environment variable
and setting value to true will prevent GridFactory of setting up its own
shutdown hook and you can stop all grid instances in your own one.
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);
Here is how a grid instance can be configured from Spring XML configuration file. The
example below configures a grid instance with additional user attributes
(see GridNode.getAttributes()) and specifies a grid name:
<bean id="grid.cfg" class="org.gridgain.grid.GridConfigurationAdapter" scope="singleton">
...
<property name="gridName" value="mygrid"/>
<property name="userAttributes">
<map>
<entry key="group" value="worker"/>
<entry key="grid.node.benchmark">
<bean class="org.gridgain.grid.benchmarks.GridLocalNodeBenchmark" init-method="start"/>
</entry>
</map>
</property>
...
</bean>
A grid instance with Spring configuration above can be started as following. Note that
you do not need to pass path to Spring XML file if you are using
GRIDGAIN_HOME/config/default-spring.xml. Also note, that the path can be
absolute or relative to GRIDGAIN_HOME.
GridFactory.start("/path/to/spring/xml/file.xml");
You can also instantiate grid directly from Spring without using GridFactory.
For more information refer to GridSpringBean documentation.
Documentation
Email Support
Online Forums
Issue Tracking
Author: 2005-2008 Copyright © GridGain Systems. All Rights Reserved. ver. 2.1.0
![]() |
![]() |
![]() |
![]() |
| 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 named grid instance. |
static Grid |
getGrid(UUID localNodeId)
Gets a grid instance for given local node ID. |
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(org.springframework.context.ApplicationContext springCtx)
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 Grid |
start(String springCfgPath,
org.springframework.context.ApplicationContext ctx)
Starts all grids specified within given Spring XML configuration file. |
static Grid |
start(URL springCfgUrl)
Starts all grids specified within given Spring XML configuration file URL. |
static Grid |
start(URL springCfgUrl,
org.springframework.context.ApplicationContext ctx)
Starts all grids specified within given Spring XML configuration file URL. |
static boolean |
stop(boolean cancel)
Stops default grid. |
static boolean |
stop(boolean cancel,
boolean wait)
Stops default grid. |
static boolean |
stop(String name,
boolean cancel)
Stops named grid. |
static boolean |
stop(String name,
boolean cancel,
boolean wait)
Stops named grid. |
static void |
stopAll(boolean cancel)
Stops all started grids. |
static void |
stopAll(boolean cancel,
boolean wait)
Stops all started grids. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static GridFactoryState getState()
public static GridFactoryState getState(String name)
name - Grid name. If name is null, then state of
default no-name grid is returned.
public static boolean stop(boolean cancel)
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
public static boolean stop(boolean cancel,
boolean wait)
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.wait - If true then method will wait for all task being
executed until they finish their execution.
public static boolean stop(String name,
boolean cancel)
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.
public static boolean stop(String name,
boolean cancel,
boolean wait)
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.wait - If true then method will wait for all task being
executed until they finish their execution.
public static void stopAll(boolean cancel)
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.
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
public static void stopAll(boolean cancel,
boolean wait)
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.
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 executionwait - If true then method will wait for all tasks being
executed until they finish their execution.
public static Grid start()
throws GridException
GridException - If default grid could not be started. This exception will be thrown
also if default grid has already been started.
public static Grid start(org.springframework.context.ApplicationContext springCtx)
throws GridException
GridException - If default grid could not be started. This exception will be thrown
also if default grid has already been started.springCtx - Spring application context.
public static Grid start(GridConfiguration cfg)
throws GridException
GridException - If grid could not be started. This exception will be thrown
also if named grid has already been started.cfg - Grid configuration. This cannot be null.
public static Grid start(GridConfiguration cfg,
org.springframework.context.ApplicationContext springCtx)
throws GridException
GridException - If grid could not be started. This exception will be thrown
also if named grid has already been started.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.
public static Grid start(String springCfgPath)
throws GridException
Usually 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.
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.springCfgPath - Spring XML configuration file path or URL. This cannot be null.
public static Grid start(String springCfgPath,
org.springframework.context.ApplicationContext ctx)
throws GridException
Usually 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.
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.springCfgPath - Spring XML configuration file path or URL. This cannot be null.ctx - Spring application context.
public static Grid start(URL springCfgUrl)
throws GridException
Usually 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.
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.springCfgUrl - Spring XML configuration file URL. This cannot be null.
public static Grid start(URL springCfgUrl,
org.springframework.context.ApplicationContext ctx)
throws GridException
Usually 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.
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.springCfgUrl - Spring XML configuration file URL. This cannot be null.ctx - Spring application context.
public static Grid getGrid()
throws IllegalStateException
This method is identical to GridFactory.getGrid(null) call.
IllegalStateException - Thrown if default grid was not properly
initialized or grid instance was stopped or was not started.
public static List<Grid> getAllGrids()
public static Grid getGrid(UUID localNodeId)
throws IllegalStateException
IllegalStateException - Thrown if grid was not properly
initialized or grid instance was stopped or was not started.localNodeId - ID of local node the requested grid instance is managing.
public static Grid getGrid(String name)
throws IllegalStateException
Note that Java VM can run multiple grid instances and every grid instance (and its node) can belong to a different grid. Grid name defines what grid a particular grid instance (and correspondently its node) belongs to.
IllegalStateException - Thrown if default grid was not properly
initialized or grid instance was stopped or was not started.name - Grid name to which requested grid instance belongs to. If null,
then grid instanced belonging to a default no-name grid will be returned.
public static void addListener(GridFactoryListener listener)
listener - Listener for grid life cycle events.public static boolean removeListener(GridFactoryListener listener)
GridFactory.addListener(GridFactoryListener) method.
listener - Listener to remove.
|
GridGain 2.1.0
Java API Specification |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
|
GridGain - Grid Computing Made Simple, ver. 2.1.0.19122008
2005-2008 Copyright © GridGain Systems. All Rights Reserved. |
|
|