use of cn.moyada.dubbo.faker.core.model.FutureResult in project dubbo-faker by moyada.
the class AsyncInvoker method invoke.
@Override
public void invoke(Object[] argsValue) {
super.count.increment();
Timestamp invokeTime = Timestamp.from(Instant.now());
CompletableFuture.supplyAsync(() -> {
FutureResult result;
// 开始时间
long start = System.nanoTime();
try {
result = FutureResult.success(super.execute(argsValue));
} catch (Throwable e) {
result = FutureResult.failed(e.getMessage());
}
result.setSpend(start);
// result.setSpend((System.nanoTime() - start) / 1000_000);
return result;
}, this.excutor).whenComplete((result, ex) -> {
// 完成计算耗时
result.setSpend((System.nanoTime() - result.getSpend()) / 1000_000);
// result.setSpend(Duration.between(now, Instant.now()).toMillis());
super.callback(new InvokeFuture(result, invokeTime, Arrays.toString(argsValue)));
super.count.decrement();
});
}
use of cn.moyada.dubbo.faker.core.model.FutureResult in project dubbo-faker by moyada.
the class DefaultInvoker method invoke.
@Override
public void invoke(Object[] argsValue) {
super.count.increment();
this.excutor.submit(() -> {
// 开始时间
Timestamp invokeTime = Timestamp.from(Instant.now());
FutureResult result;
long start = System.nanoTime();
try {
result = FutureResult.success(super.execute(argsValue));
} catch (Throwable e) {
result = FutureResult.failed(e.getMessage());
}
// 完成计算耗时
result.setSpend((System.nanoTime() - start) / 1000_000);
super.callback(new InvokeFuture(result, invokeTime, Arrays.toString(argsValue)));
super.count.decrement();
});
}
use of cn.moyada.dubbo.faker.core.model.FutureResult in project dubbo-faker by moyada.
the class FiberInvoker method invoke.
@Suspendable
@Override
public void invoke(Object[] argsValue) {
super.count.increment();
Timestamp invokeTime = Timestamp.from(Instant.now());
Fiber<FutureResult> fiber = this.scheduler.newFiber((SuspendableCallable<FutureResult>) () -> {
FutureResult result;
long start = System.nanoTime();
try {
result = FutureResult.success(execute(argsValue));
} catch (Throwable e) {
result = FutureResult.failed(e.getMessage());
}
result.setSpend((System.nanoTime() - start) / 1000_000);
return result;
}).start();
for (; ; ) {
if (fiber.isDone()) {
try {
FutureResult result = fiber.get();
super.callback(new InvokeFuture(result, invokeTime, Arrays.toString(argsValue)));
} catch (ExecutionException | InterruptedException e) {
e.printStackTrace();
}
super.count.decrement();
break;
}
}
}
Aggregations