@Override public <R extends MessageLite, C extends RpcCommand<R, ProxyConnection>> void runCommand(C cmd) { manager.runCommand(new ProxyCommand<>(cmd, protocol)); }
@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(); }
FabricConnectionManager getConnectionManager(FabricIdentity remoteIdentity) { assert localIdentity != null : "Fabric identity must be set before a connection manager can be retrieved"; assert remoteIdentity != null : "Identity cannot be null."; assert remoteIdentity.getAddress() != null && !remoteIdentity.getAddress().isEmpty() : "RemoteIdentity's server address cannot be null."; assert remoteIdentity.getPort() > 0 : String.format("Fabric Port must be set to a port between 1 and 65k. Was set to %d.", remoteIdentity.getPort()); FabricConnectionManager m = registry.get(remoteIdentity); if (m == null) { m = new FabricConnectionManager(config, allocator, remoteIdentity, localIdentity, eventLoop, handler, engineFactory); FabricConnectionManager m2 = registry.putIfAbsent(remoteIdentity, m); if (m2 != null) { m = m2; } } return m; }