public ProxyConnection(FabricConnection connection, FabricProtocol protocol) { super(connection); this.connection = connection; this.protocol = protocol; this.rpcConfig = protocol.getConfig(); }
void registerProtocol(FabricProtocol protocol){ Preconditions.checkArgument(protocols[protocol.getProtocolId()] == null, "Protocols already registered at logical id " + protocol.getProtocolId()); protocols[protocol.getProtocolId()] = protocol; sync.incrementAndGet(); }
BufferAllocator allocator = protocol.getAllocator(); if(allocator.getHeadroom() < buf.getPossibleMemoryConsumed()){ throw new RpcException(String.format("Message of length %d arrived at node %s:%d, send from %s:%d. Unfortunately, local memory for protocol %d is %d which is too close to the limit of %d. Message rejected.", protocol.handle(connection, message.getInnerRpcType(), message.getMessage(), dBody, new ChainedResponseSender(responseSender, protocolId)); } finally {
@SuppressWarnings("unchecked") @Override public void success(FabricMessage value, ByteBuf buffer) { try{ MessageLite m = protocol.getResponseDefaultInstance(value.getInnerRpcType()); assert rpcConfig.checkReceive(value.getInnerRpcType(), m.getClass()); Parser<?> parser = m.getParserForType(); Object convertedValue = parser.parseFrom(value.getMessage()); innerListener.success((RECEIVE) convertedValue, buffer); }catch(Exception ex){ logger.error("Failure", ex); innerListener.failed(new RpcException(ex)); } }
private <SEND extends MessageLite> FabricMessage msg(EnumLite rpcType, SEND protobufBody){ return FabricMessage.newBuilder() .setProtocolId(protocol.getProtocolId()) .setInnerRpcType(rpcType.getNumber()) .setMessage(protobufBody.toByteString()) .build(); }