【发布时间】:2014-07-04 13:20:47
【问题描述】:
我正在尝试使用 Java 8 和流,而我想要替换的一件事是我们拥有的系统
- 使用方面来测量调用延迟(每个配置时间段)到网络服务,然后
- 将这些结果输入复杂事件处理器 (esper),以便
- 我们可以发送警报通知
所以,一次一步。第一步,我需要生成一个流(我认为),它允许我将这些延迟数字提供给现有的侦听器。了解这一点,获得下一个系列号码可能必须等到有电话。
我该怎么做?这是 cmets 的延迟方面。
public class ProfilingAspect {
private ProfilingAction action;
public ProfilingAspect(ProfilingAction action) {
this.action = action;
}
public Object doAroundAdvice(ProceedingJoinPoint jp) throws Throwable{
long startTime = System.currentTimeMillis();
Object retVal = null;
Throwable error = null;
try{
retVal = jp.proceed();
}catch (Throwable t){
error = t;
}
Class withinType = jp.getSourceLocation().getWithinType();
String methodName = jp.getSignature().getName();
long endTime = System.currentTimeMillis();
long runningTime = endTime - startTime;
// Let the IntStream know we have a new latency. Or really, we have an object
// stream with all this extra data
action.perform(withinType, methodName, jp.getArgs(), runningTime, error);
if( error != null ){
throw error;
}
return retVal;
}
}
【问题讨论】:
标签: java java-8 java-stream