org.springframework.util.StopWatch#getTotalTimeMillis ( )源码实例Demo

下面列出了org.springframework.util.StopWatch#getTotalTimeMillis ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: spring-analysis-note   文件: AbstractHttpServer.java
@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);
			}
		}
	}

}
 
@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);
			}
		}
	}

}
 
源代码3 项目: java-microservice   文件: CallMonitoringAspect.java
@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();
    }
}
 
@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();
    }
}
 
@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();
    }
}
 
源代码6 项目: spring-cloud-gateway   文件: AbstractHttpServer.java
@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);
			}
		}
	}

}
 
源代码7 项目: cacheonix-core   文件: CallMonitoringAspect.java
@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();
	}
}
 
@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();
    }
}
 
源代码9 项目: audit4j-demo   文件: CallMonitoringAspect.java
@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();
    }
}
 
源代码10 项目: jhipster   文件: AsyncSpringLiquibase.java
/**
 * <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);
    }
}
 
源代码11 项目: spring-boot-rxjava   文件: GithubServiceTest.java
@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);
}
 
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);
}
 
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);
}
 
源代码14 项目: hentai   文件: LoggingAspect.java
private String createTimerString(StopWatch stopWatch) {
    long millis = stopWatch.getTotalTimeMillis();
    return format(" [%d ms]", millis);
}
 
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);
}