Search in sources :

Example 6 with ApplicationReadyEvent

use of org.xwiki.bridge.event.ApplicationReadyEvent in project xwiki-platform by xwiki.

the class ScriptingIntegrationTest method initialize.

@Before
public void initialize() throws Exception {
    this.scriptService = this.componentManager.getInstance(ScriptService.class, "mailsender");
    // Set the EC
    Execution execution = this.componentManager.getInstance(Execution.class);
    ExecutionContext executionContext = new ExecutionContext();
    XWikiContext xContext = new XWikiContext();
    xContext.setWikiId("wiki");
    executionContext.setProperty(XWikiContext.EXECUTIONCONTEXT_KEY, xContext);
    execution.setContext(executionContext);
    Copier<ExecutionContext> executionContextCloner = this.componentManager.getInstance(new DefaultParameterizedType(null, Copier.class, ExecutionContext.class));
    // Just return the same execution context
    when(executionContextCloner.copy(executionContext)).thenReturn(executionContext);
    // Simulate receiving the Application Ready Event to start the mail threads
    MailSenderInitializerListener listener = this.componentManager.getInstance(EventListener.class, MailSenderInitializerListener.LISTENER_NAME);
    listener.onEvent(new ApplicationReadyEvent(), null, null);
}
Also used : ScriptService(org.xwiki.script.service.ScriptService) MailSenderScriptService(org.xwiki.mail.script.MailSenderScriptService) DefaultExecution(org.xwiki.context.internal.DefaultExecution) Execution(org.xwiki.context.Execution) ExecutionContext(org.xwiki.context.ExecutionContext) Copier(org.xwiki.mail.internal.thread.context.Copier) ApplicationReadyEvent(org.xwiki.bridge.event.ApplicationReadyEvent) XWikiContext(com.xpn.xwiki.XWikiContext) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) MailSenderInitializerListener(org.xwiki.mail.internal.thread.MailSenderInitializerListener) Before(org.junit.Before)

Example 7 with ApplicationReadyEvent

use of org.xwiki.bridge.event.ApplicationReadyEvent in project xwiki-platform by xwiki.

the class XWikiInitializerJob method runInternal.

@Override
protected void runInternal() throws Exception {
    this.logger.info("Start XWiki initialization");
    this.progressManager.pushLevelProgress(2, this);
    try {
        this.progressManager.startStep(this);
        XWikiContext xcontext = this.xcontextProvider.get();
        XWiki xwiki = new XWiki(xcontext, xcontext.getEngineContext(), true);
        // initialize stub context here instead of during Execution context initialization because
        // during Execution context initialization, the XWikiContext is not fully initialized (does not
        // contains XWiki object) which make it unusable
        this.stubContextProvider.initialize(xcontext);
        this.progressManager.endStep(this);
        this.progressManager.startStep(this);
        this.logger.info("XWiki initialization done");
        // Send Event to signal that the application is ready to service requests.
        this.observation.notify(new ApplicationReadyEvent(), xwiki, xcontext);
        // Make XWiki class available to others (among other things it unlock page loading)
        xcontext.getEngineContext().setAttribute(XWiki.DEFAULT_MAIN_WIKI, xwiki);
    } finally {
        this.progressManager.popLevelProgress(this);
    }
}
Also used : ApplicationReadyEvent(org.xwiki.bridge.event.ApplicationReadyEvent) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki)

Example 8 with ApplicationReadyEvent

use of org.xwiki.bridge.event.ApplicationReadyEvent in project xwiki-platform by xwiki.

the class DefaultWikiComponentManagerEventListener method onEvent.

@Override
public void onEvent(Event event, Object source, Object data) {
    if (source instanceof DocumentModelBridge) {
        // Get the document reference
        DocumentModelBridge document = (DocumentModelBridge) source;
        DocumentReference documentReference = document.getDocumentReference();
        if (event instanceof DocumentCreatedEvent || event instanceof DocumentUpdatedEvent) {
            registerDocumentComponents(document.getDocumentReference());
        } else if (event instanceof DocumentDeletedEvent) {
            // Unregister components from the deleted document, if any
            this.wikiComponentManagerEventListenerHelper.unregisterComponents(documentReference);
        }
    /* If we are at application startup time, we have to instanciate every document or object that we can find
         * in the wiki */
    } else if (event instanceof ApplicationReadyEvent || event instanceof WikiReadyEvent) {
        // These 2 events are created when the database is ready. We register all wiki components.
        registerAllDocumentComponents();
    }
}
Also used : DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) ApplicationReadyEvent(org.xwiki.bridge.event.ApplicationReadyEvent) DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) WikiReadyEvent(org.xwiki.bridge.event.WikiReadyEvent) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) DocumentReference(org.xwiki.model.reference.DocumentReference)

Aggregations

ApplicationReadyEvent (org.xwiki.bridge.event.ApplicationReadyEvent)8 XWikiContext (com.xpn.xwiki.XWikiContext)3 Before (org.junit.Before)3 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)3 MailSenderInitializerListener (org.xwiki.mail.internal.thread.MailSenderInitializerListener)3 Test (org.junit.Test)2 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)2 Execution (org.xwiki.context.Execution)2 ExecutionContext (org.xwiki.context.ExecutionContext)2 MailSender (org.xwiki.mail.MailSender)2 DefaultMailSender (org.xwiki.mail.internal.DefaultMailSender)2 Copier (org.xwiki.mail.internal.thread.context.Copier)2 XWiki (com.xpn.xwiki.XWiki)1 DocumentCreatedEvent (org.xwiki.bridge.event.DocumentCreatedEvent)1 DocumentDeletedEvent (org.xwiki.bridge.event.DocumentDeletedEvent)1 DocumentUpdatedEvent (org.xwiki.bridge.event.DocumentUpdatedEvent)1 WikiReadyEvent (org.xwiki.bridge.event.WikiReadyEvent)1 DefaultExecution (org.xwiki.context.internal.DefaultExecution)1 MailSenderScriptService (org.xwiki.mail.script.MailSenderScriptService)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1