Search in sources :

Example 1 with ClusterResourceListeners

use of org.apache.kafka.common.internals.ClusterResourceListeners in project kafka by apache.

the class MetadataTest method testClusterListenerGetsNotifiedOfUpdate.

@Test
public void testClusterListenerGetsNotifiedOfUpdate() {
    long time = 0;
    MockClusterResourceListener mockClusterListener = new MockClusterResourceListener();
    ClusterResourceListeners listeners = new ClusterResourceListeners();
    listeners.maybeAdd(mockClusterListener);
    metadata = new Metadata(refreshBackoffMs, metadataExpireMs, false, listeners);
    String hostName = "www.example.com";
    Cluster cluster = Cluster.bootstrap(Arrays.asList(new InetSocketAddress(hostName, 9002)));
    metadata.update(cluster, Collections.<String>emptySet(), time);
    assertFalse("ClusterResourceListener should not called when metadata is updated with bootstrap Cluster", MockClusterResourceListener.IS_ON_UPDATE_CALLED.get());
    metadata.update(new Cluster("dummy", Arrays.asList(new Node(0, "host1", 1000)), Arrays.asList(new PartitionInfo("topic", 0, null, null, null), new PartitionInfo("topic1", 0, null, null, null)), Collections.<String>emptySet(), Collections.<String>emptySet()), Collections.<String>emptySet(), 100);
    assertEquals("MockClusterResourceListener did not get cluster metadata correctly", "dummy", mockClusterListener.clusterResource().clusterId());
    assertTrue("MockClusterResourceListener should be called when metadata is updated with non-bootstrap Cluster", MockClusterResourceListener.IS_ON_UPDATE_CALLED.get());
}
Also used : ClusterResourceListeners(org.apache.kafka.common.internals.ClusterResourceListeners) InetSocketAddress(java.net.InetSocketAddress) Node(org.apache.kafka.common.Node) MockClusterResourceListener(org.apache.kafka.test.MockClusterResourceListener) Cluster(org.apache.kafka.common.Cluster) PartitionInfo(org.apache.kafka.common.PartitionInfo) Test(org.junit.Test)

Example 2 with ClusterResourceListeners

use of org.apache.kafka.common.internals.ClusterResourceListeners in project kafka by apache.

the class KafkaProducer method configureClusterResourceListeners.

private ClusterResourceListeners configureClusterResourceListeners(Serializer<K> keySerializer, Serializer<V> valueSerializer, List<?>... candidateLists) {
    ClusterResourceListeners clusterResourceListeners = new ClusterResourceListeners();
    for (List<?> candidateList : candidateLists) clusterResourceListeners.maybeAddAll(candidateList);
    clusterResourceListeners.maybeAdd(keySerializer);
    clusterResourceListeners.maybeAdd(valueSerializer);
    return clusterResourceListeners;
}
Also used : ClusterResourceListeners(org.apache.kafka.common.internals.ClusterResourceListeners)

Example 3 with ClusterResourceListeners

use of org.apache.kafka.common.internals.ClusterResourceListeners in project kafka by apache.

the class KafkaConsumer method configureClusterResourceListeners.

private ClusterResourceListeners configureClusterResourceListeners(Deserializer<K> keyDeserializer, Deserializer<V> valueDeserializer, List<?>... candidateLists) {
    ClusterResourceListeners clusterResourceListeners = new ClusterResourceListeners();
    for (List<?> candidateList : candidateLists) clusterResourceListeners.maybeAddAll(candidateList);
    clusterResourceListeners.maybeAdd(keyDeserializer);
    clusterResourceListeners.maybeAdd(valueDeserializer);
    return clusterResourceListeners;
}
Also used : ClusterResourceListeners(org.apache.kafka.common.internals.ClusterResourceListeners)

Aggregations

ClusterResourceListeners (org.apache.kafka.common.internals.ClusterResourceListeners)3 InetSocketAddress (java.net.InetSocketAddress)1 Cluster (org.apache.kafka.common.Cluster)1 Node (org.apache.kafka.common.Node)1 PartitionInfo (org.apache.kafka.common.PartitionInfo)1 MockClusterResourceListener (org.apache.kafka.test.MockClusterResourceListener)1 Test (org.junit.Test)1