Search in sources :

Example 36 with StopWatch

use of org.apache.commons.lang.time.StopWatch in project jspwiki by apache.

the class WikiEngine method textToHTML.

/**
 *  Converts raw page data to HTML.
 *
 *  @param pagedata Raw page data to convert to HTML
 *  @param context  The WikiContext in which the page is to be rendered
 *  @return Rendered page text
 */
public String textToHTML(WikiContext context, String pagedata) {
    String result = "";
    boolean runFilters = "true".equals(m_variableManager.getValue(context, PROP_RUNFILTERS, "true"));
    StopWatch sw = new StopWatch();
    sw.start();
    try {
        if (runFilters)
            pagedata = m_filterManager.doPreTranslateFiltering(context, pagedata);
        result = m_renderingManager.getHTML(context, pagedata);
        if (runFilters)
            result = m_filterManager.doPostTranslateFiltering(context, result);
    } catch (FilterException e) {
    // FIXME: Don't yet know what to do
    }
    sw.stop();
    if (log.isDebugEnabled())
        log.debug("Page " + context.getRealPage().getName() + " rendered, took " + sw);
    return result;
}
Also used : FilterException(org.apache.wiki.api.exceptions.FilterException) StopWatch(org.apache.commons.lang.time.StopWatch)

Example 37 with StopWatch

use of org.apache.commons.lang.time.StopWatch in project jspwiki by apache.

the class WikiEngine method textToHTML.

/**
 *  Helper method for doing the HTML translation.
 *
 *  @param context The WikiContext in which to do the conversion
 *  @param pagedata The data to render
 *  @param localLinkHook Is called whenever a wiki link is found
 *  @param extLinkHook   Is called whenever an external link is found
 *  @param parseAccessRules Parse the access rules if we encounter them
 *  @param justParse Just parses the pagedata, does not actually render.  In this case,
 *                   this methods an empty string.
 *  @return HTML-rendered page text.
 */
private String textToHTML(WikiContext context, String pagedata, StringTransmutator localLinkHook, StringTransmutator extLinkHook, StringTransmutator attLinkHook, boolean parseAccessRules, boolean justParse) {
    String result = "";
    if (pagedata == null) {
        log.error("NULL pagedata to textToHTML()");
        return null;
    }
    boolean runFilters = "true".equals(m_variableManager.getValue(context, PROP_RUNFILTERS, "true"));
    try {
        StopWatch sw = new StopWatch();
        sw.start();
        if (runFilters && m_filterManager != null)
            pagedata = m_filterManager.doPreTranslateFiltering(context, pagedata);
        MarkupParser mp = m_renderingManager.getParser(context, pagedata);
        mp.addLocalLinkHook(localLinkHook);
        mp.addExternalLinkHook(extLinkHook);
        mp.addAttachmentLinkHook(attLinkHook);
        if (!parseAccessRules)
            mp.disableAccessRules();
        WikiDocument doc = mp.parse();
        // 
        if (!justParse) {
            result = m_renderingManager.getHTML(context, doc);
            if (runFilters && m_filterManager != null)
                result = m_filterManager.doPostTranslateFiltering(context, result);
        }
        sw.stop();
        if (log.isDebugEnabled())
            log.debug("Page " + context.getRealPage().getName() + " rendered, took " + sw);
    } catch (IOException e) {
        log.error("Failed to scan page data: ", e);
    } catch (FilterException e) {
        log.error("page filter threw exception: ", e);
    // FIXME: Don't yet know what to do
    }
    return result;
}
Also used : FilterException(org.apache.wiki.api.exceptions.FilterException) IOException(java.io.IOException) WikiDocument(org.apache.wiki.parser.WikiDocument) StopWatch(org.apache.commons.lang.time.StopWatch) MarkupParser(org.apache.wiki.parser.MarkupParser)

Example 38 with StopWatch

use of org.apache.commons.lang.time.StopWatch in project jspwiki by apache.

the class ReferenceManager method serializeToDisk.

/**
 *  Serializes hashmaps to disk.  The format is private, don't touch it.
 */
private synchronized void serializeToDisk() {
    ObjectOutputStream out = null;
    try {
        StopWatch sw = new StopWatch();
        sw.start();
        File f = new File(m_engine.getWorkDir(), SERIALIZATION_FILE);
        out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(f)));
        out.writeLong(serialVersionUID);
        // Timestamp
        out.writeLong(System.currentTimeMillis());
        out.writeObject(m_refersTo);
        out.writeObject(m_referredBy);
        out.close();
        sw.stop();
        log.debug("serialization done - took " + sw);
    } catch (IOException e) {
        log.error("Unable to serialize!");
        try {
            if (out != null)
                out.close();
        } catch (IOException ex) {
        }
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) StopWatch(org.apache.commons.lang.time.StopWatch)

