/** * Begin connecting to the given node, return true if we are already connected and ready to send to that node. * * @param node The node to check * @param now The current timestamp * @return True if we are ready to send to the given node */ @Override public boolean ready(Node node, long now) { if (node.isEmpty()) throw new IllegalArgumentException("Cannot connect to empty node " + node); if (isReady(node, now)) return true; if (connectionStates.canConnect(node.idString(), now)) // if we are interested in sending to a node and we don't have a connection to it, initiate one initiateConnect(node, now); return false; }
public String createUniqueTopic(String prefix, int partitions, Properties topicConfig) throws InterruptedException { checkReady(); String topic = (prefix + UUID.randomUUID().toString().substring(0, 5)).replaceAll("[^a-zA-Z0-9._-]", "_"); AdminUtils.createTopic(kafkaServer.zkUtils(), topic, partitions, 1, topicConfig, AdminUtils.createTopic$default$6()); waitForPassing(Duration.ofSeconds(5), () -> { assertTrue(AdminUtils.fetchTopicMetadataFromZk(topic, kafkaServer.zkUtils()) .partitionMetadata().stream() .allMatch(pm -> !pm.leader().isEmpty())); }); return topic; }
public static Node from(org.apache.kafka.common.Node node) { return new Node(node.hasRack(), node.host(), node.id(), node.idString(), node.isEmpty(), node.port(), node.rack()); }
public String searchTree (Node n, String searchVal) { if (n.isEmpty())//no more children { return null; } else if (n.root().toString().equals(searchVal) //we found it { return n.root(); } else if (searchVal < n.root().toString()) //search left child { return searchTree(n.leftChild(),searchVal); } else //search right child { return searchTree(n.rightChild(),searchVal); } }