use of org.springframework.beans.factory.support.AbstractBeanFactory 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