public class GridComputeImpl extends Object implements GridCompute
GridCompute implementation.| Constructor and Description |
|---|
GridComputeImpl(GridKernalContext ctx,
GridProjection prj,
UUID subjId) |
| Modifier and Type | Method and Description |
|---|---|
<R> GridFuture<R> |
affinityCall(String cacheName,
Object affKey,
Callable<R> job)
Executes given job on the node where data for provided affinity key is located
(a.k.a.
|
GridFuture<?> |
affinityRun(String cacheName,
Object affKey,
Runnable job)
Executes given job on the node where data for provided affinity key is located
(a.k.a.
|
<T,R> GridFuture<Collection<R>> |
apply(GridClosure<T,R> job,
Collection<? extends T> args)
Executes provided closure job on nodes within this grid projection.
|
<R,T> GridFuture<R> |
apply(GridClosure<T,R> job,
T arg)
Executes provided closure job on a node in this grid projection.
|
<R1,R2,T> GridFuture<R2> |
apply(GridClosure<T,R1> job,
Collection<? extends T> args,
GridReducer<R1,R2> rdc)
Executes provided closure job on nodes within this grid projection.
|
<R> GridFuture<Collection<R>> |
broadcast(Callable<R> job)
Broadcasts given job to all nodes in grid projection.
|
<R,T> GridFuture<Collection<R>> |
broadcast(GridClosure<T,R> job,
T arg)
Broadcasts given closure job with passed in argument to all nodes in grid projection.
|
GridFuture<?> |
broadcast(Runnable job)
Broadcasts given job to all nodes in grid projection.
|
<R> GridFuture<R> |
call(Callable<R> job)
Executes provided job on a node in this grid projection.
|
<R> GridFuture<Collection<R>> |
call(Collection<? extends Callable<R>> jobs)
Executes collection of jobs on nodes within this grid projection.
|
<R1,R2> GridFuture<R2> |
call(Collection<? extends Callable<R1>> jobs,
GridReducer<R1,R2> rdc)
Executes collection of jobs on nodes within this grid projection.
|
void |
cancelJob(GridUuid jobId)
Cancels job with the given job ID, if it is currently running inside this projection.
|
void |
cancelTask(GridUuid sesId)
Cancels task with the given execution session ID, if it currently running inside this projection.
|
<T,R> GridComputeTaskFuture<R> |
execute(Class<? extends GridComputeTask<T,R>> taskCls,
T arg)
Executes given task on the grid projection.
|
<T,R> GridComputeTaskFuture<R> |
execute(GridComputeTask<T,R> task,
T arg)
Executes given task on this grid projection.
|
<T,R> GridComputeTaskFuture<R> |
execute(String taskName,
T arg)
Executes given task on this grid projection.
|
ExecutorService |
executorService()
Creates new
ExecutorService which will execute all submitted
Callable and Runnable jobs on nodes in this grid projection. |
void |
localDeployTask(Class<? extends GridComputeTask> taskCls,
ClassLoader clsLdr)
Explicitly deploys a task with given class loader on the local node.
|
Map<String,Class<? extends GridComputeTask<?,?>>> |
localTasks()
Gets map of all locally deployed tasks keyed by their task name .
|
GridProjection |
projection()
Gets grid projection to which this
GridCompute instance belongs. |
GridFuture<?> |
run(Collection<? extends Runnable> jobs)
Executes collection of jobs on grid nodes within this grid projection.
|
GridFuture<?> |
run(Runnable job)
Executes provided job on a node in this grid projection.
|
<R> GridComputeTaskFuture<R> |
taskFuture(GridUuid sesId)
Gets task future based on execution session ID.
|
void |
undeployTask(String taskName)
Makes the best attempt to undeploy a task with given name from this grid projection.
|
GridCompute |
withName(String taskName)
Sets task name for the next executed task on this projection in the current thread.
|
GridCompute |
withNoFailover()
Sets no-failover flag for the next executed task on this projection in the current thread.
|
GridCompute |
withTimeout(long timeout)
Sets task timeout for the next executed task on this projection in the current thread.
|
public GridComputeImpl(GridKernalContext ctx, GridProjection prj, UUID subjId)
ctx - Kernal context.prj - Projection.public GridProjection projection()
GridCompute instance belongs.projection in interface GridComputeGridCompute instance belongs.public GridFuture<?> affinityRun(@Nullable String cacheName, Object affKey, Runnable job)
affinityRun in interface GridComputecacheName - Name of the cache to use for affinity co-location.affKey - Affinity key.job - Job which will be co-located on the node with given affinity key.GridComputeJobContext.cacheName(),
GridComputeJobContext.affinityKey()public <R> GridFuture<R> affinityCall(@Nullable String cacheName, Object affKey, Callable<R> job)
affinityCall in interface GridComputecacheName - Name of the cache to use for affinity co-location.affKey - Affinity key.job - Job which will be co-located on the node with given affinity key.GridComputeJobContext.cacheName(),
GridComputeJobContext.affinityKey()public <T,R> GridComputeTaskFuture<R> execute(String taskName, @Nullable T arg)
GridComputeTask documentation.
If task for given name has not been deployed yet, then taskName will be
used as task class name to auto-deploy the task (see GridCompute.localDeployTask(Class, ClassLoader) method).
execute in interface GridComputetaskName - Name of the task to execute.arg - Optional argument of task execution, can be null.for information about task execution.public <T,R> GridComputeTaskFuture<R> execute(Class<? extends GridComputeTask<T,R>> taskCls, @Nullable T arg)
GridComputeTask documentation.execute in interface GridComputetaskCls - Class of the task to execute. If class has GridComputeTaskName annotation,
then task is deployed under a name specified within annotation. Otherwise, full
class name is used as task name.arg - Optional argument of task execution, can be null.public <T,R> GridComputeTaskFuture<R> execute(GridComputeTask<T,R> task, @Nullable T arg)
GridComputeTask documentation.execute in interface GridComputetask - Instance of task to execute. If task class has GridComputeTaskName annotation,
then task is deployed under a name specified within annotation. Otherwise, full
class name is used as task name.arg - Optional argument of task execution, can be null.public GridFuture<?> broadcast(Runnable job)
broadcast in interface GridComputejob - Job to broadcast to all projection nodes.public <R> GridFuture<Collection<R>> broadcast(Callable<R> job)
broadcast in interface GridComputejob - Job to broadcast to all projection nodes.public <R,T> GridFuture<Collection<R>> broadcast(GridClosure<T,R> job, @Nullable T arg)
broadcast in interface GridComputejob - Job to broadcast to all projection nodes.arg - Job closure argument.public GridFuture<?> run(Runnable job)
run in interface GridComputejob - Job closure to execute.public GridFuture<?> run(Collection<? extends Runnable> jobs)
run in interface GridComputejobs - Collection of jobs to execute.public <R,T> GridFuture<R> apply(GridClosure<T,R> job, @Nullable T arg)
run(...) and call(...) methods in a way that it receives job argument
which is then passed into the closure at execution time.apply in interface GridComputejob - Job to run.arg - Job argument.public <R> GridFuture<R> call(Callable<R> job)
call in interface GridComputejob - Job to execute.public <R> GridFuture<Collection<R>> call(Collection<? extends Callable<R>> jobs)
call in interface GridComputejobs - Collection of jobs to execute.public ExecutorService executorService()
ExecutorService which will execute all submitted
Callable and Runnable jobs on nodes in this grid projection. This essentially
creates a Distributed Thread Pool that can be used as a
replacement for local thread pools.executorService in interface GridComputeExecutorService.public <T,R> GridFuture<Collection<R>> apply(GridClosure<T,R> job, @Nullable Collection<? extends T> args)
apply in interface GridComputejob - Job to run.args - Job arguments.public <R1,R2> GridFuture<R2> call(Collection<? extends Callable<R1>> jobs, GridReducer<R1,R2> rdc)
call in interface GridComputejobs - Collection of jobs to execute.rdc - Reducer to reduce all job results into one individual return value.public <R1,R2,T> GridFuture<R2> apply(GridClosure<T,R1> job, Collection<? extends T> args, GridReducer<R1,R2> rdc)
apply in interface GridComputejob - Job to run.args - Job arguments.rdc - Reducer to reduce all job results into one individual return value.@Nullable public <R> GridComputeTaskFuture<R> taskFuture(GridUuid sesId)
taskFuture in interface GridComputeR - Task result type.sesId - Session ID for task execution.null otherwise.public void cancelTask(GridUuid sesId) throws GridException
cancelTask in interface GridComputesesId - Execution session ID.GridException - If task cancellation failed.public void cancelJob(GridUuid jobId) throws GridException
cancelJob in interface GridComputejobId - Job ID.GridException - If task cancellation failed.public GridCompute withName(String taskName)
GridComputeTask.
Here is an example.
GridGain.grid().withName("MyTask").run(new MyRunnable() {...});
withName in interface GridComputetaskName - Task name.GridCompute instance for chaining calls.public GridCompute withTimeout(long timeout)
GridComputeTask.
Here is an example.
GridGain.grid().withTimeout(10000).run(new MyRunnable() {...});
withTimeout in interface GridComputetimeout - Computation timeout in milliseconds.GridCompute instance for chaining calls.public GridCompute withNoFailover()
Here is an example.
GridGain.grid().compute().withNoFailover().run(new MyRunnable() {...});
withNoFailover in interface GridComputethis).public void localDeployTask(Class<? extends GridComputeTask> taskCls, ClassLoader clsLdr) throws GridException
Note that tasks are automatically deployed upon first execution (if peer-class-loading is enabled),
so use this method only when the provided class loader is different from the
taskClass.getClassLoader().
Another way of class deployment is deployment from local class path. Classes from local class path always have a priority over P2P deployed ones.
Note that class can be deployed multiple times on remote nodes, i.e. re-deployed. GridGain maintains internal version of deployment for each instance of deployment (analogous to class and class loader in Java). Execution happens always on the latest deployed instance.
This method has no effect if the class passed in was already deployed.
localDeployTask in interface GridComputetaskCls - Task class to deploy. If task class has GridComputeTaskName annotation,
then task will be deployed under the name specified within annotation. Otherwise, full
class name will be used as task's name.clsLdr - Task class loader. This class loader is in charge
of loading all necessary resources for task execution.GridException - If task is invalid and cannot be deployed.public Map<String,Class<? extends GridComputeTask<?,?>>> localTasks()
localTasks in interface GridComputepublic void undeployTask(String taskName) throws GridException
undeployTask in interface GridComputetaskName - Name of the task to undeploy.GridException - Thrown if undeploy failed.Copyright © 2014. All rights reserved.