Example 39 with StopWatch

use of org.apache.commons.lang.time.StopWatch in project jspwiki by apache.

the class ReferenceManager method serializeAttrsToDisk.

/**
 *  Serializes hashmaps to disk.  The format is private, don't touch it.
 */
private synchronized void serializeAttrsToDisk(WikiPage p) {
    ObjectOutputStream out = null;
    StopWatch sw = new StopWatch();
    sw.start();
    try {
        File f = new File(m_engine.getWorkDir(), SERIALIZATION_DIR);
        if (!f.exists())
            f.mkdirs();
        // 
        // Create a digest for the name
        // 
        f = new File(f, getHashFileName(p.getName()));
        // FIXME: There is a concurrency issue here...
        Set entries = p.getAttributes().entrySet();
        if (entries.size() == 0) {
            // Nothing to serialize, therefore we will just simply remove the
            // serialization file so that the next time we boot, we don't
            // deserialize old data.
            f.delete();
            return;
        }
        out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(f)));
        out.writeLong(serialVersionUID);
        // Timestamp
        out.writeLong(System.currentTimeMillis());
        out.writeUTF(p.getName());
        out.writeLong(entries.size());
        for (Iterator i = entries.iterator(); i.hasNext(); ) {
            Map.Entry e = (Map.Entry) i.next();
            if (e.getValue() instanceof Serializable) {
                out.writeUTF((String) e.getKey());
                out.writeObject(e.getValue());
            }
        }
        out.close();
    } catch (IOException e) {
        log.error("Unable to serialize!");
        try {
            if (out != null)
                out.close();
        } catch (IOException ex) {
        }
    } catch (NoSuchAlgorithmException e) {
        log.fatal("No MD5 algorithm!?!");
    } finally {
        sw.stop();
        log.debug("serialization for " + p.getName() + " done - took " + sw);
    }
}
Also used : Serializable(java.io.Serializable) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ObjectOutputStream(java.io.ObjectOutputStream) StopWatch(org.apache.commons.lang.time.StopWatch) FileOutputStream(java.io.FileOutputStream) Iterator(java.util.Iterator) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) HashMap(java.util.HashMap) Map(java.util.Map)

Example 40 with StopWatch

use of org.apache.commons.lang.time.StopWatch in project cdap by caskdata.

the class DefaultAuthorizationEnforcer method doEnforce.

private void doEnforce(EntityId entity, Principal principal, Set<Action> actions) throws Exception {
    // bypass the check when the principal is the master user and the entity is in the system namespace
    if (isAccessingSystemNSAsMasterUser(entity, principal) || isEnforcingOnSamePrincipalId(entity, principal)) {
        return;
    }
    LOG.trace("Enforcing actions {} on {} for principal {}.", actions, entity, principal);
    // create new stopwatch instance every time enforce is called since the DefaultAuthorizationEnforcer is binded as
    // singleton we don't want the stopwatch instance to get re-used across multiple calls.
    StopWatch watch = new StopWatch();
    watch.start();
    try {
        authorizerInstantiator.get().enforce(entity, principal, actions);
    } finally {
        watch.stop();
        long timeTaken = watch.getTime();
        String logLine = "Enforced actions {} on {} for principal {}. Time spent in enforcement was {} ms.";
        if (timeTaken > logTimeTakenAsWarn) {
            LOG.warn(logLine, actions, entity, principal, watch.getTime());
        } else {
            LOG.trace(logLine, actions, entity, principal, watch.getTime());
        }
    }
}
Also used : StopWatch(org.apache.commons.lang.time.StopWatch)

Aggregations

StopWatch (org.apache.commons.lang.time.StopWatch)48 IOException (java.io.IOException)13 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 File (java.io.File)4 Path (java.nio.file.Path)4 HashMap (java.util.HashMap)4 FileNotFoundException (java.io.FileNotFoundException)3 ObjectOutputStream (java.io.ObjectOutputStream)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 Map (java.util.Map)3 SchemaHolder (org.motechproject.mds.dto.SchemaHolder)3 YarnApplicationReport (com.continuuity.weave.internal.yarn.YarnApplicationReport)2 BufferedInputStream (java.io.BufferedInputStream)2 BufferedOutputStream (java.io.BufferedOutputStream)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 ObjectInputStream (java.io.ObjectInputStream)2 NoSuchFileException (java.nio.file.NoSuchFileException)2 HashSet (java.util.HashSet)2