use of org.apache.ignite.compute.ComputeJobAdapter in project ignite by apache.
the class SingleSplitTestTask method map.
/** {@inheritDoc} */
@Override
public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, Integer arg) {
assert !subgrid.isEmpty() : "Subgrid cannot be empty.";
Map<ComputeJobAdapter, ClusterNode> jobs = new HashMap<>(subgrid.size());
taskSes.setAttribute("1st", "1");
taskSes.setAttribute("2nd", "2");
Collection<UUID> assigned = new ArrayList<>(subgrid.size());
for (int i = 0; i < arg; i++) {
ComputeJobAdapter job = new ComputeJobAdapter(1) {
/** */
@TaskSessionResource
private ComputeTaskSession jobSes;
/** {@inheritDoc} */
@Override
public Object execute() {
assert jobSes != null;
Integer arg = this.<Integer>argument(0);
assert arg != null;
return new SingleSplitTestJobTarget().executeLoadTestJob(arg, jobSes);
}
};
ClusterNode node = balancer.getBalancedNode(job, null);
assert node != null;
assigned.add(node.id());
jobs.put(job, node);
}
taskSes.setAttribute("nodes", assigned);
return jobs;
}
use of org.apache.ignite.compute.ComputeJobAdapter in project ignite by apache.
the class GridContinuousMapperTask1 method sendJob.
/**
* Sends job to node.
*
* @param n Node.
* @throws IgniteException If failed.
*/
private void sendJob(ClusterNode n) {
try {
int jobId = queue.take();
sentJobs.incrementAndGet();
mapper.send(new ComputeJobAdapter(jobId) {
@IgniteInstanceResource
private Ignite g;
@Override
public Object execute() {
Integer jobId = argument(0);
X.println(">>> Received job for ID: " + jobId);
return g.cache("replicated").localPeek(jobId, CachePeekMode.ONHEAP);
}
}, n);
} catch (InterruptedException e) {
throw new IgniteException(e);
}
}
use of org.apache.ignite.compute.ComputeJobAdapter in project ignite by apache.
the class GridSingleSplitNewNodesTestTask method map.
/** {@inheritDoc} */
@Override
public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, Integer arg) {
assert !subgrid.isEmpty() : "Subgrid cannot be empty.";
Map<ComputeJobAdapter, ClusterNode> jobs = new HashMap<>(subgrid.size());
taskSes.setAttribute("1st", "1");
taskSes.setAttribute("2nd", "2");
Collection<UUID> assigned = new ArrayList<>(subgrid.size());
for (int i = 0; i < arg; i++) {
ComputeJobAdapter job = new ComputeJobAdapter(1) {
/** */
@TaskSessionResource
private ComputeTaskSession jobSes;
/** {@inheritDoc} */
@Override
public Serializable execute() {
assert jobSes != null;
Integer arg = this.<Integer>argument(0);
assert arg != null;
return new GridSingleSplitNewNodesTestJobTarget().executeLoadTestJob(arg, jobSes);
}
};
ClusterNode node = balancer.getBalancedNode(job, null);
assert node != null;
assigned.add(node.id());
jobs.put(job, node);
}
taskSes.setAttribute("nodes", assigned);
return jobs;
}
use of org.apache.ignite.compute.ComputeJobAdapter in project ignite by apache.
the class GridContinuousMapperTask2 method map.
/** {@inheritDoc} */
@Override
public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, @Nullable int[] jobIds) {
Map<ComputeJob, ClusterNode> mappings = new HashMap<>(jobIds.length);
Iterator<ClusterNode> nodeIter = g.cluster().forRemotes().nodes().iterator();
for (int jobId : jobIds) {
ComputeJob job = new ComputeJobAdapter(jobId) {
@IgniteInstanceResource
private Ignite g;
@Override
public Object execute() {
Integer jobId = argument(0);
X.println(">>> Received job for ID: " + jobId);
return g.cache("replicated").localPeek(jobId, CachePeekMode.ONHEAP);
}
};
// If only local node in the grid.
if (g.cluster().nodes().size() == 1)
mappings.put(job, g.cluster().localNode());
else {
ClusterNode n = nodeIter.hasNext() ? nodeIter.next() : (nodeIter = g.cluster().forRemotes().nodes().iterator()).next();
mappings.put(job, n);
}
}
return mappings;
}
use of org.apache.ignite.compute.ComputeJobAdapter in project ignite by apache.
the class GarHelloWorldTask method split.
/** {@inheritDoc} */
@Override
public Collection<? extends ComputeJob> split(int gridSize, String arg) throws IgniteException {
// Create Spring context.
AbstractBeanFactory fac = new XmlBeanFactory(new ClassPathResource("org/apache/ignite/spi/deployment/uri/tasks/gar-spring-bean.xml", getClass().getClassLoader()));
fac.setBeanClassLoader(getClass().getClassLoader());
// Load imported bean from GAR/lib folder.
GarHelloWorldBean bean = (GarHelloWorldBean) fac.getBean("example.bean");
String msg = bean.getMessage(arg);
assert msg != null;
// Split the passed in phrase into multiple words separated by spaces.
List<String> words = Arrays.asList(msg.split(" "));
Collection<ComputeJob> jobs = new ArrayList<>(words.size());
// Use imperative OOP APIs.
for (String word : words) {
// Every job gets its own word as an argument.
jobs.add(new ComputeJobAdapter(word) {
/*
* Simply prints the job's argument.
*/
@Nullable
@Override
public Serializable execute() {
System.out.println(">>>");
System.out.println(">>> Printing '" + argument(0) + "' on this node from grid job.");
System.out.println(">>>");
// This job does not return any result.
return null;
}
});
}
return jobs;
}
Aggregations