Search in sources :

Example 16 with OLATRuntimeException

use of org.olat.core.logging.OLATRuntimeException in project OpenOLAT by OpenOLAT.

the class XMLParser method parse.

/**
 * @param in
 * @param validateXML
 * @return parsed document
 */
public Document parse(InputStream in, boolean validateXML) {
    Document document;
    try {
        SAXReader reader = new SAXReader();
        reader.setEntityResolver(er);
        reader.setValidation(validateXML);
        document = reader.read(in, "");
        document.normalize();
    } catch (Exception e) {
        throw new OLATRuntimeException(XMLParser.class, "Exception reading XML", e);
    }
    return document;
}
Also used : OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) SAXReader(org.dom4j.io.SAXReader) Document(org.dom4j.Document) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException)

Example 17 with OLATRuntimeException

use of org.olat.core.logging.OLATRuntimeException 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 18 with OLATRuntimeException

use of org.olat.core.logging.OLATRuntimeException in project OpenOLAT by OpenOLAT.

the class QuotaManagerImpl method deleteCustomQuota.

/**
 * @param quota to be deleted
 * @return true if quota successfully deleted or no such quota, false if quota
 *         not deleted because it was a default quota that can not be deleted
 */
@Override
public boolean deleteCustomQuota(Quota quota) {
    if (defaultQuotas == null) {
        throw new OLATRuntimeException(QuotaManagerImpl.class, "Quota manager has not been initialized properly! Must call init() first.", null);
    }
    // do not allow to delete default quotas!
    if (quota.getPath().startsWith(QuotaConstants.IDENTIFIER_DEFAULT)) {
        return false;
    }
    PropertyManager pm = PropertyManager.getInstance();
    Property p = pm.findProperty(null, null, quotaResource, QUOTA_CATEGORY, quota.getPath());
    if (p != null)
        pm.deleteProperty(p);
    return true;
}
Also used : OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) PropertyManager(org.olat.properties.PropertyManager) Property(org.olat.properties.Property)

Example 19 with OLATRuntimeException

use of org.olat.core.logging.OLATRuntimeException in project OpenOLAT by OpenOLAT.

the class QuotaManagerImpl method setCustomQuotaKB.

/**
 * Sets or updates the quota (in KB) for this path. Important: Must provide a
 * path with a valid base.
 *
 * @param quota
 */
@Override
public void setCustomQuotaKB(Quota quota) {
    if (defaultQuotas == null) {
        throw new OLATRuntimeException(QuotaManagerImpl.class, "Quota manager has not been initialized properly! Must call init() first.", null);
    }
    PropertyManager pm = PropertyManager.getInstance();
    Property p = pm.findProperty(null, null, quotaResource, QUOTA_CATEGORY, quota.getPath());
    if (p == null) {
        // create new entry
        p = pm.createPropertyInstance(null, null, quotaResource, QUOTA_CATEGORY, quota.getPath(), null, null, assembleQuota(quota), null);
        pm.saveProperty(p);
    } else {
        p.setStringValue(assembleQuota(quota));
        pm.updateProperty(p);
    }
    // if the quota is a default quota, rebuild the default quota list
    if (quota.getPath().startsWith(QuotaConstants.IDENTIFIER_DEFAULT)) {
        initDefaultQuotas();
    }
}
Also used : OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) PropertyManager(org.olat.properties.PropertyManager) Property(org.olat.properties.Property)

Example 20 with OLATRuntimeException

use of org.olat.core.logging.OLATRuntimeException in project OpenOLAT by OpenOLAT.

the class QuotaManagerImpl method getCustomQuota.

/**
 * Get the quota (in KB) for this path. Important: Must provide a path with a
 * valid base.
 *
 * @param path
 * @return Quota object.
 */
@Override
public Quota getCustomQuota(String path) {
    if (defaultQuotas == null) {
        throw new OLATRuntimeException(QuotaManagerImpl.class, "Quota manager has not been initialized properly! Must call init() first.", null);
    }
    StringBuilder query = new StringBuilder();
    query.append("select prop.name, prop.stringValue from ").append(Property.class.getName()).append(" as prop where ").append(" prop.category='").append(QUOTA_CATEGORY).append("'").append(" and prop.resourceTypeName='").append(quotaResource.getResourceableTypeName()).append("'").append(" and prop.resourceTypeId=").append(quotaResource.getResourceableId()).append(" and prop.name=:name").append(" and prop.identity is null and prop.grp is null");
    DBQuery dbquery = DBFactory.getInstance().createQuery(query.toString());
    dbquery.setString("name", path);
    dbquery.setCacheable(true);
    @SuppressWarnings("unchecked") List<Object[]> props = dbquery.list();
    if (props.isEmpty()) {
        return null;
    }
    Object[] p = props.get(0);
    return parseQuota((String) p[0], (String) p[1]);
}
Also used : OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) DBQuery(org.olat.core.commons.persistence.DBQuery)

Aggregations

OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)268 IOException (java.io.IOException)104 File (java.io.File)50 ModuleConfiguration (org.olat.modules.ModuleConfiguration)26 ArrayList (java.util.ArrayList)22 AssertException (org.olat.core.logging.AssertException)22 FileOutputStream (java.io.FileOutputStream)20 OutputStream (java.io.OutputStream)20 Properties (java.util.Properties)20 FileInputStream (java.io.FileInputStream)18 HashMap (java.util.HashMap)18 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)18 QTIItemObject (org.olat.ims.qti.export.helper.QTIItemObject)18 DefaultElement (org.dom4j.tree.DefaultElement)16 Element (org.jdom.Element)16 InputStream (java.io.InputStream)14 BufferedInputStream (java.io.BufferedInputStream)12 List (java.util.List)12 Document (org.dom4j.Document)12 CPItem (org.olat.ims.cp.objects.CPItem)12