打印rpc消息传输耗时等信息:术语rpcFly
5219
private static void logRpcFly(JSONObject msgJson, ChannelHandlerContext ctx) {
        try {
            String ssid = msgJson.getString("$ssid");
            String from = msgJson.getString("$LOCAL_NODE_ID");
            String msgType = msgJson.getString("$msgType");
            if (ssid != null) {
                long start = (long) msgJson.remove("$timestampMs");//目前是用完删掉,避免传递到业务层
                LOG.debug(new JSONObject() {{
                    put("cost", System.currentTimeMillis() - start);
                    put("type", "rpcFly");
                    put("ssid", ssid);
                    put("from", from);
                    /*put("length", msgStr.length());*/
                    /*put("fullMsg", msgStr);*/
                    put("msgType", msgType);
                    put("client", ctx.channel().localAddress());
                    put("server", ctx.channel().remoteAddress());
                }});
            }
        } catch (Throwable e) {
            LOG.error(e);
        }
    }
85523
def _send_rpc(self, device_info, control_info, address, rpc_id, payload, poll_interval, timeout):
        """"""

        write_address, write_data = control_info.format_rpc(address, rpc_id, payload)
        self._jlink.memory_write32(write_address, write_data)

        self._trigger_rpc(device_info)

        start = monotonic()
        now = start

        poll_address, poll_mask = control_info.poll_info()

        while (now - start) < timeout:
            time.sleep(poll_interval)
            value, = self._jlink.memory_read8(poll_address, 1)

            if value & poll_mask:
                break

            now = monotonic()

        if (now - start) >= timeout:
            raise HardwareError("Timeout waiting for RPC response", timeout=timeout, poll_interval=poll_interval)

        read_address, read_length = control_info.response_info()
        read_data = self._read_memory(read_address, read_length, join=True)

        return control_info.format_response(read_data)
357623
function rpc(functionName, ...datatypes) {
  const qrpc = qtypes.QInt.from(Types.RPCCALL);
  const qfunctionName = qtypes.QByteArray.from(`2${functionName}`);
  return function(target, _key, descriptor) {
    return {
      enumerable: false,
      configurable: false,
      writable: false,
      value: function(...args) {
        const data = descriptor.value.apply(this, args);
        this.qtsocket.write([
          qrpc,
          qfunctionName,
          ...data.map((value, index) => datatypes[index].from(value))
        ]);
      }
    };
  };
}
425413
def _enable_rpcs(self, conn, services, timeout=1.0):
        

        #FIXME: Check for characteristic existence in a try/catch and return failure if not found

        success, result = self._set_notification(conn, services[TileBusService]['characteristics'][TileBusReceiveHeaderCharacteristic], True, timeout)
        if not success:
            return success, result

        return self._set_notification(conn, services[TileBusService]['characteristics'][TileBusReceivePayloadCharacteristic], True, timeout)
462245
def event(self, interface_id, address, value_key, value):
        """"""
        LOG.debug("RPCFunctions.event: interface_id = %s, address = %s, value_key = %s, value = %s" % (
            interface_id, address, value_key.upper(), str(value)))
        self.devices_all[interface_id.split(
            '-')[-1]][address].event(interface_id, value_key.upper(), value)
        if self.eventcallback:
            self.eventcallback(interface_id=interface_id, address=address,
                               value_key=value_key.upper(), value=value)
        return True
87969
public long sendRpc(ByteBuffer message, RpcResponseCallback callback) {
    if (logger.isTraceEnabled()) {
      logger.trace("Sending RPC to {}", getRemoteAddress(channel));
    }

    long requestId = requestId();
    handler.addRpcRequest(requestId, callback);

    RpcChannelListener listener = new RpcChannelListener(requestId, callback);
    channel.writeAndFlush(new RpcRequest(requestId, new NioManagedBuffer(message)))
      .addListener(listener);

    return requestId;
  }
771913
def make_rpc_call(self, rpc_command):
        
        # ~~~ hack: ~~~
        if not self.is_alive():
            self.close()  # force close for safety
            self.open()  # reopen
        # ~~~ end hack ~~~
        result = self._execute_rpc(rpc_command)
        return ET.tostring(result)
1345523
private RpcElement readRpc(Location location, String documentation) {
    String name = reader.readName();

    reader.require('(');

    boolean requestStreaming = false;
    String requestType;
    String word = reader.readWord();
    if (word.equals("stream")) {
      requestStreaming = true;
      requestType = reader.readDataType();
    } else {
      requestType = reader.readDataType(word);
    }
    reader.require(')');

    if (!reader.readWord().equals("returns")) throw reader.unexpected("expected 'returns'");

    reader.require('(');

    boolean responseStreaming = false;
    String responseType;
    word = reader.readWord();
    if (word.equals("stream")) {
      responseStreaming = true;
      responseType = reader.readDataType();
    } else {
      responseType = reader.readDataType(word);
    }
    reader.require(')');

    ImmutableList.Builder<OptionElement> options = ImmutableList.builder();
    if (reader.peekChar('{')) {
      while (true) {
        String rpcDocumentation = reader.readDocumentation();
        if (reader.peekChar('}')) {
          break;
        }
        Object declared = readDeclaration(rpcDocumentation, Context.RPC);
        if (declared instanceof OptionElement) {
          options.add((OptionElement) declared);
        }
      }
    } else {
      reader.require(';');
    }

    return new RpcElement(
        location,
        name,
        documentation,
        requestType,
        responseType,
        requestStreaming,
        responseStreaming,
        options.build()
    );
  }
