1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.internal

File XWikiInitializerJob.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

4
27
6
1
145
82
8
0.3
4.5
6
1.33

Classes

Class Line # Actions
XWikiInitializerJob 46 27 0% 8 3
0.918918991.9%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package com.xpn.xwiki.internal;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24    import javax.inject.Provider;
25    import javax.inject.Singleton;
26   
27    import org.xwiki.bridge.event.ApplicationReadyEvent;
28    import org.xwiki.component.annotation.Component;
29    import org.xwiki.job.AbstractJob;
30    import org.xwiki.job.Request;
31    import org.xwiki.observation.ObservationManager;
32   
33    import com.xpn.xwiki.XWiki;
34    import com.xpn.xwiki.XWikiContext;
35    import com.xpn.xwiki.util.XWikiStubContextProvider;
36   
37    /**
38    * Job dedicated to XWiki initialization.
39    *
40    * @version $Id: 0a45919cb054dffdb90c30722244e08544daeecd $
41    * @since 6.1M1
42    */
43    @Component
44    @Named(XWikiInitializerJob.JOBTYPE)
45    @Singleton
 
46    public class XWikiInitializerJob extends AbstractJob<XWikiInitializerRequest, XWikiInitializerJobStatus>
47    {
48    /**
49    * The id of the job.
50    */
51    public static final String JOBTYPE = "xwiki.init";
52   
53    @Inject
54    private Provider<XWikiContext> xcontextProvider;
55   
56    @Inject
57    private XWikiStubContextProvider stubContextProvider;
58   
59    @Inject
60    private ObservationManager observation;
61   
62    private Thread thread;
63   
 
64  32 toggle @Override
65    protected XWikiInitializerRequest castRequest(Request request)
66    {
67  32 XWikiInitializerRequest indexerRequest;
68  32 if (request instanceof XWikiInitializerRequest) {
69  32 indexerRequest = (XWikiInitializerRequest) request;
70    } else {
71  0 indexerRequest = new XWikiInitializerRequest(request);
72    }
73   
74  32 return indexerRequest;
75    }
76   
 
77  32 toggle @Override
78    protected XWikiInitializerJobStatus createNewStatus(XWikiInitializerRequest request)
79    {
80  32 return new XWikiInitializerJobStatus(request, this.observationManager, this.loggerManager);
81    }
82   
 
83  160 toggle @Override
84    public String getType()
85    {
86  160 return JOBTYPE;
87    }
88   
89    /**
90    * Start the job in a thread.
91    */
 
92  32 toggle public synchronized void startAsync()
93    {
94  32 if (this.thread == null) {
95  32 initialize(new XWikiInitializerRequest());
96   
97  32 this.thread = new Thread(this);
98   
99  32 this.thread.setDaemon(true);
100  32 this.thread.setName("XWiki initialization");
101  32 this.thread.start();
102    }
103    }
104   
 
105  32 toggle @Override
106    protected void runInternal() throws Exception
107    {
108  32 this.logger.info("Start XWiki initialization");
109   
110  32 this.progressManager.pushLevelProgress(2, this);
111   
112  32 try {
113  32 this.progressManager.startStep(this);
114   
115  32 XWikiContext xcontext = this.xcontextProvider.get();
116   
117  32 XWiki xwiki = new XWiki(xcontext, xcontext.getEngineContext(), true);
118   
119    // initialize stub context here instead of during Execution context initialization because
120    // during Execution context initialization, the XWikiContext is not fully initialized (does not
121    // contains XWiki object) which make it unusable
122  32 this.stubContextProvider.initialize(xcontext);
123   
124  32 this.progressManager.startStep(this);
125   
126  32 this.logger.info("XWiki initialization done");
127   
128    // Send Event to signal that the application is ready to service requests.
129  32 this.observation.notify(new ApplicationReadyEvent(), xwiki, xcontext);
130   
131    // Make XWiki class available to others (among other things it unlock page loading)
132  32 xcontext.getEngineContext().setAttribute(XWiki.DEFAULT_MAIN_WIKI, xwiki);
133    } finally {
134  32 this.progressManager.popLevelProgress(this);
135    }
136    }
137   
 
138  32 toggle @Override
139    protected void jobFinished(Throwable exception)
140    {
141  32 super.jobFinished(exception);
142   
143  32 this.thread = null;
144    }
145    }