You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by vkulichenko <va...@gmail.com> on 2016/03/25 01:35:25 UTC

Re: Scheduler - clustered singleton service.

Hi,

Can you please properly subscribe to the mailing list so that the community
receives email notifications? Here is the instruction:
http://apache-ignite-users.70518.x6.nabble.com/mailing_list/MailingListOptions.jtp?forum=1


dingutak wrote
> I would like to run a scheduler process that runs every 5 minutes to read
> data from the database and submit it to the compute grid.
> 
> The scheduler need to be cluster singleton. So, inside the execute method,
> I am starting the java concurrent's ScheduledExecutorService that executes
> a Task implements Runnable (say MyTask)
> 
> I was trying to @Autowire and @SpringResource another service into the
> MyTask but none of the options would inject the service (just returns
> nulls for injected files) into the task.
> 
> I would like to know if it's possible to start a scheduler inside the
> Service's execute and use spring to wire the task with services (load data
> from database etc).

You can inject Spring application context into the runnable and use it to
get beans from it:

    public class MyTask implements IgniteRunnable {
        @SpringApplicationContextResource
        private ApplicationContext appCtx;

        @Override public void run() {
            DataSource dataSource = appCtx.getBean(DataSource.class);

            // ...
        }
    }

Let us know if this helps.

-Val



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Scheduler-clustered-singleton-service-tp3671p3674.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.