XMLDeliveryCache arbeitet jetzt mit Strings statt XML-Elementen (verbessert Performance der Cache-Operationen)

git-svn-id: https://svn.libreccm.org/ccm/trunk@2155 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2013-05-28 15:36:34 +00:00
parent 023048dd16
commit ef794424de
3 changed files with 123 additions and 69 deletions

View File

@ -25,7 +25,7 @@ public final class XMLDeliveryCache {
*/ */
private CacheTable cache = new CacheTable(XMLDeliveryCache.class.getName(), private CacheTable cache = new CacheTable(XMLDeliveryCache.class.getName(),
CMSConfig.getInstance().getXmlCacheSize(), CMSConfig.getInstance().getXmlCacheSize(),
CMSConfig.getInstance().getXmlCacheSize(), CMSConfig.getInstance().getXmlCacheAge(),
true); true);
/** /**
* Maps from the OID of the master version of an item in the cache to the OID of the item in the cache. * Maps from the OID of the master version of an item in the cache to the OID of the item in the cache.
@ -127,14 +127,18 @@ public final class XMLDeliveryCache {
context)); context));
} }
Element cacheElem; //Element cacheElem;
String cached;
if (listMode) { if (listMode) {
cacheElem = cachedXml.getCachedXml(Mode.LIST_MODE); //cacheElem = cachedXml.getCachedXml(Mode.LIST_MODE);
cached = cachedXml.getCachedXml(Mode.LIST_MODE);
} else { } else {
cacheElem = cachedXml.getCachedXml(Mode.DEFAULT); //cacheElem = cachedXml.getCachedXml(Mode.DEFAULT);
cached = cachedXml.getCachedXml(Mode.LIST_MODE);
} }
if (cacheElem == null) { //if (cacheElem == null) {
if (cached == null) {
if (listMode) { if (listMode) {
throw new IllegalArgumentException(String.format( throw new IllegalArgumentException(String.format(
"The item with the OID '%s' is not cached for context '%s' in list mode", "The item with the OID '%s' is not cached for context '%s' in list mode",
@ -150,18 +154,33 @@ public final class XMLDeliveryCache {
} }
} }
cacheElem.syncDocs(); //cacheElem.syncDocs();
final Iterator<Map.Entry<String, String>> attrs = cacheElem.getAttributes().entrySet().iterator(); Map<String, String> cachedAttributes;
Map.Entry<String, String> attr; if (listMode) {
while (attrs.hasNext()) { cachedAttributes = cachedXml.getCachedAttributes(Mode.LIST_MODE);
attr = attrs.next(); } else {
parent.addAttribute(attr.getKey(), attr.getValue()); cachedAttributes = cachedXml.getCachedAttributes(Mode.DEFAULT);
} }
final Iterator<Element> childs = cacheElem.getChildren().iterator();
while (childs.hasNext()) { if (cachedAttributes != null) {
copyElement(parent, childs.next()); for (Map.Entry<String, String> attribute : cachedAttributes.entrySet()) {
parent.addAttribute(attribute.getKey(), attribute.getValue());
}
} }
parent.setText(cached);
// final Iterator<Map.Entry<String, String>> attrs = cacheElem.getAttributes().entrySet().iterator();
// Map.Entry<String, String> attr;
// while (attrs.hasNext()) {
// attr = attrs.next();
// parent.addAttribute(attr.getKey(), attr.getValue());
// }
// final Iterator<Element> childs = cacheElem.getChildren().iterator();
// while (childs.hasNext()) {
// copyElement(parent, childs.next());
// }
} }
/** /**
@ -219,24 +238,36 @@ public final class XMLDeliveryCache {
cachedItem.put(context, cachedXml); cachedItem.put(context, cachedXml);
} }
final Element cacheElem = new Element("cachedItem"); // final Element cacheElem = new Element("cachedItem");
final Iterator<Map.Entry<String, String>> attrs = parent.getAttributes().entrySet().iterator(); // final Iterator<Map.Entry<String, String>> attrs = parent.getAttributes().entrySet().iterator();
Map.Entry<String, String> attr; // Map.Entry<String, String> attr;
while (attrs.hasNext()) { // while (attrs.hasNext()) {
attr = attrs.next(); // attr = attrs.next();
cacheElem.addAttribute(attr.getKey(), attr.getValue()); // cacheElem.addAttribute(attr.getKey(), attr.getValue());
} // }
final Iterator<Element> childs = parent.getChildren().iterator(); // final Iterator<Element> childs = parent.getChildren().iterator();
while (childs.hasNext()) { // while (childs.hasNext()) {
copyElement(cacheElem, childs.next()); // copyElement(cacheElem, childs.next());
// }
final Mode mode;
if (listMode) {
mode = Mode.LIST_MODE;
} else {
mode = Mode.DEFAULT;
} }
if (listMode) { final Iterator<Map.Entry<String, String>> attrs = parent.getAttributes().entrySet().iterator();
cachedXml.putCachedXml(Mode.LIST_MODE, cacheElem); Map.Entry<String, String> attr;
} else { final Map<String, String> attributes = new HashMap<String, String>();
cachedXml.putCachedXml(Mode.DEFAULT, cacheElem); while (attrs.hasNext()) {
attr = attrs.next();
attributes.put(attr.getKey(), attr.getValue());
} }
cachedXml.putCachedXml(mode, parent.toString());
cachedXml.pubCachedAttributes(mode, attributes);
if (item.getDraftVersion() != null) { if (item.getDraftVersion() != null) {
cachedItems.put(item.getDraftVersion().getOID().toString(), oid.toString()); cachedItems.put(item.getDraftVersion().getOID().toString(), oid.toString());
} }
@ -261,29 +292,29 @@ public final class XMLDeliveryCache {
} }
} }
private void copyElement(final Element parent, final Element element) { // private void copyElement(final Element parent, final Element element) {
final Element copy = parent.newChildElement(element.getName()); // final Element copy = parent.newChildElement(element.getName());
final Iterator attrs = element.getAttributes().entrySet().iterator(); // final Iterator attrs = element.getAttributes().entrySet().iterator();
Map.Entry attr; // Map.Entry attr;
while (attrs.hasNext()) { // while (attrs.hasNext()) {
attr = (Map.Entry) attrs.next(); // attr = (Map.Entry) attrs.next();
copy.addAttribute((String) attr.getKey(), (String) attr.getValue()); // copy.addAttribute((String) attr.getKey(), (String) attr.getValue());
} // }
//
final Iterator childs = element.getChildren().iterator(); // final Iterator childs = element.getChildren().iterator();
while (childs.hasNext()) { // while (childs.hasNext()) {
copyElement(copy, (Element) childs.next()); // copyElement(copy, (Element) childs.next());
} // }
//
if (element.getText() != null) { // if (element.getText() != null) {
copy.setText(element.getText()); // copy.setText(element.getText());
} // }
//
if (element.getCDATASection() != null) { // if (element.getCDATASection() != null) {
copy.setCDATASection(element.getCDATASection()); // copy.setCDATASection(element.getCDATASection());
} // }
//
} // }
private class CachedItem { private class CachedItem {
@ -300,27 +331,47 @@ public final class XMLDeliveryCache {
public void put(final String context, final CachedXml cachedXml) { public void put(final String context, final CachedXml cachedXml) {
this.cachedXml.put(context, cachedXml); this.cachedXml.put(context, cachedXml);
} }
} }
private class CachedXml { private class CachedXml {
private final Map<Mode, Element> cachedXml = new EnumMap<Mode, Element>(Mode.class); //private final Map<Mode, Element> cachedXml = new EnumMap<Mode, Element>(Mode.class);
private final Map<Mode, String> cachedXml = new EnumMap<Mode, String>(Mode.class);
private final Map<Mode, Map<String, String>> cachedAttributes = new EnumMap<Mode, Map<String, String>>(
Mode.class);
public CachedXml() { public CachedXml() {
//Nothing //Nothing
} }
public Element getCachedXml(final Mode mode) { // public Element getCachedXml(final Mode mode) {
// return cachedXml.get(mode);
// }
public String getCachedXml(final Mode mode) {
return cachedXml.get(mode); return cachedXml.get(mode);
} }
public void putCachedXml(final Mode mode, final Element element) { public Map<String, String> getCachedAttributes(final Mode mode) {
return cachedAttributes.get(mode);
}
// public void putCachedXml(final Mode mode, final Element element) {
// cachedXml.put(mode, element);
// }
public void pubCachedAttributes(final Mode mode, final Map<String, String> attributes) {
cachedAttributes.put(mode, attributes);
}
public void putCachedXml(final Mode mode, final String element) {
cachedXml.put(mode, element); cachedXml.put(mode, element);
} }
} }
private enum Mode { private enum Mode {
DEFAULT, DEFAULT,
LIST_MODE,} LIST_MODE,
}
} }

View File

@ -50,8 +50,7 @@ import org.apache.log4j.Logger;
* Web Developer Support Application Servlet class, central entry point to create and process the applications UI. * Web Developer Support Application Servlet class, central entry point to create and process the applications UI.
* *
* We should have subclassed BebopApplicationServlet but couldn't overwrite doService() method to add permission * We should have subclassed BebopApplicationServlet but couldn't overwrite doService() method to add permission
* checking. So we use our own page mapping. The general logic is the same as for BebopApplicationServlet. * checking. So we use our own page mapping. The general logic is the same as for BebopApplicationServlet. {
* {
* *
* @see com.arsdigita.bebop.page.BebopApplicationServlet} * @see com.arsdigita.bebop.page.BebopApplicationServlet}
* *
@ -193,11 +192,14 @@ public class AdminServlet extends BaseApplicationServlet
new GroupAdministrationTab(); new GroupAdministrationTab();
/* /*
* Create group administration panel * Create application administration panel
*/ */
ApplicationsAdministrationTab appsAdministrationTab = ApplicationsAdministrationTab appsAdministrationTab =
new ApplicationsAdministrationTab(); new ApplicationsAdministrationTab();
SettingsTab settingsTab = new SettingsTab();
// Create the Admin's page tab bar, currently 2 elements: user & groups // Create the Admin's page tab bar, currently 2 elements: user & groups
TabbedPane tb = new TabbedPane(); TabbedPane tb = new TabbedPane();
tb.setIdAttr("page-body"); tb.setIdAttr("page-body");
@ -205,6 +207,7 @@ public class AdminServlet extends BaseApplicationServlet
tb.addTab(USER_TAB_TITLE, userSplitPanel); tb.addTab(USER_TAB_TITLE, userSplitPanel);
tb.addTab(GROUP_TAB_TITLE, groupAdministrationTab); tb.addTab(GROUP_TAB_TITLE, groupAdministrationTab);
tb.addTab(APPLICATIONS_TAB_TITLE, appsAdministrationTab); tb.addTab(APPLICATIONS_TAB_TITLE, appsAdministrationTab);
tb.addTab("Settings", settingsTab);
browsePane.setTabbedPane(tb); browsePane.setTabbedPane(tb);
browsePane.setGroupAdministrationTab(groupAdministrationTab); browsePane.setGroupAdministrationTab(groupAdministrationTab);

View File

@ -9,7 +9,7 @@
name="scientificcms" name="scientificcms"
prettyName="Scientific CMS" prettyName="Scientific CMS"
version="2-1-0" version="2-1-0"
release="alpha4-r2123" release="SNAPSHOT-r2151"
webxml="web-sci.xml" webxml="web-sci.xml"
webapp="ROOT" webapp="ROOT"
xsi:schemaLocation="http://ccm.redhat.com/ccm-project file:tools-ng/common/xsd/project.xsd"> xsi:schemaLocation="http://ccm.redhat.com/ccm-project file:tools-ng/common/xsd/project.xsd">