Search in sources :

Example 16 with MultiUserEvent

use of org.olat.core.util.event.MultiUserEvent in project OpenOLAT by OpenOLAT.

the class JMSTest method testSendReceive.

@Test
public void testSendReceive() {
    // enable test only if we have the cluster configuration enabled.
    // this test requires that an JMS Provider is running
    // (see file serviceconfig/org/olat/core/_spring/coreextconfig.xml)
    EventBus bus = CoordinatorManager.getInstance().getCoordinator().getEventBus();
    if (bus instanceof ClusterEventBus) {
        Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("jms");
        // send and wait some time until a message should arrive at the latest.
        final OLATResourceable ores = OresHelper.createOLATResourceableInstance("hellojms", new Long(123));
        final CountDownLatch doneSignal = new CountDownLatch(1);
        bus.registerFor(new GenericEventListener() {

            @Override
            public void event(Event event) {
                log.audit("Event received: " + event);
                doneSignal.countDown();
            }
        }, id, ores);
        MultiUserEvent mue = new MultiUserEvent("amuecommand");
        bus.fireEventToListenersOf(mue, ores);
        try {
            boolean interrupt = doneSignal.await(5, TimeUnit.SECONDS);
            assertTrue("Test takes too long (more than 5s)", interrupt);
        } catch (InterruptedException e) {
            fail("" + e.getMessage());
        }
    }
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) MultiUserEvent(org.olat.core.util.event.MultiUserEvent) Event(org.olat.core.gui.control.Event) EventBus(org.olat.core.util.event.EventBus) GenericEventListener(org.olat.core.util.event.GenericEventListener) Identity(org.olat.core.id.Identity) CountDownLatch(java.util.concurrent.CountDownLatch) MultiUserEvent(org.olat.core.util.event.MultiUserEvent) Test(org.junit.Test)

Example 17 with MultiUserEvent

use of org.olat.core.util.event.MultiUserEvent in project openolat by klemens.

the class NotificationsManagerImpl method markPublisherNews.

/**
 * call this method to indicate that there is news for the given
 * subscriptionContext
 *
 * @param subscriptionContext
 * @param ignoreNewsFor
 */
@Override
public void markPublisherNews(final SubscriptionContext subscriptionContext, Identity ignoreNewsFor, boolean sendEvents) {
    // to make sure: ignore if no subscriptionContext
    if (subscriptionContext == null)
        return;
    Publisher toUpdate = getPublisherForUpdate(subscriptionContext);
    if (toUpdate == null) {
        return;
    }
    toUpdate.setLatestNewsDate(new Date());
    Publisher publisher = dbInstance.getCurrentEntityManager().merge(toUpdate);
    // commit the select for update
    dbInstance.commit();
    // user
    if (ignoreNewsFor != null) {
        markSubscriberRead(ignoreNewsFor, publisher);
    }
    if (sendEvents) {
        // commit all things on the database
        dbInstance.commit();
        // channel-notify all interested listeners (e.g. the pnotificationsportletruncontroller)
        // 1. find all subscribers which can be affected
        List<Subscriber> subscribers = getValidSubscribersOf(publisher);
        Set<Long> subsKeys = new HashSet<Long>();
        // 2. collect all keys of the affected subscribers
        for (Subscriber subscriber : subscribers) {
            subsKeys.add(subscriber.getKey());
        }
        // fire the event
        MultiUserEvent mue = EventFactory.createAffectedEvent(subsKeys);
        CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(mue, oresMyself);
    }
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) Publisher(org.olat.core.commons.services.notifications.Publisher) MultiUserEvent(org.olat.core.util.event.MultiUserEvent) Date(java.util.Date) HashSet(java.util.HashSet)

Example 18 with MultiUserEvent

use of org.olat.core.util.event.MultiUserEvent in project openolat by klemens.

the class NotificationsManagerImpl method markPublisherNews.

