gu.simplemq.MQProperties Maven / Gradle / Ivy
The newest version!
package gu.simplemq;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.EnumMap;
import java.util.Enumeration;
import java.util.Map;
import java.util.Properties;
import com.google.common.net.HostAndPort;
/**
* activemq连接参数配置对象
* @author guyadong
*
*/
public abstract class MQProperties extends Properties{
private static final long serialVersionUID = 1L;
private MQPropertiesHelper helper = getPropertiesHelper();
private MQConstProvider constProvider = helper.getConstProvider();
public MQProperties() {
super();
}
public MQProperties(Properties defaults) {
super(defaults);
}
public abstract MQPropertiesHelper getPropertiesHelper();
/**
* 对参数(props)中的服务地址归一化
* @return always props,确保{@code ACON_BROKER_URL}有定义
*/
public MQProperties normalizeLocation(){
return helper.normalizeLocation(this);
}
public String getLocationAsString(){
return helper.getLocationAsString(this);
}
public URI getLocation(){
return helper.getLocation(this);
}
public HostAndPort getHostAndPort(){
return helper.getHostAndPort(this);
}
/**
* 初始化 uri
* @param uri 不可为{@code null}
*/
public MQProperties initURI(URI uri) {
setProperty(constProvider.getMainLocationName(),checkNotNull(uri,"uri is null").toString());
return this;
}
/**
* 初始化 uri
* @param uri 不可为{@code null}
*/
public MQProperties initURI(String uri) {
setProperty(constProvider.getMainLocationName(),checkNotNull(uri,"uri is null"));
return this;
}
/**
* 初始化 ActiveMQ 参数
* @param map ActiveMQ 参数,不可为{@code null}
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public MQProperties init(Map map){
clear();
if(map instanceof Properties){
Properties props = (Properties)map;
for(Enumeration> itor = props.propertyNames();itor.hasMoreElements();){
String key = (String) itor.nextElement();
put(key, props.get(key).toString());
}
}else if(null != map){
putAll(map);
}
return this;
}
public MQProperties with(MQLocationType type) {
helper.with(type);
return this;
}
public > EnumMap asEnumMap(
Class keyType,
boolean removeIfSet,
String strippedPrefix){
return helper.asEnumMap(keyType, this, removeIfSet, strippedPrefix);
}
public > EnumMap asEnumMap(
Class keyType){
return asEnumMap(keyType, false, null);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy