use of j.nvwa.NvwaObject in project JFramework by gugumall.
the class ServiceContainer method startup.
/**
* 启动服务
* @param serviceConfig
* @throws Exception
*/
protected synchronized void startup() throws Exception {
NvwaObject nvwaObject = Nvwa.entrust(serviceConfig.getRelatedHttpHandlerPath(), serviceConfig.getClassName(), true);
nvwaObject.setFiled("serviceConfig", "value", true);
String[] fieldsKeep = serviceConfig.getFieldsKeep();
for (int i = 0; fieldsKeep != null && i < fieldsKeep.length; i++) {
nvwaObject.setFiled(fieldsKeep[i], "value", true);
}
createServant();
Thread thread = new Thread(this);
thread.start();
setStarted(true);
log.log("service " + serviceConfig.getUuid() + " started.", -1);
}
use of j.nvwa.NvwaObject in project JFramework by gugumall.
the class RouterManager method load.
/**
*/
public static void load() {
try {
loading = true;
List currentRouters = new LinkedList();
// 文件是否存在
File file = new File(Properties.getConfigPath() + "service.router.xml");
if (!file.exists()) {
throw new Exception("找不到配置文件:" + file.getAbsolutePath());
}
Document document = JUtilDom4j.parse(Properties.getConfigPath() + "service.router.xml", "UTF-8");
Element root = document.getRootElement();
List routerEles = root.elements("router");
for (int i = 0; i < routerEles.size(); i++) {
Element routerEle = (Element) routerEles.get(i);
RouterConfig config = new RouterConfig();
config.setServerUuid(routerEle.attributeValue("server-uuid"));
config.setUuid(routerEle.elementText("uuid"));
config.setName(routerEle.elementText("name"));
config.setPrivacy(routerEle.elementText("privacy"));
List routerProps = routerEle.elements("property");
for (int j = 0; j < routerProps.size(); j++) {
Element pEle = (Element) routerProps.get(j);
config.addConfig(pEle.attributeValue("key"), pEle.attributeValue("value"));
}
Element rmiEle = routerEle.element("rmi");
if (rmiEle != null && "true".equalsIgnoreCase(rmiEle.attributeValue("available"))) {
Rmi rmi = new Rmi(Properties.getProperties("rmi"));
List props = rmiEle.elements("property");
for (int j = 0; j < props.size(); j++) {
Element pEle = (Element) props.get(j);
rmi.addConfig(pEle.attributeValue("key"), pEle.attributeValue("value"));
}
config.setRmi(rmi);
}
Element httpEle = routerEle.element("http");
if (httpEle != null && "true".equalsIgnoreCase(httpEle.attributeValue("available"))) {
Http http = new Http();
List props = httpEle.elements("property");
for (int j = 0; j < props.size(); j++) {
Element pEle = (Element) props.get(j);
http.addConfig(pEle.attributeValue("key"), pEle.attributeValue("value"));
}
config.setHttp(http);
}
List clients = root.elements("client");
for (int j = 0; j < clients.size(); j++) {
Element clientEle = (Element) clients.get(j);
Client client = new Client();
client.setUuid(clientEle.attributeValue("uuid"));
client.setName(clientEle.attributeValue("name"));
client.setKey(clientEle.attributeValue("key"));
config.addClient(client);
}
currentRouters.add(config);
}
root = null;
document = null;
// 停止已启动服务
List olds = routerConfigs.listValues();
for (int i = 0; i < olds.size(); i++) {
RouterConfig config = (RouterConfig) olds.get(i);
RouterContainer containter = (RouterContainer) routerContainers.get(config.getUuid());
if (containter != null && containter.getStarted()) {
containter.shutdown();
}
RouterAgent agent = (RouterAgent) agents.get(config.getUuid());
agent.shutdown();
}
JUtilList.clear_AllNull(olds);
routerConfigs.clear();
routerContainers.clear();
agents.clear();
uuidOfRouters.clear();
uuidOfRoutersAvailableHttp.clear();
// 处理最新服务
for (int i = 0; i < currentRouters.size(); i++) {
RouterConfig routerConfig = (RouterConfig) currentRouters.get(i);
routerConfigs.put(routerConfig.getUuid(), routerConfig);
uuidOfRouters.add(routerConfig.getUuid());
if (routerConfig.getServerUuid().equals(Manager.getRouterNodeUuid())) {
// 如果是路由节点,启动路由服务
// 托管至nvwa
NvwaObject nvwaObject = Nvwa.entrust(routerConfig.getRelatedHttpHandlerPath(), routerConfig.getClassName(), true);
nvwaObject.setFiled("routerConfig", "ref", true);
JRouter router = (JRouter) Nvwa.entrustCreate(routerConfig.getRelatedHttpHandlerPath(), routerConfig.getClassName(), true);
router.setRouterConfig(routerConfig);
RouterContainer container = new RouterContainer(routerConfig, router);
routerContainers.put(routerConfig.getUuid(), container);
container.startup();
}
// 启动路由代理
RouterAgent agent = new RouterAgent(routerConfig);
agents.put(routerConfig.getUuid(), agent);
agent.startup();
}
currentRouters.clear();
currentRouters = null;
// 处理最新服务 END
// 配置文件最近修改时间
File configFile = new File(Properties.getConfigPath() + "service.router.xml");
configLastModified = configFile.lastModified();
configFile = null;
loading = false;
} catch (Exception e) {
loading = false;
log.log(e, Logger.LEVEL_FATAL);
}
}
Aggregations