Search in sources :

Example 26 with MultiUserEvent

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

the class ClusterAdminControllerCluster method event.

@Override
protected void event(UserRequest ureq, Component source, Event event) {
    if (source == syncLong) {
        // sync on a olatresourceable and hold the lock for 5 seconds.
        CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(ORES_TEST, new SyncerExecutor() {

            public void execute() {
                sleep(5000);
            }
        });
        // the runnable is executed within the same thread->
        getWindowControl().setInfo("done syncing on the test olatresourceable for 5 seconds");
    } else if (source == syncShort) {
        // sync on a olatresourceable and hold the lock for 1 second.
        CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(ORES_TEST, new SyncerExecutor() {

            public void execute() {
                sleep(1000);
            }
        });
        // the runnable is executed within the same thread->
        getWindowControl().setInfo("done syncing on the test olatresourceable for 1 second");
    } else if (source == testPerf) {
        // send 1000 (short) messages over the cluster bus
        int cnt = 1000;
        long start = System.nanoTime();
        for (int i = 0; i < cnt; i++) {
            clusBus.fireEventToListenersOf(new MultiUserEvent("jms-perf-test-" + i + " of " + cnt), ORES_TEST);
        }
        long stop = System.nanoTime();
        long dur = stop - start;
        double inmilis = dur / 1000000;
        double avg = dur / cnt;
        double avgmilis = avg / 1000000;
        getWindowControl().setInfo("sending " + cnt + " messages took " + inmilis + " ms, avg per messages was " + avg + " ns = " + avgmilis + " ms");
    } else if (source == testCachePut) {
        CacheWrapper<String, String> cw = CoordinatorManager.getInstance().getCoordinator().getCacher().getCache(this.getClass().getSimpleName(), "cachetest");
        // we explicitly use put and not putSilent to show that a put invalidates (and thus removes) this key of this cache in all other cluster nodes.
        cw.update("akey", "hello");
        updateCacheInfo();
    } else if (source == testCachePut2) {
        // we explicitly use put and not putSilent to show that a put invalidates (and thus removes) this key of this cache in all other cluster nodes.
        CacheWrapper<String, String> cw = CoordinatorManager.getInstance().getCoordinator().getCacher().getCache(this.getClass().getSimpleName(), "cachetest");
        cw.update("akey", "world");
        updateCacheInfo();
    } else if (source == testSFUPerf) {
        // acquire a sync 1000x times (does internally a select-for-update on the database)
        int cnt = 1000;
        long start = System.nanoTime();
        for (int i = 0; i < cnt; i++) {
            CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(ORES_TEST, new SyncerExecutor() {

                public void execute() {
                // empty
                }
            });
        }
        long stop = System.nanoTime();
        long dur = stop - start;
        double inmilis = dur / 1000000;
        double avg = dur / cnt;
        double avgmilis = avg / 1000000;
        getWindowControl().setInfo("acquiring " + cnt + " locks for syncing (using db's \"select for update\") took " + inmilis + " ms, avg per messages was " + avg + " ns = " + avgmilis + " ms");
    } else if (source == releaseAllLocksFor) {
        // let a user search pop up
        usc = new UserSearchController(ureq, getWindowControl(), true);
        listenTo(usc);
        getWindowControl().pushAsModalDialog(usc.getInitialComponent());
    } else if ((source == nodeInfoVc) && (event.getCommand().equals("switchToNode"))) {
        String nodeIdStr = ureq.getHttpReq().getParameter("nodeId");
        if (nodeIdStr.length() == 1) {
            nodeIdStr = "0" + nodeIdStr;
        }
        Cookie[] cookies = ureq.getHttpReq().getCookies();
        for (int i = 0; i < cookies.length; i++) {
            Cookie cookie = cookies[i];
            if ("JSESSIONID".equals(cookie.getName())) {
                String redirectedButInvalidSessionId = cookie.getValue();
                redirectedButInvalidSessionId = redirectedButInvalidSessionId.substring(0, redirectedButInvalidSessionId.length() - 2) + nodeIdStr;
                logInfo("redirecting session to node " + nodeIdStr + ", new sessionid=" + redirectedButInvalidSessionId, null);
                cookie.setValue(redirectedButInvalidSessionId);
                replaceCookie(ureq.getHttpReq(), ureq.getHttpResp(), cookie);
                // OLAT-5165: make sure we can always bypass the dmz reject mechanism (for 5min that is)
                Cookie newCookie = new Cookie("bypassdmzreject", String.valueOf(System.currentTimeMillis()));
                // 5min lifetime
                newCookie.setMaxAge(5 * 60);
                newCookie.setPath(WebappHelper.getServletContextPath());
                newCookie.setSecure(ureq.getHttpReq().isSecure());
                newCookie.setComment("cookie allowing olat admin users to bypass dmz rejects");
                ureq.getHttpResp().addCookie(newCookie);
                OncePanel oncePanel = new OncePanel("refresh");
                oncePanel.setContent(createVelocityContainer("refresh"));
                mainVc.put("refresh", oncePanel);
                break;
            }
        }
    } else if (source == toggleStartStop) {
        clusBus.resetStats();
        updatePerfInfos();
    } else if (source == resetStats) {
        clusBus.resetStats();
        updatePerfInfos();
    }
}
Also used : Cookie(javax.servlet.http.Cookie) CacheWrapper(org.olat.core.util.cache.CacheWrapper) OncePanel(org.olat.core.gui.components.panel.OncePanel) SyncerExecutor(org.olat.core.util.coordinate.SyncerExecutor) UserSearchController(org.olat.admin.user.UserSearchController) MultiUserEvent(org.olat.core.util.event.MultiUserEvent)

