exo-jcr SVN: r3269 - in kernel/branches/2.2.x: exo.kernel.commons and 12 other directories.
by do-not-reply@jboss.org
Author: aheritier
Date: 2010-10-08 15:43:00 -0400 (Fri, 08 Oct 2010)
New Revision: 3269
Modified:
kernel/branches/2.2.x/exo.kernel.commons/pom.xml
kernel/branches/2.2.x/exo.kernel.component.cache/pom.xml
kernel/branches/2.2.x/exo.kernel.component.command/pom.xml
kernel/branches/2.2.x/exo.kernel.component.common/pom.xml
kernel/branches/2.2.x/exo.kernel.component.ext.cache.impl.jboss.v3/pom.xml
kernel/branches/2.2.x/exo.kernel.component.remote/pom.xml
kernel/branches/2.2.x/exo.kernel.container/pom.xml
kernel/branches/2.2.x/exo.kernel.mc-integration/exo.kernel.mc-int-demo/pom.xml
kernel/branches/2.2.x/exo.kernel.mc-integration/exo.kernel.mc-int-tests/pom.xml
kernel/branches/2.2.x/exo.kernel.mc-integration/exo.kernel.mc-int/pom.xml
kernel/branches/2.2.x/exo.kernel.mc-integration/exo.kernel.mc-kernel-extras/pom.xml
kernel/branches/2.2.x/exo.kernel.mc-integration/pom.xml
kernel/branches/2.2.x/packaging/module/pom.xml
kernel/branches/2.2.x/pom.xml
Log:
[maven-release-plugin] prepare release 2.2.5-GA_REL
Modified: kernel/branches/2.2.x/exo.kernel.commons/pom.xml
===================================================================
--- kernel/branches/2.2.x/exo.kernel.commons/pom.xml 2010-10-08 19:42:30 UTC (rev 3268)
+++ kernel/branches/2.2.x/exo.kernel.commons/pom.xml 2010-10-08 19:43:00 UTC (rev 3269)
@@ -25,7 +25,7 @@
<parent>
<groupId>org.exoplatform.kernel</groupId>
<artifactId>kernel-parent</artifactId>
- <version>2.2.5-GA-SNAPSHOT</version>
+ <version>2.2.6-GA-SNAPSHOT</version>
</parent>
<artifactId>exo.kernel.commons</artifactId>
Modified: kernel/branches/2.2.x/exo.kernel.component.cache/pom.xml
===================================================================
--- kernel/branches/2.2.x/exo.kernel.component.cache/pom.xml 2010-10-08 19:42:30 UTC (rev 3268)
+++ kernel/branches/2.2.x/exo.kernel.component.cache/pom.xml 2010-10-08 19:43:00 UTC (rev 3269)
@@ -25,7 +25,7 @@
<parent>
<groupId>org.exoplatform.kernel</groupId>
<artifactId>kernel-parent</artifactId>
- <version>2.2.5-GA-SNAPSHOT</version>
+ <version>2.2.6-GA-SNAPSHOT</version>
</parent>
<artifactId>exo.kernel.component.cache</artifactId>
Modified: kernel/branches/2.2.x/exo.kernel.component.command/pom.xml
===================================================================
--- kernel/branches/2.2.x/exo.kernel.component.command/pom.xml 2010-10-08 19:42:30 UTC (rev 3268)
+++ kernel/branches/2.2.x/exo.kernel.component.command/pom.xml 2010-10-08 19:43:00 UTC (rev 3269)
@@ -25,7 +25,7 @@
<parent>
<groupId>org.exoplatform.kernel</groupId>
<artifactId>kernel-parent</artifactId>
- <version>2.2.5-GA-SNAPSHOT</version>
+ <version>2.2.6-GA-SNAPSHOT</version>
</parent>
<artifactId>exo.kernel.component.command</artifactId>
Modified: kernel/branches/2.2.x/exo.kernel.component.common/pom.xml
===================================================================
--- kernel/branches/2.2.x/exo.kernel.component.common/pom.xml 2010-10-08 19:42:30 UTC (rev 3268)
+++ kernel/branches/2.2.x/exo.kernel.component.common/pom.xml 2010-10-08 19:43:00 UTC (rev 3269)
@@ -25,7 +25,7 @@
<parent>
<groupId>org.exoplatform.kernel</groupId>
<artifactId>kernel-parent</artifactId>
- <version>2.2.5-GA-SNAPSHOT</version>
+ <version>2.2.6-GA-SNAPSHOT</version>
</parent>
<artifactId>exo.kernel.component.common</artifactId>
Modified: kernel/branches/2.2.x/exo.kernel.component.ext.cache.impl.jboss.v3/pom.xml
===================================================================
--- kernel/branches/2.2.x/exo.kernel.component.ext.cache.impl.jboss.v3/pom.xml 2010-10-08 19:42:30 UTC (rev 3268)
+++ kernel/branches/2.2.x/exo.kernel.component.ext.cache.impl.jboss.v3/pom.xml 2010-10-08 19:43:00 UTC (rev 3269)
@@ -23,7 +23,7 @@
<parent>
<groupId>org.exoplatform.kernel</groupId>
<artifactId>kernel-parent</artifactId>
- <version>2.2.5-GA-SNAPSHOT</version>
+ <version>2.2.6-GA-SNAPSHOT</version>
</parent>
<artifactId>exo.kernel.component.ext.cache.impl.jboss.v3</artifactId>
<name>eXo Kernel :: Cache Extension :: JBoss Cache Implementation</name>
Modified: kernel/branches/2.2.x/exo.kernel.component.remote/pom.xml
===================================================================
--- kernel/branches/2.2.x/exo.kernel.component.remote/pom.xml 2010-10-08 19:42:30 UTC (rev 3268)
+++ kernel/branches/2.2.x/exo.kernel.component.remote/pom.xml 2010-10-08 19:43:00 UTC (rev 3269)
@@ -25,7 +25,7 @@
<parent>
<groupId>org.exoplatform.kernel</groupId>
<artifactId>kernel-parent</artifactId>
- <version>2.2.5-GA-SNAPSHOT</version>
+ <version>2.2.6-GA-SNAPSHOT</version>
</parent>
<artifactId>exo.kernel.component.remote</artifactId>
Modified: kernel/branches/2.2.x/exo.kernel.container/pom.xml
===================================================================
--- kernel/branches/2.2.x/exo.kernel.container/pom.xml 2010-10-08 19:42:30 UTC (rev 3268)
+++ kernel/branches/2.2.x/exo.kernel.container/pom.xml 2010-10-08 19:43:00 UTC (rev 3269)
@@ -12,7 +12,7 @@
<parent>
<groupId>org.exoplatform.kernel</groupId>
<artifactId>kernel-parent</artifactId>
- <version>2.2.5-GA-SNAPSHOT</version>
+ <version>2.2.6-GA-SNAPSHOT</version>
</parent>
<artifactId>exo.kernel.container</artifactId>
<name>eXo Kernel :: Container</name>
Modified: kernel/branches/2.2.x/exo.kernel.mc-integration/exo.kernel.mc-int/pom.xml
===================================================================
--- kernel/branches/2.2.x/exo.kernel.mc-integration/exo.kernel.mc-int/pom.xml 2010-10-08 19:42:30 UTC (rev 3268)
+++ kernel/branches/2.2.x/exo.kernel.mc-integration/exo.kernel.mc-int/pom.xml 2010-10-08 19:43:00 UTC (rev 3269)
@@ -6,7 +6,7 @@
<parent>
<groupId>org.exoplatform.kernel</groupId>
<artifactId>mc-integration-parent</artifactId>
- <version>2.2.5-GA-SNAPSHOT</version>
+ <version>2.2.6-GA-SNAPSHOT</version>
</parent>
<artifactId>exo.kernel.mc-int</artifactId>
Modified: kernel/branches/2.2.x/exo.kernel.mc-integration/exo.kernel.mc-int-demo/pom.xml
===================================================================
--- kernel/branches/2.2.x/exo.kernel.mc-integration/exo.kernel.mc-int-demo/pom.xml 2010-10-08 19:42:30 UTC (rev 3268)
+++ kernel/branches/2.2.x/exo.kernel.mc-integration/exo.kernel.mc-int-demo/pom.xml 2010-10-08 19:43:00 UTC (rev 3269)
@@ -5,7 +5,7 @@
<parent>
<groupId>org.exoplatform.kernel</groupId>
<artifactId>mc-integration-parent</artifactId>
- <version>2.2.5-GA-SNAPSHOT</version>
+ <version>2.2.6-GA-SNAPSHOT</version>
</parent>
<artifactId>exo.kernel.mc-int-demo</artifactId>
Modified: kernel/branches/2.2.x/exo.kernel.mc-integration/exo.kernel.mc-int-tests/pom.xml
===================================================================
--- kernel/branches/2.2.x/exo.kernel.mc-integration/exo.kernel.mc-int-tests/pom.xml 2010-10-08 19:42:30 UTC (rev 3268)
+++ kernel/branches/2.2.x/exo.kernel.mc-integration/exo.kernel.mc-int-tests/pom.xml 2010-10-08 19:43:00 UTC (rev 3269)
@@ -5,7 +5,7 @@
<parent>
<groupId>org.exoplatform.kernel</groupId>
<artifactId>mc-integration-parent</artifactId>
- <version>2.2.5-GA-SNAPSHOT</version>
+ <version>2.2.6-GA-SNAPSHOT</version>
</parent>
<artifactId>exo.kernel.mc-int-tests</artifactId>
Modified: kernel/branches/2.2.x/exo.kernel.mc-integration/exo.kernel.mc-kernel-extras/pom.xml
===================================================================
--- kernel/branches/2.2.x/exo.kernel.mc-integration/exo.kernel.mc-kernel-extras/pom.xml 2010-10-08 19:42:30 UTC (rev 3268)
+++ kernel/branches/2.2.x/exo.kernel.mc-integration/exo.kernel.mc-kernel-extras/pom.xml 2010-10-08 19:43:00 UTC (rev 3269)
@@ -6,7 +6,7 @@
<parent>
<groupId>org.exoplatform.kernel</groupId>
<artifactId>mc-integration-parent</artifactId>
- <version>2.2.5-GA-SNAPSHOT</version>
+ <version>2.2.6-GA-SNAPSHOT</version>
</parent>
<artifactId>exo.kernel.mc-kernel-extras</artifactId>
Modified: kernel/branches/2.2.x/exo.kernel.mc-integration/pom.xml
===================================================================
--- kernel/branches/2.2.x/exo.kernel.mc-integration/pom.xml 2010-10-08 19:42:30 UTC (rev 3268)
+++ kernel/branches/2.2.x/exo.kernel.mc-integration/pom.xml 2010-10-08 19:43:00 UTC (rev 3269)
@@ -6,7 +6,7 @@
<parent>
<groupId>org.exoplatform.kernel</groupId>
<artifactId>kernel-parent</artifactId>
- <version>2.2.5-GA-SNAPSHOT</version>
+ <version>2.2.6-GA-SNAPSHOT</version>
</parent>
<artifactId>mc-integration-parent</artifactId>
Modified: kernel/branches/2.2.x/packaging/module/pom.xml
===================================================================
--- kernel/branches/2.2.x/packaging/module/pom.xml 2010-10-08 19:42:30 UTC (rev 3268)
+++ kernel/branches/2.2.x/packaging/module/pom.xml 2010-10-08 19:43:00 UTC (rev 3269)
@@ -2,7 +2,7 @@
<parent>
<groupId>org.exoplatform.kernel</groupId>
<artifactId>kernel-parent</artifactId>
- <version>2.2.5-GA-SNAPSHOT</version>
+ <version>2.2.6-GA-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
Modified: kernel/branches/2.2.x/pom.xml
===================================================================
--- kernel/branches/2.2.x/pom.xml 2010-10-08 19:42:30 UTC (rev 3268)
+++ kernel/branches/2.2.x/pom.xml 2010-10-08 19:43:00 UTC (rev 3269)
@@ -30,7 +30,7 @@
<groupId>org.exoplatform.kernel</groupId>
<artifactId>kernel-parent</artifactId>
- <version>2.2.5-GA-SNAPSHOT</version>
+ <version>2.2.6-GA-SNAPSHOT</version>
<packaging>pom</packaging>
<name>eXo Kernel</name>
@@ -43,9 +43,9 @@
</properties>
<scm>
- <connection>scm:svn:http://anonsvn.jboss.org/repos/exo-jcr/kernel/branches/2.2.5-GA_REL</connection>
- <developerConnection>scm:svn:https://svn.jboss.org/repos/exo-jcr/kernel/branches/2.2.5-GA_REL</developerConnection>
- <url>http://fisheye.jboss.org/browse/exo-jcr/kernel/branches/2.2.5-GA_REL</url>
+ <connection>scm:svn:http://anonsvn.jboss.org/repos/exo-jcr/kernel/branches/2.2.x/</connection>
+ <developerConnection>scm:svn:https://svn.jboss.org/repos/exo-jcr/kernel/branches/2.2.x/</developerConnection>
+ <url>http://fisheye.jboss.org/browse/exo-jcr/kernel/branches/2.2.x</url>
</scm>
<modules>
15 years, 9 months
exo-jcr SVN: r3268 - kernel/branches.
by do-not-reply@jboss.org
Author: aheritier
Date: 2010-10-08 15:42:30 -0400 (Fri, 08 Oct 2010)
New Revision: 3268
Added:
kernel/branches/2.2.5-GA_REL/
Log:
[maven-release-plugin] copy for branch 2.2.5-GA_REL
Copied: kernel/branches/2.2.5-GA_REL (from rev 3267, kernel/branches/2.2.x)
15 years, 9 months
exo-jcr SVN: r3266 - in kernel/trunk/exo.kernel.component.common/src: main/java/org/exoplatform/services/rpc/impl and 1 other directories.
by do-not-reply@jboss.org
Author: nfilotto
Date: 2010-10-08 11:24:49 -0400 (Fri, 08 Oct 2010)
New Revision: 3266
Modified:
kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/RPCService.java
kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/impl/RPCServiceImpl.java
kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/rpc/impl/TestRPCServiceImpl.java
Log:
EXOJCR-967: The method isCoordinator has been added
Modified: kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/RPCService.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/RPCService.java 2010-10-08 14:40:49 UTC (rev 3265)
+++ kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/RPCService.java 2010-10-08 15:24:49 UTC (rev 3266)
@@ -124,4 +124,11 @@
* doesn't have the {@link RuntimePermission} <code>ACCESS_RPC_SERVICE_PERMISSION</code>
*/
void unregisterCommand(RemoteCommand command) throws SecurityException;
+
+ /**
+ * Indicates whether the local node is the coordinator of the cluster
+ * @return <code>true</code> if the coordinator is the coordinator, <code>false</code> otherwise
+ * throws RPCException in case the {@link RPCService} is in an illegal state
+ */
+ boolean isCoordinator() throws RPCException;
}
\ No newline at end of file
Modified: kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/impl/RPCServiceImpl.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/impl/RPCServiceImpl.java 2010-10-08 14:40:49 UTC (rev 3265)
+++ kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/impl/RPCServiceImpl.java 2010-10-08 15:24:49 UTC (rev 3266)
@@ -130,6 +130,11 @@
protected volatile Address coordinator;
/**
+ * Indicates whether the current node is the coordinator of the cluster or not
+ */
+ protected volatile boolean isCoordinator;
+
+ /**
* The default value of the timeout
*/
private long defaultTimeout = DEFAULT_TIMEOUT;
@@ -430,6 +435,7 @@
{
this.members = view.getMembers();
this.coordinator = members != null && members.size() > 0 ? members.get(0) : null;
+ this.isCoordinator = coordinator != null && coordinator.equals(channel.getLocalAddress());
}
/**
@@ -498,6 +504,19 @@
}
/**
+ * {@inheritDoc}
+ */
+ public boolean isCoordinator() throws RPCException
+ {
+ if (state != State.STARTED)
+ {
+ throw new RPCException("Cannot know whether the local node is a coordinator or not if " +
+ "the service is not started, the current state of the service is " + state);
+ }
+ return isCoordinator;
+ }
+
+ /**
* Gives the {@link RemoteCommand} corresponding to the given id
* @param commandId the command id of the command to retrieve
* @return the corresponding {@link RemoteCommand}
@@ -553,6 +572,7 @@
security.checkPermission(RPCService.ACCESS_RPC_SERVICE_PERMISSION);
}
this.state = State.STOPPED;
+ this.isCoordinator = false;
if (channel != null && channel.isOpen())
{
if (LOG.isInfoEnabled())
Modified: kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/rpc/impl/TestRPCServiceImpl.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/rpc/impl/TestRPCServiceImpl.java 2010-10-08 14:40:49 UTC (rev 3265)
+++ kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/rpc/impl/TestRPCServiceImpl.java 2010-10-08 15:24:49 UTC (rev 3266)
@@ -221,7 +221,17 @@
{
// OK
}
+ try
+ {
+ service.isCoordinator();
+ fail("We expect a RPCException since the current state is not the expected one");
+ }
+ catch (RPCException e)
+ {
+ // OK
+ }
service.start();
+ assertEquals(true, service.isCoordinator());
service.executeCommandOnAllNodes(foo, true);
service.executeCommandOnAllNodes(foo, 10);
service.executeCommandOnCoordinator(foo, true);
@@ -668,6 +678,8 @@
service2.registerCommand(LongTask);
service1.start();
service2.start();
+ assertEquals(true, service1.isCoordinator());
+ assertEquals(false, service2.isCoordinator());
List<Object> result;
Object o;
result = service1.executeCommandOnAllNodes(CmdUnknownOnNode2, true);
@@ -739,6 +751,16 @@
assertNotNull(result);
assertTrue(result.size() == 1);
assertTrue("We expect an RPCException due to a member that has left", result.get(0) instanceof MemberHasLeftException);
+ try
+ {
+ service1.isCoordinator();
+ fail("We expect a RPCException since the current state is not the expected one");
+ }
+ catch (RPCException e)
+ {
+ // OK
+ }
+ assertEquals(true, service2.isCoordinator());
}
finally
{
15 years, 9 months
exo-jcr SVN: r3265 - kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils.
by do-not-reply@jboss.org
Author: sergiykarpenko
Date: 2010-10-08 10:40:49 -0400 (Fri, 08 Oct 2010)
New Revision: 3265
Modified:
kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/MapResourceBundle.java
Log:
EXOJCR-996: Merge performance improvements
Modified: kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/MapResourceBundle.java
===================================================================
--- kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/MapResourceBundle.java 2010-10-08 13:03:55 UTC (rev 3264)
+++ kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/MapResourceBundle.java 2010-10-08 14:40:49 UTC (rev 3265)
@@ -1,181 +1,183 @@
-/*
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.exoplatform.commons.utils;
-
-import java.io.Serializable;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.Map;
-import java.util.ResourceBundle;
-import java.util.Set;
-import java.util.Vector;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * @author Benjamin Mestrallet benjamin.mestrallet(a)exoplatform.com
- */
-public class MapResourceBundle extends ResourceBundle implements Serializable
-{
-
- /**
- * The serial version UID
- */
- private static final long serialVersionUID = -7020823660841958748L;
-
- private final static String REGEXP = "#\\{.*\\}";
-
- private Map props = new HashMap();
-
- private Locale locale;
-
- public MapResourceBundle(Locale l)
- {
- this.locale = l;
- }
-
- public MapResourceBundle(ResourceBundle rB, Locale l)
- {
- this.locale = l;
- initMap(rB);
- }
-
- private void initMap(ResourceBundle rB)
- {
- Enumeration e = rB.getKeys();
- while (e.hasMoreElements())
- {
- String s = (String)e.nextElement();
- try
- {
- if (props.get(s) == null)
- {
- String[] newArray = rB.getStringArray(s);
- props.put(s, newArray);
- }
- }
- catch (ClassCastException ex)
- {
- props.put(s, rB.getObject(s));
- }
- }
- }
-
- protected Object handleGetObject(String key)
- {
- return props.get(key);
- }
-
- public Enumeration getKeys()
- {
- return new Vector(props.keySet()).elements();
- }
-
- public Locale getLocale()
- {
- return this.locale;
- }
-
- public void add(String key, Object value)
- {
- props.put(key, value);
- }
-
- public void remove(String key)
- {
- props.remove(key);
- }
-
- public void merge(ResourceBundle bundle)
- {
- Enumeration e = bundle.getKeys();
- while (e.hasMoreElements())
- {
- String s = (String)e.nextElement();
- Object value = bundle.getObject(s);
- try
- {
- String[] newArray = bundle.getStringArray(s);
- if (props.get(s) == null)
- {
- props.put(s, newArray);
- }
- }
- catch (ClassCastException ex)
- {
- props.put(s, value);
- }
- }
- }
-
- public void resolveDependencies()
- {
- Map tempMap = new HashMap(props);
- Set keys = tempMap.keySet();
- Pattern pattern = Pattern.compile(REGEXP);
- for (Iterator iter = keys.iterator(); iter.hasNext();)
- {
- String element = (String)iter.next();
- String value = lookupKey(tempMap, element, pattern, new HashSet<String>());
- tempMap.put(element, value);
- }
- props = tempMap;
- }
-
- private String lookupKey(Map props, String key, Pattern pattern, Set<String> callStack)
- {
- String s = (String)props.get(key);
- if (s == null || callStack.contains(key))
- {
- // The value cannot be found or it has already been asked which means that
- // a loop has been detected
- return key;
- }
- callStack.add(key);
- Matcher matcher = pattern.matcher(s);
- if (matcher.find())
- {
- return recursivedResolving(props, s, pattern, callStack);
- }
- // The value could be resolved thus it can be removed from the callStack
- callStack.remove(key);
- return s;
- }
-
- private String recursivedResolving(Map props, String value, Pattern pattern, Set<String> callStack)
- {
- String resolved = value;
- StringBuilder sB = new StringBuilder();
- while (resolved.indexOf("#{") != -1)
- {
- sB.setLength(0);
- int firstIndex = resolved.indexOf('#');
- int lastIndex = resolved.indexOf('}', firstIndex);
- String realKey = resolved.substring(firstIndex + 2, lastIndex);
- sB.append(resolved.substring(0, firstIndex));
- sB.append(lookupKey(props, realKey, pattern, callStack));
- sB.append(resolved.substring(lastIndex + 1));
- resolved = sB.toString();
- }
- return resolved;
- }
-}
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.commons.utils;
+
+import java.io.Serializable;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Map;
+import java.util.ResourceBundle;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * @author Benjamin Mestrallet benjamin.mestrallet(a)exoplatform.com
+ */
+public class MapResourceBundle extends ResourceBundle implements Serializable
+{
+
+ /**
+ * The serial version UID
+ */
+ private static final long serialVersionUID = -7020823660841958748L;
+
+ private final static Pattern PATTERN = Pattern.compile("#\\{.*\\}");
+
+ private Map<String, String> props;
+
+ private Locale locale;
+
+ public MapResourceBundle(Locale l)
+ {
+ this.locale = l;
+ this.props = new HashMap<String, String>();
+ }
+
+ public MapResourceBundle(ResourceBundle rB, Locale l)
+ {
+ Map<String, String> props = new HashMap<String, String>();
+ doMerge(props, rB);
+
+ //
+ this.locale = l;
+ this.props = props;
+ }
+
+ private static void doMerge(Map<String, String> props, ResourceBundle rB)
+ {
+ Enumeration<String> e = rB.getKeys();
+ while (e.hasMoreElements())
+ {
+ String key = e.nextElement();
+ if (props.get(key) == null)
+ {
+ Object o = rB.getObject(key);
+ if (o instanceof String)
+ {
+ String value = (String)o;
+ props.put(key.intern(), value.intern());
+ }
+ }
+ }
+ }
+
+ protected Object handleGetObject(String key)
+ {
+ return props.get(key);
+ }
+
+ public Enumeration<String> getKeys()
+ {
+ final Iterator<String> i = props.keySet().iterator();
+ return new Enumeration<String>()
+ {
+ public boolean hasMoreElements()
+ {
+ return i.hasNext();
+ }
+ public String nextElement()
+ {
+ return i.next();
+ }
+ };
+ }
+
+ public Locale getLocale()
+ {
+ return this.locale;
+ }
+
+ public void add(String key, Object o)
+ {
+ if (key != null && o instanceof String)
+ {
+ String value = (String)o;
+ props.put(key.intern(), value.intern());
+ }
+ }
+
+ public void remove(String key)
+ {
+ if (key != null)
+ {
+ props.remove(key);
+ }
+ }
+
+ public void merge(ResourceBundle bundle)
+ {
+ doMerge(props, bundle);
+ }
+
+ public void resolveDependencies()
+ {
+ Map<String, String> tempMap = new HashMap<String ,String>(props);
+ for (String element : props.keySet())
+ {
+ String value = lookupKey(tempMap, element, new HashSet<String>());
+ if (value != null)
+ {
+ tempMap.put(element.intern(), value.intern());
+ }
+ }
+ props = tempMap;
+ }
+
+ private String lookupKey(Map<String, String> props, String key, Set<String> callStack)
+ {
+ String s = props.get(key);
+ if (s == null || callStack.contains(key))
+ {
+ // The value cannot be found or it has already been asked which means that
+ // a loop has been detected
+ return key;
+ }
+ callStack.add(key);
+ Matcher matcher = PATTERN.matcher(s);
+ if (matcher.find())
+ {
+ return recursivedResolving(props, s, callStack);
+ }
+ // The value could be resolved thus it can be removed from the callStack
+ callStack.remove(key);
+ return s;
+ }
+
+ private String recursivedResolving(Map props, String value, Set<String> callStack)
+ {
+ String resolved = value;
+ StringBuilder sB = new StringBuilder();
+ while (resolved.indexOf("#{") != -1)
+ {
+ sB.setLength(0);
+ int firstIndex = resolved.indexOf('#');
+ int lastIndex = resolved.indexOf('}', firstIndex);
+ String realKey = resolved.substring(firstIndex + 2, lastIndex);
+ sB.append(resolved.substring(0, firstIndex));
+ sB.append(lookupKey(props, realKey, callStack));
+ sB.append(resolved.substring(lastIndex + 1));
+ resolved = sB.toString();
+ }
+ return resolved;
+ }
+}
15 years, 9 months
exo-jcr SVN: r3264 - jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2010-10-08 09:03:55 -0400 (Fri, 08 Oct 2010)
New Revision: 3264
Removed:
jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/Recovery.java
jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/RedoLog.java
Modified:
jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
Log:
EXOJCR-987 : actions and redo successfully deleted
Modified: jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
===================================================================
--- jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2010-10-08 12:39:11 UTC (rev 3263)
+++ jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2010-10-08 13:03:55 UTC (rev 3264)
@@ -23,7 +23,6 @@
import org.exoplatform.services.jcr.dataflow.ItemDataConsumer;
import org.exoplatform.services.jcr.datamodel.ItemData;
import org.exoplatform.services.jcr.datamodel.NodeData;
-import org.exoplatform.services.jcr.impl.Constants;
import org.exoplatform.services.jcr.impl.core.query.IndexerIoMode;
import org.exoplatform.services.jcr.impl.core.query.IndexerIoModeHandler;
import org.exoplatform.services.jcr.impl.core.query.IndexerIoModeListener;
@@ -156,11 +155,6 @@
private final Object updateMonitor = new Object();
/**
- * <code>true</code> if the redo log contained entries on startup.
- */
- private boolean redoLogApplied = false;
-
- /**
* The time this index was last flushed or a transaction was committed.
*/
private long lastFlushTime;
@@ -182,11 +176,6 @@
private TimerTask flushTask;
/**
- * The RedoLog of this <code>MultiIndex</code>.
- */
- private RedoLog redoLog = null;
-
- /**
* The indexing queue with pending text extraction jobs.
*/
private IndexingQueue indexingQueue;
@@ -202,11 +191,6 @@
private long nextTransactionId = 0;
/**
- * The current transaction id.
- */
- private long currentTransactionId = -1;
-
- /**
* Flag indicating whether re-indexing is running.
*/
private boolean reindexing = false;
@@ -386,16 +370,16 @@
{
long count = 0;
// traverse and index workspace
-
+
// TODO: this was removed
//executeAndLog(new Start(Action.INTERNAL_TRANSACTION));
-
+
// NodeData rootState = (NodeData) stateMgr.getItemData(rootId);
count = createIndex(indexingTree.getIndexingRoot(), stateMgr, count);
-
+
// TODO : this was replaced
//executeAndLog(new Commit(getTransactionId()));
-
+
log.info("Created initial index for {} nodes", new Long(count));
releaseMultiReader();
scheduleFlushTask();
@@ -461,15 +445,15 @@
try
{
long transactionId = nextTransactionId++;
-
- // TODO: this was removed
+
+ // TODO: this was removed
//executeAndLog(new Start(transactionId));
for (Iterator it = remove.iterator(); it.hasNext();)
{
// TODO this was replaced
//executeAndLog(new DeleteNode(transactionId, (String)it.next()));
-
+
String uuidString = (String)it.next();
// check if indexing queue is still working on
// this node from a previous update
@@ -498,9 +482,7 @@
}
}
}
-
-
-
+
}
for (Iterator it = add.iterator(); it.hasNext();)
{
@@ -514,13 +496,13 @@
{
volatileIndex.addDocuments(new Document[]{doc});
}
-
+
// commit volatile index if needed
flush |= checkVolatileCommit();
}
}
-
- // TODO : this was replaced
+
+ // TODO : this was replaced
//executeAndLog(new Commit(transactionId));
// flush whole index when volatile index has been commited.
@@ -596,10 +578,10 @@
try
{
Term idTerm = new Term(FieldNames.UUID, uuid.toString());
-
- // TODO: this was removed
+
+ // TODO: this was removed
//executeAndLog(new Start(Action.INTERNAL_TRANSACTION));
-
+
num = volatileIndex.removeDocument(idTerm);
if (num > 0)
{
@@ -621,7 +603,7 @@
num += removed;
}
}
- // TODO : this was replaced
+ // TODO : this was replaced
//executeAndLog(new Commit(getTransactionId()));
}
finally
@@ -849,7 +831,7 @@
{
// TODO this was replaced
//executeAndLog(new DeleteIndex(getTransactionId(), indexName));
-
+
for (Iterator it2 = indexes.iterator(); it2.hasNext();)
{
PersistentIndex idx = (PersistentIndex)it2.next();
@@ -860,7 +842,7 @@
break;
}
}
-
+
}
}
@@ -871,7 +853,7 @@
///executeAndLog(new CreateIndex(getTransactionId(), index.getName()));
PersistentIndex idx = getOrCreateIndex(index.getName());
-
+
// TODO: this is replaced
//executeAndLog(new AddIndex(getTransactionId(), index.getName()));
if (!indexNames.contains(index.getName()))
@@ -891,8 +873,8 @@
{
// only commit if we are not reindexing
// when reindexing the final commit is done at the very end
-
- // TODO : this was replaced
+
+ // TODO : this was replaced
//executeAndLog(new Commit(getTransactionId()));
}
}
@@ -1130,17 +1112,6 @@
}
/**
- * Returns <code>true</code> if the redo log contained entries while this
- * index was instantiated; <code>false</code> otherwise.
- *
- * @return <code>true</code> if the redo log contained entries.
- */
- boolean getRedoLogApplied()
- {
- return redoLogApplied;
- }
-
- /**
* Removes the <code>index</code> from the list of active sub indexes. The
* Index is not acutally deleted right away, but postponed to the
* transaction commit.
@@ -1198,19 +1169,17 @@
//executeAndLog(new DeleteIndex(getTransactionId(), index.getName()));
index.close();
- deleteIndex(index);
+ deleteIndex(index);
}
}
}
- // TODO : this was replaced
+ // TODO : this was replaced
//executeAndLog(new Commit(getTransactionId()));
indexNames.write();
// reset redo log
- redoLog.clear();
-
lastFlushTime = System.currentTimeMillis();
lastFileSystemFlushTime = System.currentTimeMillis();
}
@@ -1326,48 +1295,6 @@
}
/**
- * Returns the current transaction id.
- *
- * @return the current transaction id.
- */
- private long getTransactionId()
- {
- return currentTransactionId;
- }
-
- /**
- * Executes action <code>a</code> and appends the action to the redo log if
- * successful.
- *
- * @param a
- * the <code>Action</code> to execute.
- * @return the executed action.
- * @throws IOException
- * if an error occurs while executing the action or appending
- * the action to the redo log.
- */
- private Action executeAndLog(final Action a) throws IOException
- {
- return SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Action>()
- {
- public Action run() throws Exception
- {
- a.execute(MultiIndex.this);
- redoLog.append(a);
- // please note that flushing the redo log is only required on
- // commit, but we also want to keep track of new indexes for sure.
- // otherwise it might happen that unused index folders are orphaned
- // after a crash.
- if (a.getType() == Action.TYPE_COMMIT || a.getType() == Action.TYPE_ADD_INDEX)
- {
- redoLog.flush();
- }
- return a;
- }
- });
- }
-
- /**
* Checks if it is needed to commit the volatile index according to
* {@link SearchIndex#getMaxVolatileIndexSize()}.
*
@@ -1403,31 +1330,31 @@
long time = System.currentTimeMillis();
// create index
-
+
//TODO this was replaced
-// CreateIndex create = new CreateIndex(getTransactionId(), null);
-// executeAndLog(create);
-
+ // CreateIndex create = new CreateIndex(getTransactionId(), null);
+ // executeAndLog(create);
+
PersistentIndex idx = getOrCreateIndex(null);
// commit volatile index
-
+
// TODO THIS IS REPLACED
//executeAndLog(new VolatileCommit(getTransactionId(), idx.getName()));
idx.copyIndex(volatileIndex);
resetVolatileIndex();
-
+
// TODO this is replaced
// add new index
-// AddIndex add = new AddIndex(getTransactionId(), create.getIndexName());
-// executeAndLog(add);
+ // AddIndex add = new AddIndex(getTransactionId(), create.getIndexName());
+ // executeAndLog(add);
if (!indexNames.contains(idx.getName()))
{
indexNames.addName(idx.getName());
}
-
+
// create new volatile index
resetVolatileIndex();
@@ -1465,11 +1392,11 @@
{
return count;
}
-
+
// TODO: this is replaced
//executeAndLog(new AddNode(getTransactionId(), node.getIdentifier()));
volatileIndex.addDocuments(new Document[]{createDocument(node)});
-
+
if (++count % 100 == 0)
{
@@ -1565,7 +1492,6 @@
{
try
{
- if (redoLog.hasEntries())
{
log.debug("Flushing index after being idle for " + idleTime + " ms.");
synchronized (updateMonitor)
@@ -1647,7 +1573,7 @@
{
// TODO this was replaced
//executeAndLog(new DeleteNode(getTransactionId(), (String)it.next()));
-
+
String uuidString = (String)it.next();
// check if indexing queue is still working on
// this node from a previous update
@@ -1676,8 +1602,7 @@
}
}
}
-
-
+
}
for (Iterator it = finished.values().iterator(); it.hasNext();)
{
@@ -1703,899 +1628,6 @@
// >---------------------------------------
/**
- * Defines an action on an <code>MultiIndex</code>.
- */
- public abstract static class Action
- {
-
- /**
- * Action identifier in redo log for transaction start action.
- */
- static final String START = "STR";
-
- /**
- * Action type for start action.
- */
- public static final int TYPE_START = 0;
-
- /**
- * Action identifier in redo log for add node action.
- */
- static final String ADD_NODE = "ADD";
-
- /**
- * Action type for add node action.
- */
- public static final int TYPE_ADD_NODE = 1;
-
- /**
- * Action identifier in redo log for node delete action.
- */
- static final String DELETE_NODE = "DEL";
-
- /**
- * Action type for delete node action.
- */
- public static final int TYPE_DELETE_NODE = 2;
-
- /**
- * Action identifier in redo log for transaction commit action.
- */
- static final String COMMIT = "COM";
-
- /**
- * Action type for commit action.
- */
- public static final int TYPE_COMMIT = 3;
-
- /**
- * Action identifier in redo log for volatile index commit action.
- */
- static final String VOLATILE_COMMIT = "VOL_COM";
-
- /**
- * Action type for volatile index commit action.
- */
- public static final int TYPE_VOLATILE_COMMIT = 4;
-
- /**
- * Action identifier in redo log for index create action.
- */
- static final String CREATE_INDEX = "CRE_IDX";
-
- /**
- * Action type for create index action.
- */
- public static final int TYPE_CREATE_INDEX = 5;
-
- /**
- * Action identifier in redo log for index add action.
- */
- static final String ADD_INDEX = "ADD_IDX";
-
- /**
- * Action type for add index action.
- */
- public static final int TYPE_ADD_INDEX = 6;
-
- /**
- * Action identifier in redo log for delete index action.
- */
- static final String DELETE_INDEX = "DEL_IDX";
-
- /**
- * Action type for delete index action.
- */
- public static final int TYPE_DELETE_INDEX = 7;
-
- /**
- * Transaction identifier for internal actions like volatile index
- * commit triggered by timer thread.
- */
- static final long INTERNAL_TRANSACTION = -1;
-
- /**
- * Transaction identifier for internal action that replaces indexs.
- */
- static final long INTERNAL_TRANS_REPL_INDEXES = -2;
-
- /**
- * The id of the transaction that executed this action.
- */
- private final long transactionId;
-
- /**
- * The action type.
- */
- private final int type;
-
- /**
- * Creates a new <code>Action</code>.
- *
- * @param transactionId
- * the id of the transaction that executed this action.
- * @param type
- * the action type.
- */
- Action(long transactionId, int type)
- {
- this.transactionId = transactionId;
- this.type = type;
- }
-
- /**
- * Returns the transaction id for this <code>Action</code>.
- *
- * @return the transaction id for this <code>Action</code>.
- */
- long getTransactionId()
- {
- return transactionId;
- }
-
- /**
- * Returns the action type.
- *
- * @return the action type.
- */
- int getType()
- {
- return type;
- }
-
- /**
- * Executes this action on the <code>index</code>.
- *
- * @param index
- * the index where to execute the action.
- * @throws IOException
- * if the action fails due to some I/O error in the index or
- * some other error.
- */
- public abstract void execute(MultiIndex index) throws IOException;
-
- /**
- * Executes the inverse operation of this action. That is, does an undo
- * of this action. This default implementation does nothing, but returns
- * silently.
- *
- * @param index
- * the index where to undo the action.
- * @throws IOException
- * if the action cannot be undone.
- */
- public void undo(MultiIndex index) throws IOException
- {
- }
-
- /**
- * Returns a <code>String</code> representation of this action that can
- * be written to the {@link RedoLog}.
- *
- * @return a <code>String</code> representation of this action.
- */
- @Override
- public abstract String toString();
-
- /**
- * Parses an line in the redo log and created an {@link Action}.
- *
- * @param line
- * the line from the redo log.
- * @return an <code>Action</code>.
- * @throws IllegalArgumentException
- * if the line is malformed.
- */
- static Action fromString(String line) throws IllegalArgumentException
- {
- int endTransIdx = line.indexOf(' ');
- if (endTransIdx == -1)
- {
- throw new IllegalArgumentException(line);
- }
- long transactionId;
- try
- {
- transactionId = Long.parseLong(line.substring(0, endTransIdx));
- }
- catch (NumberFormatException e)
- {
- throw new IllegalArgumentException(line);
- }
- int endActionIdx = line.indexOf(' ', endTransIdx + 1);
- if (endActionIdx == -1)
- {
- // action does not have arguments
- endActionIdx = line.length();
- }
- String actionLabel = line.substring(endTransIdx + 1, endActionIdx);
- String arguments = "";
- if (endActionIdx + 1 <= line.length())
- {
- arguments = line.substring(endActionIdx + 1);
- }
- Action a;
- if (actionLabel.equals(Action.ADD_NODE))
- {
- a = AddNode_.fromString(transactionId, arguments);
- }
- else if (actionLabel.equals(Action.ADD_INDEX))
- {
- a = AddIndex_.fromString(transactionId, arguments);
- }
- else if (actionLabel.equals(Action.COMMIT))
- {
- a = Commit_.fromString(transactionId, arguments);
- }
- else if (actionLabel.equals(Action.CREATE_INDEX))
- {
- a = CreateIndex_.fromString(transactionId, arguments);
- }
- else if (actionLabel.equals(Action.DELETE_INDEX))
- {
- a = DeleteIndex_.fromString(transactionId, arguments);
- }
- else if (actionLabel.equals(Action.DELETE_NODE))
- {
- a = DeleteNode_.fromString(transactionId, arguments);
- }
- else if (actionLabel.equals(Action.START))
- {
- a = Start_.fromString(transactionId, arguments);
- }
- else if (actionLabel.equals(Action.VOLATILE_COMMIT))
- {
- a = VolatileCommit_.fromString(transactionId, arguments);
- }
- else
- {
- throw new IllegalArgumentException(line);
- }
- return a;
- }
- }
-
- /**
- * Adds an index to the MultiIndex's active persistent index list.
- */
- private static class AddIndex_ extends Action
- {
-
- /**
- * The name of the index to add.
- */
- private String indexName;
-
- /**
- * Creates a new AddIndex action.
- *
- * @param transactionId
- * the id of the transaction that executes this action.
- * @param indexName
- * the name of the index to add, or <code>null</code> if an
- * index with a new name should be created.
- */
- AddIndex_(long transactionId, String indexName)
- {
- super(transactionId, Action.TYPE_ADD_INDEX);
- this.indexName = indexName;
- }
-
- /**
- * Creates a new AddIndex action.
- *
- * @param transactionId
- * the id of the transaction that executes this action.
- * @param arguments
- * the name of the index to add.
- * @return the AddIndex action.
- * @throws IllegalArgumentException
- * if the arguments are malformed.
- */
- static AddIndex_ fromString(long transactionId, String arguments)
- {
- return new AddIndex_(transactionId, arguments);
- }
-
- /**
- * Adds a sub index to <code>index</code>.
- *
- * @inheritDoc
- */
- @Override
- public void execute(MultiIndex index) throws IOException
- {
- PersistentIndex idx = index.getOrCreateIndex(indexName);
- if (!index.indexNames.contains(indexName))
- {
- index.indexNames.addName(indexName);
- }
- }
-
- /**
- * @inheritDoc
- */
- @Override
- public String toString()
- {
- StringBuffer logLine = new StringBuffer();
- logLine.append(Long.toString(getTransactionId()));
- logLine.append(' ');
- logLine.append(Action.ADD_INDEX);
- logLine.append(' ');
- logLine.append(indexName);
- return logLine.toString();
- }
- }
-
- /**
- * Adds a node to the index.
- */
- private static class AddNode_ extends Action
- {
-
- /**
- * The maximum length of a AddNode String.
- */
- private static final int ENTRY_LENGTH =
- Long.toString(Long.MAX_VALUE).length() + Action.ADD_NODE.length() + Constants.UUID_FORMATTED_LENGTH + 2;
-
- /**
- * The uuid of the node to add.
- */
- private final String uuid;
-
- /**
- * The document to add to the index, or <code>null</code> if not
- * available.
- */
- private Document doc;
-
- /**
- * Creates a new AddNode action.
- *
- * @param transactionId
- * the id of the transaction that executes this action.
- * @param uuid
- * the uuid of the node to add.
- */
- AddNode_(long transactionId, String uuid)
- {
- super(transactionId, Action.TYPE_ADD_NODE);
- this.uuid = uuid;
- }
-
- /**
- * Creates a new AddNode action.
- *
- * @param transactionId
- * the id of the transaction that executes this action.
- * @param doc
- * the document to add.
- */
- AddNode_(long transactionId, Document doc)
- {
- this(transactionId, doc.get(FieldNames.UUID));
- this.doc = doc;
- }
-
- /**
- * Creates a new AddNode action.
- *
- * @param transactionId
- * the id of the transaction that executes this action.
- * @param arguments
- * the arguments to this action. The uuid of the node to add
- * @return the AddNode action.
- * @throws IllegalArgumentException
- * if the arguments are malformed. Not a UUID.
- */
- static AddNode_ fromString(long transactionId, String arguments) throws IllegalArgumentException
- {
- // simple length check
- if (arguments.length() != Constants.UUID_FORMATTED_LENGTH)
- {
- throw new IllegalArgumentException("arguments is not a uuid");
- }
- return new AddNode_(transactionId, arguments);
- }
-
- /**
- * Adds a node to the index.
- *
- * @inheritDoc
- */
- @Override
- public void execute(MultiIndex index) throws IOException
- {
- if (doc == null)
- {
- try
- {
- doc = index.createDocument(uuid);
- }
- catch (RepositoryException e)
- {
- // node does not exist anymore
- log.debug(e.getMessage());
- }
- }
- if (doc != null)
- {
- index.volatileIndex.addDocuments(new Document[]{doc});
- }
- }
-
- /**
- * @inheritDoc
- */
- @Override
- public String toString()
- {
- StringBuffer logLine = new StringBuffer(ENTRY_LENGTH);
- logLine.append(Long.toString(getTransactionId()));
- logLine.append(' ');
- logLine.append(Action.ADD_NODE);
- logLine.append(' ');
- logLine.append(uuid);
- return logLine.toString();
- }
- }
-
- /**
- * Commits a transaction.
- */
- private static class Commit_ extends Action
- {
-
- /**
- * Creates a new Commit action.
- *
- * @param transactionId
- * the id of the transaction that is committed.
- */
- Commit_(long transactionId)
- {
- super(transactionId, Action.TYPE_COMMIT);
- }
-
- /**
- * Creates a new Commit action.
- *
- * @param transactionId
- * the id of the transaction that executes this action.
- * @param arguments
- * ignored by this method.
- * @return the Commit action.
- */
- static Commit_ fromString(long transactionId, String arguments)
- {
- return new Commit_(transactionId);
- }
-
- /**
- * Touches the last flush time (sets it to the current time).
- *
- * @inheritDoc
- */
- @Override
- public void execute(MultiIndex index) throws IOException
- {
- index.lastFlushTime = System.currentTimeMillis();
- }
-
- /**
- * @inheritDoc
- */
- @Override
- public String toString()
- {
- return Long.toString(getTransactionId()) + ' ' + Action.COMMIT;
- }
- }
-
- /**
- * Creates an new sub index but does not add it to the active persistent
- * index list.
- */
- private static class CreateIndex_ extends Action
- {
-
- /**
- * The name of the index to add.
- */
- private String indexName;
-
- /**
- * Creates a new CreateIndex action.
- *
- * @param transactionId
- * the id of the transaction that executes this action.
- * @param indexName
- * the name of the index to add, or <code>null</code> if an
- * index with a new name should be created.
- */
- CreateIndex_(long transactionId, String indexName)
- {
- super(transactionId, Action.TYPE_CREATE_INDEX);
- this.indexName = indexName;
- }
-
- /**
- * Creates a new CreateIndex action.
- *
- * @param transactionId
- * the id of the transaction that executes this action.
- * @param arguments
- * the name of the index to create.
- * @return the AddIndex action.
- * @throws IllegalArgumentException
- * if the arguments are malformed.
- */
- static CreateIndex_ fromString(long transactionId, String arguments)
- {
- // when created from String, this action is executed as redo action
- return new CreateIndex_(transactionId, arguments);
- }
-
- /**
- * Creates a new index.
- *
- * @inheritDoc
- */
- @Override
- public void execute(MultiIndex index) throws IOException
- {
- PersistentIndex idx = index.getOrCreateIndex(indexName);
- indexName = idx.getName();
- }
-
- /**
- * @inheritDoc
- */
- @Override
- public void undo(MultiIndex index) throws IOException
- {
- if (index.hasIndex(indexName))
- {
- PersistentIndex idx = index.getOrCreateIndex(indexName);
- idx.close();
- index.deleteIndex(idx);
- }
- }
-
- /**
- * @inheritDoc
- */
- @Override
- public String toString()
- {
- StringBuffer logLine = new StringBuffer();
- logLine.append(Long.toString(getTransactionId()));
- logLine.append(' ');
- logLine.append(Action.CREATE_INDEX);
- logLine.append(' ');
- logLine.append(indexName);
- return logLine.toString();
- }
-
- /**
- * Returns the index name that has been created. If this method is
- * called before {@link #execute(MultiIndex)} it will return
- * <code>null</code>.
- *
- * @return the name of the index that has been created.
- */
- String getIndexName()
- {
- return indexName;
- }
- }
-
- /**
- * Closes and deletes an index that is no longer in use.
- */
- private static class DeleteIndex_ extends Action
- {
-
- /**
- * The name of the index to add.
- */
- private String indexName;
-
- /**
- * Creates a new DeleteIndex action.
- *
- * @param transactionId
- * the id of the transaction that executes this action.
- * @param indexName
- * the name of the index to delete.
- */
- DeleteIndex_(long transactionId, String indexName)
- {
- super(transactionId, Action.TYPE_DELETE_INDEX);
- this.indexName = indexName;
- }
-
- /**
- * Creates a new DeleteIndex action.
- *
- * @param transactionId
- * the id of the transaction that executes this action.
- * @param arguments
- * the name of the index to delete.
- * @return the DeleteIndex action.
- * @throws IllegalArgumentException
- * if the arguments are malformed.
- */
- static DeleteIndex_ fromString(long transactionId, String arguments)
- {
- return new DeleteIndex_(transactionId, arguments);
- }
-
- /**
- * Removes a sub index from <code>index</code>.
- *
- * @inheritDoc
- */
- @Override
- public void execute(MultiIndex index) throws IOException
- {
- // get index if it exists
- for (Iterator it = index.indexes.iterator(); it.hasNext();)
- {
- PersistentIndex idx = (PersistentIndex)it.next();
- if (idx.getName().equals(indexName))
- {
- idx.close();
- index.deleteIndex(idx);
- break;
- }
- }
- }
-
- /**
- * @inheritDoc
- */
- @Override
- public String toString()
- {
- StringBuffer logLine = new StringBuffer();
- logLine.append(Long.toString(getTransactionId()));
- logLine.append(' ');
- logLine.append(Action.DELETE_INDEX);
- logLine.append(' ');
- logLine.append(indexName);
- return logLine.toString();
- }
- }
-
- /**
- * Deletes a node from the index.
- */
- private static class DeleteNode_ extends Action
- {
-
- /**
- * The maximum length of a DeleteNode String.
- */
- private static final int ENTRY_LENGTH =
- Long.toString(Long.MAX_VALUE).length() + Action.DELETE_NODE.length() + Constants.UUID_FORMATTED_LENGTH + 2;
-
- /**
- * The uuid of the node to remove.
- */
- private final String uuid;
-
- /**
- * Creates a new DeleteNode action.
- *
- * @param transactionId
- * the id of the transaction that executes this action.
- * @param uuid
- * the uuid of the node to delete.
- */
- DeleteNode_(long transactionId, String uuid)
- {
- super(transactionId, Action.TYPE_DELETE_NODE);
- this.uuid = uuid;
- }
-
- /**
- * Creates a new DeleteNode action.
- *
- * @param transactionId
- * the id of the transaction that executes this action.
- * @param arguments
- * the uuid of the node to delete.
- * @return the DeleteNode action.
- * @throws IllegalArgumentException
- * if the arguments are malformed. Not a UUID.
- */
- static DeleteNode_ fromString(long transactionId, String arguments)
- {
- // simple length check
- if (arguments.length() != Constants.UUID_FORMATTED_LENGTH)
- {
- throw new IllegalArgumentException("arguments is not a uuid");
- }
- return new DeleteNode_(transactionId, arguments);
- }
-
- /**
- * Deletes a node from the index.
- *
- * @inheritDoc
- */
- @Override
- public void execute(MultiIndex index) throws IOException
- {
- String uuidString = uuid.toString();
- // check if indexing queue is still working on
- // this node from a previous update
- Document doc = index.indexingQueue.removeDocument(uuidString);
- if (doc != null)
- {
- Util.disposeDocument(doc);
- }
- Term idTerm = new Term(FieldNames.UUID, uuidString);
- // if the document cannot be deleted from the volatile index
- // delete it from one of the persistent indexes.
- int num = index.volatileIndex.removeDocument(idTerm);
- if (num == 0)
- {
- for (int i = index.indexes.size() - 1; i >= 0; i--)
- {
- // only look in registered indexes
- PersistentIndex idx = (PersistentIndex)index.indexes.get(i);
- if (index.indexNames.contains(idx.getName()))
- {
- num = idx.removeDocument(idTerm);
- if (num > 0)
- {
- return;
- }
- }
- }
- }
- }
-
- /**
- * @inheritDoc
- */
- @Override
- public String toString()
- {
- StringBuffer logLine = new StringBuffer(ENTRY_LENGTH);
- logLine.append(Long.toString(getTransactionId()));
- logLine.append(' ');
- logLine.append(Action.DELETE_NODE);
- logLine.append(' ');
- logLine.append(uuid);
- return logLine.toString();
- }
- }
-
- /**
- * Starts a transaction.
- */
- private static class Start_ extends Action
- {
-
- /**
- * Creates a new Start transaction action.
- *
- * @param transactionId
- * the id of the transaction that started.
- */
- Start_(long transactionId)
- {
- super(transactionId, Action.TYPE_START);
- }
-
- /**
- * Creates a new Start action.
- *
- * @param transactionId
- * the id of the transaction that executes this action.
- * @param arguments
- * ignored by this method.
- * @return the Start action.
- */
- static Start_ fromString(long transactionId, String arguments)
- {
- return new Start_(transactionId);
- }
-
- /**
- * Sets the current transaction id on <code>index</code>.
- *
- * @inheritDoc
- */
- @Override
- public void execute(MultiIndex index) throws IOException
- {
- index.currentTransactionId = getTransactionId();
- }
-
- /**
- * @inheritDoc
- */
- @Override
- public String toString()
- {
- return Long.toString(getTransactionId()) + ' ' + Action.START;
- }
- }
-
- /**
- * Commits the volatile index to disk.
- */
- private static class VolatileCommit_ extends Action
- {
-
- /**
- * The name of the target index to commit to.
- */
- private final String targetIndex;
-
- /**
- * Creates a new VolatileCommit action.
- *
- * @param transactionId
- * the id of the transaction that executes this action.
- */
- VolatileCommit_(long transactionId, String targetIndex)
- {
- super(transactionId, Action.TYPE_VOLATILE_COMMIT);
- this.targetIndex = targetIndex;
- }
-
- /**
- * Creates a new VolatileCommit action.
- *
- * @param transactionId
- * the id of the transaction that executes this action.
- * @param arguments
- * ignored by this implementation.
- * @return the VolatileCommit action.
- */
- static VolatileCommit_ fromString(long transactionId, String arguments)
- {
- return new VolatileCommit_(transactionId, arguments);
- }
-
- /**
- * Commits the volatile index to disk.
- *
- * @inheritDoc
- */
- @Override
- public void execute(MultiIndex index) throws IOException
- {
- VolatileIndex volatileIndex = index.getVolatileIndex();
- PersistentIndex persistentIndex = index.getOrCreateIndex(targetIndex);
- persistentIndex.copyIndex(volatileIndex);
- index.resetVolatileIndex();
- }
-
- /**
- * @inheritDoc
- */
- @Override
- public String toString()
- {
- StringBuffer logLine = new StringBuffer();
- logLine.append(Long.toString(getTransactionId()));
- logLine.append(' ');
- logLine.append(Action.VOLATILE_COMMIT);
- logLine.append(' ');
- logLine.append(targetIndex);
- return logLine.toString();
- }
- }
-
- /**
* @see org.exoplatform.services.jcr.impl.core.query.IndexerIoModeListener#onChangeMode(org.exoplatform.services.jcr.impl.core.query.IndexerIoMode)
*/
public void onChangeMode(IndexerIoMode mode)
@@ -2626,7 +1658,6 @@
// try to stop merger in safe way
flushTask.cancel();
FLUSH_TIMER.purge();
- this.redoLog = null;
}
/**
@@ -2644,21 +1675,12 @@
releaseMultiReader();
}
- this.redoLog = new RedoLog(indexDir);
- redoLogApplied = redoLog.hasEntries();
-
- // run recovery
- Recovery.run(this, redoLog);
-
// enqueue unused segments for deletion
enqueueUnusedSegments();
attemptDelete();
// now that we are ready, start index merger
- if (redoLogApplied)
- {
- flush();
- }
+ flush();
if (indexNames.size() > 0)
{
@@ -2749,4 +1771,10 @@
}
}
}
+
+ @Deprecated
+ public boolean getRedoLogApplied()
+ {
+ return false;
+ }
}
Deleted: jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/Recovery.java
===================================================================
--- jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/Recovery.java 2010-10-08 12:39:11 UTC (rev 3263)
+++ jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/Recovery.java 2010-10-08 13:03:55 UTC (rev 3264)
@@ -1,203 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.exoplatform.services.jcr.impl.core.query.lucene;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-/**
- * Implements the recovery process.
- */
-class Recovery
-{
-
- /**
- * The logger instance for this class.
- */
- private static final Logger log = LoggerFactory.getLogger("exo.jcr.component.core.Recovery");
-
- /**
- * The MultiIndex where to run the recovery on.
- */
- private final MultiIndex index;
-
- /**
- * The redo redoLog.
- */
- private final RedoLog redoLog;
-
- /**
- * The ids of the uncommitted transactions. Set of Integer objects.
- */
- private final Set losers = new HashSet();
-
- /**
- * Creates a new Recovery instance.
- *
- * @param index the MultiIndex to recover.
- * @param redoLog the redo redoLog.
- */
- private Recovery(MultiIndex index, RedoLog redoLog)
- {
- this.index = index;
- this.redoLog = redoLog;
- }
-
- /**
- * Runs a recovery on <code>index</code> if <code>redoLog</code> contains
- * log entries.
- * <p/>
- * If recovery succeeds the <code>index</code> is flushed and the redo log
- * is cleared. That is, the <code>index</code> is stable.<br/>
- * If recovery fails an IOException is thrown, and the redo log will not
- * be modified. The recovery process can then be executed again, after
- * fixing the cause of the IOException (e.g. disk full).
- *
- * @param index the index to recover.
- * @param redoLog the redo log.
- * @throws IOException if the recovery fails.
- */
- static void run(MultiIndex index, RedoLog redoLog) throws IOException
- {
- if (!redoLog.hasEntries())
- {
- log.debug("RedoLog is empty, no recovery needed.");
- return;
- }
- log.info("Found uncommitted redo log. Applying changes now...");
- Recovery r = new Recovery(index, redoLog);
- r.run();
- log.info("Redo changes applied.");
- }
-
- /**
- * Runs the recovery process.
- *
- * @throws IOException if the recovery fails.
- */
- private void run() throws IOException
- {
- List actions = redoLog.getActions();
-
- // find loser transactions
- for (Iterator it = actions.iterator(); it.hasNext();)
- {
- MultiIndex.Action a = (MultiIndex.Action)it.next();
- if (a.getType() == MultiIndex.Action.TYPE_START)
- {
- losers.add(new Long(a.getTransactionId()));
- }
- else if (a.getType() == MultiIndex.Action.TYPE_COMMIT)
- {
- losers.remove(new Long(a.getTransactionId()));
- }
- }
-
- // find last volatile commit without changes from a loser
- int lastSafeVolatileCommit = -1;
- Set transactionIds = new HashSet();
- for (int i = 0; i < actions.size(); i++)
- {
- MultiIndex.Action a = (MultiIndex.Action)actions.get(i);
- if (a.getType() == MultiIndex.Action.TYPE_COMMIT)
- {
- transactionIds.clear();
- }
- else if (a.getType() == MultiIndex.Action.TYPE_VOLATILE_COMMIT)
- {
- transactionIds.retainAll(losers);
- // check if transactionIds contains losers
- if (transactionIds.size() > 0)
- {
- // found dirty volatile commit
- break;
- }
- else
- {
- lastSafeVolatileCommit = i;
- }
- }
- else
- {
- transactionIds.add(new Long(a.getTransactionId()));
- }
- }
-
- // delete dirty indexes
- for (int i = lastSafeVolatileCommit + 1; i < actions.size(); i++)
- {
- MultiIndex.Action a = (MultiIndex.Action)actions.get(i);
- if (a.getType() == MultiIndex.Action.TYPE_CREATE_INDEX)
- {
- a.undo(index);
- }
- }
-
- // replay actions up to last safe volatile commit
- // ignore add node actions, they are included in volatile commits
- for (int i = 0; i < actions.size() && i <= lastSafeVolatileCommit; i++)
- {
- MultiIndex.Action a = (MultiIndex.Action)actions.get(i);
- switch (a.getType())
- {
- case MultiIndex.Action.TYPE_ADD_INDEX :
- case MultiIndex.Action.TYPE_CREATE_INDEX :
- case MultiIndex.Action.TYPE_DELETE_INDEX :
- case MultiIndex.Action.TYPE_DELETE_NODE :
- // ignore actions by the index merger.
- // the previously created index of a merge has been
- // deleted because it was considered dirty.
- // we are conservative here and let the index merger do
- // its work again.
- if (a.getTransactionId() == MultiIndex.Action.INTERNAL_TRANS_REPL_INDEXES)
- {
- continue;
- }
- a.execute(index);
- }
- }
-
- // now replay the rest until we encounter a loser transaction
- for (int i = lastSafeVolatileCommit + 1; i < actions.size(); i++)
- {
- MultiIndex.Action a = (MultiIndex.Action)actions.get(i);
- if (losers.contains(new Long(a.getTransactionId())))
- {
- break;
- }
- else
- {
- // ignore actions by the index merger.
- if (a.getTransactionId() == MultiIndex.Action.INTERNAL_TRANS_REPL_INDEXES)
- {
- continue;
- }
- a.execute(index);
- }
- }
-
- // now we are consistent again -> flush
- index.flush();
- index.releaseMultiReader();
- }
-}
Deleted: jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/RedoLog.java
===================================================================
--- jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/RedoLog.java 2010-10-08 12:39:11 UTC (rev 3263)
+++ jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/RedoLog.java 2010-10-08 13:03:55 UTC (rev 3264)
@@ -1,291 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.exoplatform.services.jcr.impl.core.query.lucene;
-
-import org.apache.lucene.store.Directory;
-import org.exoplatform.services.jcr.impl.core.query.lucene.directory.IndexInputStream;
-import org.exoplatform.services.jcr.impl.core.query.lucene.directory.IndexOutputStream;
-import org.exoplatform.services.jcr.impl.util.SecurityHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import java.security.PrivilegedExceptionAction;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Implements a redo log for changes that have not been committed to disk. While
- * nodes are added to and removed from the volatile index (held in memory) a
- * redo log is written to keep track of the changes. In case the Jackrabbit
- * process terminates unexpected the redo log is applied when Jackrabbit is
- * restarted the next time.
- * <p/>
- * This class is not thread-safe.
- */
-class RedoLog
-{
-
- /**
- * Logger instance for this class
- */
- private static final Logger log = LoggerFactory.getLogger("exo.jcr.component.core.RedoLog");
-
- /**
- * Default name of the redo log file
- */
- private static final String REDO_LOG = "redo.log";
-
- /**
- * Implements a {@link ActionCollector} that counts all entries and sets
- * {@link #entryCount}.
- */
- private final ActionCollector ENTRY_COUNTER = new ActionCollector()
- {
- public void collect(MultiIndex.Action a)
- {
- entryCount++;
- }
- };
-
- /**
- * The directory where the log file is stored.
- */
- private final Directory dir;
-
- /**
- * The number of log entries in the log file
- */
- private int entryCount = 0;
-
- /**
- * Writer to the log file
- */
- private Writer out;
-
- /**
- * Creates a new <code>RedoLog</code> instance, which stores its log in the
- * given directory.
- *
- * @param dir the directory where the redo log file is located.
- * @throws IOException if an error occurs while reading the redo log.
- */
- RedoLog(Directory dir) throws IOException
- {
- this.dir = dir;
- read(ENTRY_COUNTER);
- }
-
- /**
- * Returns <code>true</code> if this redo log contains any entries,
- * <code>false</code> otherwise.
- * @return <code>true</code> if this redo log contains any entries,
- * <code>false</code> otherwise.
- */
- boolean hasEntries()
- {
- return entryCount > 0;
- }
-
- /**
- * Returns the number of entries in this redo log.
- * @return the number of entries in this redo log.
- */
- int getSize()
- {
- return entryCount;
- }
-
- /**
- * Returns a List with all {@link MultiIndex.Action} instances in the
- * redo log.
- *
- * @return an List with all {@link MultiIndex.Action} instances in the
- * redo log.
- * @throws IOException if an error occurs while reading from the redo log.
- */
- List getActions() throws IOException
- {
- final List actions = new ArrayList();
- read(new ActionCollector()
- {
- public void collect(MultiIndex.Action a)
- {
- actions.add(a);
- }
- });
- return actions;
- }
-
- /**
- * Appends an action to the log.
- *
- * @param action the action to append.
- * @throws IOException if the node cannot be written to the redo
- * log.
- */
- void append(final MultiIndex.Action action) throws IOException
- {
- SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
- {
- public Object run() throws Exception
- {
- initOut();
- out.write(action.toString() + "\n");
- entryCount++;
- return null;
- }
- });
- }
-
- /**
- * Flushes all pending writes to the underlying file.
- * @throws IOException if an error occurs while writing.
- */
- void flush() throws IOException
- {
- SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
- {
- public Object run() throws Exception
- {
- if (out != null)
- {
- out.flush();
- }
- return null;
- }
- });
- }
-
- /**
- * Clears the redo log.
- * @throws IOException if the redo log cannot be cleared.
- */
- void clear() throws IOException
- {
- SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
- {
- public Object run() throws Exception
- {
- if (out != null)
- {
- out.close();
- out = null;
- }
- if (dir.fileExists(REDO_LOG))
- {
- dir.deleteFile(REDO_LOG);
- }
- entryCount = 0;
- return null;
- }
- });
- }
-
- /**
- * Initializes the {@link #out} stream if it is not yet set.
- * @throws IOException if an error occurs while creating the
- * output stream.
- */
- private void initOut() throws IOException
- {
- SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
- {
- public Object run() throws Exception
- {
- if (out == null)
- {
- OutputStream os = new IndexOutputStream(dir.createOutput(REDO_LOG));
- out = new BufferedWriter(new OutputStreamWriter(os));
- }
- return null;
- }
- });
- }
-
- /**
- * Reads the log file and calls back {@link RedoLog.ActionCollector}.
- *
- * @param collector called back for each {@link MultiIndex.Action} read.
- * @throws IOException if an error occurs while reading from the
- * log file.
- */
- private void read(final ActionCollector collector) throws IOException
- {
- SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
- {
- public Object run() throws Exception
- {
- if (!dir.fileExists(REDO_LOG))
- {
- return null;
- }
- InputStream in = new IndexInputStream(dir.openInput(REDO_LOG));
- try
- {
- BufferedReader reader = new BufferedReader(new InputStreamReader(in));
- String line;
- while ((line = reader.readLine()) != null)
- {
- try
- {
- collector.collect(MultiIndex.Action.fromString(line));
- }
- catch (IllegalArgumentException e)
- {
- log.warn("Malformed redo entry: " + e.getMessage());
- }
- }
- }
- finally
- {
- if (in != null)
- {
- try
- {
- in.close();
- }
- catch (IOException e)
- {
- log.warn("Exception while closing redo log: " + e.toString());
- }
- }
- }
- return null;
- }
- });
- }
-
- //-----------------------< internal >---------------------------------------
-
- /**
- * Helper interface to collect Actions read from the redo log.
- */
- interface ActionCollector
- {
-
- /** Called when an action is created */
- void collect(MultiIndex.Action action);
- }
-}
15 years, 9 months
exo-jcr SVN: r3263 - jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2010-10-08 08:39:11 -0400 (Fri, 08 Oct 2010)
New Revision: 3263
Removed:
jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexMerger.java
Modified:
jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/RedoLog.java
Log:
EXOJCR-987 Getting rid of Merger and actions inside MultiIndex
Deleted: jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexMerger.java
===================================================================
--- jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexMerger.java 2010-10-08 12:04:24 UTC (rev 3262)
+++ jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexMerger.java 2010-10-08 12:39:11 UTC (rev 3263)
@@ -1,572 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.exoplatform.services.jcr.impl.core.query.lucene;
-
-import EDU.oswego.cs.dl.util.concurrent.Mutex;
-import EDU.oswego.cs.dl.util.concurrent.Sync;
-
-import org.apache.commons.collections.Buffer;
-import org.apache.commons.collections.BufferUtils;
-import org.apache.commons.collections.buffer.UnboundedFifoBuffer;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.Term;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * Merges indexes in a separate daemon thread.
- */
-class IndexMerger extends Thread implements IndexListener
-{
-
- /**
- * Logger instance for this class.
- */
- private static final Logger log = LoggerFactory.getLogger("exo.jcr.component.core.IndexMerger");
-
- /**
- * Marker task to signal the background thread to quit.
- */
- private static final Merge QUIT = new Merge(new Index[0]);
-
- /**
- * minMergeDocs config parameter.
- */
- private int minMergeDocs = SearchIndex.DEFAULT_MIN_MERGE_DOCS;
-
- /**
- * maxMergeDocs config parameter
- */
- private int maxMergeDocs = SearchIndex.DEFAULT_MAX_MERGE_DOCS;
-
- /**
- * mergeFactor config parameter
- */
- private int mergeFactor = SearchIndex.DEFAULT_MERGE_FACTOR;
-
- /**
- * Queue of merge Tasks
- */
- private final Buffer mergeTasks = BufferUtils.blockingBuffer(new UnboundedFifoBuffer());
-
- /**
- * List of id <code>Term</code> that identify documents that were deleted
- * while a merge was running.
- */
- private final List deletedDocuments = Collections.synchronizedList(new ArrayList());
-
- /**
- * List of <code>IndexBucket</code>s in ascending document limit.
- */
- private final List indexBuckets = new ArrayList();
-
- /**
- * The <code>MultiIndex</code> this index merger is working on.
- */
- private final MultiIndex multiIndex;
-
- /**
- * Monitor object to synchronize merge calculation.
- */
- private final Object lock = new Object();
-
- /**
- * Mutex that is acquired when replacing indexes on MultiIndex.
- */
- private final Sync indexReplacement = new Mutex();
-
- /**
- * When released, indicates that this index merger is idle.
- */
- private final Sync mergerIdle = new Mutex();
-
- /**
- * Creates an <code>IndexMerger</code>.
- *
- * @param multiIndex the <code>MultiIndex</code>.
- */
- IndexMerger(MultiIndex multiIndex)
- {
- this.multiIndex = multiIndex;
- setName("IndexMerger");
- setDaemon(true);
- try
- {
- mergerIdle.acquire();
- }
- catch (InterruptedException e)
- {
- // will never happen, lock is free upon construction
- throw new InternalError("Unable to acquire mutex after construction");
- }
- }
-
- /**
- * Informs the index merger that an index was added / created.
- *
- * @param name the name of the index.
- * @param numDocs the number of documents it contains.
- */
- void indexAdded(String name, int numDocs)
- {
- if (numDocs < 0)
- {
- throw new IllegalArgumentException("numDocs must be positive");
- }
- // multiple threads may enter this method:
- // - the background thread of this IndexMerger, when it replaces indexes
- // after a successful merge
- // - a regular thread that updates the workspace
- //
- // therefore we have to synchronize this block
- synchronized (lock)
- {
- // initially create buckets
- if (indexBuckets.size() == 0)
- {
- long lower = 0;
- long upper = minMergeDocs;
- while (upper < maxMergeDocs)
- {
- indexBuckets.add(new IndexBucket(lower, upper, true));
- lower = upper + 1;
- upper *= mergeFactor;
- }
- // one with upper = maxMergeDocs
- indexBuckets.add(new IndexBucket(lower, maxMergeDocs, false));
- // and another one as overflow, just in case...
- indexBuckets.add(new IndexBucket(maxMergeDocs + 1, Long.MAX_VALUE, false));
- }
-
- // put index in bucket
- IndexBucket bucket = (IndexBucket)indexBuckets.get(indexBuckets.size() - 1);
- for (int i = 0; i < indexBuckets.size(); i++)
- {
- bucket = (IndexBucket)indexBuckets.get(i);
- if (bucket.fits(numDocs))
- {
- break;
- }
- }
- bucket.add(new Index(name, numDocs));
-
- if (log.isDebugEnabled())
- {
- log.debug("index added: name=" + name + ", numDocs=" + numDocs);
- }
-
- // if bucket does not allow merge, we don't have to continue
- if (!bucket.allowsMerge())
- {
- return;
- }
-
- // check if we need a merge
- if (bucket.size() >= mergeFactor)
- {
- long targetMergeDocs = bucket.upper;
- targetMergeDocs = Math.min(targetMergeDocs * mergeFactor, maxMergeDocs);
- // sum up docs in bucket
- List indexesToMerge = new ArrayList();
- int mergeDocs = 0;
- for (Iterator it = bucket.iterator(); it.hasNext() && mergeDocs <= targetMergeDocs;)
- {
- indexesToMerge.add(it.next());
- }
- if (indexesToMerge.size() > 2)
- {
- // found merge
- Index[] idxs = (Index[])indexesToMerge.toArray(new Index[indexesToMerge.size()]);
- bucket.removeAll(indexesToMerge);
- if (log.isDebugEnabled())
- {
- log.debug("requesting merge for " + indexesToMerge);
- }
- mergeTasks.add(new Merge(idxs));
- log.debug("merge queue now contains " + mergeTasks.size() + " tasks.");
- }
- }
- }
- }
-
- /**
- * @inheritDoc
- */
- public void documentDeleted(Term id)
- {
- log.debug("document deleted: " + id.text());
- deletedDocuments.add(id);
- }
-
- /**
- * When the calling thread returns this index merger will be idle, that is
- * there will be no merge tasks pending anymore. The method returns immediately
- * if there are currently no tasks pending at all.
- */
- void waitUntilIdle() throws InterruptedException
- {
- mergerIdle.acquire();
- // and immediately release again
- mergerIdle.release();
- }
-
- /**
- * Signals this <code>IndexMerger</code> to stop and waits until it
- * has terminated.
- */
- void dispose()
- {
- log.debug("dispose IndexMerger");
- // get mutex for index replacements
- try
- {
- indexReplacement.acquire();
- }
- catch (InterruptedException e)
- {
- log.warn("Interrupted while acquiring index replacement sync: " + e);
- // try to stop IndexMerger without the sync
- }
-
- // clear task queue
- mergeTasks.clear();
-
- // send quit
- mergeTasks.add(QUIT);
- log.debug("quit sent");
-
- try
- {
- // give the merger thread some time to quit,
- // it is possible that the merger is busy working on a large index.
- // if that is the case we will just ignore it and the daemon will
- // die without being able to finish the merge.
- // at this point it is not possible anymore to replace indexes
- // on the MultiIndex because we hold the indexReplacement Sync.
- this.join(500);
- if (isAlive())
- {
- log.info("Unable to stop IndexMerger. Daemon is busy.");
- }
- else
- {
- log.debug("IndexMerger thread stopped");
- }
- log.debug("merge queue size: " + mergeTasks.size());
- }
- catch (InterruptedException e)
- {
- log.warn("Interrupted while waiting for IndexMerger thread to terminate.");
- }
- }
-
- /**
- * Implements the index merging.
- */
- public void run()
- {
- for (;;)
- {
- boolean isIdle = false;
- if (mergeTasks.size() == 0)
- {
- mergerIdle.release();
- isIdle = true;
- }
- Merge task = (Merge)mergeTasks.remove();
- if (task == QUIT)
- {
- mergerIdle.release();
- break;
- }
- if (isIdle)
- {
- try
- {
- mergerIdle.acquire();
- }
- catch (InterruptedException e)
- {
- Thread.interrupted();
- log.warn("Unable to acquire mergerIdle sync");
- }
- }
-
- log.debug("accepted merge request");
-
- // reset deleted documents
- deletedDocuments.clear();
-
- // get readers
- String[] names = new String[task.indexes.length];
- for (int i = 0; i < task.indexes.length; i++)
- {
- names[i] = task.indexes[i].name;
- }
- try
- {
- log.debug("create new index");
- PersistentIndex index = multiIndex.getOrCreateIndex(null);
- boolean success = false;
- try
- {
-
- log.debug("get index readers from MultiIndex");
- IndexReader[] readers = multiIndex.getIndexReaders(names, this);
- try
- {
- // do the merge
- long time = System.currentTimeMillis();
- index.addIndexes(readers);
- time = System.currentTimeMillis() - time;
- int docCount = 0;
- for (int i = 0; i < readers.length; i++)
- {
- docCount += readers[i].numDocs();
- }
- log.info("merged " + docCount + " documents in " + time + " ms into " + index.getName() + ".");
- }
- finally
- {
- for (int i = 0; i < readers.length; i++)
- {
- try
- {
- Util.closeOrRelease(readers[i]);
- }
- catch (IOException e)
- {
- log.warn("Unable to close IndexReader: " + e);
- }
- }
- }
-
- // inform multi index
- // if we cannot get the sync immediately we have to quit
- if (!indexReplacement.attempt(0))
- {
- log.debug("index merging canceled");
- break;
- }
- try
- {
- log.debug("replace indexes");
- multiIndex.replaceIndexes(names, index, deletedDocuments);
- }
- finally
- {
- indexReplacement.release();
- }
-
- success = true;
-
- }
- finally
- {
- if (!success)
- {
- // delete index
- log.debug("deleting index " + index.getName());
- multiIndex.deleteIndex(index);
- }
- }
- }
- catch (Throwable e)
- {
- log.error("Error while merging indexes: ", e);
- }
- }
- log.info("IndexMerger terminated");
- }
-
- //-----------------------< merge properties >-------------------------------
-
- /**
- * The merge factor.
- */
- public void setMergeFactor(int mergeFactor)
- {
- this.mergeFactor = mergeFactor;
- }
-
- /**
- * The initial threshold for number of documents to merge to a new index.
- */
- public void setMinMergeDocs(int minMergeDocs)
- {
- this.minMergeDocs = minMergeDocs;
- }
-
- /**
- * The maximum number of document to merge.
- */
- public void setMaxMergeDocs(int maxMergeDocs)
- {
- this.maxMergeDocs = maxMergeDocs;
- }
-
- //------------------------------< internal >--------------------------------
-
- /**
- * Implements a simple struct that holds the name of an index and how
- * many document it contains. <code>Index</code> is comparable using the
- * number of documents it contains.
- */
- private static final class Index implements Comparable
- {
-
- /**
- * The name of the index.
- */
- private final String name;
-
- /**
- * The number of documents the index contains.
- */
- private final int numDocs;
-
- /**
- * Creates a new index struct.
- *
- * @param name name of an index.
- * @param numDocs number of documents it contains.
- */
- Index(String name, int numDocs)
- {
- this.name = name;
- this.numDocs = numDocs;
- }
-
- /**
- * Indexes are first ordered by {@link #numDocs} and then by {@link
- * #name}.
- *
- * @param o the other <code>Index</code>.
- * @return a negative integer, zero, or a positive integer as this
- * Index is less than, equal to, or greater than the specified
- * Index.
- */
- public int compareTo(Object o)
- {
- Index other = (Index)o;
- int val = numDocs < other.numDocs ? -1 : (numDocs == other.numDocs ? 0 : 1);
- if (val != 0)
- {
- return val;
- }
- else
- {
- return name.compareTo(other.name);
- }
- }
-
- /**
- * @inheritDoc
- */
- public String toString()
- {
- return name + ":" + numDocs;
- }
- }
-
- /**
- * Defines a merge task, to merge a couple of indexes into a new index.
- */
- private static final class Merge
- {
-
- private final Index[] indexes;
-
- /**
- * Merge task, to merge <code>indexes</code> into a new index with
- * <code>name</code>.
- *
- * @param indexes the indexes to merge.
- */
- Merge(Index[] indexes)
- {
- this.indexes = new Index[indexes.length];
- System.arraycopy(indexes, 0, this.indexes, 0, indexes.length);
- }
- }
-
- /**
- * Implements a <code>List</code> with a document limit value. An
- * <code>IndexBucket</code> contains {@link Index}es with documents less
- * or equal the document limit of the bucket.
- */
- private static final class IndexBucket extends ArrayList
- {
-
- /**
- * The lower document limit.
- */
- private final long lower;
-
- /**
- * The upper document limit.
- */
- private final long upper;
-
- /**
- * Flag indicating if indexes in this bucket can be merged.
- */
- private final boolean allowMerge;
-
- /**
- * Creates a new <code>IndexBucket</code>. Limits are both inclusive.
- *
- * @param lower document limit.
- * @param upper document limit.
- * @param allowMerge if indexes in this bucket can be merged.
- */
- IndexBucket(long lower, long upper, boolean allowMerge)
- {
- this.lower = lower;
- this.upper = upper;
- this.allowMerge = allowMerge;
- }
-
- /**
- * Returns <code>true</code> if the number of documents fit in this
- * <code>IndexBucket</code>; otherwise <code>false</code>
- *
- * @param numDocs the number of documents.
- * @return <code>true</code> if <code>numDocs</code> fit.
- */
- boolean fits(long numDocs)
- {
- return numDocs >= lower && numDocs <= upper;
- }
-
- /**
- * Returns <code>true</code> if indexes in this bucket can be merged.
- *
- * @return <code>true</code> if indexes in this bucket can be merged.
- */
- boolean allowsMerge()
- {
- return allowMerge;
- }
- }
-}
Modified: jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
===================================================================
--- jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2010-10-08 12:04:24 UTC (rev 3262)
+++ jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2010-10-08 12:39:11 UTC (rev 3263)
@@ -171,11 +171,6 @@
private long lastFileSystemFlushTime;
/**
- * The <code>IndexMerger</code> for this <code>MultiIndex</code>.
- */
- private final IndexMerger merger;
-
- /**
* Timer to schedule flushes of this index after some idle time.
*/
private static final Timer FLUSH_TIMER = new Timer(true);
@@ -265,12 +260,6 @@
// as of 1.5 deletable file is not used anymore
removeDeletable();
- // initialize IndexMerger
- merger = new IndexMerger(this);
- merger.setMaxMergeDocs(handler.getMaxMergeDocs());
- merger.setMergeFactor(handler.getMergeFactor());
- merger.setMinMergeDocs(handler.getMinMergeDocs());
-
// this method is run in privileged mode internally
IndexingQueueStore store = new IndexingQueueStore(indexDir);
@@ -299,7 +288,6 @@
index.setUseCompoundFile(handler.getUseCompoundFile());
index.setTermInfosIndexDivisor(handler.getTermInfosIndexDivisor());
indexes.add(index);
- merger.indexAdded(index.getName(), index.getNumDocuments());
}
// init volatile index
@@ -398,10 +386,16 @@
{
long count = 0;
// traverse and index workspace
- executeAndLog(new Start(Action.INTERNAL_TRANSACTION));
+
+ // TODO: this was removed
+ //executeAndLog(new Start(Action.INTERNAL_TRANSACTION));
+
// NodeData rootState = (NodeData) stateMgr.getItemData(rootId);
count = createIndex(indexingTree.getIndexingRoot(), stateMgr, count);
- executeAndLog(new Commit(getTransactionId()));
+
+ // TODO : this was replaced
+ //executeAndLog(new Commit(getTransactionId()));
+
log.info("Created initial index for {} nodes", new Long(count));
releaseMultiReader();
scheduleFlushTask();
@@ -467,23 +461,67 @@
try
{
long transactionId = nextTransactionId++;
- executeAndLog(new Start(transactionId));
+
+ // TODO: this was removed
+ //executeAndLog(new Start(transactionId));
for (Iterator it = remove.iterator(); it.hasNext();)
{
- executeAndLog(new DeleteNode(transactionId, (String)it.next()));
+ // TODO this was replaced
+ //executeAndLog(new DeleteNode(transactionId, (String)it.next()));
+
+ String uuidString = (String)it.next();
+ // check if indexing queue is still working on
+ // this node from a previous update
+ Document doc = indexingQueue.removeDocument(uuidString);
+ if (doc != null)
+ {
+ Util.disposeDocument(doc);
+ }
+ Term idTerm = new Term(FieldNames.UUID, uuidString);
+ // if the document cannot be deleted from the volatile index
+ // delete it from one of the persistent indexes.
+ int num = volatileIndex.removeDocument(idTerm);
+ if (num == 0)
+ {
+ for (int i = indexes.size() - 1; i >= 0; i--)
+ {
+ // only look in registered indexes
+ PersistentIndex idx = (PersistentIndex)indexes.get(i);
+ if (indexNames.contains(idx.getName()))
+ {
+ num = idx.removeDocument(idTerm);
+ if (num > 0)
+ {
+ break;
+ }
+ }
+ }
+ }
+
+
+
}
for (Iterator it = add.iterator(); it.hasNext();)
{
Document doc = (Document)it.next();
if (doc != null)
{
- executeAndLog(new AddNode(transactionId, doc));
+ // TODO: ths is replaced
+ //executeAndLog(new AddNode(transactionId, doc));
+
+ if (doc != null)
+ {
+ volatileIndex.addDocuments(new Document[]{doc});
+ }
+
// commit volatile index if needed
flush |= checkVolatileCommit();
}
}
- executeAndLog(new Commit(transactionId));
+
+ // TODO : this was replaced
+ //executeAndLog(new Commit(transactionId));
// flush whole index when volatile index has been commited.
if (flush)
@@ -558,11 +596,15 @@
try
{
Term idTerm = new Term(FieldNames.UUID, uuid.toString());
- executeAndLog(new Start(Action.INTERNAL_TRANSACTION));
+
+ // TODO: this was removed
+ //executeAndLog(new Start(Action.INTERNAL_TRANSACTION));
+
num = volatileIndex.removeDocument(idTerm);
if (num > 0)
{
- redoLog.append(new DeleteNode(getTransactionId(), uuid));
+ // TODO: removed line
+ //redoLog.append(new DeleteNode(getTransactionId(), uuid));
}
for (int i = 0; i < indexes.size(); i++)
{
@@ -573,12 +615,14 @@
int removed = index.removeDocument(idTerm);
if (removed > 0)
{
- redoLog.append(new DeleteNode(getTransactionId(), uuid));
+ // TODO: removed line
+ //redoLog.append(new DeleteNode(getTransactionId(), uuid));
}
num += removed;
}
}
- executeAndLog(new Commit(getTransactionId()));
+ // TODO : this was replaced
+ //executeAndLog(new Commit(getTransactionId()));
}
finally
{
@@ -792,7 +836,8 @@
// if we are reindexing there is already an active transaction
if (!reindexing)
{
- executeAndLog(new Start(Action.INTERNAL_TRANS_REPL_INDEXES));
+ // TODO: this was removed
+ //executeAndLog(new Start(Action.INTERNAL_TRANS_REPL_INDEXES));
}
// delete obsolete indexes
Set names = new HashSet(Arrays.asList(obsoleteIndexes));
@@ -802,16 +847,37 @@
String indexName = (String)it.next();
if (indexNames.contains(indexName))
{
- executeAndLog(new DeleteIndex(getTransactionId(), indexName));
+ // TODO this was replaced
+ //executeAndLog(new DeleteIndex(getTransactionId(), indexName));
+
+ for (Iterator it2 = indexes.iterator(); it2.hasNext();)
+ {
+ PersistentIndex idx = (PersistentIndex)it2.next();
+ if (idx.getName().equals(indexName))
+ {
+ idx.close();
+ deleteIndex(idx);
+ break;
+ }
+ }
+
}
}
// Index merger does not log an action when it creates the
// target
// index of the merge. We have to do this here.
- executeAndLog(new CreateIndex(getTransactionId(), index.getName()));
+ // TODO this was replaced
+ ///executeAndLog(new CreateIndex(getTransactionId(), index.getName()));
- executeAndLog(new AddIndex(getTransactionId(), index.getName()));
+ PersistentIndex idx = getOrCreateIndex(index.getName());
+
+ // TODO: this is replaced
+ //executeAndLog(new AddIndex(getTransactionId(), index.getName()));
+ if (!indexNames.contains(index.getName()))
+ {
+ indexNames.addName(index.getName());
+ }
// delete documents in index
for (Iterator it = deleted.iterator(); it.hasNext();)
@@ -825,7 +891,9 @@
{
// only commit if we are not reindexing
// when reindexing the final commit is done at the very end
- executeAndLog(new Commit(getTransactionId()));
+
+ // TODO : this was replaced
+ //executeAndLog(new Commit(getTransactionId()));
}
}
finally
@@ -954,7 +1022,6 @@
// stop index merger
// when calling this method we must not lock this MultiIndex, otherwise
// a deadlock might occur
- merger.dispose();
synchronized (this)
{
@@ -1108,7 +1175,8 @@
synchronized (this)
{
// commit volatile index
- executeAndLog(new Start(Action.INTERNAL_TRANSACTION));
+ // TODO: this was removed
+ //executeAndLog(new Start(Action.INTERNAL_TRANSACTION));
commitVolatileIndex();
// commit persistent indexes
@@ -1126,11 +1194,17 @@
// check if index still contains documents
if (index.getNumDocuments() == 0)
{
- executeAndLog(new DeleteIndex(getTransactionId(), index.getName()));
+ // TODO THIS was replaced
+ //executeAndLog(new DeleteIndex(getTransactionId(), index.getName()));
+
+ index.close();
+ deleteIndex(index);
+
}
}
}
- executeAndLog(new Commit(getTransactionId()));
+ // TODO : this was replaced
+ //executeAndLog(new Commit(getTransactionId()));
indexNames.write();
@@ -1329,16 +1403,31 @@
long time = System.currentTimeMillis();
// create index
- CreateIndex create = new CreateIndex(getTransactionId(), null);
- executeAndLog(create);
+
+ //TODO this was replaced
+// CreateIndex create = new CreateIndex(getTransactionId(), null);
+// executeAndLog(create);
+
+ PersistentIndex idx = getOrCreateIndex(null);
// commit volatile index
- executeAndLog(new VolatileCommit(getTransactionId(), create.getIndexName()));
+
+ // TODO THIS IS REPLACED
+ //executeAndLog(new VolatileCommit(getTransactionId(), idx.getName()));
+ idx.copyIndex(volatileIndex);
+ resetVolatileIndex();
+
+ // TODO this is replaced
// add new index
- AddIndex add = new AddIndex(getTransactionId(), create.getIndexName());
- executeAndLog(add);
+// AddIndex add = new AddIndex(getTransactionId(), create.getIndexName());
+// executeAndLog(add);
+ if (!indexNames.contains(idx.getName()))
+ {
+ indexNames.addName(idx.getName());
+ }
+
// create new volatile index
resetVolatileIndex();
@@ -1376,7 +1465,11 @@
{
return count;
}
- executeAndLog(new AddNode(getTransactionId(), node.getIdentifier()));
+
+ // TODO: this is replaced
+ //executeAndLog(new AddNode(getTransactionId(), node.getIdentifier()));
+ volatileIndex.addDocuments(new Document[]{createDocument(node)});
+
if (++count % 100 == 0)
{
@@ -1552,11 +1645,45 @@
{
for (Iterator it = finished.keySet().iterator(); it.hasNext();)
{
- executeAndLog(new DeleteNode(getTransactionId(), (String)it.next()));
+ // TODO this was replaced
+ //executeAndLog(new DeleteNode(getTransactionId(), (String)it.next()));
+
+ String uuidString = (String)it.next();
+ // check if indexing queue is still working on
+ // this node from a previous update
+ Document doc = indexingQueue.removeDocument(uuidString);
+ if (doc != null)
+ {
+ Util.disposeDocument(doc);
+ }
+ Term idTerm = new Term(FieldNames.UUID, uuidString);
+ // if the document cannot be deleted from the volatile index
+ // delete it from one of the persistent indexes.
+ int num = volatileIndex.removeDocument(idTerm);
+ if (num == 0)
+ {
+ for (int i = indexes.size() - 1; i >= 0; i--)
+ {
+ // only look in registered indexes
+ PersistentIndex idx = (PersistentIndex)indexes.get(i);
+ if (indexNames.contains(idx.getName()))
+ {
+ num = idx.removeDocument(idTerm);
+ if (num > 0)
+ {
+ return;
+ }
+ }
+ }
+ }
+
+
}
for (Iterator it = finished.values().iterator(); it.hasNext();)
{
- executeAndLog(new AddNode(getTransactionId(), (Document)it.next()));
+ // TODO this was replaced
+ //executeAndLog(new AddNode(getTransactionId(), (Document)it.next()));
+ volatileIndex.addDocuments(new Document[]{(Document)it.next()});
}
}
else
@@ -1790,35 +1917,35 @@
Action a;
if (actionLabel.equals(Action.ADD_NODE))
{
- a = AddNode.fromString(transactionId, arguments);
+ a = AddNode_.fromString(transactionId, arguments);
}
else if (actionLabel.equals(Action.ADD_INDEX))
{
- a = AddIndex.fromString(transactionId, arguments);
+ a = AddIndex_.fromString(transactionId, arguments);
}
else if (actionLabel.equals(Action.COMMIT))
{
- a = Commit.fromString(transactionId, arguments);
+ a = Commit_.fromString(transactionId, arguments);
}
else if (actionLabel.equals(Action.CREATE_INDEX))
{
- a = CreateIndex.fromString(transactionId, arguments);
+ a = CreateIndex_.fromString(transactionId, arguments);
}
else if (actionLabel.equals(Action.DELETE_INDEX))
{
- a = DeleteIndex.fromString(transactionId, arguments);
+ a = DeleteIndex_.fromString(transactionId, arguments);
}
else if (actionLabel.equals(Action.DELETE_NODE))
{
- a = DeleteNode.fromString(transactionId, arguments);
+ a = DeleteNode_.fromString(transactionId, arguments);
}
else if (actionLabel.equals(Action.START))
{
- a = Start.fromString(transactionId, arguments);
+ a = Start_.fromString(transactionId, arguments);
}
else if (actionLabel.equals(Action.VOLATILE_COMMIT))
{
- a = VolatileCommit.fromString(transactionId, arguments);
+ a = VolatileCommit_.fromString(transactionId, arguments);
}
else
{
@@ -1831,7 +1958,7 @@
/**
* Adds an index to the MultiIndex's active persistent index list.
*/
- private static class AddIndex extends Action
+ private static class AddIndex_ extends Action
{
/**
@@ -1848,7 +1975,7 @@
* the name of the index to add, or <code>null</code> if an
* index with a new name should be created.
*/
- AddIndex(long transactionId, String indexName)
+ AddIndex_(long transactionId, String indexName)
{
super(transactionId, Action.TYPE_ADD_INDEX);
this.indexName = indexName;
@@ -1865,9 +1992,9 @@
* @throws IllegalArgumentException
* if the arguments are malformed.
*/
- static AddIndex fromString(long transactionId, String arguments)
+ static AddIndex_ fromString(long transactionId, String arguments)
{
- return new AddIndex(transactionId, arguments);
+ return new AddIndex_(transactionId, arguments);
}
/**
@@ -1882,9 +2009,6 @@
if (!index.indexNames.contains(indexName))
{
index.indexNames.addName(indexName);
- // now that the index is in the active list let the merger know
- // about it
- index.merger.indexAdded(indexName, idx.getNumDocuments());
}
}
@@ -1907,7 +2031,7 @@
/**
* Adds a node to the index.
*/
- private static class AddNode extends Action
+ private static class AddNode_ extends Action
{
/**
@@ -1935,7 +2059,7 @@
* @param uuid
* the uuid of the node to add.
*/
- AddNode(long transactionId, String uuid)
+ AddNode_(long transactionId, String uuid)
{
super(transactionId, Action.TYPE_ADD_NODE);
this.uuid = uuid;
@@ -1949,7 +2073,7 @@
* @param doc
* the document to add.
*/
- AddNode(long transactionId, Document doc)
+ AddNode_(long transactionId, Document doc)
{
this(transactionId, doc.get(FieldNames.UUID));
this.doc = doc;
@@ -1966,14 +2090,14 @@
* @throws IllegalArgumentException
* if the arguments are malformed. Not a UUID.
*/
- static AddNode fromString(long transactionId, String arguments) throws IllegalArgumentException
+ static AddNode_ fromString(long transactionId, String arguments) throws IllegalArgumentException
{
// simple length check
if (arguments.length() != Constants.UUID_FORMATTED_LENGTH)
{
throw new IllegalArgumentException("arguments is not a uuid");
}
- return new AddNode(transactionId, arguments);
+ return new AddNode_(transactionId, arguments);
}
/**
@@ -2021,7 +2145,7 @@
/**
* Commits a transaction.
*/
- private static class Commit extends Action
+ private static class Commit_ extends Action
{
/**
@@ -2030,7 +2154,7 @@
* @param transactionId
* the id of the transaction that is committed.
*/
- Commit(long transactionId)
+ Commit_(long transactionId)
{
super(transactionId, Action.TYPE_COMMIT);
}
@@ -2044,9 +2168,9 @@
* ignored by this method.
* @return the Commit action.
*/
- static Commit fromString(long transactionId, String arguments)
+ static Commit_ fromString(long transactionId, String arguments)
{
- return new Commit(transactionId);
+ return new Commit_(transactionId);
}
/**
@@ -2074,7 +2198,7 @@
* Creates an new sub index but does not add it to the active persistent
* index list.
*/
- private static class CreateIndex extends Action
+ private static class CreateIndex_ extends Action
{
/**
@@ -2091,7 +2215,7 @@
* the name of the index to add, or <code>null</code> if an
* index with a new name should be created.
*/
- CreateIndex(long transactionId, String indexName)
+ CreateIndex_(long transactionId, String indexName)
{
super(transactionId, Action.TYPE_CREATE_INDEX);
this.indexName = indexName;
@@ -2108,10 +2232,10 @@
* @throws IllegalArgumentException
* if the arguments are malformed.
*/
- static CreateIndex fromString(long transactionId, String arguments)
+ static CreateIndex_ fromString(long transactionId, String arguments)
{
// when created from String, this action is executed as redo action
- return new CreateIndex(transactionId, arguments);
+ return new CreateIndex_(transactionId, arguments);
}
/**
@@ -2171,7 +2295,7 @@
/**
* Closes and deletes an index that is no longer in use.
*/
- private static class DeleteIndex extends Action
+ private static class DeleteIndex_ extends Action
{
/**
@@ -2187,7 +2311,7 @@
* @param indexName
* the name of the index to delete.
*/
- DeleteIndex(long transactionId, String indexName)
+ DeleteIndex_(long transactionId, String indexName)
{
super(transactionId, Action.TYPE_DELETE_INDEX);
this.indexName = indexName;
@@ -2204,9 +2328,9 @@
* @throws IllegalArgumentException
* if the arguments are malformed.
*/
- static DeleteIndex fromString(long transactionId, String arguments)
+ static DeleteIndex_ fromString(long transactionId, String arguments)
{
- return new DeleteIndex(transactionId, arguments);
+ return new DeleteIndex_(transactionId, arguments);
}
/**
@@ -2249,7 +2373,7 @@
/**
* Deletes a node from the index.
*/
- private static class DeleteNode extends Action
+ private static class DeleteNode_ extends Action
{
/**
@@ -2271,7 +2395,7 @@
* @param uuid
* the uuid of the node to delete.
*/
- DeleteNode(long transactionId, String uuid)
+ DeleteNode_(long transactionId, String uuid)
{
super(transactionId, Action.TYPE_DELETE_NODE);
this.uuid = uuid;
@@ -2288,14 +2412,14 @@
* @throws IllegalArgumentException
* if the arguments are malformed. Not a UUID.
*/
- static DeleteNode fromString(long transactionId, String arguments)
+ static DeleteNode_ fromString(long transactionId, String arguments)
{
// simple length check
if (arguments.length() != Constants.UUID_FORMATTED_LENGTH)
{
throw new IllegalArgumentException("arguments is not a uuid");
}
- return new DeleteNode(transactionId, arguments);
+ return new DeleteNode_(transactionId, arguments);
}
/**
@@ -2355,7 +2479,7 @@
/**
* Starts a transaction.
*/
- private static class Start extends Action
+ private static class Start_ extends Action
{
/**
@@ -2364,7 +2488,7 @@
* @param transactionId
* the id of the transaction that started.
*/
- Start(long transactionId)
+ Start_(long transactionId)
{
super(transactionId, Action.TYPE_START);
}
@@ -2378,9 +2502,9 @@
* ignored by this method.
* @return the Start action.
*/
- static Start fromString(long transactionId, String arguments)
+ static Start_ fromString(long transactionId, String arguments)
{
- return new Start(transactionId);
+ return new Start_(transactionId);
}
/**
@@ -2407,7 +2531,7 @@
/**
* Commits the volatile index to disk.
*/
- private static class VolatileCommit extends Action
+ private static class VolatileCommit_ extends Action
{
/**
@@ -2421,7 +2545,7 @@
* @param transactionId
* the id of the transaction that executes this action.
*/
- VolatileCommit(long transactionId, String targetIndex)
+ VolatileCommit_(long transactionId, String targetIndex)
{
super(transactionId, Action.TYPE_VOLATILE_COMMIT);
this.targetIndex = targetIndex;
@@ -2436,9 +2560,9 @@
* ignored by this implementation.
* @return the VolatileCommit action.
*/
- static VolatileCommit fromString(long transactionId, String arguments)
+ static VolatileCommit_ fromString(long transactionId, String arguments)
{
- return new VolatileCommit(transactionId, arguments);
+ return new VolatileCommit_(transactionId, arguments);
}
/**
@@ -2500,7 +2624,6 @@
protected void setReadOny()
{
// try to stop merger in safe way
- merger.dispose();
flushTask.cancel();
FLUSH_TIMER.purge();
this.redoLog = null;
@@ -2532,18 +2655,8 @@
attemptDelete();
// now that we are ready, start index merger
- merger.start();
if (redoLogApplied)
{
- // wait for the index merge to finish pending jobs
- try
- {
- merger.waitUntilIdle();
- }
- catch (InterruptedException e)
- {
- // move on
- }
flush();
}
Modified: jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/RedoLog.java
===================================================================
--- jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/RedoLog.java 2010-10-08 12:04:24 UTC (rev 3262)
+++ jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/RedoLog.java 2010-10-08 12:39:11 UTC (rev 3263)
@@ -193,7 +193,10 @@
out.close();
out = null;
}
- dir.deleteFile(REDO_LOG);
+ if (dir.fileExists(REDO_LOG))
+ {
+ dir.deleteFile(REDO_LOG);
+ }
entryCount = 0;
return null;
}
@@ -208,17 +211,17 @@
private void initOut() throws IOException
{
SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
+ {
+ public Object run() throws Exception
{
- public Object run() throws Exception
- {
if (out == null)
{
OutputStream os = new IndexOutputStream(dir.createOutput(REDO_LOG));
out = new BufferedWriter(new OutputStreamWriter(os));
}
- return null;
- }
- });
+ return null;
+ }
+ });
}
/**
@@ -231,9 +234,9 @@
private void read(final ActionCollector collector) throws IOException
{
SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
+ {
+ public Object run() throws Exception
{
- public Object run() throws Exception
- {
if (!dir.fileExists(REDO_LOG))
{
return null;
@@ -269,9 +272,9 @@
}
}
}
- return null;
- }
- });
+ return null;
+ }
+ });
}
//-----------------------< internal >---------------------------------------
15 years, 9 months
exo-jcr SVN: r3262 - in jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr: impl/core and 1 other directory.
by do-not-reply@jboss.org
Author: sergiykarpenko
Date: 2010-10-08 08:04:24 -0400 (Fri, 08 Oct 2010)
New Revision: 3262
Added:
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/JCRPathExt.java
Modified:
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/datamodel/InternalQName.java
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/datamodel/QPathEntry.java
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/JCRName.java
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/JCRPath.java
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/LocationFactory.java
Log:
JCR-1473: merge performance improvements
Modified: jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/datamodel/InternalQName.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/datamodel/InternalQName.java 2010-10-08 11:45:06 UTC (rev 3261)
+++ jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/datamodel/InternalQName.java 2010-10-08 12:04:24 UTC (rev 3262)
@@ -32,7 +32,7 @@
/**
* InternalQName constructor.
- *
+ *
* @param namespace
* - namespace URI
* @param name
@@ -79,9 +79,18 @@
if (o == null)
return false;
- if (!(o instanceof InternalQName))
- return false;
+ if (o instanceof InternalQName)
+ {
+ InternalQName that = (InternalQName)o;
+ if (hashCode == that.hashCode)
+ {
+ String s1 = getAsString();
+ String s2 = that.getAsString();
+ return s1.equals(s2);
+ }
+ }
- return hashCode == o.hashCode() && getAsString().equals(((QName)o).getAsString());
+ return false;
+
}
}
Modified: jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/datamodel/QPathEntry.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/datamodel/QPathEntry.java 2010-10-08 11:45:06 UTC (rev 3261)
+++ jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/datamodel/QPathEntry.java 2010-10-08 12:04:24 UTC (rev 3262)
@@ -32,6 +32,10 @@
*/
private final int index;
+ private String cachedToString;
+
+ private String cachedToStringShowIndex;
+
/**
* QPathEntry constructor.
*
@@ -128,7 +132,44 @@
*/
public String getAsString(boolean showIndex)
{
- return super.getAsString() + (showIndex ? QPath.PREFIX_DELIMITER + this.index : "");
+ if (showIndex)
+ {
+ if (cachedToStringShowIndex != null)
+ {
+ return cachedToStringShowIndex;
+ }
+ }
+ else
+ {
+ if (cachedToString != null)
+ {
+ return cachedToString;
+ }
+ }
+
+ //
+ String res;
+ if (showIndex)
+ {
+ res = super.getAsString() + QPath.PREFIX_DELIMITER + this.index;
+ }
+ else
+ {
+ res = super.getAsString();
+ }
+
+ //
+ if (showIndex)
+ {
+ cachedToStringShowIndex = res;
+ }
+ else
+ {
+ cachedToString = res;
+ }
+
+ //
+ return res;
}
/**
Modified: jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/JCRName.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/JCRName.java 2010-10-08 11:45:06 UTC (rev 3261)
+++ jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/JCRName.java 2010-10-08 12:04:24 UTC (rev 3262)
@@ -40,17 +40,43 @@
protected final int hashCode;
+ protected JCRName(InternalQName qname, String prefix)
+ {
+ this(qname.getNamespace(), qname.getName(), prefix);
+ }
+
+ JCRName(JCRPath.PathElement that)
+ {
+ this.prefix = that.prefix;
+ this.name = that.name;
+ this.namespace = that.namespace;
+ this.stringName = that.stringName;
+ this.hashCode = that.hashCode;
+ }
+
JCRName(String namespace, String name, String prefix)
{
- this.name = name.intern();
- this.namespace = namespace.intern();
- this.prefix = prefix.intern();
+ int hk = 31 + namespace.hashCode();
+ hk = hk * 31 + name.hashCode();
+ int hashCode = hk * 31 + prefix.hashCode();
- this.stringName = ((this.prefix.length() == 0 ? "" : this.prefix + ":") + this.name);
+ //
+ String stringName;
+ if (prefix.length() == 0)
+ {
+ stringName = name;
+ }
+ else
+ {
+ stringName = prefix + ":" + name;
+ }
- int hk = 31 + this.namespace.hashCode();
- hk = hk * 31 + this.name.hashCode();
- this.hashCode = hk * 31 + this.prefix.hashCode();
+ //
+ this.name = name;
+ this.namespace = namespace;
+ this.prefix = prefix;
+ this.stringName = stringName;
+ this.hashCode = hashCode;
}
/**
Modified: jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/JCRPath.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/JCRPath.java 2010-10-08 11:45:06 UTC (rev 3261)
+++ jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/JCRPath.java 2010-10-08 12:04:24 UTC (rev 3262)
@@ -18,16 +18,15 @@
*/
package org.exoplatform.services.jcr.impl.core;
+import org.exoplatform.services.jcr.core.NamespaceAccessor;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
import org.exoplatform.services.jcr.datamodel.QPath;
import org.exoplatform.services.jcr.datamodel.QPathEntry;
-import org.exoplatform.services.jcr.impl.Constants;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
-import java.util.ArrayList;
+import javax.jcr.RepositoryException;
-import javax.jcr.PathNotFoundException;
-
/**
* Created by The eXo Platform SAS.
*
@@ -35,7 +34,7 @@
* @version $Id: JCRPath.java 11907 2008-03-13 15:36:21Z ksm $
*/
-public class JCRPath
+public abstract class JCRPath
{
public final static String ROOT_PATH = "/";
@@ -48,250 +47,117 @@
protected static Log log = ExoLogger.getLogger("exo.jcr.component.core.JCRPath");
- protected PathElement[] names;
-
- JCRPath()
+ public static JCRPath createJCRPath()
{
- this.names = new PathElement[0];
+ return JCRPathExt.ROOT;
}
- public boolean isAbsolute()
+ public static JCRPath createJCRPath(NamespaceAccessor namespaces, QPath qpath) throws RepositoryException
{
- if (names.length > 0)
- {
- PathElement first = names[0];
- if (first.getName().equals(ROOT_NAME))
- {
- return true;
- }
- }
- return false;
+ return new JCRPathExt(namespaces, qpath.getEntries());
}
- JCRPath addEntry(String namespace, String name, String prefix, int index)
+ public static JCRPath createJCRPath(NamespaceAccessor namespaces, QPathEntry[] relPath) throws RepositoryException
{
- if (name.equals(THIS_RELPATH))
- return this;
-
- if (name.equals(PARENT_RELPATH))
- {
- return addEntry(new MoveUpElement());
- }
-
- return addEntry(new PathElement(namespace, name, prefix, index));
+ return new JCRPathExt(namespaces, relPath);
}
- JCRPath addEntry(PathElement entry)
- {
- if (names.length > 0 && entry instanceof MoveUpElement && !(names[names.length - 1] instanceof MoveUpElement))
- {
- return removeLastEntry();
- }
+ public abstract boolean isAbsolute();
- PathElement[] newNames = new PathElement[names.length + 1];
- for (int i = 0; i < names.length; i++)
- newNames[i] = names[i];
- newNames[names.length] = entry;
- names = newNames;
- return this;
- }
+ abstract JCRPath addEntry(String namespace, String name, String prefix, int index);
- JCRPath removeLastEntry()
- {
+ abstract JCRPath addEntry(PathElement entry);
- if (names.length <= 0)
- {
- log.warn("Wrong relative path. Can't move up in path hierarhy. " + getAsString(true));
- return this;
- }
+ abstract JCRPath add(JCRPath path);
- PathElement[] newNames = new PathElement[names.length - 1];
- for (int i = 0; i < newNames.length; i++)
- newNames[i] = names[i];
- names = newNames;
- return this;
- }
+ abstract JCRPath addEntries(PathElement... entries);
- public JCRPath makeParentPath()
- {
- return makeAncestorPath(1);
- }
+ public abstract JCRPath makeParentPath();
- /**
- * Makes ancestor path by relative degree (For ex relativeDegree == 1 means parent path etc)
- *
- * @param relativeDegree
- * @return
- * @throws PathNotFoundException
- */
- public JCRPath makeAncestorPath(int relativeDegree)
- {
+ public abstract JCRPath makeAncestorPath(int relativeDegree);
- JCRPath path = new JCRPath();
- for (int i = 0; i < names.length - relativeDegree; i++)
- path.addEntry(names[i]);
- return path;
- }
+ public abstract PathElement[] getRelPath(int relativeDegree);
- public PathElement[] getRelPath(int relativeDegree)
- {
- ArrayList<PathElement> entries = new ArrayList<PathElement>();
- for (int i = names.length - relativeDegree; i < names.length; i++)
- entries.add(names[i]);
- PathElement[] relPath = new PathElement[entries.size()];
- for (int i = 0; i < relPath.length; i++)
- relPath[i] = entries.get(i);
- return relPath;
- }
+ public abstract QPath getInternalPath();
- public QPath getInternalPath()
- {
+ public abstract String getAsString(boolean showIndex);
- QPathEntry[] entries = new QPathEntry[names.length];
+ public abstract int getDepth();
- for (int i = 0; i < names.length; i++)
- entries[i] = new QPathEntry(names[i].getNamespace(), names[i].getName(), names[i].getIndex());
+ public abstract int getLength();
- QPath qpath = new QPath(entries);
- return qpath;
- }
+ public abstract PathElement getEntry(int index);
- public String getAsString(boolean showIndex)
- {
+ public abstract PathElement[] getEntries();
- // [PN] 27.06.07
- String path = "";
- if (isAbsolute())
- {
- if (size() == 1)
- return "/";
+ public abstract boolean isDescendantOf(JCRPath ancestorLocation, boolean childOnly);
- for (int i = 1; i < names.length; i++)
- {
- path += "/" + names[i].getAsString(showIndex);
- }
- }
- else
- {
- // relative
- for (int i = 0; i < names.length; i++)
- {
- path += i > 0 ? "/" + names[i].getAsString(showIndex) : names[i].getAsString(showIndex);
- }
- }
+ public abstract boolean isAncestorOf(JCRPath descendantLocation, boolean childOnly);
- return path;
- }
+ public abstract PathElement getName();
- public int getDepth()
- {
- return size() - 1;
- }
+ public abstract int getIndex();
- public boolean isDescendantOf(JCRPath ancestorLocation, boolean childOnly)
- {
- int depthDiff = getDepth() - ancestorLocation.getDepth();
- if (depthDiff <= 0 || (childOnly && depthDiff != 1))
- return false;
+ public abstract boolean isIndexSetExplicitly();
- JCRPath.PathElement[] anotherNames = ancestorLocation.getEntries();
- for (int i = 0; i < anotherNames.length; i++)
- {
- boolean result = anotherNames[i].equals(names[i]);
- if (!result)
- return false;
- }
- return true;
- }
+ public abstract boolean isSameNameSibling(JCRPath anotherPath);
- public boolean isAncestorOf(JCRPath descendantLocation, boolean childOnly)
- {
- return descendantLocation.isDescendantOf(this, childOnly);
- }
+ public abstract boolean equals(Object obj);
- private int size()
+ protected JCRPath()
{
- return names.length;
}
- public JCRName getName()
+ public static class PathElement extends JCRName
{
- if (size() > 0)
- return names[size() - 1];
- return new ThisElement();
- }
+ private final int index;
- public int getIndex()
- {
- return names[size() - 1].getIndex();
- }
+ private final boolean indexSetExplicitly;
- public boolean isIndexSetExplicitly()
- {
- return names[size() - 1].isIndexSetExplicitly();
- }
+ private String cachedToString;
- public boolean isSameNameSibling(JCRPath anotherPath)
- {
- JCRName[] anotherNames = anotherPath.getEntries();
- for (int i = 0; i < anotherNames.length - 1; i++)
- {
- boolean result = anotherNames[i].equals(names[i]);
- if (!result)
- return false;
- }
- return getName().getName().equals(anotherPath.getName().getName())
- && this.getName().getPrefix().equals(anotherPath.getName().getPrefix());
- }
+ private String cachedToStringShowIndex;
- public boolean equals(Object obj)
- {
- if (this == obj)
+ public PathElement(String namespace, String name, String prefix, int index)
{
- return true;
- }
- if (obj instanceof JCRPath)
- {
- JCRPath other = (JCRPath)obj;
- return this.getInternalPath().equals(other.getInternalPath());
- }
- return false;
- }
+ super(namespace, name, prefix);
- PathElement[] getEntries()
- {
- return names;
- }
-
- public class ThisElement extends PathElement
- {
-
- ThisElement()
- {
- super(Constants.NS_DEFAULT_URI, THIS_RELPATH, Constants.NS_EMPTY_PREFIX, -1);
+ //
+ if (index == -1)
+ {
+ this.index = 1;
+ this.indexSetExplicitly = false;
+ }
+ else
+ {
+ this.index = index;
+ this.indexSetExplicitly = true;
+ }
}
- }
- public class MoveUpElement extends PathElement
- {
-
- MoveUpElement()
+ public PathElement(InternalQName qname, String prefix, int index)
{
- super(Constants.NS_DEFAULT_URI, PARENT_RELPATH, Constants.NS_EMPTY_PREFIX, -1);
+ super(qname, prefix);
+
+ //
+ if (index == -1)
+ {
+ this.index = 1;
+ this.indexSetExplicitly = false;
+ }
+ else
+ {
+ this.index = index;
+ this.indexSetExplicitly = true;
+ }
}
- }
- public class PathElement extends JCRName
- {
-
- private final int index;
-
- private final boolean indexSetExplicitly;
-
- public PathElement(String namespace, String name, String prefix, int index)
+ public PathElement(PathElement that, int index)
{
- super(namespace, name, prefix);
+ super(that);
+
+ //
if (index == -1)
{
this.index = 1;
@@ -306,7 +172,7 @@
public PathElement clone(int newIndex)
{
- return new PathElement(this.namespace, this.name, this.prefix, newIndex);
+ return new PathElement(this, newIndex);
}
public int getIndex()
@@ -324,12 +190,38 @@
public String getAsString(boolean showIndex)
{
- String indexStr;
+ if (showIndex)
+ {
+ if (cachedToStringShowIndex != null)
+ {
+ return cachedToStringShowIndex;
+ }
+ }
+ else
+ {
+ if (cachedToString != null)
+ {
+ return cachedToString;
+ }
+ }
+
+ StringBuffer sb = new StringBuffer(super.getAsString());
if (showIndex || getIndex() > 1)
- indexStr = "[" + getIndex() + "]";
+ sb.append("[").append(index).append("]");
+ String res = sb.toString();
+
+ //
+ if (showIndex)
+ {
+ cachedToStringShowIndex = res;
+ }
else
- indexStr = "";
- return (super.getAsString() + indexStr);
+ {
+ cachedToString = res;
+ }
+
+ //
+ return res;
}
public boolean isIndexSetExplicitly()
@@ -337,5 +229,4 @@
return indexSetExplicitly;
}
}
-
}
Added: jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/JCRPathExt.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/JCRPathExt.java (rev 0)
+++ jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/JCRPathExt.java 2010-10-08 12:04:24 UTC (rev 3262)
@@ -0,0 +1,394 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.core;
+
+import org.exoplatform.services.jcr.core.NamespaceAccessor;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.datamodel.QPath;
+import org.exoplatform.services.jcr.datamodel.QPathEntry;
+import org.exoplatform.services.jcr.impl.Constants;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * @author <a href="mailto:geaz@users.sourceforge.net">Gennady Azarenkov </a>
+ * @version $Id: JCRPath.java 11907 2008-03-13 15:36:21Z ksm $
+ */
+
+public class JCRPathExt extends JCRPath
+{
+
+ private static PathElement[] EMPTY_PATH = new PathElement[0];
+
+ private static final PathElement THIS_ELEMENT = new PathElement(Constants.NS_DEFAULT_URI, THIS_RELPATH, Constants.NS_EMPTY_PREFIX, -1);
+
+ private static final PathElement MOVE_UP_ELEMENT = new PathElement(Constants.NS_DEFAULT_URI, PARENT_RELPATH, Constants.NS_EMPTY_PREFIX, -1);
+
+ protected final PathElement[] names;
+
+ protected final int size;
+
+ protected String cachedToString;
+
+ protected String cachedToStringShowIndex;
+
+ protected QPath cachedInternalQPath;
+
+ public final static JCRPathExt ROOT = new JCRPathExt();
+
+ private JCRPathExt()
+ {
+ this(EMPTY_PATH);
+ }
+
+ JCRPathExt(NamespaceAccessor namespaces, QPathEntry[] path) throws RepositoryException
+ {
+ PathElement[] names = new PathElement[path.length];
+ int size = 0;
+ for (QPathEntry entry : path)
+ {
+ String prefix = namespaces.getNamespacePrefixByURI(entry.getNamespace());
+ PathElement element = element(entry.getNamespace(), entry.getName(), prefix, entry.getIndex());
+ size = addEntry(names, size, element);
+ }
+
+ //
+ this.names = names;
+ this.size = size;
+ }
+
+ JCRPathExt(JCRPathExt that, PathElement[] addedEntries, int addedSize)
+ {
+ PathElement[] names = new PathElement[that.size + addedSize];
+ int size = 0;
+ for (int i = 0;i < that.size;i++)
+ {
+ size = addEntry(names, size, that.names[i]);
+ }
+ for (int i = 0;i < addedSize;i++)
+ {
+ size = addEntry(names, size, addedEntries[i]);
+ }
+
+ //
+ this.names = names;
+ this.size = size;
+ }
+
+ JCRPathExt(PathElement[] names)
+ {
+ this(names, names.length);
+ }
+
+ JCRPathExt(PathElement[] names, int size)
+ {
+ if (size < 0)
+ {
+ throw new AssertionError("Size value is negative: " + size);
+ }
+ if (size > names.length)
+ {
+ throw new AssertionError("Size value is too large: " + size + " instead of max: " + names.length);
+ }
+
+ //
+ this.names = names;
+ this.size = size;
+ }
+
+ public boolean isAbsolute()
+ {
+ if (size > 0)
+ {
+ PathElement first = names[0];
+ if (first.getName().equals(ROOT_NAME))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ JCRPath add(JCRPath path)
+ {
+ return new JCRPathExt(this, ((JCRPathExt)path).names, ((JCRPathExt)path).size);
+ }
+
+ @Override
+ JCRPath addEntries(PathElement... entries)
+ {
+ return new JCRPathExt(this, entries, entries.length);
+ }
+
+ JCRPathExt addEntry(String namespace, String name, String prefix, int index)
+ {
+ return addEntry(element(namespace, name, prefix, index));
+ }
+
+ public JCRPathExt makeAncestorPath(int relativeDegree)
+ {
+ return new JCRPathExt(names, size - relativeDegree);
+ }
+
+ JCRPathExt addEntry(PathElement entry)
+ {
+ return new JCRPathExt(this, new PathElement[]{entry}, 1);
+ }
+
+ private static PathElement element(String namespace, String name, String prefix, int index)
+ {
+ if (name.equals(THIS_RELPATH))
+ {
+ return THIS_ELEMENT;
+ }
+ else if (name.equals(PARENT_RELPATH))
+ {
+ return MOVE_UP_ELEMENT;
+ }
+ else
+ {
+ return new PathElement(namespace, name, prefix, index);
+ }
+ }
+
+ private static int addEntry(PathElement[] entries, int size, PathElement entry)
+ {
+ if (entry == THIS_ELEMENT)
+ {
+ return size;
+ }
+ if (size > 0 && entry == MOVE_UP_ELEMENT && !(entries[size - 1] == MOVE_UP_ELEMENT))
+ {
+ if (size <= 0)
+ {
+ log.warn("Wrong relative path. Can't move up in path hierarhy.");
+ return 0;
+ }
+ return size - 1;
+ }
+
+ //
+ entries[size] = entry;
+
+ //
+ return size + 1;
+ }
+
+ public JCRPathExt makeParentPath()
+ {
+ return makeAncestorPath(1);
+ }
+
+ @Override
+ public int getLength()
+ {
+ return size;
+ }
+
+ @Override
+ public PathElement getEntry(int index)
+ {
+ if (index > size)
+ {
+ throw new ArrayIndexOutOfBoundsException();
+ }
+ return names[index];
+ }
+
+ public PathElement[] getRelPath(int relativeDegree)
+ {
+ PathElement[] relPath = new PathElement[relativeDegree];
+ System.arraycopy(names, size - relativeDegree, relPath, 0, relativeDegree);
+ return relPath;
+ }
+
+ public QPath getInternalPath()
+ {
+ if (cachedInternalQPath == null)
+ {
+ QPathEntry[] entries = new QPathEntry[size];
+
+ for (int i = 0; i < size; i++)
+ entries[i] = new QPathEntry(names[i].getNamespace(), names[i].getName(), names[i].getIndex());
+
+ cachedInternalQPath = new QPath(entries);
+ }
+
+ return cachedInternalQPath;
+ }
+
+ public String getAsString(boolean showIndex)
+ {
+ if (showIndex)
+ {
+ if (cachedToStringShowIndex != null)
+ {
+ return cachedToStringShowIndex;
+ }
+ }
+ else
+ {
+ if (cachedToString != null)
+ {
+ return cachedToString;
+ }
+ }
+
+ // [PN] 27.06.07
+ String path;
+ if (isAbsolute())
+ {
+ if (size == 1)
+ {
+ path = "/";
+ }
+ else
+ {
+ StringBuilder builder = new StringBuilder();
+ for (int i = 1; i < size; i++)
+ {
+ builder.append("/").append(names[i].getAsString(showIndex));
+ }
+ path = builder.toString();
+ }
+ }
+ else
+ {
+ // relative
+ StringBuilder builder = new StringBuilder();
+ for (int i = 0; i < size; i++)
+ {
+ if (i > 0)
+ {
+ builder.append("/");
+ }
+ else
+ {
+
+ }
+ builder.append(names[i].getAsString(showIndex));
+ }
+ path = builder.toString();
+ }
+
+
+ //
+ if (showIndex)
+ {
+ cachedToStringShowIndex = path;
+ }
+ else
+ {
+ cachedToString = path;
+ }
+
+ //
+ return path;
+ }
+
+ public int getDepth()
+ {
+ return size - 1;
+ }
+
+ public boolean isDescendantOf(JCRPath ancestorLocation, boolean childOnly)
+ {
+ return isDescendantOf((JCRPathExt)ancestorLocation, childOnly);
+ }
+
+ public boolean isDescendantOf(JCRPathExt ancestorLocation, boolean childOnly)
+ {
+ int depthDiff = getDepth() - ancestorLocation.getDepth();
+ if (depthDiff <= 0 || (childOnly && depthDiff != 1))
+ return false;
+
+ JCRPathExt.PathElement[] anotherNames = ancestorLocation.names;
+ for (int i = 0; i < ancestorLocation.size; i++)
+ {
+ boolean result = anotherNames[i].equals(names[i]);
+ if (!result)
+ return false;
+ }
+ return true;
+ }
+
+ public boolean isAncestorOf(JCRPath descendantLocation, boolean childOnly)
+ {
+ return descendantLocation.isDescendantOf(this, childOnly);
+ }
+
+ public PathElement getName()
+ {
+ if (size > 0)
+ return names[size - 1];
+
+ return THIS_ELEMENT;
+ }
+
+ public int getIndex()
+ {
+ return names[size - 1].getIndex();
+ }
+
+ public boolean isIndexSetExplicitly()
+ {
+ return names[size - 1].isIndexSetExplicitly();
+ }
+
+ public boolean isSameNameSibling(JCRPath anotherPath)
+ {
+ return isSameNameSibling((JCRPathExt)anotherPath);
+ }
+
+ public boolean isSameNameSibling(JCRPathExt anotherPath)
+ {
+ JCRName[] anotherNames = anotherPath.names;
+ for (int i = 0; i < anotherPath.size - 1; i++)
+ {
+ boolean result = anotherNames[i].equals(names[i]);
+ if (!result)
+ return false;
+ }
+ return getName().getName().equals(anotherPath.getName().getName())
+ && this.getName().getPrefix().equals(anotherPath.getName().getPrefix());
+ }
+
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (obj instanceof JCRPathExt)
+ {
+ JCRPathExt other = (JCRPathExt)obj;
+ return this.getInternalPath().equals(other.getInternalPath());
+ }
+ return false;
+ }
+
+ public PathElement[] getEntries()
+ {
+ return names.clone();
+ }
+
+}
Modified: jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/LocationFactory.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/LocationFactory.java 2010-10-08 11:45:06 UTC (rev 3261)
+++ jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/LocationFactory.java 2010-10-08 12:04:24 UTC (rev 3262)
@@ -65,19 +65,8 @@
*/
public JCRPath createJCRPath(JCRPath parentLoc, String relPath) throws RepositoryException
{
-
- JCRPath path = new JCRPath();
- for (int i = 0; i < parentLoc.getEntries().length; i++)
- {
- path.addEntry(parentLoc.getEntries()[i]);
- }
-
JCRPath addPath = parseNames(relPath, false);
- for (int i = 0; i < addPath.getEntries().length; i++)
- {
- path.addEntry(addPath.getEntries()[i]);
- }
- return path;
+ return parentLoc.add(addPath);
}
/**
@@ -125,30 +114,21 @@
*/
public JCRPath createJCRPath(QPath qPath) throws RepositoryException
{
-
- JCRPath path = new JCRPath();
- for (int i = 0; i < qPath.getEntries().length; i++)
- {
- QPathEntry entry = qPath.getEntries()[i];
- String prefix = namespaces.getNamespacePrefixByURI(entry.getNamespace());
- path.addEntry(entry.getNamespace(), entry.getName(), prefix, entry.getIndex());
- }
-
- return path;
+ return JCRPath.createJCRPath(namespaces, qPath);
}
public JCRName createJCRName(InternalQName qname) throws RepositoryException
{
String prefix = namespaces.getNamespacePrefixByURI(qname.getNamespace());
- return new JCRName(qname.getNamespace(), qname.getName(), prefix);
+ return new JCRName(qname, prefix);
}
public String formatPathElement(QPathEntry qe) throws RepositoryException
{
String prefix = namespaces.getNamespacePrefixByURI(qe.getNamespace());
- JCRPath p = new JCRPath();
- p.addEntry(qe.getNamespace(), qe.getName(), prefix, qe.getIndex());
- return p.getEntries()[0].getAsString(false);
+ JCRPath p = JCRPath.createJCRPath();
+ p = p.addEntry(qe.getNamespace(), qe.getName(), prefix, qe.getIndex());
+ return p.getEntry(0).getAsString(false);
}
/**
@@ -160,25 +140,17 @@
*/
public JCRName parseJCRName(String name) throws RepositoryException
{
- JCRPath.PathElement entry = parsePathEntry(new JCRPath(), name);
-
- return new JCRName(entry.getNamespace(), entry.getName(), entry.getPrefix());
+ JCRPath path = parsePathEntry(JCRPath.createJCRPath(), name);
+ JCRPath.PathElement entry = path.getName();
+ return new JCRName(entry);
}
public JCRPath.PathElement[] createRelPath(QPathEntry[] relPath) throws RepositoryException
{
- JCRPath path = new JCRPath();
- // JCRPath.PathElement[] entries = new JCRPath.PathElement[relPath.length];
- for (QPathEntry element : relPath)
- {
- String uri = namespaces.getNamespaceURIByPrefix(element.getNamespace());
- String prefix = namespaces.getNamespacePrefixByURI(uri);
- path.addEntry(uri, element.getName(), prefix, element.getIndex());
- }
- return path.getEntries();
+ return JCRPath.createJCRPath(namespaces, relPath).getEntries();
}
- private JCRPath.PathElement parsePathEntry(JCRPath path, String name) throws RepositoryException
+ private JCRPath parsePathEntry(JCRPath path, String name) throws RepositoryException
{
// should be reset here (if there is explicit index) or
@@ -232,8 +204,8 @@
throw new RepositoryException("Illegal path entry: \"" + name + "\"");
}
- path.addEntry(namespaces.getNamespaceURIByPrefix(prefix), someName, prefix, index);
- return (JCRPath.PathElement)path.getName();
+ path = path.addEntry(namespaces.getNamespaceURIByPrefix(prefix), someName, prefix, index);
+ return path;
}
catch (Exception e)
@@ -250,7 +222,7 @@
throw new RepositoryException("Illegal relPath: \"" + path + "\"");
}
- JCRPath jcrPath = new JCRPath();
+ JCRPath jcrPath = JCRPath.createJCRPath();
int start = 0;
if (!absolute)
{
@@ -262,7 +234,7 @@
{
throw new RepositoryException("Illegal relPath: \"" + path + "\"");
}
- jcrPath.addEntry(namespaces.getNamespaceURIByPrefix(""), "", "", -1);
+ jcrPath = jcrPath.addEntry(namespaces.getNamespaceURIByPrefix(""), "", "", -1);
}
else
{
@@ -280,7 +252,7 @@
if (start + 1 != path.length())
{
- parsePathEntry(jcrPath, qname);
+ jcrPath = parsePathEntry(jcrPath, qname);
}
else
{
15 years, 9 months
exo-jcr SVN: r3261 - kernel/branches/2.2.x/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils.
by do-not-reply@jboss.org
Author: sergiykarpenko
Date: 2010-10-08 07:45:06 -0400 (Fri, 08 Oct 2010)
New Revision: 3261
Modified:
kernel/branches/2.2.x/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/MapResourceBundle.java
kernel/branches/2.2.x/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/QName.java
Log:
JCR-1473:merge performance improvements
Modified: kernel/branches/2.2.x/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/MapResourceBundle.java
===================================================================
--- kernel/branches/2.2.x/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/MapResourceBundle.java 2010-10-08 10:07:12 UTC (rev 3260)
+++ kernel/branches/2.2.x/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/MapResourceBundle.java 2010-10-08 11:45:06 UTC (rev 3261)
@@ -25,8 +25,6 @@
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
-import java.util.Set;
-import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -36,41 +34,43 @@
public class MapResourceBundle extends ResourceBundle implements Serializable
{
- private final static String REGEXP = "#\\{.*\\}";
+ private final static Pattern PATTERN = Pattern.compile("#\\{.*\\}");
- private Map props = new HashMap();
+ private Map<String, String> props;
private Locale locale;
public MapResourceBundle(Locale l)
{
this.locale = l;
+ this.props = new HashMap<String, String>();
}
public MapResourceBundle(ResourceBundle rB, Locale l)
{
+ Map<String, String> props = new HashMap<String, String>();
+ doMerge(props, rB);
+
+ //
this.locale = l;
- initMap(rB);
+ this.props = props;
}
- private void initMap(ResourceBundle rB)
+ private static void doMerge(Map<String, String> props, ResourceBundle rB)
{
- Enumeration e = rB.getKeys();
+ Enumeration<String> e = rB.getKeys();
while (e.hasMoreElements())
{
- String s = (String)e.nextElement();
- try
+ String key = e.nextElement();
+ if (props.get(key) == null)
{
- if (props.get(s) == null)
+ Object o = rB.getObject(key);
+ if (o instanceof String)
{
- String[] newArray = rB.getStringArray(s);
- props.put(s, newArray);
+ String value = (String)o;
+ props.put(key.intern(), value.intern());
}
}
- catch (ClassCastException ex)
- {
- props.put(s, rB.getObject(s));
- }
}
}
@@ -79,9 +79,20 @@
return props.get(key);
}
- public Enumeration getKeys()
+ public Enumeration<String> getKeys()
{
- return new Vector(props.keySet()).elements();
+ final Iterator<String> i = props.keySet().iterator();
+ return new Enumeration<String>()
+ {
+ public boolean hasMoreElements()
+ {
+ return i.hasNext();
+ }
+ public String nextElement()
+ {
+ return i.next();
+ }
+ };
}
public Locale getLocale()
@@ -89,69 +100,63 @@
return this.locale;
}
- public void add(String key, Object value)
+ public void add(String key, Object o)
{
- props.put(key, value);
+ if (key != null && o instanceof String)
+ {
+ String value = (String)o;
+ props.put(key.intern(), value.intern());
+ }
}
public void remove(String key)
{
- props.remove(key);
+ if (key != null)
+ {
+ props.remove(key);
+ }
}
public void merge(ResourceBundle bundle)
{
- Enumeration e = bundle.getKeys();
- while (e.hasMoreElements())
- {
- String s = (String)e.nextElement();
- Object value = bundle.getObject(s);
- try
- {
- String[] newArray = bundle.getStringArray(s);
- if (props.get(s) == null)
- {
- props.put(s, newArray);
- }
- }
- catch (ClassCastException ex)
- {
- props.put(s, value);
- }
- }
+ doMerge(props, bundle);
}
public void resolveDependencies()
{
- Map tempMap = new HashMap();
- Set keys = props.keySet();
- Pattern pattern = Pattern.compile(REGEXP);
- for (Iterator iter = keys.iterator(); iter.hasNext();)
+ Map<String, String> tempMap = new HashMap<String ,String>();
+ for (String element : props.keySet())
{
- String element = (String)iter.next();
- String value = lookupKey(element, pattern);
- tempMap.put(element, value);
+ String value = lookupKey(element);
+ if (value != null)
+ {
+ tempMap.put(element.intern(), value.intern());
+ }
}
props = tempMap;
}
- private String lookupKey(String key, Pattern pattern)
+ private String lookupKey(String key)
{
- String s = (String)props.get(key);
+ String s = props.get(key);
if (s == null)
+ {
return key;
- Matcher matcher = pattern.matcher(s);
+ }
+
+ //
+ Matcher matcher = PATTERN.matcher(s);
if (matcher.find())
{
- return recursivedResolving(s, pattern);
+ return recursivedResolving(s);
}
return s;
}
- private String recursivedResolving(String key, Pattern pattern)
+ private String recursivedResolving(String key)
{
String resolved = key;
- StringBuffer sB = new StringBuffer();
+ StringBuilder sB = new StringBuilder();
while (resolved.indexOf("#{") != -1)
{
sB.setLength(0);
@@ -159,7 +164,7 @@
int lastIndex = resolved.indexOf('}', firstIndex);
String realKey = resolved.substring(firstIndex + 2, lastIndex);
sB.append(resolved.substring(0, firstIndex));
- sB.append(lookupKey(realKey, pattern));
+ sB.append(lookupKey(realKey));
sB.append(resolved.substring(lastIndex + 1));
resolved = sB.toString();
}
Modified: kernel/branches/2.2.x/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/QName.java
===================================================================
--- kernel/branches/2.2.x/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/QName.java 2010-10-08 10:07:12 UTC (rev 3260)
+++ kernel/branches/2.2.x/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/QName.java 2010-10-08 11:45:06 UTC (rev 3261)
@@ -37,14 +37,23 @@
protected final int hashCode;
public QName(String namespace, String name)
- {
- this.namespace = (namespace != null ? namespace : "").intern();
- this.name = (name != null ? name : "");
-
- this.stringName = ("[" + this.namespace + "]" + this.name);
-
- int hk = 31 + this.namespace.hashCode();
- this.hashCode = hk * 31 + this.name.hashCode();
+ {
+ if (namespace == null)
+ {
+ namespace = "";
+ }
+ if (name == null)
+ {
+ name = "";
+ }
+ String stringName = ("[" + namespace + "]" + name);
+ int hashCode = (31 + namespace.hashCode()) * 31 + name.hashCode();
+
+ //
+ this.namespace = namespace;
+ this.name = name;
+ this.stringName = stringName;
+ this.hashCode = hashCode;
}
public String getNamespace()
15 years, 9 months