AdminBrokerProcessor#processRequest#getBrokerConfig
private RemotingCommand getBrokerConfig(ChannelHandlerContext ctx, RemotingCommand request) {
final RemotingCommand response = RemotingCommand.createResponseCommand(GetBrokerConfigResponseHeader.class);
final GetBrokerConfigResponseHeader responseHeader = (GetBrokerConfigResponseHeader) response.readCustomHeader();
//获取所有的broker配置
String content = this.brokerController.getConfiguration().getAllConfigsFormatString();
if (content != null && content.length() > 0) {
try {
response.setBody(content.getBytes(MixAll.DEFAULT_CHARSET));
} catch (UnsupportedEncodingException e) {
log.error("", e);
response.setCode(ResponseCode.SYSTEM_ERROR);
response.setRemark("UnsupportedEncodingException " + e);
return response;
}
}
responseHeader.setVersion(this.brokerController.getConfiguration().getDataVersionJson());
response.setCode(ResponseCode.SUCCESS);
response.setRemark(null);
return response;
}
Configuration#getAllConfigsFormatString
this.brokerController.getConfiguration().getAllConfigsFormatString();
public String getAllConfigsFormatString() {
try {
readWriteLock.readLock().lockInterruptibly();
try {
return getAllConfigsInternal();
} finally {
readWriteLock.readLock().unlock();
}
} catch (InterruptedException e) {
log.error("getAllConfigsFormatString lock error");
}
return null;
}
Configuration#getAllConfigsInternal()
private String getAllConfigsInternal() {
StringBuilder stringBuilder = new StringBuilder();
// reload from config object ?
//将所有的configObjectList中配置放进allConfigs
for (Object configObject : this.configObjectList) {
Properties properties = MixAll.object2Properties(configObject);
if (properties != null) {
merge(properties, this.allConfigs);
} else {
log.warn("getAllConfigsInternal object2Properties is null, {}", configObject.getClass());
}
}
{
// 将所有allConfigs中配置放入stringBuilder
stringBuilder.append(MixAll.properties2String(this.allConfigs));
}
return stringBuilder.toString();
}
在更新broker配置时也曾调用getAllConfigsInternal方法获取所有的broker配置,用于将所有配置持久化到配置文件。