use of org.olat.core.util.event.EventBus in project openolat by klemens.
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.EventBus in project openolat by klemens.
the class InfoMessageManager method setInfoMessage.
/**
* @param message The new info message that will show up on the login screen
* Synchronized to prevent two users creating or updating the info message property
* at the same time
*/
public void setInfoMessage(final String message) {
// o_clusterOK synchronized
OLATResourceable ores = OresHelper.createOLATResourceableInstance(INFO_MSG, KEY);
coordinatorManager.getCoordinator().getSyncer().doInSync(ores, new SyncerExecutor() {
public void execute() {
PropertyManager pm = PropertyManager.getInstance();
Property p = pm.findProperty(null, null, null, "_o3_", INFO_MSG);
if (p == null) {
p = pm.createPropertyInstance(null, null, null, "_o3_", INFO_MSG, null, null, null, "");
pm.saveProperty(p);
}
p.setTextValue(message);
// set Message in RAM
InfoMessageManager.infoMessage = message;
pm.updateProperty(p);
}
});
// end syncerCallback
EventBus eb = coordinatorManager.getCoordinator().getEventBus();
MultiUserEvent mue = new MultiUserEvent(message);
eb.fireEventToListenersOf(mue, INFO_MESSAGE_ORES);
}
Aggregations