}
}
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
long start = System.currentTimeMillis();
Result result = invoker.invoke(invocation);
long end = System.currentTimeMillis();
if (tracers.size() > 0) {
String key = invoker.getInterface().getName() + "." + invocation.getMethodName();
Set<Channel> channels = tracers.get(key);
if (channels == null || channels.size() == 0) {
key = invoker.getInterface().getName();
channels = tracers.get(key);
}
if (channels != null && channels.size() > 0) {
for (Channel channel : new ArrayList<Channel>(channels)) {
if (channel.isConnected()) {
try {
int max = 1;
Integer m = (Integer) channel.getAttribute(TRACE_MAX);
if (m != null) {
max = (int) m;
}
int count = 0;
AtomicInteger c = (AtomicInteger) channel.getAttribute(TRACE_COUNT);
if (c == null) {
c = new AtomicInteger();
channel.setAttribute(TRACE_COUNT, c);
}
count = c.getAndIncrement();
if (count < max) {
String prompt = channel.getUrl().getParameter("prompt", "telnet");
channel.send("\r\n" + RpcContext.getContext().getRemoteAddress() + " -> "
+ invoker.getInterface().getName()
+ "." + invocation.getMethodName()
+ "(" + JSON.json(invocation.getArguments()) + ")" + " -> " + JSON.json(result.getResult())
+ "\r\nelapsed: "+(end - start) +" ms."
+ "\r\n\r\n" + prompt + "> ");
}
if(count >= max - 1) {
channels.remove(channel);