Search in sources :

Example 11 with EventBus

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());
        }
    }
}
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 12 with EventBus

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);
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) PropertyManager(org.olat.properties.PropertyManager) SyncerExecutor(org.olat.core.util.coordinate.SyncerExecutor) EventBus(org.olat.core.util.event.EventBus) Property(org.olat.properties.Property) MultiUserEvent(org.olat.core.util.event.MultiUserEvent)

Aggregations

EventBus (org.olat.core.util.event.EventBus)12 OLATResourceable (org.olat.core.id.OLATResourceable)6 MultiUserEvent (org.olat.core.util.event.MultiUserEvent)6 Identity (org.olat.core.id.Identity)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 HashSet (java.util.HashSet)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Test (org.junit.Test)2 Event (org.olat.core.gui.control.Event)2 AssertException (org.olat.core.logging.AssertException)2 ILoggingAction (org.olat.core.logging.activity.ILoggingAction)2 SyncerExecutor (org.olat.core.util.coordinate.SyncerExecutor)2 GenericEventListener (org.olat.core.util.event.GenericEventListener)2 ICourse (org.olat.course.ICourse)2 Structure (org.olat.course.Structure)2 RecertificationTimeUnit (org.olat.course.certificate.RecertificationTimeUnit)2 CourseConfigEvent (org.olat.course.config.CourseConfigEvent)2 CourseNode (org.olat.course.nodes.CourseNode)2 CourseEditorTreeNode (org.olat.course.tree.CourseEditorTreeNode)2 BusinessGroup (org.olat.group.BusinessGroup)2