Example usage for org.springframework.util StopWatch getLastTaskTimeMillis

List of usage examples for org.springframework.util StopWatch getLastTaskTimeMillis

Introduction

In this page you can find the example usage for org.springframework.util StopWatch getLastTaskTimeMillis.

Prototype

public long getLastTaskTimeMillis() throws IllegalStateException 

Source Link

Document

Get the time taken by the last task in milliseconds.

Usage

From source file:org.nebulaframework.grid.Grid.java

/**
 * Starts a Light-weight {@link GridNode} (a GridNode without
 * Job Execution Support, that is non-worker) with default
 * settings, read from default properties file.
 * //from   w w w .  ja  va  2  s  .  co m
 * @param useConfigDiscovery indicates whether to use information
 * from configuration to discover
 * 
 * @param isGui indicates that the application is a GUI based
 * application and any disconnection notifications should be
 * done through message boxes.
 * 
 * @return GridNode
 * 
 * @throws IllegalStateException if a Grid Member (Cluster / Node) has
 * already started with in the current VM. Nebula supports only one Grid
 * Member per VM.
 */
public synchronized static GridNode startLightGridNode(boolean useConfigDiscovery, final boolean isGui)
        throws IllegalStateException {

    if (isInitialized()) {
        // A Grid Member has already started in this VM
        throw new IllegalStateException("A Grid Memeber Already Started in VM");
    }

    initializeDefaultExceptionHandler();

    StopWatch sw = new StopWatch();

    try {
        sw.start();

        // Set Security Manager
        System.setSecurityManager(new SecurityManager());

        Properties config = ConfigurationSupport.detectNodeConfiguration();

        log.info("GridNode Attempting Discovery...");

        // Discover Cluster If Needed
        GridNodeDiscoverySupport.discover(config, useConfigDiscovery);

        checkJMSBroker(config.getProperty(ConfigurationKeys.CLUSTER_SERVICE.value()));

        // If we reach here, connection test succeeded

        log.debug("Starting up Spring Container...");

        applicationContext = new NebulaApplicationContext(GRIDNODE_LIGHT_CONTEXT, config);

        log.debug("Spring Container Started");

        node = true;
        lightweight = true;

        sw.stop();
        log.info("GridNode Started Up. " + sw.getLastTaskTimeMillis() + " ms");

        GridNode node = (GridNode) applicationContext.getBean("localNode");
        ServiceEventsSupport.addServiceHook(new ServiceHookCallback() {

            @Override
            public void onServiceEvent(ServiceMessage message) {

                log.warn("[GridNode] Disconnected from Cluster");
                log.warn("[GridNode] Shutting Down");

                if (isGui) {
                    JOptionPane.showMessageDialog(UISupport.activeWindow(),
                            "Disconnected from Cluster, terminating VM");
                }
                System.exit(0);
            }

        }, node.getClusterId().toString(), ServiceMessageType.NODE_DISCONNECTED);

        return node;

    } finally {
        if (sw.isRunning()) {
            sw.stop();
        }
    }
}

From source file:curly.commons.logging.MethodExecutionAspectInterceptor.java

@Around(value = "execution(* *(..)) && @annotation(loggable)) ", argNames = "joinPoint, loggable")
public Object invoke(ProceedingJoinPoint joinPoint, Loggable loggable) throws Throwable {
    if (executionEnabled) {
        StopWatch watch = new StopWatch(joinPoint.toShortString());
        watch.start();//from w ww. j  ava2  s. c om
        try {
            return joinPoint.proceed();
        } finally {
            watch.stop();
            synchronized (this) {
                if (actuatorEnabled && (gaugeService != null)) {
                    String gagueName = "gauge.execution." + joinPoint.getTarget() + "."
                            + joinPoint.getSignature().getName();
                    gaugeService.submit(gagueName, watch.getLastTaskTimeMillis());
                }
                log(loggable.value(), joinPoint.getTarget().getClass(), "Executed method {} in {} ms",
                        joinPoint.getSignature().getName(), watch.getLastTaskTimeMillis());
            }
        }

    }
    return joinPoint.proceed();
}

From source file:io.curly.commons.logging.MethodExecutionAspectInterceptor.java

@SuppressWarnings("ArgNamesErrorsInspection")
@Around(value = "execution(* *(..)) && @annotation(loggable)) ", argNames = "joinPoint, loggable")
public Object invoke(ProceedingJoinPoint joinPoint, Loggable loggable) throws Throwable {
    if (executionEnabled) {
        StopWatch watch = new StopWatch(joinPoint.toShortString());
        watch.start();/*from ww w . ja  v  a  2s  .  c o  m*/
        try {
            return joinPoint.proceed();
        } finally {
            watch.stop();
            synchronized (this) {
                if (actuatorEnabled && (gaugeService != null)) {
                    String gagueName = "gauge.execution." + joinPoint.getTarget() + "."
                            + joinPoint.getSignature().getName();
                    gaugeService.submit(gagueName, watch.getLastTaskTimeMillis());
                }
                log(loggable.value(), joinPoint.getTarget().getClass(), "Executed method {} in {} ms",
                        joinPoint.getSignature().getName(), watch.getLastTaskTimeMillis());
            }
        }

    }
    return joinPoint.proceed();
}

