📄 xlobexpressionstore.java
字号:
/* * Copyright (c) 2005, John Mettraux, OpenWFE.org * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * . Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * . Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * . Neither the name of the "OpenWFE" nor the names of its contributors may be * used to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * $Id: XlobExpressionStore.java,v 1.3 2005/07/17 16:31:50 jmettraux Exp $ *///// XlobExpressionStore.java//// jmettraux@openwfe.org//// generated with // jtmpl 1.1.00 16.08.2003 John Mettraux (jmettraux@openwfe.org)//package openwfe.org.xlob.engine;import openwfe.org.ServiceException;import openwfe.org.ApplicationContext;import openwfe.org.xml.XmlUtils;import openwfe.org.engine.expool.PoolException;import openwfe.org.engine.impl.expool.AbstractExpressionStore;import openwfe.org.engine.expressions.ReplyException;import openwfe.org.engine.expressions.FlowExpression;import openwfe.org.engine.expressions.FlowExpressionId;import openwfe.org.engine.expressions.ExpressionWithTimeOut;import openwfe.org.xlob.XlobSession;import openwfe.org.xlob.XlobException;/** * Storing expressions through Xlob * * <p><font size=2>CVS Info : * <br>$Author: jmettraux $ * <br>$Id: XlobExpressionStore.java,v 1.3 2005/07/17 16:31:50 jmettraux Exp $ </font> * * @author john.mettraux@openwfe.org */public class XlobExpressionStore extends AbstractExpressionStore{ private final static org.apache.log4j.Logger log = org.apache.log4j.Logger .getLogger(XlobExpressionStore.class.getName()); // // CONSTANTS & co /* * * This prefix is appended at the beginning of each xdbc clientId : * if the xdbc set of SQL tables is used by other applications / components * it will be easier to fetch expressions : their clientId should all * begin with 'owfe_exp' * / public final static String EXP_PREFIX = "owfe_exp"; */ // // FIELDS private XlobSession xlobSession = null; // // CONSTRUCTORS public void init (final String serviceName, final ApplicationContext context, final java.util.Map serviceParams) throws ServiceException { super.init(serviceName, context, serviceParams); // // create xdbc session this.xlobSession = openwfe.org.xlob.XlobSessionImpl .createSession(getContext(), getParams()); } // // METHODS from ExpressionStore /** * stores the expression */ public void storeExpression (final FlowExpression fe) throws PoolException { long start = System.currentTimeMillis(); final Object monitor = getMonitorMap().getMonitor(fe.getId()); log.debug ("storeExpression() >in> monitor "+monitor+" for "+fe.getId()); synchronized (monitor) { try { this.xlobSession.storeBean(fe.getId(), fe); } catch (final XlobException xe) { throw new PoolException("storage failure", xe); } } log.debug ("storeExpression() <out< monitor "+monitor+" for "+fe.getId()); long duration = System.currentTimeMillis() - start; log.debug("storing the expression took "+duration+" ms"); } /** * removes an expression from the store */ public void unstoreExpression (final FlowExpression fe) throws PoolException { final Object monitor = getMonitorMap().getMonitor(fe.getId()); log.debug ("unstoreExpression() >in> monitor "+monitor+" for "+fe.getId()); synchronized (monitor) { try { this.xlobSession.remove(fe.getId()); } catch (final XlobException xe) { throw new PoolException ("Failed to remove expression from xlob store", xe); } } log.debug ("unstoreExpression() <out< monitor "+monitor+" for "+fe.getId()); } /** * loads expression from the store */ public FlowExpression loadExpression (final FlowExpressionId fei) throws PoolException { try { final FlowExpression fe = (FlowExpression)this.xlobSession.findBean(fei); fe.setApplicationContext(getContext()); return fe; } catch (final XlobException xe) { throw new PoolException ("load failure", xe); } } /** * returns true if the expression behind the expression id is still * alive (present in the store). */ public boolean isExpressionActive (final FlowExpressionId fei) { try { return (this.xlobSession.count(fei) > 0); } catch (final XlobException xe) { log.warn("isExpressionActive() failure", xe); } return false; } // // METHODS /** * Iterates over all the expression stored and returns the one of the * given 'assignClass'. * If null is passwed as assignClass, it will return all the expressions. */ public java.util.Iterator contentIterator (final Class assignClass) { java.util.Set result = new java.util.HashSet(); try { final String[] expressionShortNames = determineExpressionShortNames(assignClass); if (expressionShortNames == null) log.debug("contentIterator() esn : null"); else log.debug("contentIterator() esn.length : "+expressionShortNames.length); if (expressionShortNames != null && expressionShortNames.length > 0) { for (int i=0; i<expressionShortNames.length; i++) { final FlowExpressionId criterion = new FlowExpressionId(); criterion.setExpressionName(expressionShortNames[i]); fetchExpressions(criterion, result); } } else { fetchExpressions(null, result); } } catch (final Throwable t) { log.warn("contentIterator() failure", t); return null; } return result.iterator(); } /* * Used by contentIterator(). */ private void fetchExpressions (final FlowExpressionId criterion, final java.util.Set result) throws XlobException { final java.util.Set expressions = this.xlobSession.queryBeans(criterion); final java.util.Iterator it = expressions.iterator(); while (it.hasNext()) { final FlowExpression fe = (FlowExpression)it.next(); fe.setApplicationContext(getContext()); result.add(fe); } } /** * Returns how many expressions are stored in this ExpressionStore * implementation. */ public int size () { try { return this.xlobSession.count(null); } catch (final XlobException xe) { log.warn("size() count failure", xe); } return -1; } // // METHODS from Service /** * Status is outputted as a JDOM element. The status is various * information about a service activities and state. */ public org.jdom.Element getStatus () { org.jdom.Element result = new org.jdom.Element(getName()); result.addContent(XmlUtils.getClassElt(this)); result.addContent(XmlUtils.getRevisionElt("$Id: XlobExpressionStore.java,v 1.3 2005/07/17 16:31:50 jmettraux Exp $")); org.jdom.Element eTotalExpressionCount = new org.jdom.Element("expressionsStored"); eTotalExpressionCount.addContent (new org.jdom.Text(""+this.size())); result.addContent(eTotalExpressionCount); /* // // count expressions per flow instance java.util.List l = null; try { l = this.xdbcSession.listClientIds(EXP_PREFIX+" %"); } catch (XdbcException xe) { log.warn ("Failed to count expressions per flow instance "+ "for getStatus()", xe); return result; } java.util.Map expressionsPerFlow = new java.util.HashMap(); java.util.Map expressionsPerInstance = new java.util.HashMap(); java.util.Iterator it = l.iterator(); while (it.hasNext()) { String clientId = (String)it.next(); clientId = clientId.substring(EXP_PREFIX.length()+1); int i = clientId.lastIndexOf(" "); clientId = clientId.substring(0, i); i = clientId.lastIndexOf(" "); clientId = clientId.substring(0, i); //log.debug("taking into account >"+clientId+"<"); openwfe.org.Utils.inc(expressionsPerInstance, clientId); i = clientId.lastIndexOf(" "); clientId = clientId.substring(0, i); openwfe.org.Utils.inc(expressionsPerFlow, clientId); } org.jdom.Element eFlows = new org.jdom.Element("flows"); it = expressionsPerFlow.keySet().iterator(); while (it.hasNext()) { String flowDef = (String)it.next(); Integer count = (Integer)expressionsPerFlow.get(flowDef); org.jdom.Element eFlow = new org.jdom.Element("flow"); eFlow.setAttribute("def", flowDef); eFlow.setAttribute("expressions", count.toString()); eFlows.addContent(eFlow); } it = expressionsPerInstance.keySet().iterator(); while (it.hasNext()) { String flowId = (String)it.next(); Integer count = (Integer)expressionsPerInstance.get(flowId); org.jdom.Element eFlow = new org.jdom.Element("flow"); eFlow.setAttribute("id", flowId); eFlow.setAttribute("expressions", count.toString()); eFlows.addContent(eFlow); } result.addContent(eFlows); */ // // the end return result; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -