All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.logicbus.service.ServiceReload Maven / Gradle / Ivy

There is a newer version: 1.6.16
Show newest version
package com.logicbus.service;

import java.util.HashMap;
import java.util.Map;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import com.anysoft.util.Settings;
import com.logicbus.backend.AbstractServant;
import com.logicbus.backend.Context;
import com.logicbus.backend.ServantException;
import com.logicbus.backend.ServantFactory;
import com.logicbus.backend.ServantPool;
import com.logicbus.backend.message.JsonMessage;
import com.logicbus.backend.message.XMLMessage;
import com.logicbus.models.catalog.Path;
import com.logicbus.models.servant.ServantManager;
import com.logicbus.models.servant.ServiceDescription;

/**
 * 重载服务
 * 
 * 
* 重新装载服务,刷新服务配置.
* * 实现了一个内部核心服务,定义在/com/logicbus/service/servant.xml中,具体配置如下:
* * {@code * * } * *
* 本服务需要客户端传送参数,包括:
* - service 要查询的服务ID,本参数属于必选项
* * 本服务属于系统核心管理服务,内置了快捷访问,在其他服务的URL中加上reload参数即可直接访问, * 例如:要暂停/demo/logicbus/Helloworld服务,可输入URL为:
* {@code * http://[host]:[port]/[webcontext]/services/demo/logicbus/Helloworld?reload * } *
* 如果配置在服务器中,访问地址为:
* {@code * http://[host]:[port]/[webcontext]/services/core/ServiceReload?service=[服务ID] * } * * @author duanyy * @version 1.2.6 [20140807 duanyy]
* - ServantPool和ServantFactory插件化 * * @version 1.2.8.2 [20141014 duanyy]
* - 支持双协议:XML,JSON
* * @version 1.4.0 [20141117 duanyy]
* - 将MessageDoc和Context进行合并整合
*/ public class ServiceReload extends AbstractServant { protected void onDestroy() { } protected void onCreate(ServiceDescription sd) throws ServantException { } protected int onXml(Context ctx) throws Exception { XMLMessage msg = (XMLMessage)ctx.asMessage(XMLMessage.class); String id = ctx.GetValue("service", ""); if (id == null || id.length() <= 0) { throw new ServantException("client.args_not_found", "Can not find parameter:service"); } Path path = new Path(id); ServantManager sm = ServantManager.get(); ServiceDescription sd = sm.get(path); if (sd == null){ throw new ServantException("user.data_not_found","Service does not exist:" + id); } Element root = msg.getRoot(); Document doc = root.getOwnerDocument(); Element service = doc.createElement("service"); sd.report(service); Settings settings = Settings.get(); ServantFactory sf = (ServantFactory)settings.get("servantFactory"); ServantPool pool = sf.getPool(path); if (pool != null) { pool.reload(sd); pool.report(service); } root.appendChild(service); return 0; } protected int onJson(Context ctx) throws Exception { JsonMessage msg = (JsonMessage)ctx.asMessage(JsonMessage.class); String id = getArgument("service", ctx); Path path = new Path(id); ServantManager sm = ServantManager.get(); ServiceDescription sd = sm.get(path); if (sd == null){ throw new ServantException("user.data_not_found","Service does not exist:" + id); } Map root = msg.getRoot(); Map service = new HashMap(); sd.report(service); //关联服务的实时统计信息 Settings settings = Settings.get(); ServantFactory sf = (ServantFactory)settings.get("servantFactory"); ServantPool pool = sf.getPool(path); if (pool != null) { pool.reload(sd); pool.report(service); } root.put("service", service); return 0; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy