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;
}
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;
}
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) {
}
}
}
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);
}
}
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());
}
}
}
Aggregations