org.apache.kafka.clients.producer.internals
Class Metadata

java.lang.Object
  extended by org.apache.kafka.clients.producer.internals.Metadata

public final class Metadata
extends java.lang.Object

A class encapsulating some of the logic around metadata.

This class is shared by the client thread (for partitioning) and the background sender thread. Metadata is maintained for only a subset of topics, which can be added to over time. When we request metdata for a topic we don't have any metadata for it will trigger a metadata update.


Constructor Summary
Metadata()
          Create a metadata instance with reasonable defaults
Metadata(long refreshBackoffMs, long metadataExpireMs)
          Create a new Metadata instance
 
Method Summary
 void add(java.lang.String topic)
          Add the topic to maintain in the metadata
 void awaitUpdate(int lastVerison, long maxWaitMs)
          Wait for metadata update until the current version is larger than the last version we know of
 Cluster fetch()
          Get the current cluster info without blocking
 long lastUpdate()
          The last time metadata was updated.
 long refreshBackoff()
          The metadata refresh backoff in ms
 int requestUpdate()
          Request an update of the current cluster metadata info, return the current version before the update
 long timeToNextUpdate(long nowMs)
          The next time to update the cluster info is the maximum of the time the current info will expire and the time the current info can be updated (i.e.
 java.util.Set<java.lang.String> topics()
          Get the list of topics we are currently maintaining metadata for
 void update(Cluster cluster, long now)
          Update the cluster metadata
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Metadata

public Metadata()
Create a metadata instance with reasonable defaults


Metadata

public Metadata(long refreshBackoffMs,
                long metadataExpireMs)
Create a new Metadata instance

Parameters:
refreshBackoffMs - The minimum amount of time that must expire between metadata refreshes to avoid busy polling
metadataExpireMs - The maximum amount of time that metadata can be retained without refresh
Method Detail

fetch

public Cluster fetch()
Get the current cluster info without blocking


add

public void add(java.lang.String topic)
Add the topic to maintain in the metadata


timeToNextUpdate

public long timeToNextUpdate(long nowMs)
The next time to update the cluster info is the maximum of the time the current info will expire and the time the current info can be updated (i.e. backoff time has elapsed); If an update has been request then the expiry time is now


requestUpdate

public int requestUpdate()
Request an update of the current cluster metadata info, return the current version before the update


awaitUpdate

public void awaitUpdate(int lastVerison,
                        long maxWaitMs)
Wait for metadata update until the current version is larger than the last version we know of


topics

public java.util.Set<java.lang.String> topics()
Get the list of topics we are currently maintaining metadata for


update

public void update(Cluster cluster,
                   long now)
Update the cluster metadata


lastUpdate

public long lastUpdate()
The last time metadata was updated.


refreshBackoff

public long refreshBackoff()
The metadata refresh backoff in ms