From source file:org.nebulaframework.util.profiling.ProfilingAspect.java

/**
 * Advice of Profiling Aspect. Measures and logs the exection
 * time of advised method./*from  w ww  .  j a  v a2  s  .c o m*/
 * 
 * @param pjp {ProceedingJoinPoint}
 * @return Object result
 * @throws Throwable if exception occurs
 */
@Around("profilingPointcut()")
public Object profile(ProceedingJoinPoint pjp) throws Throwable {

    StopWatch sw = new StopWatch();

    Log localLog = null;

    try {
        // Get Log
        localLog = LogFactory.getLog(pjp.getTarget().getClass());

        // Start StopWatch
        sw.start();

        // Proceed Invocation
        return pjp.proceed();

    } finally {

        // Stop StopWatch
        sw.stop();
        if (localLog == null) {
            // If local Log not found, use ProfilingAspect's Log
            localLog = log;
        }

        //Log Stats
        localLog.debug("[Profiling] " + pjp.getTarget().getClass().getName() + "->"
                + pjp.getSignature().getName() + "() | " + sw.getLastTaskTimeMillis() + " ms");
    }
}

From source file:org.dd4t.core.factories.impl.GenericPageFactory.java

/**
 * Transform source into a page.//w w  w  . j a v a2 s . com
 * 
 * @param source
 * @return
 */
public GenericPage getPageFromSource(String source) {

    StopWatch stopWatch = null;
    try {
        if (logger.isDebugEnabled()) {
            stopWatch = new StopWatch();
            stopWatch.start("getPageFromSource");
        }
        return (GenericPage) this.getSerializer().deserialize(source, GenericPage.class);
    } catch (Exception e) {
        logger.error("Exception when deserializing page: ", e);
        throw new RuntimeException(e);
    } finally {
        if (logger.isDebugEnabled()) {
            stopWatch.stop();
            logger.debug("Deserialization of page took: " + stopWatch.getLastTaskTimeMillis() + " ms");
        }
    }

}

From source file:org.dd4t.core.factories.impl.GenericComponentFactory.java

public DynamicComponent getDCPFromSource(com.tridion.dcp.ComponentPresentation dcp) {
    StopWatch stopWatch = null;
    DynamicComponentImpl dynComp = null;
    if (logger.isDebugEnabled()) {
        stopWatch = new StopWatch("getComponentFromSource");
        stopWatch.start();/*  w ww. j a v a2  s .  c  om*/
    }
    try {
        if (logger.isDebugEnabled()) {
            stopWatch.stop();
            stopWatch.start();
        }

        dynComp = (DynamicComponentImpl) this.getSerializer().deserialize(dcp.getContent(),
                DynamicComponentImpl.class);
        dynComp.setNativeDCP(dcp);
    } catch (Exception e) {
        logger.error("error when deserializing component", e);
        throw new RuntimeException(e);
    } finally {
        if (logger.isDebugEnabled()) {
            stopWatch.stop();
            logger.debug("Deserialization of component took: " + stopWatch.getLastTaskTimeMillis() + " ms");
        }
    }
    return dynComp;
}

From source file:ru.anr.cmdline.base.BootstrapImpl.java

/**
 * {@inheritDoc}/*from www  .j av a 2  s. c  o m*/
 */
@Override
@Transactional(propagation = Propagation.REQUIRED)
public ExitShellRequest run() {

    StopWatch sw = new StopWatch("Shell Watch");
    sw.start();

    String[] commandsToExecuteAndThenQuit = commandLine.getShellCommandsToExecute();
    // The shell is used
    JLineShellComponent shell = context.getBean("shell", JLineShellComponent.class);
    ExitShellRequest exitShellRequest;

    if (null == commandsToExecuteAndThenQuit) {
        shell.start();
        shell.promptLoop();
        exitShellRequest = shell.getExitShellRequest();
        if (exitShellRequest == null) {
            // shouldn't really happen, but we'll fallback to this anyway
            exitShellRequest = ExitShellRequest.NORMAL_EXIT;
        }
        shell.waitForComplete();

    } else {
        boolean successful = false;
        exitShellRequest = ExitShellRequest.FATAL_EXIT;

        for (String cmd : commandsToExecuteAndThenQuit) {
            successful = shell.executeCommand(cmd).isSuccess();
            if (!successful) {
                break;
            }
        }

        // if all commands were successful, set the normal exit status
        if (successful) {
            exitShellRequest = ExitShellRequest.NORMAL_EXIT;
        }

    }

    sw.stop();

    if (shell.isDevelopmentMode()) {
        logger.info("Total execution time: {} ms", sw.getLastTaskTimeMillis());
    }
    return exitShellRequest;
}

