public <SEND extends MessageLite, RECEIVE extends MessageLite> void send( RpcOutcomeListener<RECEIVE> outcomeListener, EnumLite rpcType, SEND protobufBody, Class<RECEIVE> clazz, ByteBuf... dataBodies) { assert rpcConfig.checkSend(rpcType, protobufBody.getClass(), clazz); connection.send(new ProxyListener<RECEIVE>(outcomeListener), RpcType.MESSAGE, msg(rpcType, protobufBody), FabricMessage.class, dataBodies); }
public RpcConfig build() { Preconditions.checkArgument(timeout > -1, "Timeout must be a positive number or zero for disabled."); Preconditions.checkArgument(name != null, "RpcConfig name must be set."); return new RpcConfig(name, sendMap, receiveMap, timeout, executor, sslConfig); }
rpcMapping.hasTimeout() ? (long) (rpcMapping.getTimeout() * 1000.0 * PERCENT_TIMEOUT_BEFORE_SENDING_PING) : -1;
/** * Initialize the {@code SocketChannel}. * * This method initializes a new channel created by the {@code ServerBootstrap} * * The default implementation create a remote connection, configures a default pipeline * which handles coding/decoding messages, handshaking, timeout and error handling based * on {@code RpcConfig} instance provided at construction time. * * On each call to this method, every handler added must be a new instance. As of now, the * handlers cannot be shared across connections. * * Subclasses can override it to add extra handlers if needed. * * @param ch the socket channel */ protected void initChannel(final SocketChannel ch) throws SSLException { C connection = initRemoteConnection(ch); connection.setChannelCloseHandler(newCloseListener(ch, connection)); final ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast(PROTOCOL_ENCODER, new RpcEncoder("s-" + rpcConfig.getName())); pipeline.addLast(MESSAGE_DECODER, newDecoder(connection.getAllocator())); pipeline.addLast(HANDSHAKE_HANDLER, newHandshakeHandler(connection)); if (rpcConfig.hasTimeout()) { pipeline.addLast(TIMEOUT_HANDLER, new LoggingReadTimeoutHandler(connection, rpcConfig.getTimeout())); } pipeline.addLast(MESSAGE_HANDLER, new InboundHandler(connection)); pipeline.addLast(EXCEPTION_HANDLER, new RpcExceptionHandler<>(connection)); }
@SuppressWarnings("unchecked") public SimpleProtocol(int protocolId, Map<Integer, ReceiveHandler<MessageLite, MessageLite>> handlers, BufferAllocator allocator, String name) { super(); this.protocolId = protocolId; this.handlers = new ReceiveHandler[2048]; this.defaultResponseInstances = new MessageLite[2048]; this.defaultRequestInstances = new MessageLite[2048]; RpcConfigBuilder builder = RpcConfig.newBuilder() .name(name) .timeout(0); for(Entry<Integer, ReceiveHandler<MessageLite, MessageLite>> e : handlers.entrySet()) { final int id = e.getKey(); final ReceiveHandler<?,?> handler = e.getValue(); final EnumLite num = new PseudoEnum(id); builder.add(num, (Class<? extends MessageLite>) handler.getDefaultRequest().getClass(), num, (Class<? extends MessageLite>) handler.getDefaultResponse().getClass()); this.handlers[id] = e.getValue(); this.defaultResponseInstances[id] = e.getValue().getDefaultResponse(); this.defaultRequestInstances[id] = e.getValue().getDefaultRequest(); } this.config = builder.build(); this.allocator = allocator; }
@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 static RpcConfig getMapping(SabotConfig config) { return RpcConfig.newBuilder() .name("CoordToCoord") .timeout(config.getInt(RpcConstants.BIT_RPC_TIMEOUT)) .add(RpcType.REQ_QUERY_CANCEL, CoordRPC.JobCancelRequest.class, RpcType.ACK, Ack.class) .add(RpcType.REQ_QUERY_PROFILE, ExternalId.class, RpcType.RESP_QUERY_PROFILE, QueryProfile.class) .build(); } }
private static RpcConfig getMapping(SabotConfig config) { return RpcConfig.newBuilder() .name("ReflectionExecToCoord") .timeout(config.getInt(BIT_RPC_TIMEOUT)) .add(ReflectionRPC.RpcType.REQ_REFLECTION_INFO, ReflectionRPC.ReflectionInfoReq.class, ReflectionRPC.RpcType.RESP_REFLECTION_INFO, ReflectionRPC.ReflectionInfoResp.class) .add(ReflectionRPC.RpcType.REQ_REFRESH_INFO, ReflectionRPC.RefreshInfoReq.class, ReflectionRPC.RpcType.RESP_REFRESH_INFO, ReflectionRPC.RefreshInfoResp.class) .build(); } }
public RpcBus(RpcConfig rpcConfig) { this.rpcConfig = rpcConfig; this.sendDurations = Metrics.getInstance() .histogram(rpcConfig.getName() + "-send-durations-ms"); }
public <SEND extends MessageLite, RECEIVE extends MessageLite> void sendUnsafe( RpcOutcomeListener<RECEIVE> outcomeListener, EnumLite rpcType, SEND protobufBody, Class<RECEIVE> clazz, ByteBuf... dataBodies) { assert rpcConfig.checkSend(rpcType, protobufBody.getClass(), clazz); connection.sendUnsafe(new ProxyListener<RECEIVE>(outcomeListener), RpcType.MESSAGE, msg(rpcType, protobufBody), FabricMessage.class, dataBodies); }
private static RpcConfig getMapping(SabotConfig config) { return RpcConfig.newBuilder() .name("CatalogProtocol") .timeout(config.getInt(RpcConstants.BIT_RPC_TIMEOUT)) .add(RpcType.REQ_SOURCE_CONFIG, SourceWrapper.class, RpcType.ACK, Ack.class) .add(RpcType.REQ_DEL_SOURCE, SourceWrapper.class, RpcType.ACK, Ack.class) .build(); }
assert rpcConfig.checkSend(rpcType, protobufBody.getClass(), clazz);
public static RpcConfig getMapping(int rpcTimeout, Executor executor, Optional<SSLConfig> sslConfig) { return RpcConfig.newBuilder() .name("FABRIC") .executor(executor) .timeout(rpcTimeout) .sslConfig(sslConfig) .add(RpcType.HANDSHAKE, FabricHandshake.class, RpcType.HANDSHAKE, FabricHandshake.class) .add(RpcType.MESSAGE, FabricMessage.class, RpcType.MESSAGE, FabricMessage.class) .build(); }
@Override protected void initChannel(SocketChannel ch) throws Exception { connection = initRemoteConnection(ch); // each handler in the pipeline is created per connection ch.closeFuture().addListener(newCloseListener(ch, connection)); final ChannelPipeline pipe = ch.pipeline(); pipe.addLast(PROTOCOL_ENCODER, new RpcEncoder("c-" + rpcConfig.getName())); pipe.addLast(PROTOCOL_DECODER, newDecoder(connection.getAllocator())); pipe.addLast(HANDSHAKE_HANDLER, new ClientHandshakeHandler()); if (timeoutInMillis != -1) { pipe.addLast(IDLE_STATE_HANDLER, new IdlePingHandler(timeoutInMillis)); } pipe.addLast(MESSAGE_HANDLER, new InboundHandler(connection)); pipe.addLast(EXCEPTION_HANDLER, new RpcExceptionHandler<>(connection)); } });
private static RpcConfig getMapping(SabotConfig config) { return RpcConfig.newBuilder() .name("DATA") .timeout(config.getInt(RpcConstants.BIT_RPC_TIMEOUT)) .add(RpcType.REQ_RECORD_BATCH, FragmentRecordBatch.class, RpcType.ACK, Ack.class) .add(RpcType.REQ_STREAM_COMPLETE, FragmentStreamComplete.class, RpcType.ACK, Ack.class) .add(RpcType.REQ_RECEIVER_FINISHED, FinishedReceiver.class, RpcType.ACK, Ack.class) .add(RpcType.REQ_OOB_MESSAGE, OOBMessage.class, RpcType.ACK, Ack.class) .build(); }
@Override public void handle(PhysicalConnection connection, int rpcType, ByteString pBody, ByteBuf dBody, ResponseSender sender) throws RpcException { MessageLite defaultInstance = defaultRequestInstances[rpcType]; try{ MessageLite value = defaultInstance.getParserForType().parseFrom(pBody); SentResponseMessage<MessageLite> response = handlers[rpcType].handle(value, (ArrowBuf) dBody); sender.send(new Response(new PseudoEnum(rpcType), response.getBody(), response.getBuffers())); } catch(Exception e){ final String fail = String.format("Failure consuming message for protocol[%d], request[%d] in the %s rpc layer.", getProtocolId(), rpcType, getConfig().getName()); throw new UserRpcException(NodeEndpoint.getDefaultInstance(), fail, e); } } }
private static RpcConfig getMapping(SabotConfig config) { return RpcConfig.newBuilder() .name("CoordToExec") .timeout(config.getInt(RpcConstants.BIT_RPC_TIMEOUT)) .add(RpcType.REQ_START_FRAGMENTS, InitializeFragments.class, RpcType.ACK, Ack.class) .add(RpcType.REQ_CANCEL_FRAGMENTS, FragmentHandle.class, RpcType.ACK, Ack.class) .add(RpcType.REQ_FRAGMENT_STATUS, FragmentStatus.class, RpcType.ACK, Ack.class) .add(RpcType.REQ_QUERY_DATA, QueryData.class, RpcType.ACK, Ack.class) .add(RpcType.REQ_NODE_QUERY_STATUS, NodeQueryStatus.class, RpcType.ACK, Ack.class) .build(); }
public FabricConnectionManager( final RpcConfig rpcConfig, final BufferAllocator allocator, final FabricIdentity remoteIdentity, final FabricIdentity localIdentity, final EventLoopGroup eventLoop, final FabricMessageHandler handler, Optional<SSLEngineFactory> engineFactory ) { super( rpcConfig.getName(), FabricHandshake.newBuilder() .setRpcVersion(FabricRpcConfig.RPC_VERSION) .setIdentity(localIdentity) .build(), remoteIdentity.getAddress(), remoteIdentity.getPort()); this.rpcConfig = rpcConfig; this.eventLoop = eventLoop; this.allocator = allocator; this.remoteIdentity = remoteIdentity; this.localIdentity = localIdentity; this.handler = handler; this.engineFactory = engineFactory; }