Example 27 with MultiUserEvent

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

the class ClusterEventBus method serveMessage.

void serveMessage(Message message, long receiveEnqueueTime) {
    // stats
    final long receiveTime = System.currentTimeMillis();
    if (receiveEnqueueTime > 0) {
        final long diff = receiveTime - receiveEnqueueTime;
        mrtgProbeJMSEnqueueTime_.addMeasurement(diff);
    }
    if (lastOnMessageFinishTime_ != -1) {
        final long waitingTime = receiveTime - lastOnMessageFinishTime_;
        // the waiting time is inverted to represent more like a frequency
        // the values it translates to are the following:
        // 0ms -> 100
        // 1ms ->  66
        // 2ms ->  50
        // 4ms ->  33
        // 6ms ->  25
        // 8ms ->  20
        // 18ms ->  10
        // 20ms ->   9
        // 23ms ->   8
        // 26.5ms -> 7
        // 31ms ->   6
        // 38ms ->   5
        mrtgProbeJMSLoad_.addMeasurement((long) (100.0 / ((waitingTime / 2.0) + 1.0)));
        lastOnMessageFinishTime_ = -1;
    }
    ObjectMessage om = (ObjectMessage) message;
    try {
        // unpack
        JMSWrapper jmsWrapper = (JMSWrapper) om.getObject();
        Integer nodeId = jmsWrapper.getNodeId();
        MultiUserEvent event = jmsWrapper.getMultiUserEvent();
        OLATResourceable ores = jmsWrapper.getOres();
        boolean fromSameNode = clusterConfig.getNodeId().equals(nodeId);
        String recMsg = "received msg: " + (fromSameNode ? "[same node]" : "") + " from node:" + nodeId + ", olat-id:" + jmsWrapper.getMsgId() + ", ores:" + ores.getResourceableTypeName() + ":" + ores.getResourceableId() + ", event:" + event + "}";
        // stats
        final long jmsTimestamp = om.getJMSTimestamp();
        if (jmsTimestamp != 0) {
            final long deliveryTime = receiveTime - jmsTimestamp;
            if (deliveryTime > 1500) {
                // then issue a log statement
                log.warn("message received with long delivery time (longer than 1500ms: " + deliveryTime + "): " + recMsg);
            }
            mrtgProbeJMSDeliveryTime_.addMeasurement(deliveryTime);
        }
        addToReceivedScreen(recMsg);
        if (log.isDebug())
            log.debug(recMsg);
        // message with destination and source both having this vm are ignored here, since they were already
        // "inline routed" when having been sent (direct call within the vm).
        // TODO jms if (!fromSameNode) {
        // distribute the unmarshalled event to all JVM wide listeners for this channel.
        doFire(event, ores);
        // TODO jms } // else message already sent "in-vm"
        // stats
        final long doneTime = System.currentTimeMillis();
        final long processingTime = doneTime - receiveTime;
        if (processingTime > 500) {
            // then issue a log statement
            log.warn("message received with long processing time (longer than 500ms: " + processingTime + "): " + recMsg);
        }
        mrtgProbeJMSProcessingTime_.addMeasurement(processingTime);
    } catch (Error er) {
        log.error("Uncaught Error in ClusterEventBus.onMessage!", er);
        throw er;
    } catch (RuntimeException re) {
        log.error("Uncaught RuntimeException in ClusterEventBus.onMessage!", re);
        throw re;
    } catch (JMSException e) {
        log.warn("JMSException in ClusterEventBus.onMessage", e);
        throw new OLATRuntimeException("error when receiving jms messages", e);
    } catch (Throwable th) {
        log.error("Uncaught Throwable in ClusterEventBus.onMessage!", th);
    } finally {
        lastOnMessageFinishTime_ = System.currentTimeMillis();
    }
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) JMSException(javax.jms.JMSException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) ObjectMessage(javax.jms.ObjectMessage) MultiUserEvent(org.olat.core.util.event.MultiUserEvent)

Example 28 with MultiUserEvent

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

the class LockController method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
 */
public void event(UserRequest ureq, Controller source, Event event) {
    if (source == tableCtr) {
        if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
            TableEvent te = (TableEvent) event;
            LockEntry lockToRelease = locksTableModel.getObject(te.getRowId());
            dialogController = activateYesNoDialog(ureq, null, translate("lock.release.sure"), dialogController);
            dialogController.setUserObject(lockToRelease);
        }
    } else if (source == dialogController) {
        if (DialogBoxUIFactory.isYesEvent(event)) {
            LockEntry lockToRelease = (LockEntry) dialogController.getUserObject();
            MultiUserEvent mue = new LockRemovedEvent(lockToRelease);
            OLATResourceable lockEntryOres = OresHelper.createOLATResourceableInstance(LockEntry.class, 0l);
            CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(mue, lockEntryOres);
            CoordinatorManager.getInstance().getCoordinator().getLocker().releaseLockEntry(lockToRelease);
            lockToRelease = null;
            resetTableModel();
        }
    }
}
Also used : LockRemovedEvent(org.olat.core.util.coordinate.LockRemovedEvent) TableEvent(org.olat.core.gui.components.table.TableEvent) LockEntry(org.olat.core.util.coordinate.LockEntry) OLATResourceable(org.olat.core.id.OLATResourceable) MultiUserEvent(org.olat.core.util.event.MultiUserEvent)

Example 29 with MultiUserEvent

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

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)

Example 30 with MultiUserEvent

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

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)

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