List of usage examples for org.springframework.util StopWatch StopWatch
public StopWatch(String id)
From source file:org.kuali.rice.krad.datadictionary.DataDictionary.java
/** * Populates and processes the dictionary bean factory based on the configured files and * performs indexing/*from www.j a v a2 s . c o m*/ * * @param allowConcurrentValidation - indicates whether the indexing should occur on a different thread * or the same thread */ public void parseDataDictionaryConfigurationFiles(boolean allowConcurrentValidation) { timer = new StopWatch("DD Processing"); setupProcessor(ddBeans); loadDictionaryBeans(ddBeans, moduleDictionaryFiles, ddIndex, beanValidationFiles); performDictionaryPostProcessing(allowConcurrentValidation); }
From source file:org.springframework.aop.interceptor.CustomizableTraceInterceptor.java
/** * Writes a log message before the invocation based on the value of {@code enterMessage}. * If the invocation succeeds, then a log message is written on exit based on the value * {@code exitMessage}. If an exception occurs during invocation, then a message is * written based on the value of {@code exceptionMessage}. * @see #setEnterMessage//from w w w . j av a 2 s . co m * @see #setExitMessage * @see #setExceptionMessage */ @Override protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable { String name = ClassUtils.getQualifiedMethodName(invocation.getMethod()); StopWatch stopWatch = new StopWatch(name); Object returnValue = null; boolean exitThroughException = false; try { stopWatch.start(name); writeToLog(logger, replacePlaceholders(this.enterMessage, invocation, null, null, -1)); returnValue = invocation.proceed(); return returnValue; } catch (Throwable ex) { if (stopWatch.isRunning()) { stopWatch.stop(); } exitThroughException = true; writeToLog(logger, replacePlaceholders(this.exceptionMessage, invocation, null, ex, stopWatch.getTotalTimeMillis()), ex); throw ex; } finally { if (!exitThroughException) { if (stopWatch.isRunning()) { stopWatch.stop(); } writeToLog(logger, replacePlaceholders(this.exitMessage, invocation, returnValue, null, stopWatch.getTotalTimeMillis())); } } }
From source file:org.springframework.aop.interceptor.PerformanceMonitorInterceptor.java
@Override protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable { String name = createInvocationTraceName(invocation); StopWatch stopWatch = new StopWatch(name); stopWatch.start(name);/* w ww . j a v a 2s. c o m*/ try { return invocation.proceed(); } finally { stopWatch.stop(); writeToLog(logger, stopWatch.shortSummary()); } }
From source file:org.springframework.batch.admin.jmx.StepExecutionServiceLevelMonitor.java
public void invoke(ProceedingJoinPoint joinPoint, final StepExecution stepExecution, Step step) throws Throwable { final AtomicBoolean finished = new AtomicBoolean(false); final StopWatch timer = new StopWatch(stepExecution.getStepName() + ":execution"); try {//from w ww. ja v a 2 s. c om if (timeout > 0) { if (notificationPublisher != null) { Notification notification = new Notification("INFO", this, sequence++, "Starting:" + stepExecution); notificationPublisher.sendNotification(notification); } timer.start("StepExecution.Id:" + stepExecution.getId()); final long threshold = (long) (timeout * (1 - warningMargin)); Date warningTime = new Date(System.currentTimeMillis() + threshold); logger.debug("Scheduling warning after (ms) " + threshold); taskScheduler.schedule(new Runnable() { public void run() { if (!finished.get()) { logger.debug("Sending warning (step not complete after " + threshold + " ms): " + stepExecution); if (notificationPublisher != null) { Notification notification = new Notification("WARN", StepExecutionServiceLevelMonitor.this, sequence++, "Warning:" + stepExecution); notificationPublisher.sendNotification(notification); } } else { logger.debug("No warning necessary for " + stepExecution); } } }, warningTime); } joinPoint.proceed(); } finally { finished.set(true); if (timeout > 0) { timer.stop(); Executors.newSingleThreadScheduledExecutor().shutdown(); if (timer.getLastTaskTimeMillis() > timeout) { overruns++; logger.debug("Notifying overrun " + stepExecution); if (notificationPublisher != null) { Notification notification = new Notification("ERROR", this, sequence++, "Overrun:" + stepExecution); notificationPublisher.sendNotification(notification); } } } } }
From source file:org.springframework.batch.core.scope.StepScopePerformanceTests.java
private int doTest(String name, String test) throws Exception { @SuppressWarnings("unchecked") ItemStreamReader<String> reader = (ItemStreamReader<String>) applicationContext.getBean(name); reader.open(new ExecutionContext()); StopWatch stopWatch = new StopWatch(test); stopWatch.start();//from ww w.j ava 2 s .c o m int count = 0; while (reader.read() != null) { // do nothing count++; } stopWatch.stop(); reader.close(); logger.info(stopWatch.shortSummary()); return count; }
From source file:org.springframework.batch.item.xml.AbstractStaxEventWriterItemWriterTests.java
/** * Write list of domain objects and check the output file. */// w w w . j a v a 2 s. c o m @SuppressWarnings("resource") @Test public void testWrite() throws Exception { StopWatch stopWatch = new StopWatch(getClass().getSimpleName()); stopWatch.start(); for (int i = 0; i < MAX_WRITE; i++) { new TransactionTemplate(new ResourcelessTransactionManager()).execute(new TransactionCallback<Void>() { @Override public Void doInTransaction(TransactionStatus status) { try { writer.write(objects); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalStateException("Exception encountered on write", e); } return null; } }); } writer.close(); stopWatch.stop(); logger.info("Timing for XML writer: " + stopWatch); XMLUnit.setIgnoreWhitespace(true); // String content = FileUtils.readFileToString(resource.getFile()); // System.err.println(content); XMLAssert.assertXMLEqual(new FileReader(expected.getFile()), new FileReader(resource.getFile())); }
From source file:org.springframework.integration.monitor.DirectChannelMetrics.java
private Object monitorSend(MethodInvocation invocation, MessageChannel channel, Message<?> message) throws Throwable { if (logger.isTraceEnabled()) { logger.trace("Recording send on channel(" + channel + ") : message(" + message + ")"); }/* w ww. ja v a 2 s . c o m*/ final StopWatch timer = new StopWatch(channel + ".send:execution"); try { timer.start(); sendCount.incrementAndGet(); sendRate.increment(); Object result = invocation.proceed(); timer.stop(); if ((Boolean) result) { sendSuccessRatio.success(); sendDuration.append(timer.getTotalTimeMillis()); } else { sendSuccessRatio.failure(); sendErrorCount.incrementAndGet(); sendErrorRate.increment(); } return result; } catch (Throwable e) { sendSuccessRatio.failure(); sendErrorCount.incrementAndGet(); sendErrorRate.increment(); throw e; } finally { if (logger.isTraceEnabled()) { logger.trace(timer); } } }
From source file:org.springframework.integration.monitor.DirectChannelMonitor.java
private Object monitorSend(MethodInvocation invocation, MessageChannel channel, Message<?> message) throws Throwable { if (logger.isTraceEnabled()) { logger.trace("Recording send on channel(" + channel + ") : message(" + message + ")"); }/*from www .j a v a 2 s . c o m*/ final StopWatch timer = new StopWatch(channel + ".send:execution"); try { timer.start(); sendCount.incrementAndGet(); sendRate.increment(); Object result = invocation.proceed(); timer.stop(); if ((Boolean) result) { sendSuccessRatio.success(); sendDuration.append(timer.getTotalTimeSeconds()); } else { sendSuccessRatio.failure(); sendErrorCount.incrementAndGet(); sendErrorRate.increment(); } return result; } catch (Throwable e) { sendSuccessRatio.failure(); sendErrorCount.incrementAndGet(); sendErrorRate.increment(); throw e; } finally { if (logger.isTraceEnabled()) { logger.trace(timer); } } }
From source file:org.springframework.integration.monitor.SimpleMessageHandlerMetrics.java
private void handleMessage(MethodInvocation invocation, Message<?> message) throws Throwable { if (logger.isTraceEnabled()) { logger.trace("messageHandler(" + this.handler + ") message(" + message + ") :"); }/*from w ww . j av a 2 s . c o m*/ String name = this.name; if (name == null) { name = this.handler.toString(); } StopWatch timer = new StopWatch(name + ".handle:execution"); try { timer.start(); this.handleCount.incrementAndGet(); this.activeCount.incrementAndGet(); invocation.proceed(); timer.stop(); this.duration.append(timer.getTotalTimeMillis()); } catch (Throwable e) { this.errorCount.incrementAndGet(); throw e; } finally { this.activeCount.decrementAndGet(); } }
From source file:org.springframework.integration.monitor.SimpleMessageHandlerMonitor.java
public void handleMessage(Message<?> message) throws MessageRejectedException, MessageHandlingException, MessageDeliveryException { if (logger.isTraceEnabled()) { logger.trace("messageHandler(" + handler + ") message(" + message + ") :"); }/*from w w w. ja va 2 s . co m*/ String name = this.name; if (name == null) { name = handler.toString(); } StopWatch timer = new StopWatch(name + ".handle:execution"); try { timer.start(); handleCount.incrementAndGet(); handler.handleMessage(message); timer.stop(); duration.append(timer.getTotalTimeSeconds()); } catch (RuntimeException e) { errorCount.incrementAndGet(); throw e; } catch (Error e) { errorCount.incrementAndGet(); throw e; } }