869826
async def rpc_message(self, request, message):
        ''''''
        await self.pubsub.publish(self.channel, message)
        return 'OK'
592820
function TransmitOralProcessWithInit(client, req) {
    return new Promise(function (resolve, reject) {
        // 通过client对象调用想要访问的接口，需要传入请求对象以及响应回调函数
        client.TransmitOralProcessWithInit(req, function (err, response) {
            if (err) {
                reject(err)
                return;
            }
            // 请求正常返回，打印response对象
            resolve(response)
        });
    })
}
1361260
@Override
    public void closeConnection(RpcClient rpcClient, ClientTransportConfig transportConfig, Url url) {
        if (rpcClient == null || transportConfig == null || url == null) {
            return;
        }
        // 先删除
        Connection connection = urlConnectionMap.remove(transportConfig);
        if (connection == null) {
            return;
        }
        // 再判断是否需要关闭
        boolean needDestroy;
        AtomicInteger integer = connectionRefCounter.get(connection);
        if (integer == null) {
            needDestroy = true;
        } else {
            // 当前连接引用数
            int currentCount = integer.decrementAndGet();
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Client transport {} of {} , current ref count is: {}", url.toString(),
                    NetUtils.channelToString(connection.getLocalAddress(), connection.getRemoteAddress()),
                    currentCount);
            }
            if (currentCount <= 0) {
                // 此长连接无任何引用，可以销毁
                connectionRefCounter.remove(connection);
                needDestroy = true;
            } else {
                needDestroy = false;
            }
        }
        if (needDestroy) {
            rpcClient.closeStandaloneConnection(connection);
        }
    }
869516
def rpc(self, feature, cmd, *args, **kw):
        

        rpc_id = (feature << 8 | cmd)

        result_format = _create_resp_format(kw.get('result_type'), kw.get('result_format'))
        arg_format = kw.get('arg_format')
        if arg_format is None:
            arg_format = _create_arg_format(args)

        passed_kw = {}
        if 'timeout' in kw:
            passed_kw['timeout'] = kw['timeout']

        response = self.rpc_v2(rpc_id, arg_format, result_format, *args, **passed_kw)

        old_return = kw.get('result_type')
        if old_return is not None:
            return _create_old_return_value(response, *old_return)

        return response
758257
def rpc_call(payload):
    

    # Send the request and store the requests Unique ID.
    corr_id = RPC_CLIENT.send_request(payload)

    # Wait until we have received a response.
    while RPC_CLIENT.queue[corr_id] is None:
        sleep(0.1)

    # Return the response to the user.
    return RPC_CLIENT.queue[corr_id]
1048725
public int get_rpc_protocol(final DeviceProxy deviceProxy) throws DevFailed {
        checkIfTaco(deviceProxy, "get_rpc_protocol");

        build_connection(deviceProxy);

        return deviceProxy.taco_device.get_rpc_protocol();
    }
1063267
def rpc(message_name, data=nil, opts={})
      message_name = validated_message_name(message_name)
      publisher.rpc(message_name, data, opts)
    end
797673
def call_rpc(self, rpc_id, payload=bytes()):
        
        if rpc_id < 0 or rpc_id > 0xFFFF:
            raise RPCInvalidIDError("Invalid RPC ID: {}".format(rpc_id))

        if rpc_id not in self._rpcs:
            raise RPCNotFoundError("rpc_id: {}".format(rpc_id))

        return self._rpcs[rpc_id](payload)
332989
private Object invokeRpc(Method method, Object[] args) throws Exception {
		String methodName = method.getName();
		Class<?>[] parameterTypes = method.getParameterTypes();
		Annotation[][] parameterAnnotations = method.getParameterAnnotations();
		Time futureTimeout = extractRpcTimeout(parameterAnnotations, args, timeout);

		final RpcInvocation rpcInvocation = createRpcInvocationMessage(methodName, parameterTypes, args);

		Class<?> returnType = method.getReturnType();

		final Object result;

		if (Objects.equals(returnType, Void.TYPE)) {
			tell(rpcInvocation);

			result = null;
		} else {
			// execute an asynchronous call
			CompletableFuture<?> resultFuture = ask(rpcInvocation, futureTimeout);

			CompletableFuture<?> completableFuture = resultFuture.thenApply((Object o) -> {
				if (o instanceof SerializedValue) {
					try {
						return  ((SerializedValue<?>) o).deserializeValue(getClass().getClassLoader());
					} catch (IOException | ClassNotFoundException e) {
						throw new CompletionException(
							new RpcException("Could not deserialize the serialized payload of RPC method : "
								+ methodName, e));
					}
				} else {
					return o;
				}
			});

			if (Objects.equals(returnType, CompletableFuture.class)) {
				result = completableFuture;
			} else {
				try {
					result = completableFuture.get(futureTimeout.getSize(), futureTimeout.getUnit());
				} catch (ExecutionException ee) {
					throw new RpcException("Failure while obtaining synchronous RPC result.", ExceptionUtils.stripExecutionException(ee));
				}
			}
		}

		return result;
	}