From source file:net.sf.juffrou.reflect.spring.BeanWrapperTests.java

@Test
public void testLargeMatchingPrimitiveArray() {
    if (LogFactory.getLog(BeanWrapperTests.class).isTraceEnabled()) {
        // Skip this test: Trace logging blows the time limit.
        return;/*from   w  w  w .  ja  v  a2 s.  c o  m*/
    }

    PrimitiveArrayBean tb = new PrimitiveArrayBean();
    BeanWrapper bw = new JuffrouSpringBeanWrapper(tb);
    int[] input = new int[1024];
    StopWatch sw = new StopWatch();
    sw.start("array1");
    for (int i = 0; i < 1000; i++) {
        bw.setPropertyValue("array", input);
    }
    sw.stop();
    assertEquals(1024, tb.getArray().length);
    assertEquals(0, tb.getArray()[0]);
    long time1 = sw.getLastTaskTimeMillis();
    assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);

    bw.registerCustomEditor(String.class, new StringTrimmerEditor(false));
    sw.start("array2");
    for (int i = 0; i < 1000; i++) {
        bw.setPropertyValue("array", input);
    }
    sw.stop();
    assertTrue("Took too long", sw.getLastTaskTimeMillis() < 125);

    bw.registerCustomEditor(int.class, "array.somePath", new CustomNumberEditor(Integer.class, false));
    sw.start("array3");
    for (int i = 0; i < 1000; i++) {
        bw.setPropertyValue("array", input);
    }
    sw.stop();
    assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);

    bw.registerCustomEditor(int.class, "array[0].somePath", new CustomNumberEditor(Integer.class, false));
    sw.start("array3");
    for (int i = 0; i < 1000; i++) {
        bw.setPropertyValue("array", input);
    }
    sw.stop();
    assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);

    bw.registerCustomEditor(int.class, new CustomNumberEditor(Integer.class, false));
    sw.start("array4");
    for (int i = 0; i < 100; i++) {
        bw.setPropertyValue("array", input);
    }
    sw.stop();
    assertEquals(1024, tb.getArray().length);
    assertEquals(0, tb.getArray()[0]);
    assertTrue("Took too long", sw.getLastTaskTimeMillis() > time1);
}

From source file:com.jxt.web.controller.ScatterChartController.java

/**
 * @param applicationName//from   w ww.  j a v a 2 s  . c  o  m
 * @param from
 * @param to
 * @param limit           max number of data return. if the requested data exceed this limit, we need additional calls to
 *                        fetch the rest of the data
 * @return
 */
@RequestMapping(value = "/getScatterData", method = RequestMethod.GET)
public ModelAndView getScatterData(@RequestParam("application") String applicationName,
        @RequestParam("from") long from, @RequestParam("to") long to,
        @RequestParam("xGroupUnit") int xGroupUnit, @RequestParam("yGroupUnit") int yGroupUnit,
        @RequestParam("limit") int limit,
        @RequestParam(value = "backwardDirection", required = false, defaultValue = "true") boolean backwardDirection,
        @RequestParam(value = "filter", required = false) String filterText,
        @RequestParam(value = "_callback", required = false) String jsonpCallback,
        @RequestParam(value = "v", required = false, defaultValue = "1") int version) {
    limit = LimitUtils.checkRange(limit);

    StopWatch watch = new StopWatch();
    watch.start("getScatterData");

    // TODO range check verification exception occurs. "from" is bigger than "to"
    final Range range = Range.createUncheckedRange(from, to);
    logger.debug(
            "fetch scatter data. RANGE={}, X-Group-Unit:{}, Y-Group-Unit:{}, LIMIT={}, BACKWARD_DIRECTION:{}, FILTER:{}",
            range, xGroupUnit, yGroupUnit, limit, backwardDirection, filterText);

    ModelAndView mv = null;
    if (StringUtils.isEmpty(filterText)) {
        mv = selectScatterData(applicationName, range, xGroupUnit, yGroupUnit, limit, backwardDirection,
                version);
    } else {
        mv = selectFilterScatterData(applicationName, range, xGroupUnit, yGroupUnit, limit, backwardDirection,
                filterText, version);
    }

    if (jsonpCallback == null) {
        mv.setViewName("jsonView");
    } else {
        mv.setViewName("jsonpView");
    }

    watch.stop();

    logger.info("Fetch scatterData time : {}ms", watch.getLastTaskTimeMillis());

    return mv;
}