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.runtime.kafka; 021 022import java.util.Properties; 023 024import org.nuxeo.common.xmap.annotation.XNode; 025import org.nuxeo.common.xmap.annotation.XNodeMap; 026import org.nuxeo.common.xmap.annotation.XObject; 027 028@SuppressWarnings("CanBeFinal") 029@XObject("kafkaConfig") 030public class KafkaConfigDescriptor { 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("@randomPrefix") 042 public Boolean randomPrefix = Boolean.FALSE; 043 044 @XNode("producer") 045 protected ProducerProperties producerProperties; 046 047 @XNode("consumer") 048 protected ConsumerProperties consumerProperties; 049 050 public Properties getProducerProperties() { 051 if (producerProperties == null) { 052 return new Properties(); 053 } 054 return producerProperties.properties; 055 } 056 057 public Properties getConsumerProperties() { 058 if (consumerProperties == null) { 059 return new Properties(); 060 } 061 return consumerProperties.properties; 062 } 063 064 public String getTopicPrefix() { 065 String ret = (topicPrefix == null) ? "" : topicPrefix; 066 if (randomPrefix) { 067 ret += System.currentTimeMillis() + "-"; 068 } 069 return ret; 070 } 071 072 @XObject("producer") 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("consumer") 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}