Java Code Examples for org.springframework.util.StopWatch#getTotalTimeMillis()

The following examples show how to use org.springframework.util.StopWatch#getTotalTimeMillis() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public final void start() {
	synchronized (this.lifecycleMonitor) {
		if (!isRunning()) {
			String serverName = getClass().getSimpleName();
			if (logger.isDebugEnabled()) {
				logger.debug("Starting " + serverName + "...");
			}
			this.running = true;
			try {
				StopWatch stopWatch = new StopWatch();
				stopWatch.start();
				startInternal();
				long millis = stopWatch.getTotalTimeMillis();
				if (logger.isDebugEnabled()) {
					logger.debug("Server started on port " + getPort() + "(" + millis + " millis).");
				}
			}
			catch (Throwable ex) {
				throw new IllegalStateException(ex);
			}
		}
	}

}
 
Example 2
@Override
public final void start() {
	synchronized (this.lifecycleMonitor) {
		if (!isRunning()) {
			String serverName = getClass().getSimpleName();
			if (logger.isDebugEnabled()) {
				logger.debug("Starting " + serverName + "...");
			}
			this.running = true;
			try {
				StopWatch stopWatch = new StopWatch();
				stopWatch.start();
				startInternal();
				long millis = stopWatch.getTotalTimeMillis();
				if (logger.isDebugEnabled()) {
					logger.debug("Server started on port " + getPort() + "(" + millis + " millis).");
				}
			}
			catch (Throwable ex) {
				throw new IllegalStateException(ex);
			}
		}
	}

}
 
Example 3
Source Project: java-microservice   File: CallMonitoringAspect.java    License: MIT License 6 votes vote down vote up
@Around("@annotation(com.apssouza.monitoring.Monitored)")
public Object invoke(ProceedingJoinPoint joinPoint) throws Throwable {
    System.out.println("callend");
    Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
    if (this.enabled) {
        StopWatch sw = new StopWatch(joinPoint.toShortString());

        sw.start("invoke");
        try {
            return joinPoint.proceed();
        } finally {
            sw.stop();
            synchronized (this) {
                this.callCount++;
                this.accumulatedCallTime += sw.getTotalTimeMillis();
            }
            publisher.publishEvent(new MonitoringInvokedEvent(
                    method.getName(),
                    this.accumulatedCallTime
            ));
        }
    } else {
        return joinPoint.proceed();
    }
}
 
Example 4
@Around("within(@org.springframework.stereotype.Repository *)")
public Object invoke(ProceedingJoinPoint joinPoint) throws Throwable {
    if (this.enabled) {
        StopWatch sw = new StopWatch(joinPoint.toShortString());

        sw.start("invoke");
        try {
            return joinPoint.proceed();
        } finally {
            sw.stop();
            synchronized (this) {
                this.callCount++;
                this.accumulatedCallTime += sw.getTotalTimeMillis();
            }
        }
    } else {
        return joinPoint.proceed();
    }
}
 
Example 5
@Around("within(@org.springframework.stereotype.Repository *)")
public Object invoke(ProceedingJoinPoint joinPoint) throws Throwable {
    if (this.enabled) {
        StopWatch sw = new StopWatch(joinPoint.toShortString());

        sw.start("invoke");
        try {
            return joinPoint.proceed();
        } finally {
            sw.stop();
            synchronized (this) {
                this.callCount++;
                this.accumulatedCallTime += sw.getTotalTimeMillis();
            }
        }
    } else {
        return joinPoint.proceed();
    }
}
 
Example 6
@Override
public final void start() {
	synchronized (this.lifecycleMonitor) {
		if (!isRunning()) {
			String serverName = getClass().getSimpleName();
			if (logger.isDebugEnabled()) {
				logger.debug("Starting " + serverName + "...");
			}
			this.running = true;
			try {
				StopWatch stopWatch = new StopWatch();
				stopWatch.start();
				startInternal();
				long millis = stopWatch.getTotalTimeMillis();
				if (logger.isDebugEnabled()) {
					logger.debug("Server started on port " + getPort() + "(" + millis
							+ " millis).");
				}
			}
			catch (Throwable ex) {
				throw new IllegalStateException(ex);
			}
		}
	}

}
 
Example 7
@Around("within(@org.springframework.stereotype.Service *)")
public Object invoke(ProceedingJoinPoint joinPoint) throws Throwable {
	if (this.isEnabled) {
		StopWatch sw = new StopWatch(joinPoint.toShortString());

		sw.start("invoke");
		try {
			return joinPoint.proceed();
		}
		finally {
			sw.stop();
			synchronized (this) {
				this.callCount++;
				this.accumulatedCallTime += sw.getTotalTimeMillis();
			}
		}
	}

	else {
		return joinPoint.proceed();
	}
}
 
