List of usage examples for org.springframework.util StopWatch isRunning
public boolean isRunning()
From source file:example.springdata.redis.sentinel.RedisSentinelApplication.java
private static void startStopWatchIfNotRunning(StopWatch stopWatch) { if (!stopWatch.isRunning()) { stopWatch.start();// www .j a va 2 s . c om } }
From source file:example.springdata.redis.sentinel.RedisSentinelApplication.java
private static void printBackFromErrorStateInfoIfStopWatchIsRunning(StopWatch stopWatch) { if (stopWatch.isRunning()) { stopWatch.stop();/* w w w . j av a 2s . c o m*/ System.err.println("INFO: Recovered after: " + stopWatch.getLastTaskInfo().getTimeSeconds()); } }
From source file:org.arrow.test.SpringWorkflowTestExecutionListener.java
@Override public void afterTestMethod(TestContext testContext) throws Exception { CONTEXT_HOLDER.set(null);//from w w w . ja v a 2 s . c o m StopWatch stopWatch = (StopWatch) testContext.getAttribute("stopWatch"); if (stopWatch != null && stopWatch.isRunning()) { stopWatch.stop(); System.out.println(stopWatch); } }
From source file:org.sharetask.utility.log.PerformanceInterceptor.java
@SuppressWarnings("PMD.AvoidCatchingThrowable") @Override// www . j a va 2 s. c o m protected Object invokeUnderTrace(final MethodInvocation invocation, final Log logger) throws Throwable { final String name = invocation.getMethod().getDeclaringClass().getName() + "." + invocation.getMethod().getName(); final StopWatch stopWatch = new StopWatch(name); Object returnValue = null; try { stopWatch.start(name); returnValue = invocation.proceed(); return returnValue; } catch (final Throwable ex) { if (stopWatch.isRunning()) { stopWatch.stop(); } throw ex; } finally { if (stopWatch.isRunning()) { stopWatch.stop(); } writeToLog(logger, replacePlaceholders(exitMessage, invocation, returnValue, null, stopWatch.getTotalTimeMillis())); } }
From source file:org.nebulaframework.grid.Grid.java
/** * Starts a {@link GridNode} with default settings, read from * default properties file.// w w w . j a v a 2 s . c om * * @param useConfigDiscovery indicates whether to use information * from configuration to discover * * @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 startGridNode(boolean useConfigDiscovery) 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()); // Detect Configuration Properties config = ConfigurationSupport.detectNodeConfiguration(); log.info("GridNode Attempting Discovery..."); // Discover Cluster If Needed GridNodeDiscoverySupport.discover(config, useConfigDiscovery); checkJMSBroker(config.getProperty(ConfigurationKeys.CLUSTER_SERVICE.value())); log.debug("Starting up Spring Container..."); applicationContext = new NebulaApplicationContext(GRIDNODE_CONTEXT, config); log.debug("Spring Container Started"); node = true; sw.stop(); log.info("GridNode Started Up. " + sw.getLastTaskTimeMillis() + " ms"); return (GridNode) applicationContext.getBean("localNode"); } finally { if (sw.isRunning()) { sw.stop(); } } }
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 ww. j a v a2 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:org.alfresco.repo.search.impl.solr.DbOrIndexSwitchingQueryLanguage.java
public ResultSet executeQuery(SearchParameters searchParameters, ADMLuceneSearcherImpl admLuceneSearcher) { QueryConsistency consistency = searchParameters.getQueryConsistency(); if (consistency == QueryConsistency.DEFAULT) { consistency = queryConsistency;/*from w w w. j ava 2 s . c o m*/ } switch (consistency) { case EVENTUAL: if (indexQueryLanguage != null) { if (logger.isDebugEnabled()) { logger.debug("Using SOLR query: " + dbQueryLanguage.getName() + " for " + searchParameters); } StopWatch stopWatch = new StopWatch("index only"); stopWatch.start(); ResultSet results = indexQueryLanguage.executeQuery(searchParameters, admLuceneSearcher); stopWatch.stop(); if (logger.isDebugEnabled()) { logger.debug("SOLR returned " + results.length() + " results in " + stopWatch.getLastTaskTimeMillis() + "ms"); } return results; } else { throw new QueryModelException("No query language available"); } case TRANSACTIONAL: if (dbQueryLanguage != null) { if (logger.isDebugEnabled()) { logger.debug("Trying db query for " + dbQueryLanguage.getName() + " for " + searchParameters); } StopWatch stopWatch = new StopWatch("database only"); stopWatch.start(); ResultSet results = dbQueryLanguage.executeQuery(flattenDBQuery(searchParameters), admLuceneSearcher); stopWatch.stop(); if (logger.isDebugEnabled()) { logger.debug("DB returned " + results.length() + " results in " + stopWatch.getLastTaskTimeMillis() + "ms"); } return results; } else { throw new QueryModelException("No query language available"); } case HYBRID: if (!hybridEnabled) { throw new DisabledFeatureException("Hybrid query is disabled."); } return executeHybridQuery(searchParameters, admLuceneSearcher); case DEFAULT: case TRANSACTIONAL_IF_POSSIBLE: default: StopWatch stopWatch = new StopWatch("DB if possible"); if (dbQueryLanguage != null) { try { if (logger.isDebugEnabled()) { logger.debug( "Trying db query for " + dbQueryLanguage.getName() + " for " + searchParameters); } stopWatch.start(); ResultSet results = dbQueryLanguage.executeQuery(flattenDBQuery(searchParameters), admLuceneSearcher); stopWatch.stop(); if (logger.isDebugEnabled()) { logger.debug("DB returned " + results.length() + " results in " + stopWatch.getLastTaskTimeMillis() + "ms"); } return results; } catch (QueryModelException qme) { if (stopWatch.isRunning()) { stopWatch.stop(); } // MNT-10323: Logging configuration on JBoss leads to clogging of the log with a lot of these errors because of INFO level when WQS module is installed if (logger.isDebugEnabled()) { logger.debug( "DB query failed for " + dbQueryLanguage.getName() + " for " + searchParameters, qme); } if (indexQueryLanguage != null) { if (logger.isDebugEnabled()) { logger.debug( "Using SOLR query: " + dbQueryLanguage.getName() + " for " + searchParameters); } stopWatch.start(); ResultSet results = indexQueryLanguage.executeQuery(searchParameters, admLuceneSearcher); stopWatch.stop(); if (logger.isDebugEnabled()) { logger.debug("SOLR returned " + results.length() + " results in " + stopWatch.getLastTaskTimeMillis() + "ms"); } return results; } } } else { if (indexQueryLanguage != null) { if (logger.isDebugEnabled()) { logger.debug("(No DB QL) Using SOLR query: " + "dbQueryLanguage==null" + " for " + searchParameters); } stopWatch.start(); ResultSet results = indexQueryLanguage.executeQuery(searchParameters, admLuceneSearcher); stopWatch.stop(); if (logger.isDebugEnabled()) { logger.debug("SOLR returned " + results.length() + " results in " + stopWatch.getLastTaskTimeMillis() + "ms"); } return results; } } throw new QueryModelException("No query language available"); } }
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// www. j a v a2s . c om * @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())); } } }