@SuppressWarnings("unchecked") @Override public FabricConnection initRemoteConnection(SocketChannel channel) { return new FabricConnection("fabric client", channel, this, allocator); }
@Override protected BufferAllocator getAllocator() { return connection.getAllocator(); }
@Override public MessageLite getHandshakeResponse(FabricHandshake inbound) throws Exception { // logger.debug("Handling handshake from other bit. {}", inbound); if (inbound.getRpcVersion() != FabricRpcConfig.RPC_VERSION) { throw new RpcException(String.format("Invalid rpc version. Expected %d, actual %d.", inbound.getRpcVersion(), FabricRpcConfig.RPC_VERSION)); } if (!inbound.hasIdentity() || inbound.getIdentity().getAddress().isEmpty() || inbound.getIdentity().getPort() < 1) { throw new RpcException(String.format("RPC didn't provide valid counter identity. Received %s.", inbound.getIdentity())); } connection.setIdentity(inbound.getIdentity()); final boolean isLoopback = inbound.getIdentity().getAddress().equals(address) && inbound.getIdentity().getPort() == port; if (!isLoopback) { FabricConnectionManager manager = connectionRegistry.getConnectionManager(inbound.getIdentity()); // update the close handler. connection.wrapCloseHandler(manager.getCloseHandlerCreator()); // add to the connection manager. manager.addExternalConnection(connection); } return FabricHandshake.newBuilder().setRpcVersion(FabricRpcConfig.RPC_VERSION).build(); }
@Override protected void handle(FabricConnection connection, int rpcType, byte[] pBody, ByteBuf dBody, ResponseSender sender) throws RpcException { handler.handle(connection.getIdentity(), localIdentity, connection, rpcType, pBody, dBody, sender); }
@Override protected void finalizeConnection(FabricHandshake handshake, FabricConnection connection) { connection.setIdentity(handshake.getIdentity()); }
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 <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); }
@Override public FabricConnection initRemoteConnection(SocketChannel channel) { return new FabricConnection("fabric server", channel, this, allocator); }