Search in sources :

Example 1 with DefaultDistributionJob

use of org.xwiki.extension.distribution.internal.job.DefaultDistributionJob in project xwiki-platform by xwiki.

the class DefaultDistributionManager method startFarmJob.

@Override
public DefaultDistributionJob startFarmJob() {
    try {
        this.farmDistributionJob = this.componentManager.getInstance(Job.class, DefaultDistributionJob.HINT);
        XWikiContext xcontext = this.xcontextProvider.get();
        final DistributionRequest request = new DistributionRequest();
        request.setId(getFarmJobId());
        request.setWiki(xcontext.getMainXWiki());
        request.setUserReference(xcontext.getUserReference());
        request.setInteractive(this.configuration.getProperty("distribution.job.interactive", true));
        Thread distributionJobThread = new Thread(new Runnable() {

            @Override
            public void run() {
                // Create a clean Execution Context
                ExecutionContext context = new ExecutionContext();
                try {
                    executionContextManager.initialize(context);
                } catch (ExecutionContextException e) {
                    throw new RuntimeException("Failed to initialize farm distribution job execution context", e);
                }
                farmDistributionJob.initialize(request);
                farmDistributionJob.run();
            }
        });
        distributionJobThread.setDaemon(true);
        distributionJobThread.setName("Farm distribution initialization");
        distributionJobThread.start();
        // Wait until the job is ready (or finished)
        this.farmDistributionJob.awaitReady();
        return this.farmDistributionJob;
    } catch (Exception e) {
        this.logger.error("Failed to create farm distribution job", e);
    }
    return null;
}
Also used : DistributionRequest(org.xwiki.extension.distribution.internal.job.DistributionRequest) ExecutionContext(org.xwiki.context.ExecutionContext) XWikiContext(com.xpn.xwiki.XWikiContext) DistributionJob(org.xwiki.extension.distribution.internal.job.DistributionJob) Job(org.xwiki.job.Job) DefaultDistributionJob(org.xwiki.extension.distribution.internal.job.DefaultDistributionJob) ExecutionContextException(org.xwiki.context.ExecutionContextException) XWikiException(com.xpn.xwiki.XWikiException) InitializationException(org.xwiki.component.phase.InitializationException) ExecutionContextException(org.xwiki.context.ExecutionContextException)

Aggregations

XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiException (com.xpn.xwiki.XWikiException)1 InitializationException (org.xwiki.component.phase.InitializationException)1 ExecutionContext (org.xwiki.context.ExecutionContext)1 ExecutionContextException (org.xwiki.context.ExecutionContextException)1 DefaultDistributionJob (org.xwiki.extension.distribution.internal.job.DefaultDistributionJob)1 DistributionJob (org.xwiki.extension.distribution.internal.job.DistributionJob)1 DistributionRequest (org.xwiki.extension.distribution.internal.job.DistributionRequest)1 Job (org.xwiki.job.Job)1