ozeigermann 2004/07/07 08:08:59
Modified: src/webdav/server/org/apache/slide/webdav/method
AbstractWebdavMethod.java
src/webdav/server/org/apache/slide/webdav/util
UriHandler.java
Log:
Resurrected HACK to limit the number of sub collections in history folder to 10.
This is needed to help Slide remain responsive when lots of resources are versioned.
Revision Changes Path
1.36 +16 -5
jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/AbstractWebdavMethod.java
Index: AbstractWebdavMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/AbstractWebdavMethod.java,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- AbstractWebdavMethod.java 5 Jul 2004 10:15:23 -0000 1.35
+++ AbstractWebdavMethod.java 7 Jul 2004 15:08:59 -0000 1.36
@@ -296,6 +296,10 @@
public void run(HttpServletRequest req, HttpServletResponse resp)
throws WebdavException {
+ // XXX this is a pretty ugly spot and way to set this
+ // TODO find a better solution
+ UriHandler.setGloballyUseHistoryCollectionHack(useHistoryCollectionHack());
+
this.req = req;
this.resp = resp;
this.slideToken = WebdavUtils.getSlideToken(req);
@@ -790,8 +794,15 @@
protected boolean getBooleanInitParameter( String name ) {
return "true".equalsIgnoreCase( getConfig().getInitParameter(name) );
}
-
-
+
+ /**
+ * Checks whether the hack that restricts the size of collections in
+ * the history collection is configured to be used.
+ */
+ protected boolean useHistoryCollectionHack() {
+ return
"true".equalsIgnoreCase(token.getNamespaceConfig().getParameter("history-collection-hack"));
+ }
+
/**
* Returns the value of an integer init parameter of the servlet.
* Default value: -1.
1.32 +230 -77
jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/UriHandler.java
Index: UriHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/UriHandler.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- UriHandler.java 5 May 2004 12:30:27 -0000 1.31
+++ UriHandler.java 7 Jul 2004 15:08:59 -0000 1.32
@@ -29,15 +29,18 @@
import org.apache.slide.common.SlideToken;
import org.apache.slide.common.NamespaceAccessToken;
import org.apache.slide.common.ServiceAccessException;
+import org.apache.slide.structure.ObjectAlreadyExistsException;
import org.apache.slide.structure.ObjectNotFoundException;
import org.apache.slide.structure.LinkedObjectNotFoundException;
import org.apache.slide.structure.Structure;
+import org.apache.slide.structure.SubjectNode;
import org.apache.slide.content.Content;
import org.apache.slide.content.NodeProperty;
import org.apache.slide.content.NodeProperty.NamespaceCache;
import org.apache.slide.content.NodeRevisionDescriptors;
import org.apache.slide.content.NodeRevisionDescriptor;
import org.apache.slide.content.NodeRevisionNumber;
+import org.apache.slide.content.RevisionAlreadyExistException;
import org.apache.slide.content.RevisionNotFoundException;
import org.apache.slide.content.RevisionDescriptorNotFoundException;
import org.apache.slide.lock.ObjectLockedException;
@@ -49,7 +52,23 @@
* Helper class for the handling of URIs
*/
public class UriHandler implements DeltavConstants, AclConstants, DaslConstants {
-
+
+ /**
+ * Determines whether the hack that restricts the size of collections in
+ * the history collection is configured to be used.
+ */
+ protected static boolean useHistoryCollectionHack = false;
+
+ /**
+ * Sets whether the hack that restricts the size of collections in
+ * the history collection is configured to be used.
+ */
+ public static void setGloballyUseHistoryCollectionHack(boolean
useHistoryCollectionHack) {
+ // XXX it is truely ugly to do things this way, it would be better to have
an Uri factory
+ // that gets initialized with this value
+ UriHandler.useHistoryCollectionHack = useHistoryCollectionHack;
+ }
+
/**
* Factory method.
*/
@@ -110,52 +129,138 @@
String uniqueUri = structure.generateUniqueUri(sToken, hpath);
if (uniqueUri != null) {
- result = new UriHandler(uniqueUri);
+ if (UriHandler.useHistoryCollectionHack) {
+ // XXX this is a bit silly: first compose it, now analyze it...
+ String nextHnStr = uniqueUri.substring(uniqueUri.lastIndexOf('/') +
1);
+ // XXX start with (at least) 10 to
+ // assure no resources are created directly in history folder
+ long nextHnLong = Long.parseLong(nextHnStr) + 10;
+ nextHnStr = String.valueOf(nextHnLong);
+
+ // make hpath/1/2/3 out of 1234
+ StringBuffer pathBuffer = new StringBuffer(hpath);
+ for (int i = 0; i < nextHnStr.length() - 1; i++) {
+ pathBuffer.append('/');
+ pathBuffer.append(nextHnStr.charAt(i));
+ // as we have no information how this number may look like we
will have to assure the full
+ // path is created
+ String dir = pathBuffer.toString();
+ try {
+ structure.retrieve(sToken, dir);
+ } catch (ObjectNotFoundException onfe) {
+ try {
+ structure.create(sToken, new SubjectNode(), dir);
+ content.create(sToken, dir, new
NodeRevisionDescriptor(0), null);
+ } catch (ObjectAlreadyExistsException oae) {
+ Domain.warn("Object " + dir + " already exists.");
+ } catch (RevisionAlreadyExistException rae) {
+ Domain.warn("Revision " + dir + " already exists.");
+ }
+ }
+ }
+
+ // make hpath/1/2/3/h4 out of 1234
+ pathBuffer.append("/h").append(nextHnStr.charAt(nextHnStr.length()
- 1));
+ String fullPath = pathBuffer.toString();
+
+ return new UriHandler(fullPath);
+
+ } else {
+ return new UriHandler(uniqueUri);
+ }
} else {
- NodeRevisionDescriptors hpathNrds =
- content.retrieve( sToken, hpath );
-
- NodeRevisionDescriptor hpathNrd =
- content.retrieve( sToken, hpathNrds );
-
- NodeProperty nextHnProp = hpathNrd.getProperty(I_NEXT_HISTORY_NAME,
-
NamespaceCache.SLIDE_URI);
- if (nextHnProp == null) {
- // convert to slide namespace if this property is still
- // in DAV: namespace
- nextHnProp = hpathNrd.getProperty( I_NEXT_HISTORY_NAME );
- if (nextHnProp != null) {
- hpathNrd.removeProperty(nextHnProp);
- nextHnProp = new NodeProperty(I_NEXT_HISTORY_NAME,
- nextHnProp.getValue(),
- NamespaceCache.SLIDE_URI);
- nextHnProp.setKind( NodeProperty.Kind.PROTECTED );
- hpathNrd.setProperty( nextHnProp );
- }
- }
- if( nextHnProp == null || nextHnProp.getValue() == null ) {
- nextHnProp =
- new NodeProperty(I_NEXT_HISTORY_NAME,
- I_INITIAL_HISTORY_NAME,
- NamespaceCache.SLIDE_URI);
- nextHnProp.setKind( NodeProperty.Kind.PROTECTED );
- hpathNrd.setProperty( nextHnProp );
+
+ NodeRevisionDescriptors hpathNrds = content.retrieve(sToken, hpath);
+ NodeRevisionDescriptor hpathNrd = content.retrieve(sToken, hpathNrds);
+ NodeProperty nextHnProp = hpathNrd.getProperty(I_NEXT_HISTORY_NAME,
NamespaceCache.SLIDE_URI);
+
+ if (UriHandler.useHistoryCollectionHack) {
+
+ if (nextHnProp == null || nextHnProp.getValue() == null) {
+ // XXX start with historyCollectionHackChildren to assure no
+ // resources are created directly in history folder
+ nextHnProp = new NodeProperty(I_NEXT_HISTORY_NAME, "10",
NamespaceCache.SLIDE_URI);
+ nextHnProp.setKind(NodeProperty.Kind.PROTECTED);
+ hpathNrd.setProperty(nextHnProp);
+ }
+
+ String nextHnStr = (String) nextHnProp.getValue();
+ long nextHnLong = Long.parseLong(nextHnStr);
+
+ if (nextHnLong % 10 == 0) {
+ // create parent collection
+ long dirNum = nextHnLong / 10;
+ char dirChar[] = Long.toString(dirNum).toCharArray();
+ StringBuffer buf = new StringBuffer();
+ for (int i = 0; i < dirChar.length - 1; i++) {
+ buf.append(dirChar[i]);
+ buf.append('/');
+ }
+ buf.append(dirChar[dirChar.length - 1]);
+ String dirPath = hpath + "/" + buf.toString();
+
+ try {
+ structure.create(sToken, new SubjectNode(), dirPath);
+ //content.create(sToken,dirPath,true);
+ //NodeRevisionDescriptors dnrds =
+ // structure.retrieve(stoken,dirPath);
+ content.create(sToken, dirPath, new
NodeRevisionDescriptor(0), null);
+ } catch (ObjectAlreadyExistsException oae) {
+ Domain.warn("Object " + dirPath + " already exists.");
+ } catch (RevisionAlreadyExistException rae) {
+ Domain.warn("Revision " + dirPath + " already exists.");
+ }
+ }
+
+ StringBuffer buf = new StringBuffer();
+ char nextHnChar[] = nextHnStr.toCharArray();
+ for (int i = 0; i < nextHnChar.length - 1; i++) {
+ buf.append(nextHnChar[i]);
+ buf.append('/');
+ }
+ buf.append('h');
+ buf.append(nextHnChar[nextHnChar.length - 1]);
+
+ result = new UriHandler(hpath + "/" + buf.toString());
+
+ nextHnProp = new NodeProperty(I_NEXT_HISTORY_NAME,
String.valueOf(nextHnLong + 1),
+ NamespaceCache.SLIDE_URI);
+ hpathNrd.setProperty(nextHnProp);
+
+ } else {
+
+ if (nextHnProp == null) {
+ // convert to slide namespace if this property is still
+ // in DAV: namespace
+ nextHnProp = hpathNrd.getProperty(I_NEXT_HISTORY_NAME);
+ if (nextHnProp != null) {
+ hpathNrd.removeProperty(nextHnProp);
+ nextHnProp = new NodeProperty(I_NEXT_HISTORY_NAME,
nextHnProp.getValue(),
+ NamespaceCache.SLIDE_URI);
+ nextHnProp.setKind(NodeProperty.Kind.PROTECTED);
+ hpathNrd.setProperty(nextHnProp);
+ }
+ }
+ if (nextHnProp == null || nextHnProp.getValue() == null) {
+ nextHnProp = new NodeProperty(I_NEXT_HISTORY_NAME,
I_INITIAL_HISTORY_NAME, NamespaceCache.SLIDE_URI);
+ nextHnProp.setKind(NodeProperty.Kind.PROTECTED);
+ hpathNrd.setProperty(nextHnProp);
+ }
+
+ String nextHnStr = (String) nextHnProp.getValue();
+ result = new UriHandler(hpath + "/" + nextHnStr);
+
+ long nextHnLong = Long.parseLong(nextHnStr);
+ nextHnProp = new NodeProperty(I_NEXT_HISTORY_NAME,
String.valueOf(nextHnLong + 1),
+ NamespaceCache.SLIDE_URI);
+ hpathNrd.setProperty(nextHnProp);
+
}
-
- String nextHnStr = (String)nextHnProp.getValue();
- result = new UriHandler( hpath+"/"+nextHnStr );
-
- long nextHnLong = Long.parseLong( nextHnStr );
- nextHnProp = new NodeProperty(I_NEXT_HISTORY_NAME,
- String.valueOf(nextHnLong + 1),
- NamespaceCache.SLIDE_URI );
- hpathNrd.setProperty( nextHnProp );
-
- content.store( sToken, hpath, hpathNrd, null ); //revisionContent = null
+ content.store(sToken, hpath, hpathNrd, null); //revisionContent = null
+ return result;
}
-
- return result;
}
+
/**
* Generates the next available workingresource URI and returns an URI handler
for it.
@@ -381,18 +486,33 @@
*/
public boolean isHistoryUri() {
HistoryPathHandler hpathHandler =
HistoryPathHandler.getHistoryPathHandler();
- String[] hpathTokens = hpathHandler.getUriTokens();
-
- if( (hpathTokens.length + 1) == uriTokens.length ) {
- if( hpathHandler.isHistoryPathUri(getParentUriHandler()) ) {
- try {
- Integer.parseInt( uriTokens[uriTokens.length - 1] );
- return true;
- }
- catch( NumberFormatException x ) {};
- }
+
+ if (UriHandler.useHistoryCollectionHack) {
+ if (hpathHandler.isAncestorOf(this)) {
+ String[] hpathTokens = hpathHandler.getUriTokens();
+ if (uriTokens.length < hpathTokens.length + 1) {
+ return false;
+ }
+ String h = uriTokens[uriTokens.length - 1];
+ return (h.charAt(0) == 'h');
+ } else {
+ return false;
+ }
+ } else {
+ String[] hpathTokens = hpathHandler.getUriTokens();
+
+ if ((hpathTokens.length + 1) == uriTokens.length) {
+ if (hpathHandler.isHistoryPathUri(getParentUriHandler())) {
+ try {
+ Integer.parseInt(uriTokens[uriTokens.length - 1]);
+ return true;
+ } catch (NumberFormatException x) {
+ }
+ ;
+ }
+ }
+ return false;
}
- return false;
}
/**
@@ -400,13 +520,32 @@
*/
public boolean isVersionUri() {
HistoryPathHandler hpathHandler =
HistoryPathHandler.getHistoryPathHandler();
- String[] hpathTokens = hpathHandler.getUriTokens();
-
- if( (hpathTokens.length + 2) == uriTokens.length ) {
- if( getParentUriHandler().isHistoryUri() )
- return true;
+
+ if (UriHandler.useHistoryCollectionHack) {
+ /*
+ * Version Uris look like /my/history/path/1/2/3/h9/1.0
+ */
+
+ if (hpathHandler.isAncestorOf(this)) {
+ String[] hpathTokens = hpathHandler.getUriTokens();
+ if (uriTokens.length < hpathTokens.length + 2) {
+ return false;
+ }
+ String h = uriTokens[uriTokens.length - 2];
+ return (h.charAt(0) == 'h');
+ } else {
+ return false;
+ }
+ } else {
+
+ String[] hpathTokens = hpathHandler.getUriTokens();
+
+ if ((hpathTokens.length + 2) == uriTokens.length) {
+ if (getParentUriHandler().isHistoryUri())
+ return true;
+ }
+ return false;
}
- return false;
}
/**
@@ -496,31 +635,45 @@
public String getHistoryName() {
UriHandler hpathHandler = HistoryPathHandler.getHistoryPathHandler();
String[] hpathTokens = hpathHandler.getUriTokens();
-
- if( !isHistoryUri() && !isVersionUri() )
- throw new IllegalStateException(
- "URI "+uri+" is neither history nor version URI" );
-
- return uriTokens[hpathTokens.length];
+
+ if (UriHandler.useHistoryCollectionHack) {
+ if (isHistoryUri()) {
+ return getName();
+ } else if (isVersionUri()) {
+ return uriTokens[uriTokens.length - 2];
+ } else {
+ throw new IllegalStateException("URI " + toString() + " is neither
history nor version URI");
+ }
+ } else {
+ if (!isHistoryUri() && !isVersionUri())
+ throw new IllegalStateException("URI " + uri + " is neither history
nor version URI");
+
+ return uriTokens[hpathTokens.length];
+ }
}
/**
* Returns the version name from the uri
+ *
* @pre isVersionUri()
*/
public String getVersionName() {
- UriHandler hpathHandler = HistoryPathHandler.getHistoryPathHandler();
- String[] hpathTokens = hpathHandler.getUriTokens();
-
- if( !isVersionUri() )
- throw new IllegalStateException(
- "URI "+uri+" is not a version URI" );
-
- return uriTokens[hpathTokens.length + 1];
+ if (!isVersionUri())
+ throw new IllegalStateException("URI " + uri + " is not a version URI");
+
+ if (UriHandler.useHistoryCollectionHack) {
+ return getName();
+ } else {
+ UriHandler hpathHandler = HistoryPathHandler.getHistoryPathHandler();
+ String[] hpathTokens = hpathHandler.getUriTokens();
+
+ return uriTokens[hpathTokens.length + 1];
+ }
}
/**
* Returns the associated history URI of this version URI
+ *
* @pre isVersionUri()
*/
public String getAssociatedHistoryUri() {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]