use of app.hongs.Core in project HongsCORE by ihongs.
the class Data method getInstance.
/**
* 获取实例
* 生命周期将交由 Core 维护
* @param conf
* @param form
* @return
* @throws HongsException
*/
public static Data getInstance(String conf, String form) throws HongsException {
Data inst;
Core core = Core.getInstance();
String name = Data.class.getName() + ":" + conf + ":" + form;
if (core.containsKey(name)) {
inst = (Data) core.got(name);
} else {
inst = new Data(conf, form);
core.put(name, inst);
}
return inst;
}
use of app.hongs.Core in project HongsCORE by ihongs.
the class ActionDriver method destroy.
/**
* 公共销毁
*/
@Override
public void destroy() {
if (!INIT) {
return;
}
if (0 < Core.DEBUG && 8 != (8 & Core.DEBUG)) {
Core core = Core.GLOBAL_CORE;
long time = System.currentTimeMillis() - Core.STARTS_TIME;
CoreLogger.debug(new StringBuilder("...").append("\r\n\tSERVER_ID : ").append(Core.SERVER_ID).append("\r\n\tObjects : ").append(core.toString()).append("\r\n\tRuntime : ").append(Tool.humanTime(time)).toString());
}
try {
Core.GLOBAL_CORE.close();
} catch (Throwable e) {
CoreLogger.error(e);
}
}
use of app.hongs.Core in project HongsCORE by ihongs.
the class ActionDriver method doDriver.
final void doDriver(ServletRequest rep, ServletResponse rsp, final DriverProxy agt) throws ServletException, IOException {
HttpServletRequest req = (HttpServletRequest) rep;
HttpServletResponse rsq = (HttpServletResponse) rsp;
ActionHelper hlpr;
Core core = (Core) req.getAttribute(Core.class.getName());
if (core == null) {
/**
* 外层调用
*/
core = Core.getInstance();
req.setAttribute(Core.class.getName(), core);
hlpr = new ActionHelper(req, rsq);
core.put(ActionHelper.class.getName(), hlpr);
try {
doLaunch(core, hlpr, req, rsq);
agt.doDriver(core, hlpr);
doCommit(core, hlpr, req, rsq);
} catch (IOException ex) {
CoreLogger.error(ex);
} catch (ServletException ex) {
CoreLogger.error(ex);
} catch (RuntimeException ex) {
CoreLogger.error(ex);
} catch (Error er) {
CoreLogger.error(er);
} finally {
doFinish(core, hlpr, req);
}
} else {
/**
* 内层调用
*/
Core.THREAD_CORE.set(core);
hlpr = core.get(ActionHelper.class);
hlpr.updateHelper(req, rsq);
/**/
agt.doDriver(core, hlpr);
}
}
use of app.hongs.Core in project HongsCORE by ihongs.
the class ActionDriver method doFinish.
private void doFinish(Core core, ActionHelper hlpr, HttpServletRequest req) {
try {
if (0 < Core.DEBUG && 8 != (8 & Core.DEBUG)) {
/**
* 提取必要的客户相关标识
* 以便判断用户和模拟登录
*/
req = hlpr.getRequest();
HttpSession ses = req.getSession(false);
Object uid = hlpr.getSessibute(Cnst.UID_SES);
String mem;
if (ses == null) {
mem = "-";
} else {
mem = ses.getId();
}
if (uid != null) {
mem += " " + uid;
}
long time = System.currentTimeMillis() - Core.ACTION_TIME.get();
StringBuilder sb = new StringBuilder("...");
sb.append("\r\n\tACTION_NAME : ").append(Core.ACTION_NAME.get()).append("\r\n\tACTION_TIME : ").append(Core.ACTION_TIME.get()).append("\r\n\tACTION_LANG : ").append(Core.ACTION_LANG.get()).append("\r\n\tACTION_ZONE : ").append(Core.ACTION_ZONE.get()).append("\r\n\tMethod : ").append(req.getMethod()).append("\r\n\tMember : ").append(mem).append("\r\n\tObjects : ").append(core.toString()).append("\r\n\tRuntime : ").append(Tool.humanTime(time));
/**
* 显示请求报头及输入输出
* 这对调试程序非常有帮助
*/
CoreConfig cf = CoreConfig.getInstance();
if (cf.getProperty("core.debug.action.request", false)) {
Map rd = null;
try {
rd = hlpr.getRequestData();
} catch (HongsExpedient ex) {
CoreLogger.debug(ex.getMessage());
}
if (rd != null && !rd.isEmpty()) {
sb.append("\r\n\tRequest : ").append(Tool.indent(Data.toString(rd)).substring(1));
}
}
if (cf.getProperty("core.debug.action.results", false)) {
Map xd = hlpr.getResponseData();
if (xd == null) {
xd = (Map) req.getAttribute(Cnst.RESP_ATTR);
}
if (xd != null && !xd.isEmpty()) {
sb.append("\r\n\tResults : ").append(Tool.indent(Data.toString(xd)).substring(1));
}
}
if (cf.getProperty("core.debug.action.session", false) && ses != null) {
Map map = new HashMap();
Enumeration<String> nms = ses.getAttributeNames();
while (nms.hasMoreElements()) {
String nme = nms.nextElement();
map.put(nme, ses.getAttribute(nme));
}
if (!map.isEmpty()) {
sb.append("\r\n\tSession : ").append(Tool.indent(Data.toString(map)).substring(1));
}
}
if (cf.getProperty("core.debug.action.context", false)) {
Map map = new HashMap();
Enumeration<String> nms = req.getAttributeNames();
while (nms.hasMoreElements()) {
String nme = nms.nextElement();
map.put(nme, req.getAttribute(nme));
}
if (!map.isEmpty()) {
sb.append("\r\n\tContext : ").append(Tool.indent(Data.toString(map)).substring(1));
}
}
if (cf.getProperty("core.debug.action.headers", false)) {
Map map = new HashMap();
Enumeration<String> nms = req.getHeaderNames();
while (nms.hasMoreElements()) {
String nme = nms.nextElement();
map.put(nme, req.getHeader(nme));
}
if (!map.isEmpty()) {
sb.append("\r\n\tHeaders : ").append(Tool.indent(Data.toString(map)).substring(1));
}
}
if (cf.getProperty("core.debug.action.cookies", false)) {
Map map = new HashMap();
Cookie[] cks = req.getCookies();
for (Cookie cke : cks) {
map.put(cke.getName(), cke.getValue());
}
if (!map.isEmpty()) {
sb.append("\r\n\tCookies : ").append(Tool.indent(Data.toString(map)).substring(1));
}
}
CoreLogger.debug(sb.toString());
}
// 删除上传的临时文件
Map<String, List<Part>> ud = Synt.asMap(hlpr.getAttribute(Cnst.UPLOAD_ATTR));
if (ud != null) {
for (List<Part> pa : ud.values()) {
for (Part pr : pa) {
try {
pr.delete();
} catch (IOException ex) {
CoreLogger.error(ex);
}
}
}
}
} finally {
// 销毁此周期内的对象
try {
core.close();
} catch (Error e) {
CoreLogger.error(e);
} catch (Exception e) {
CoreLogger.error(e);
}
req.removeAttribute(Core.class.getName());
Core.THREAD_CORE.remove();
Core.ACTION_TIME.remove();
Core.ACTION_ZONE.remove();
Core.ACTION_LANG.remove();
Core.ACTION_NAME.remove();
}
}
use of app.hongs.Core in project HongsCORE by ihongs.
the class LuceneRecord method getInstance.
/**
* 获取实例
* 存储为 conf/form 表单为 conf.form
* 表单缺失则尝试获取 conf/form.form
* 实例生命周期将交由 Core 维护
* @param conf
* @param form
* @return
* @throws HongsException
*/
public static LuceneRecord getInstance(String conf, String form) throws HongsException {
String code = LuceneRecord.class.getName() + ":" + conf + "." + form;
Core core = Core.getInstance();
if (!core.containsKey(code)) {
String path = conf + "/" + form;
String name = conf + "." + form;
String cxnf = FormSet.hasConfFile(path) ? path : conf;
Map fxrm = FormSet.getInstance(cxnf).getForm(form);
// 表单配置中可指定数据路径
Map c = (Map) fxrm.get("@");
if (c != null) {
String p;
p = (String) c.get("data-path");
if (null != p && 0 < p.length()) {
path = p;
}
p = (String) c.get("data-name");
if (null != p && 0 < p.length()) {
name = p;
}
}
LuceneRecord inst = new LuceneRecord(fxrm, path, name);
core.put(code, inst);
return inst;
} else {
return (LuceneRecord) core.got(code);
}
}
Aggregations