Search in sources :

Example 1 with ZkSerializer

use of org.I0Itec.zkclient.serialize.ZkSerializer in project nutzboot by nutzam.

the class ZkClientStarter method getZkSerializer.

public ZkSerializer getZkSerializer() {
    ZkSerializer serializer = null;
    String zkSerializer = conf.get(PROP_SERIALIZER);
    if (!Strings.isBlank(zkSerializer)) {
        serializer = ioc.get(ZkSerializer.class, zkSerializer);
    }
    if (serializer == null) {
        serializer = new SerializableSerializer();
    }
    return serializer;
}
Also used : SerializableSerializer(org.I0Itec.zkclient.serialize.SerializableSerializer) ZkSerializer(org.I0Itec.zkclient.serialize.ZkSerializer)

Example 2 with ZkSerializer

use of org.I0Itec.zkclient.serialize.ZkSerializer in project nifi by apache.

the class KafkaUtils method retrievePartitionCountForTopic.

/**
 * Will retrieve the amount of partitions for a given Kafka topic.
 */
static int retrievePartitionCountForTopic(String zookeeperConnectionString, String topicName) {
    ZkClient zkClient = null;
    try {
        zkClient = new ZkClient(zookeeperConnectionString);
        zkClient.setZkSerializer(new ZkSerializer() {

            @Override
            public byte[] serialize(Object o) throws ZkMarshallingError {
                return ZKStringSerializer.serialize(o);
            }

            @Override
            public Object deserialize(byte[] bytes) throws ZkMarshallingError {
                return ZKStringSerializer.deserialize(bytes);
            }
        });
        scala.collection.Set<TopicMetadata> topicMetadatas = AdminUtils.fetchTopicMetadataFromZk(JavaConversions.asScalaSet(Collections.singleton(topicName)), zkClient);
        if (topicMetadatas != null && topicMetadatas.size() > 0) {
            return JavaConversions.asJavaSet(topicMetadatas).iterator().next().partitionsMetadata().size();
        } else {
            throw new IllegalStateException("Failed to get metadata for topic " + topicName);
        }
    } catch (Exception e) {
        throw new IllegalStateException("Failed to retrieve partitions for topic " + topicName, e);
    } finally {
        try {
            zkClient.close();
        } catch (Exception e2) {
        // ignore
        }
    }
}
Also used : ZkClient(org.I0Itec.zkclient.ZkClient) ZkMarshallingError(org.I0Itec.zkclient.exception.ZkMarshallingError) ZkSerializer(org.I0Itec.zkclient.serialize.ZkSerializer) TopicMetadata(kafka.api.TopicMetadata)

Aggregations

ZkSerializer (org.I0Itec.zkclient.serialize.ZkSerializer)2 TopicMetadata (kafka.api.TopicMetadata)1 ZkClient (org.I0Itec.zkclient.ZkClient)1 ZkMarshallingError (org.I0Itec.zkclient.exception.ZkMarshallingError)1 SerializableSerializer (org.I0Itec.zkclient.serialize.SerializableSerializer)1