001/* 002 * (C) Copyright 2006-2016 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * 017 * Contributors: 018 * anechaev 019 */ 020package org.nuxeo.ecm.platform.importer.mqueues.kafka; 021 022import org.nuxeo.common.xmap.annotation.XNode; 023import org.nuxeo.common.xmap.annotation.XNodeMap; 024import org.nuxeo.common.xmap.annotation.XObject; 025 026import java.util.Properties; 027 028@XObject("kafkaConfig") 029public class KafkaConfigDescriptor { 030 private static final String RANDOM_TOPIC_PREFIX = "RANDOM()"; 031 032 @XNode("@name") 033 public String name; 034 035 @XNode("@zkServers") 036 public String zkServers; 037 038 @XNode("@topicPrefix") 039 public String topicPrefix; 040 041 @XNode("producerProperties") 042 protected ProducerProperties producerProperties; 043 044 @XNode("consumerProperties") 045 protected ConsumerProperties consumerProperties; 046 047 048 public Properties getProducerProperties() { 049 if (producerProperties == null) { 050 return new Properties(); 051 } 052 return producerProperties.properties; 053 } 054 055 public Properties getConsumerProperties() { 056 if (consumerProperties == null) { 057 return new Properties(); 058 } 059 return consumerProperties.properties; 060 } 061 062 public String getTopicPrefix() { 063 if (topicPrefix == null) { 064 return ""; 065 } 066 if (RANDOM_TOPIC_PREFIX.equals(topicPrefix)) { 067 topicPrefix = "nuxeo-test-" + System.currentTimeMillis() + "-"; 068 } 069 return topicPrefix; 070 } 071 072 @XObject("producerProperties") 073 public static class ProducerProperties { 074 @XNodeMap(value = "property", key = "@name", type = Properties.class, componentType = String.class) 075 protected Properties properties = new Properties(); 076 } 077 078 @XObject("consumerProperties") 079 public static class ConsumerProperties { 080 @XNodeMap(value = "property", key = "@name", type = Properties.class, componentType = String.class) 081 protected Properties properties = new Properties(); 082 } 083}