/** @see ConnectionFactory#refreshMetadata(Collection) */ @Override public void refreshMetadata(Collection<String> topics) { try { this.lock.writeLock().lock(); String brokerAddressesAsString = ListIterate.collect(this.configuration.getBrokerAddresses(), Functions.getToString()) .makeString(","); Seq<Broker> brokers = null; try { brokers = ClientUtils$.MODULE$.parseBrokerList(brokerAddressesAsString); } catch (Exception e) { throw new IllegalStateException( "Can not parse Kafka Brokers for: [" + brokerAddressesAsString + "]", e); } TopicMetadataResponse topicMetadataResponse = new TopicMetadataResponse( ClientUtils$.MODULE$.fetchTopicMetadata( JavaConversions.asScalaSet(new HashSet<>(topics)), brokers, this.configuration.getClientId(), this.configuration.getFetchMetadataTimeout(), 0)); PartitionIterable<TopicMetadata> selectWithoutErrors = Iterate.partition( topicMetadataResponse.topicsMetadata(), errorlessTopicMetadataPredicate); this.metadataCacheHolder.set( this.metadataCacheHolder.get().merge(selectWithoutErrors.getSelected())); if (log.isInfoEnabled()) { for (TopicMetadata topicMetadata : selectWithoutErrors.getRejected()) { log.info( String.format("No metadata could be retrieved for '%s'", topicMetadata.topic()), ErrorMapping.exceptionFor(topicMetadata.errorCode())); } } } finally { this.lock.writeLock().unlock(); } }
@Test public void partition() { PartitionIterable<Integer> partition = this.lazyIterable.partition(IntegerPredicates.isEven()); Assert.assertEquals(iList(2, 4, 6), partition.getSelected()); Assert.assertEquals(iList(1, 3, 5, 7), partition.getRejected()); }