Example 8
@Around("within(@org.springframework.stereotype.Repository *)")
public Object invoke(ProceedingJoinPoint joinPoint) throws Throwable {
    if (this.enabled) {
        StopWatch sw = new StopWatch(joinPoint.toShortString());

        sw.start("invoke");
        try {
            return joinPoint.proceed();
        } finally {
            sw.stop();
            synchronized (this) {
                this.callCount++;
                this.accumulatedCallTime += sw.getTotalTimeMillis();
            }
        }
    } else {
        return joinPoint.proceed();
    }
}
 
Example 9
@Around("within(@org.springframework.stereotype.Repository *)")
public Object invoke(ProceedingJoinPoint joinPoint) throws Throwable {
    if (this.enabled) {
        StopWatch sw = new StopWatch(joinPoint.toShortString());

        sw.start("invoke");
        try {
            return joinPoint.proceed();
        } finally {
            sw.stop();
            synchronized (this) {
                this.callCount++;
                this.accumulatedCallTime += sw.getTotalTimeMillis();
            }
        }
    } else {
        return joinPoint.proceed();
    }
}
 
Example 10
Source Project: jhipster   File: AsyncSpringLiquibase.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * <p>initDb.</p>
 *
 * @throws liquibase.exception.LiquibaseException if any.
 */
protected void initDb() throws LiquibaseException {
    StopWatch watch = new StopWatch();
    watch.start();
    super.afterPropertiesSet();
    watch.stop();
    logger.debug(STARTED_MESSAGE, watch.getTotalTimeMillis());
    if (watch.getTotalTimeMillis() > SLOWNESS_THRESHOLD * 1000L) {
        logger.warn(SLOWNESS_MESSAGE, SLOWNESS_THRESHOLD);
    }
}
 
Example 11
@Test
public void testGetUser() throws Exception {
    StopWatch stopwatch = new StopWatch();
    stopwatch.start();

    GithubUser foo = githubService.getUser("foo");
    stopwatch.stop();

    long duration = stopwatch.getTotalTimeMillis();

    assertThat(foo).isNotNull();

    assertThat(foo.getUser()).isNotNull();
    assertThat(foo.getUser().getLogin()).isEqualTo("foo");
    assertThat(foo.getUser().getName()).isEqualTo("foo bar");

    assertThat(foo.getFollowers())
            .hasSize(3)
            .extracting("name")
            .contains("bar", "qix", "baz");
    assertThat(foo.getRepositories())
            .hasSize(2)
            .extracting("name")
            .contains("foo", "bar");

    // duration should be at least 300ms & max 400ms with overhead
    assertThat(duration).isGreaterThanOrEqualTo(300);
    assertThat(duration).isLessThanOrEqualTo(400);
}
 
Example 12
private void assertStopWatchTimeLimit(final StopWatch sw, final long maxTimeMillis) {
	long totalTimeMillis = sw.getTotalTimeMillis();
	assertTrue("'" + sw.getLastTaskName() + "' took too long: expected less than<" + maxTimeMillis +
			"> ms, actual<" + totalTimeMillis + "> ms.", totalTimeMillis < maxTimeMillis);
}
 
Example 13
private void assertStopWatchTimeLimit(final StopWatch sw, final long maxTimeMillis) {
	long totalTimeMillis = sw.getTotalTimeMillis();
	assertTrue("'" + sw.getLastTaskName() + "' took too long: expected less than<" + maxTimeMillis +
			"> ms, actual<" + totalTimeMillis + "> ms.", totalTimeMillis < maxTimeMillis);
}
 
Example 14
Source Project: hentai   File: LoggingAspect.java    License: Apache License 2.0 4 votes vote down vote up
private String createTimerString(StopWatch stopWatch) {
    long millis = stopWatch.getTotalTimeMillis();
    return format(" [%d ms]", millis);
}
 
Example 15
private static void assertStopWatchTimeLimit(final StopWatch sw, final long maxTimeMillis) {
	final long totalTimeMillis = sw.getTotalTimeMillis();
	assertTrue("'" + sw.getLastTaskName() + "' took too long: expected less than<" + maxTimeMillis
			+ "> ms, actual<" + totalTimeMillis + "> ms.", totalTimeMillis < maxTimeMillis);
}