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());
}
}
}
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);
}
}
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);
}
}
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);
}
}
}
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));
}
}
Aggregations