@Override
public void markPublisherNews(String publisherType, String data, Identity ignoreNewsFor, boolean sendEvents) {
    // to make sure: ignore if no subscriptionContext
    if (!StringHelper.containsNonWhitespace(publisherType) || !StringHelper.containsNonWhitespace(data))
        return;
    List<Publisher> publisherToUpdates = getPublishers(publisherType, data);
    if (publisherToUpdates == null || publisherToUpdates.isEmpty()) {
        return;
    }
    List<Publisher> updatedPublishers = new ArrayList<>(publisherToUpdates.size());
    for (Publisher toUpdate : publisherToUpdates) {
        toUpdate = getPublisherForUpdate(toUpdate);
        toUpdate.setLatestNewsDate(new Date());
        Publisher publisher = dbInstance.getCurrentEntityManager().merge(toUpdate);
        // commit the select for update
        dbInstance.commit();
        updatedPublishers.add(publisher);
    }
    // user
    if (ignoreNewsFor != null) {
        for (Publisher publisher : updatedPublishers) {
            markSubscriberRead(ignoreNewsFor, publisher);
        }
    }
    if (sendEvents) {
        // commit all things on the database
        dbInstance.commit();
        // channel-notify all interested listeners (e.g. the pnotificationsportletruncontroller)
        // 1. find all subscribers which can be affected
        List<Subscriber> subscribers = getValidSubscribersOf(publisherType, data);
        Set<Long> subsKeys = new HashSet<Long>();
        // 2. collect all keys of the affected subscribers
        for (Subscriber subscriber : subscribers) {
            subsKeys.add(subscriber.getKey());
        }
        // fire the event
        MultiUserEvent mue = EventFactory.createAffectedEvent(subsKeys);
        CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(mue, oresMyself);
    }
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) ArrayList(java.util.ArrayList) Publisher(org.olat.core.commons.services.notifications.Publisher) MultiUserEvent(org.olat.core.util.event.MultiUserEvent) Date(java.util.Date) HashSet(java.util.HashSet)

Example 19 with MultiUserEvent

use of org.olat.core.util.event.MultiUserEvent in project openolat by klemens.

the class LanguageChooserController method formInnerEvent.

/**
 * @see org.olat.core.gui.components.form.flexible.FormDefaultController#formInnerEvent(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.components.form.flexible.FormItem,
 *      org.olat.core.gui.components.form.flexible.FormEvent)
 */
@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (source == langs) {
        Locale loc = i18nManager.getLocaleOrDefault(getSelectedLanguage());
        MultiUserEvent mue = new LanguageChangedEvent(loc, ureq);
        setLocale(loc, true);
        ureq.getUserSession().setLocale(loc);
        ureq.getUserSession().putEntry(LocaleNegotiator.NEGOTIATED_LOCALE, loc);
        nextButton.setTranslator(getTranslator());
        if (fireStandardEvent) {
            fireEvent(ureq, mue);
        } else {
            OLATResourceable wrappedLocale = OresHelper.createOLATResourceableType(Locale.class);
            ureq.getUserSession().getSingleUserEventCenter().fireEventToListenersOf(mue, wrappedLocale);
        }
    }
}
Also used : Locale(java.util.Locale) OLATResourceable(org.olat.core.id.OLATResourceable) LanguageChangedEvent(org.olat.core.commons.chiefcontrollers.LanguageChangedEvent) MultiUserEvent(org.olat.core.util.event.MultiUserEvent)

Example 20 with MultiUserEvent

use of org.olat.core.util.event.MultiUserEvent in project openolat by klemens.

the class RepositoryManager method sendDeferredEvents.

private void sendDeferredEvents(List<? extends MultiUserEvent> events, OLATResourceable ores) {
    EventBus eventBus = CoordinatorManager.getInstance().getCoordinator().getEventBus();
    for (MultiUserEvent event : events) {
        eventBus.fireEventToListenersOf(event, ores);
        eventBus.fireEventToListenersOf(event, OresHelper.lookupType(RepositoryEntry.class));
    }
}
Also used : EventBus(org.olat.core.util.event.EventBus) MultiUserEvent(org.olat.core.util.event.MultiUserEvent)

Aggregations

MultiUserEvent (org.olat.core.util.event.MultiUserEvent)48 OLATResourceable (org.olat.core.id.OLATResourceable)16 EntryChangedEvent (org.olat.repository.controllers.EntryChangedEvent)10 ArrayList (java.util.ArrayList)8 File (java.io.File)6 Date (java.util.Date)6 HashSet (java.util.HashSet)6 Identity (org.olat.core.id.Identity)6 SyncerExecutor (org.olat.core.util.coordinate.SyncerExecutor)6 EventBus (org.olat.core.util.event.EventBus)6 List (java.util.List)4 Locale (java.util.Locale)4 Publisher (org.olat.core.commons.services.notifications.Publisher)4 Subscriber (org.olat.core.commons.services.notifications.Subscriber)4 ICourse (org.olat.course.ICourse)3 IOException (java.io.IOException)2 Collection (java.util.Collection)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 JMSException (javax.jms.JMSException)2 ObjectMessage (javax.jms.ObjectMessage)2