bshloglistener.java
来自「java pos,你可以直接编译运行,」· Java 代码 · 共 320 行 · 第 1/2 页
JAVA
320 行
ret[i] = buff.toString(); } return ret; } public LogEvent log(org.jpos.util.LogEvent ev) { LogEvent ret = ev; boolean processed = false; try{ String[] sources = replace(cfg.getAll("source"), patterns, new String[] {ev.tag, ev.getRealm()}); for(int i=0; i<sources.length && ret != null; i++){ try{ Interpreter bsh = new Interpreter(); BSHLogListener.ScriptInfo info = getScriptInfo(sources[i]); NameSpace ns = (info!=null)?info.getNameSpace():null; if(ns!=null) bsh.setNameSpace(ns); bsh.set("event", ret); bsh.set("cfg", cfg); File f = new File(sources[i]); if(!cfg.getBoolean("preload-scripts")){ if(f.exists() && f.canRead() && f.isFile()){ //if(f.lastModified()) processed = true; bsh.eval(new java.io.FileReader(f)); } }else{ if(info == null) scripts.put(sources[i], info=new ScriptInfo()); String code; if(System.currentTimeMillis() > info.getLastCheck() + cfg.getLong("reload")){ info.setLastCheck(System.currentTimeMillis()); if(f.exists() && f.canRead() && f.isFile()){ if(info.getLastModified() != f.lastModified()) { info.setLastModified(f.lastModified()); info.setCode(loadCode(f)); } }else{ info.setCode(null); } } if(info.getCode() != null){ processed = true; bsh.eval(new StringReader(info.getCode())); }else scripts.remove(sources[i]); } ret = (LogEvent)bsh.get("event"); Object saveNS = bsh.get("saveNameSpace"); boolean saveNameSpace = (saveNS instanceof Boolean)?((Boolean)saveNS).booleanValue():cfg.getBoolean("save-name-space"); if(saveNameSpace) { if(info!=null) info.setNameSpace(bsh.getNameSpace()); else scripts.put(sources[i], new ScriptInfo(bsh.getNameSpace())); }else if (info!=null) info.setNameSpace(null); }catch(Exception e){ ret.addMessage(e); } } return (!processed && cfg.getBoolean("filter-by-default"))?null:ret; }catch(Exception e){ ret.addMessage(e); return ret; } } protected String loadCode(File f) throws IOException{ FileReader r = new FileReader(f); StringBuffer buf = new StringBuffer((int)f.length()); char[] content = new char[(int)f.length()]; int l; while((l=r.read(content))!=-1) buf.append(content,0,l); return buf.toString(); } protected ScriptInfo getScriptInfo(String filename){ return (ScriptInfo)scripts.get(filename); } protected void addScriptInfo(String filename, String code, long lastModified){ scripts.put(filename, new ScriptInfo(code, lastModified)); } protected class ScriptInfo{ String code; long lastModified; long lastCheck; NameSpace nameSpace; public ScriptInfo(){ } public ScriptInfo(NameSpace ns){ nameSpace = ns; } public ScriptInfo(String code, long lastModified){ setCode(code); setLastModified(lastModified); } /** Getter for property code. * @return Value of property code. * */ public java.lang.String getCode() { return code; } /** Setter for property code. * @param code New value of property code. * */ public void setCode(java.lang.String code) { this.code = code; } /** Getter for property lastModified. * @return Value of property lastModified. * */ public long getLastModified() { return lastModified; } /** Setter for property lastModified. * @param lastModified New value of property lastModified. * */ public void setLastModified(long lastModified) { this.lastModified = lastModified; } /** Getter for property lastCheck. * @return Value of property lastCheck. * */ public long getLastCheck() { return lastCheck; } /** Setter for property lastCheck. * @param lastCheck New value of property lastCheck. * */ public void setLastCheck(long lastCheck) { this.lastCheck = lastCheck; } /** Getter for property nameSpace. * @return Value of property nameSpace. * */ public NameSpace getNameSpace() { return nameSpace; } /** Setter for property nameSpace. * @param nameSpace New value of property nameSpace. * */ public void setNameSpace(NameSpace nameSpace) { this.nameSpace = nameSpace; } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?