amoeba源码分析(一)-AmoebaProxyServer入口类分析 (四)

2014-11-24 11:45:01 · 作者: · 浏览: 42
et.getOutputStream().write(command.toByteBuffer(null).array());
socket.getOutputStream().flush();
PacketInputStream pis = new MonitorPacketInputStream();

byte[] message = pis.readPacket(socket.getInputStream());
MonitorCommandPacket response = new MonitorCommandPacket();
response.init(message, null);
if(response.funType == MonitorConstant.FUN_TYPE_OK){
System.out.println("remote application= "+ appplicationName+":"+port+" response OK");
}

socket.close();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}以上代码中:ConfigUtil.filter("${amoeba.home}") 指加载环境变量中key=amoeba.home的值。filter过滤掉${}后获取系统环境变量

2 log4j配置加载,主要对配置XML加载并解析处理。通过log4j的FileWatchdog实现配置动态更新加载。


[java]
String log4jConf = System.getProperty("log4j.conf","${amoeba.home}/conf/log4j.xml");
log4jConf = ConfigUtil.filter(log4jConf);
File logconf = new File(log4jConf);
if(logconf.exists() && logconf.isFile()){
DOMConfigurator.configureAndWatch(logconf.getAbsolutePath(), System.getProperties());
}

String log4jConf = System.getProperty("log4j.conf","${amoeba.home}/conf/log4j.xml");
log4jConf = ConfigUtil.filter(log4jConf);
File logconf = new File(log4jConf);
if(logconf.exists() && logconf.isFile()){
DOMConfigurator.configureAndWatch(logconf.getAbsolutePath(), System.getProperties());
}3 amoeba配置加载,用于加载amoeba.xml的系统配置

[java]
final Logger logger = Logger.getLogger(AmoebaProxyServer.class);
String config = System.getProperty("amoeba.conf","${amoeba.home}/conf/amoeba.xml");
String contextClass = System.getProperty("amoeba.context.class",ProxyRuntimeContext.class.getName());

if(contextClass != null){
//生成运行上下文环境对象
ProxyRuntimeContext context = (ProxyRuntimeContext)Class.forName(contextClass).newInstance();
ProxyRuntimeContext.setInstance(context);
}

config = ConfigUtil.filter(config);
File configFile = new File(config);

if(config == null || !configFile.exists()){
logger.error("could not find config file:"+configFile.getAbsolutePath());
System.exit(-1);
}else{
//通过配置文件初始化上下文环境对象
ProxyRuntimeContext.getInstance().init(configFile.getAbsolutePath());
}
//注册到报告列表中
registerReporter(ProxyRuntimeContext.getInstance());
for(ConnectionManager connMgr :ProxyRuntimeContext.getInstance().getConnectionManagerList().values()){
registerReporter(connMgr);
}

final Logger logger = Logger.getLogger(AmoebaProxyServer.class);
String config = System.getProperty("amoeba.conf","${amoeba.home}/conf/amoeba.xml");
String contextClass = System.getProperty("amoeba.context.class",ProxyRuntimeContext.class.getName());

if(contextClass != null){
//生成运行上下文环境对象
ProxyRuntimeContext context = (ProxyRuntimeContext)Class.forName(contextClass).newInstance();
ProxyRuntimeContext.setInstance(context);
}

config = ConfigUtil.filter(config);
File configFile = new File(config);

if(config == null || !configFile.exists()){
logger.error("could not find config file:"+configFile.getAbsolutePath());
System.exit(-1);
}else{
//通过配置文件初始化上下文环境对象
ProxyRuntimeContext.getInstance().init(configFile.getAbsolutePath());
}
//注册到报告列表中
registerReporte