Search in sources :

Example 1 with AbstractBeanFactory

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;
}
Also used : Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) ComputeJobAdapter(org.apache.ignite.compute.ComputeJobAdapter) ClassPathResource(org.springframework.core.io.ClassPathResource) ComputeJob(org.apache.ignite.compute.ComputeJob) AbstractBeanFactory(org.springframework.beans.factory.support.AbstractBeanFactory) XmlBeanFactory(org.springframework.beans.factory.xml.XmlBeanFactory) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 ComputeJob (org.apache.ignite.compute.ComputeJob)1 ComputeJobAdapter (org.apache.ignite.compute.ComputeJobAdapter)1 Nullable (org.jetbrains.annotations.Nullable)1 AbstractBeanFactory (org.springframework.beans.factory.support.AbstractBeanFactory)1 XmlBeanFactory (org.springframework.beans.factory.xml.XmlBeanFactory)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1