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
Source File: AbstractHttpServer.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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
Source File: AbstractHttpServer.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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 File: CallMonitoringAspect.java    From java-microservice with 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
Source File: CallMonitoringAspect.java    From DevOps-for-Web-Development with MIT License 6 votes vote down vote up
@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
Source File: CallMonitoringAspect.java    From DevOps-for-Web-Development with MIT License 6 votes vote down vote up
@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
Source File: AbstractHttpServer.java    From spring-cloud-gateway with Apache License 2.0 6 votes vote down vote up
@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
Source File: CallMonitoringAspect.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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
Source File: CallMonitoringAspect.java    From docker-workflow-plugin with MIT License 6 votes vote down vote up
@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
Source File: CallMonitoringAspect.java    From audit4j-demo with Apache License 2.0 6 votes vote down vote up
@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 File: AsyncSpringLiquibase.java    From jhipster with 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
Source File: GithubServiceTest.java    From spring-boot-rxjava with Apache License 2.0 5 votes vote down vote up
@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
Source File: AspectJAutoProxyCreatorTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
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
Source File: AspectJAutoProxyCreatorTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
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 File: LoggingAspect.java    From hentai with 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
Source File: AspectJAutoProxyCreatorTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
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);
}