Search in sources :

Example 26 with OLATResourceable

use of org.olat.core.id.OLATResourceable in project OpenOLAT by OpenOLAT.

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 27 with OLATResourceable

use of org.olat.core.id.OLATResourceable in project OpenOLAT by OpenOLAT.

the class ChecklistManager method deleteChecklist.

/**
 * Delete checklist.
 * @param checklist
 */
public void deleteChecklist(final Checklist cl) {
    final DB db = DBFactory.getInstance();
    OLATResourceable ores = OresHelper.createOLATResourceableInstance(Checklist.class, cl.getKey());
    CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(ores, new SyncerExecutor() {

        public void execute() {
            Checklist checklist = (Checklist) db.loadObject(cl);
            db.deleteObject(checklist);
        }
    });
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) SyncerExecutor(org.olat.core.util.coordinate.SyncerExecutor) DB(org.olat.core.commons.persistence.DB)

Example 28 with OLATResourceable

use of org.olat.core.id.OLATResourceable in project OpenOLAT by OpenOLAT.

the class UserAdminMainController method acquireDeleteUserLock.

/**
 * Acquire lock for whole delete-user workflow
 */
private Controller acquireDeleteUserLock(UserRequest ureq) {
    OLATResourceable lockResourceable = OresHelper.createOLATResourceableTypeWithoutCheck(TabbedPaneController.class.getName());
    lock = CoordinatorManager.getInstance().getCoordinator().getLocker().acquireLock(lockResourceable, ureq.getIdentity(), "deleteGroup");
    if (!lock.isSuccess()) {
        String fullname = userManager.getUserDisplayName(lock.getOwner());
        String text = getTranslator().translate("error.deleteworkflow.locked.by", new String[] { fullname });
        Controller monoCtr = MessageUIFactory.createInfoMessage(ureq, getWindowControl(), null, text);
        return monoCtr;
    }
    return null;
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) UserCreateController(org.olat.admin.user.UserCreateController) TabbedPaneController(org.olat.admin.user.delete.TabbedPaneController) NewUsersNotificationsController(org.olat.admin.user.NewUsersNotificationsController) DirectDeleteController(org.olat.admin.user.delete.DirectDeleteController) LayoutMain3ColsController(org.olat.core.commons.fullWebApp.LayoutMain3ColsController) UserAdminController(org.olat.admin.user.UserAdminController) UserImportController(org.olat.admin.user.imp.UserImportController) Controller(org.olat.core.gui.control.Controller) UsermanagerUserSearchController(org.olat.admin.user.UsermanagerUserSearchController) MainLayoutBasicController(org.olat.core.gui.control.controller.MainLayoutBasicController) TabbedPaneController(org.olat.admin.user.delete.TabbedPaneController)

Example 29 with OLATResourceable

use of org.olat.core.id.OLATResourceable in project OpenOLAT by OpenOLAT.

the class ICalFileCalendarManager method removeFutureOfEvent.

@Override
public boolean removeFutureOfEvent(Kalendar cal, KalendarRecurEvent kalendarEvent) {
    OLATResourceable calOres = getOresHelperFor(cal);
    Boolean removeSuccessful = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(calOres, new SyncerCallback<Boolean>() {

        @Override
        public Boolean execute() {
            boolean successfullyPersist = false;
            try {
                String uid = kalendarEvent.getID();
                Date occurenceDate = kalendarEvent.getOccurenceDate();
                Kalendar loadedCal = getCalendarFromCache(cal.getType(), cal.getCalendarID());
                KalendarEvent rootEvent = loadedCal.getEvent(kalendarEvent.getID(), null);
                String rRule = rootEvent.getRecurrenceRule();
                Recur recur = new Recur(rRule);
                recur.setUntil(CalendarUtils.createDate(occurenceDate));
                RRule rrule = new RRule(recur);
                rootEvent.setRecurrenceRule(rrule.getValue());
                for (KalendarEvent kEvent : loadedCal.getEvents()) {
                    if (uid.equals(kEvent.getID()) && StringHelper.containsNonWhitespace(kEvent.getRecurrenceID()) && occurenceDate.before(kEvent.getBegin())) {
                        loadedCal.removeEvent(kEvent);
                    }
                }
                successfullyPersist = persistCalendar(loadedCal);
            } catch (ParseException e) {
                log.error("", e);
            }
            return new Boolean(successfullyPersist);
        }
    });
    // inform all controller about calendar change for reload
    CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CalendarGUIModifiedEvent(cal), OresHelper.lookupType(CalendarManager.class));
    return removeSuccessful.booleanValue();
}
Also used : RRule(net.fortuna.ical4j.model.property.RRule) OLATResourceable(org.olat.core.id.OLATResourceable) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) Date(java.util.Date) ExDate(net.fortuna.ical4j.model.property.ExDate) CalendarManager(org.olat.commons.calendar.CalendarManager) Kalendar(org.olat.commons.calendar.model.Kalendar) ParseException(java.text.ParseException) CalendarGUIModifiedEvent(org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent) Recur(net.fortuna.ical4j.model.Recur)

