标签:oid final vat pac 不同的 ESS spro lstat inter
interface Product {
void otherMethods();
}
class ConcreteProductA implements Product {
@Override
public void otherMethods() {
// do something
}
}
class ConcreteProductB implements Product {
@Override
public void otherMethods() {
// do something
}
}
interface Factory {
Product createProduct();
}
class ConcreteProductAFactory implements Factory {
@Override
public Product createProduct() {
return new ConcreteProductA();
}
}
class ConcreteProductBFactory implements Factory {
@Override
public Product createProduct() {
return new ConcreteProductB();
}
}
interface Factory {
Product createProduct();
Product createProduct(String name);
Product createProduct(Object obj);
}
abstract class Factory {
public abstract Product createProduct();
public void otherMethods() {
createProduct().otherMethods();
}
}
@SPI("dubbo")
public interface RegistryFactory {
@Adaptive({"protocol"})
Registry getRegistry(URL url);
}
public class NacosRegistryFactory extends AbstractRegistryFactory {
private final Logger logger = LoggerFactory.getLogger(getClass());
protected Registry createRegistry(URL url) {
return new NacosRegistry(url, buildNamingService(url));
}
private NamingService buildNamingService(URL url) {
Properties nacosProperties = buildNacosProperties(url);
NamingService namingService = null;
try {
namingService = NacosFactory.createNamingService(nacosProperties);
} catch (NacosException e) {
if (logger.isErrorEnabled()) {
logger.error(e.getErrMsg(), e);
}
throw new IllegalStateException(e);
}
return namingService;
}
private Properties buildNacosProperties(URL url) {
Properties properties = new Properties();
setServerAddr(url, properties);
setProperties(url, properties);
return properties;
}
private void setServerAddr(URL url, Properties properties) {
StringBuilder serverAddrBuilder =
new StringBuilder(url.getHost()) // Host
.append(":")
.append(url.getPort()); // Port
// Append backup parameter as other servers
String backup = url.getParameter(BACKUP_KEY);
if (backup != null) {
serverAddrBuilder.append(",").append(backup);
}
String serverAddr = serverAddrBuilder.toString();
properties.put(SERVER_ADDR, serverAddr);
}
private void setProperties(URL url, Properties properties) {
putPropertyIfAbsent(url, properties, NAMESPACE);
putPropertyIfAbsent(url, properties, NACOS_NAMING_LOG_NAME);
putPropertyIfAbsent(url, properties, ENDPOINT);
putPropertyIfAbsent(url, properties, ACCESS_KEY);
putPropertyIfAbsent(url, properties, SECRET_KEY);
putPropertyIfAbsent(url, properties, CLUSTER_NAME);
}
private void putPropertyIfAbsent(URL url, Properties properties, String propertyName) {
String propertyValue = url.getParameter(propertyName);
if (StringUtils.isNotEmpty(propertyValue)) {
properties.setProperty(propertyName, propertyValue);
}
}
}
public class RedisRegistryFactory extends AbstractRegistryFactory {
@Override
protected Registry createRegistry(URL url) {
return new RedisRegistry(url);
}
}
标签:oid final vat pac 不同的 ESS spro lstat inter
原文地址:https://www.cnblogs.com/zby9527/p/13287326.html