Example 30 with OLATResourceable

use of org.olat.core.id.OLATResourceable in project OpenOLAT by OpenOLAT.

the class ICalFileCalendarManager method removeEventFrom.

/**
 * @see org.olat.commons.calendar.CalendarManager#removeEventFrom(org.olat.commons.calendar.model.Kalendar, org.olat.commons.calendar.model.KalendarEvent)
 */
@Override
public boolean removeEventFrom(final Kalendar cal, final KalendarEvent kalendarEvent) {
    OLATResourceable calOres = getOresHelperFor(cal);
    Boolean removeSuccessful = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(calOres, new SyncerCallback<Boolean>() {

        @Override
        public Boolean execute() {
            String uid = kalendarEvent.getID();
            String recurrenceId = kalendarEvent.getRecurrenceID();
            Kalendar loadedCal = getCalendarFromCache(cal.getType(), cal.getCalendarID());
            if (StringHelper.containsNonWhitespace(recurrenceId)) {
                loadedCal.removeEvent(kalendarEvent);
                KalendarEvent rootEvent = loadedCal.getEvent(kalendarEvent.getID(), null);
                if (rootEvent != null && kalendarEvent instanceof KalendarRecurEvent) {
                    Date recurrenceDate = ((KalendarRecurEvent) kalendarEvent).getOccurenceDate();
                    rootEvent.addRecurrenceExc(recurrenceDate);
                }
            } else {
                for (KalendarEvent kEvent : loadedCal.getEvents()) {
                    if (uid.equals(kEvent.getID())) {
                        loadedCal.removeEvent(kEvent);
                    }
                }
            }
            boolean successfullyPersist = persistCalendar(loadedCal);
            return new Boolean(successfullyPersist);
        }
    });
    // inform all controller about calendar change for reload
    CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CalendarGUIModifiedEvent(cal), OresHelper.lookupType(CalendarManager.class));
    return removeSuccessful.booleanValue();
}
Also used : CalendarManager(org.olat.commons.calendar.CalendarManager) Kalendar(org.olat.commons.calendar.model.Kalendar) OLATResourceable(org.olat.core.id.OLATResourceable) KalendarRecurEvent(org.olat.commons.calendar.model.KalendarRecurEvent) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) Date(java.util.Date) ExDate(net.fortuna.ical4j.model.property.ExDate) CalendarGUIModifiedEvent(org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent)

Aggregations

OLATResourceable (org.olat.core.id.OLATResourceable)924 WindowControl (org.olat.core.gui.control.WindowControl)304 Test (org.junit.Test)158 Identity (org.olat.core.id.Identity)154 RepositoryEntry (org.olat.repository.RepositoryEntry)130 ContextEntry (org.olat.core.id.context.ContextEntry)82 ArrayList (java.util.ArrayList)68 OLATResource (org.olat.resource.OLATResource)60 Controller (org.olat.core.gui.control.Controller)48 Date (java.util.Date)46 AssertException (org.olat.core.logging.AssertException)32 StateSite (org.olat.core.id.context.StateSite)30 SyncerExecutor (org.olat.core.util.coordinate.SyncerExecutor)30 ICourse (org.olat.course.ICourse)30 CourseNode (org.olat.course.nodes.CourseNode)28 DBCheckbox (org.olat.course.nodes.cl.model.DBCheckbox)28 BusinessControl (org.olat.core.id.context.BusinessControl)24 BusinessGroup (org.olat.group.BusinessGroup)24 LayoutMain3ColsController (org.olat.core.commons.fullWebApp.LayoutMain3ColsController)22 BinderSecurityCallback (org.olat.modules.portfolio.BinderSecurityCallback)22