exo-jcr SVN: r2606 - jcr/trunk/exo.jcr.component.core/src/test/resources.
by do-not-reply@jboss.org
Author: dkatayev
Date: 2010-06-15 10:25:05 -0400 (Tue, 15 Jun 2010)
New Revision: 2606
Modified:
jcr/trunk/exo.jcr.component.core/src/test/resources/test.policy
Log:
EXOJCR-756 test.policy formated
Modified: jcr/trunk/exo.jcr.component.core/src/test/resources/test.policy
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/resources/test.policy 2010-06-15 14:13:39 UTC (rev 2605)
+++ jcr/trunk/exo.jcr.component.core/src/test/resources/test.policy 2010-06-15 14:25:05 UTC (rev 2606)
@@ -1,15 +1,13 @@
grant codeBase "file:@MAVEN_REPO@-"{
- permission java.security.AllPermission;
+ permission java.security.AllPermission;
};
-grant codeBase "file:@MAIN_CLASSES@-"{
- permission java.security.AllPermission;
+grant codeBase "file:@MAIN_CLASSES@-"{
+ permission java.security.AllPermission;
};
-
-
grant codeBase "file:@TEST_CLASSES@-"{
- permission java.lang.RuntimePermission "setSecurityManager";
- permission java.lang.RuntimePermission "getJCRSystemSession";
- permission java.lang.RuntimePermission "manageRepository";
+ permission java.lang.RuntimePermission "setSecurityManager";
+ permission java.lang.RuntimePermission "getJCRSystemSession";
+ permission java.lang.RuntimePermission "manageRepository";
};
16 years, 1 month
exo-jcr SVN: r2605 - jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/utils/io.
by do-not-reply@jboss.org
Author: natasha.vakulenko
Date: 2010-06-15 10:13:39 -0400 (Tue, 15 Jun 2010)
New Revision: 2605
Modified:
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/utils/io/TestSpoolFile.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/utils/io/TestSwapFile.java
Log:
EXOJCR-791: Renamed constants in classes TestSpoolFile and TestSwaplFile.
Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/utils/io/TestSpoolFile.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/utils/io/TestSpoolFile.java 2010-06-15 13:46:56 UTC (rev 2604)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/utils/io/TestSpoolFile.java 2010-06-15 14:13:39 UTC (rev 2605)
@@ -31,22 +31,22 @@
public class TestSpoolFile extends TestCase
{
- private static final String dirName = "../";
+ private static final String DIR_NAME = "../";
- private static final String fileName = "testSpoolFile";
+ private static final String FILE_NAME = "testSpoolFile";
public void testCreateTempFile() throws IOException
{
// This method creates a file on disk space.
// When calling a method delete() it should be removed.
- SpoolFile sf = SpoolFile.createTempFile("prefix", "suffics", new File(dirName));
+ SpoolFile sf = SpoolFile.createTempFile("prefix", "suffics", new File(DIR_NAME));
assertNotNull("File should be created.", sf);
assertTrue("File should be deleted.", sf.delete());
}
public void testAcquireFile() throws FileNotFoundException
{
- SpoolFile sf = new SpoolFile(dirName + fileName);
+ SpoolFile sf = new SpoolFile(DIR_NAME + FILE_NAME);
// Add new holder of file, now file must be in use.
sf.acquire("holder");
@@ -69,7 +69,7 @@
public void testReleaseFile() throws FileNotFoundException
{
- SpoolFile sf = new SpoolFile(dirName + fileName);
+ SpoolFile sf = new SpoolFile(DIR_NAME + FILE_NAME);
// Add new holder of file.
sf.acquire("holder");
@@ -94,7 +94,7 @@
public void testFileInUse() throws FileNotFoundException
{
- SpoolFile sf = new SpoolFile(dirName + fileName);
+ SpoolFile sf = new SpoolFile(DIR_NAME + FILE_NAME);
sf.acquire("holder");
assertTrue("The file has holder. It must be in use.", sf.inUse());
@@ -119,7 +119,7 @@
public void testDeleteFile() throws FileNotFoundException
{
// This method not creates a file on disk space.
- SpoolFile sf = new SpoolFile(dirName + fileName);
+ SpoolFile sf = new SpoolFile(DIR_NAME + FILE_NAME);
// Add and release new holder of file.
sf.acquire("holder");
Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/utils/io/TestSwapFile.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/utils/io/TestSwapFile.java 2010-06-15 13:46:56 UTC (rev 2604)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/utils/io/TestSwapFile.java 2010-06-15 14:13:39 UTC (rev 2605)
@@ -30,16 +30,16 @@
public class TestSwapFile extends TestCase
{
- private static final String dirName = "../";
+ private static final String DIR_NAME = "../";
- private static final String fileName = "childSwapFile";
+ private static final String FILE_NAME = "childSwapFile";
public void testCreateTempFile()
{
// Not applicable creation.
try
{
- SwapFile.createTempFile("prefix", "suffix", new File(dirName));
+ SwapFile.createTempFile("prefix", "suffix", new File(DIR_NAME));
fail("IOException should have been thrown.");
}
catch (IOException e)
@@ -51,7 +51,7 @@
public void testGetSwapFile() throws IOException
{
// Get swap file is possible only in this way.
- SwapFile sf = SwapFile.get(new File(dirName), fileName);
+ SwapFile sf = SwapFile.get(new File(DIR_NAME), FILE_NAME);
assertNotNull("File should be created.", sf);
sf.spoolDone();
sf.delete();
@@ -59,7 +59,7 @@
public void testIsSpooled() throws IOException
{
- SwapFile sf = SwapFile.get(new File(dirName), fileName);
+ SwapFile sf = SwapFile.get(new File(DIR_NAME), FILE_NAME);
assertFalse("Spool is not over.", sf.isSpooled());
sf.spoolDone();
assertTrue("Spool is over.", sf.isSpooled());
@@ -68,7 +68,7 @@
public void testSpoolDone() throws IOException
{
- SwapFile sf = SwapFile.get(new File(dirName), fileName);
+ SwapFile sf = SwapFile.get(new File(DIR_NAME), FILE_NAME);
sf.spoolDone();
assertTrue("Spool should be done.", sf.isSpooled());
sf.delete();
@@ -76,7 +76,7 @@
public void testDeleteSpoolFile() throws IOException
{
- SwapFile sf = SwapFile.get(new File(dirName), fileName);
+ SwapFile sf = SwapFile.get(new File(DIR_NAME), FILE_NAME);
sf.spoolDone();
// File on disk does not exist. It will not be removed from disk space.
16 years, 1 month
exo-jcr SVN: r2604 - in jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/utils: io and 1 other directory.
by do-not-reply@jboss.org
Author: natasha.vakulenko
Date: 2010-06-15 09:46:56 -0400 (Tue, 15 Jun 2010)
New Revision: 2604
Added:
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/utils/io/
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/utils/io/TestSpoolFile.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/utils/io/TestSwapFile.java
Log:
EXOJCR-791: Added unit tests for SwapFile and SpoolFile.
Added: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/utils/io/TestSpoolFile.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/utils/io/TestSpoolFile.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/utils/io/TestSpoolFile.java 2010-06-15 13:46:56 UTC (rev 2604)
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.impl.utils.io;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.File;
+
+import org.exoplatform.services.jcr.impl.util.io.SpoolFile;
+
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:natasha.vakulenko@gmail.com">Natasha Vakulenko</a>
+ * @version $Id$
+ */
+
+public class TestSpoolFile extends TestCase
+{
+ private static final String dirName = "../";
+
+ private static final String fileName = "testSpoolFile";
+
+ public void testCreateTempFile() throws IOException
+ {
+ // This method creates a file on disk space.
+ // When calling a method delete() it should be removed.
+ SpoolFile sf = SpoolFile.createTempFile("prefix", "suffics", new File(dirName));
+ assertNotNull("File should be created.", sf);
+ assertTrue("File should be deleted.", sf.delete());
+ }
+
+ public void testAcquireFile() throws FileNotFoundException
+ {
+ SpoolFile sf = new SpoolFile(dirName + fileName);
+
+ // Add new holder of file, now file must be in use.
+ sf.acquire("holder");
+ assertTrue("File must be in use.", sf.inUse());
+
+ sf.release("holder");
+ sf.delete();
+
+ // Use non-existent file.
+ try
+ {
+ sf.acquire("anotherHolder");
+ fail("FileNotFoundException should have been thrown.");
+ }
+ catch (FileNotFoundException e)
+ {
+ // Ok.
+ }
+ }
+
+ public void testReleaseFile() throws FileNotFoundException
+ {
+ SpoolFile sf = new SpoolFile(dirName + fileName);
+
+ // Add new holder of file.
+ sf.acquire("holder");
+
+ // Release file from holder.
+ sf.release("holder");
+
+ assertFalse("File should not have holders.", sf.inUse());
+ sf.delete();
+
+ // Use non-existent file.
+ try
+ {
+ sf.release("someHolder");
+ fail("FileNotFoundException should have been thrown.");
+ }
+ catch (FileNotFoundException e)
+ {
+ // Ok.
+ }
+ }
+
+ public void testFileInUse() throws FileNotFoundException
+ {
+ SpoolFile sf = new SpoolFile(dirName + fileName);
+
+ sf.acquire("holder");
+ assertTrue("The file has holder. It must be in use.", sf.inUse());
+
+ sf.release("holder");
+ assertFalse("The file has no holder. It should not be in use.", sf.inUse());
+
+ sf.delete();
+
+ // Work with non-existent file.
+ try
+ {
+ sf.inUse();
+ fail("FileNotFoundException should have been thrown.");
+ }
+ catch (FileNotFoundException e)
+ {
+ // Ok.
+ }
+ }
+
+ public void testDeleteFile() throws FileNotFoundException
+ {
+ // This method not creates a file on disk space.
+ SpoolFile sf = new SpoolFile(dirName + fileName);
+
+ // Add and release new holder of file.
+ sf.acquire("holder");
+ sf.release("holder");
+
+ // Now file is free. It can be deleted.
+ // File on disk does not exist. It will not be removed from disk space.
+ assertFalse("Deleted file was not created on the disk.", sf.delete());
+ }
+}
Property changes on: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/utils/io/TestSpoolFile.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/utils/io/TestSwapFile.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/utils/io/TestSwapFile.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/utils/io/TestSwapFile.java 2010-06-15 13:46:56 UTC (rev 2604)
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.impl.utils.io;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.exoplatform.services.jcr.impl.util.io.SwapFile;
+
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:natasha.vakulenko@gmail.com">Natasha Vakulenko</a>
+ * @version $Id$
+ */
+
+public class TestSwapFile extends TestCase
+{
+ private static final String dirName = "../";
+
+ private static final String fileName = "childSwapFile";
+
+ public void testCreateTempFile()
+ {
+ // Not applicable creation.
+ try
+ {
+ SwapFile.createTempFile("prefix", "suffix", new File(dirName));
+ fail("IOException should have been thrown.");
+ }
+ catch (IOException e)
+ {
+ // Ok.
+ }
+ }
+
+ public void testGetSwapFile() throws IOException
+ {
+ // Get swap file is possible only in this way.
+ SwapFile sf = SwapFile.get(new File(dirName), fileName);
+ assertNotNull("File should be created.", sf);
+ sf.spoolDone();
+ sf.delete();
+ }
+
+ public void testIsSpooled() throws IOException
+ {
+ SwapFile sf = SwapFile.get(new File(dirName), fileName);
+ assertFalse("Spool is not over.", sf.isSpooled());
+ sf.spoolDone();
+ assertTrue("Spool is over.", sf.isSpooled());
+ sf.delete();
+ }
+
+ public void testSpoolDone() throws IOException
+ {
+ SwapFile sf = SwapFile.get(new File(dirName), fileName);
+ sf.spoolDone();
+ assertTrue("Spool should be done.", sf.isSpooled());
+ sf.delete();
+ }
+
+ public void testDeleteSpoolFile() throws IOException
+ {
+ SwapFile sf = SwapFile.get(new File(dirName), fileName);
+ sf.spoolDone();
+
+ // File on disk does not exist. It will not be removed from disk space.
+ assertFalse("Deleted file was not created on the disk.", sf.delete());
+ }
+}
Property changes on: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/utils/io/TestSwapFile.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
16 years, 1 month
exo-jcr SVN: r2603 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services: jcr/impl/core/lock/jbosscache and 3 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-06-15 09:37:48 -0400 (Tue, 15 Jun 2010)
New Revision: 2603
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RepositoryImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/SpoolFile.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/transaction/jbosscache/JBossTransactionsService.java
Log:
EXOJCR-756: replace operations on privileged operations
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RepositoryImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RepositoryImpl.java 2010-06-15 13:24:09 UTC (rev 2602)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RepositoryImpl.java 2010-06-15 13:37:48 UTC (rev 2603)
@@ -45,6 +45,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
@@ -293,7 +294,7 @@
return;
}
- WorkspaceContainer wsContainer = repositoryContainer.getWorkspaceContainer(workspaceName);
+ final WorkspaceContainer wsContainer = repositoryContainer.getWorkspaceContainer(workspaceName);
if (wsContainer == null)
throw new RepositoryException("Workspace " + workspaceName
@@ -301,8 +302,17 @@
repositoryContainer.getWorkspaceContainer(workspaceName).getWorkspaceInitializer().initWorkspace();
- wsContainer.start();
+ PrivilegedAction<Object> action = new PrivilegedAction<Object>()
+ {
+ public Object run()
+ {
+ wsContainer.start();
+ return null;
+ }
+ };
+ AccessController.doPrivileged(action);
+
LOG.info("Workspace " + workspaceName + "@" + this.name + " is initialized");
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java 2010-06-15 13:24:09 UTC (rev 2602)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java 2010-06-15 13:37:48 UTC (rev 2603)
@@ -56,7 +56,6 @@
import org.exoplatform.services.naming.InitialContextInitializer;
import org.exoplatform.services.transaction.TransactionService;
import org.jboss.cache.Cache;
-import org.jboss.cache.CacheException;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
@@ -72,6 +71,7 @@
import java.security.AccessController;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
+import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.sql.Connection;
@@ -258,38 +258,28 @@
cache = factory.createCache(config.getLockManager());
- PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
+ PrivilegedAction<Object> action = new PrivilegedAction<Object>()
{
- public Object run() throws Exception
+ public Object run()
{
cache.create();
- // Add the cache loader needed to prevent TimeoutException
- addCacheLoader();
- cache.start();
-
return null;
}
};
- try
+ AccessController.doPrivileged(action);
+
+ // Add the cache loader needed to prevent TimeoutException
+ addCacheLoader();
+
+ action = new PrivilegedAction<Object>()
{
- AccessController.doPrivileged(action);
- }
- catch (PrivilegedActionException pae)
- {
- Throwable cause = pae.getCause();
- if (cause instanceof CacheException)
+ public Object run()
{
- throw (CacheException)cause;
+ cache.start();
+ return null;
}
- else if (cause instanceof RuntimeException)
- {
- throw (RuntimeException)cause;
- }
- else
- {
- throw new RuntimeException(cause);
- }
- }
+ };
+ AccessController.doPrivileged(action);
createStructuredNode(lockRoot);
@@ -839,7 +829,16 @@
lockRemover.halt();
lockRemover.interrupt();
sessionLockManagers.clear();
- cache.stop();
+
+ PrivilegedAction<Object> action = new PrivilegedAction<Object>()
+ {
+ public Object run()
+ {
+ cache.stop();
+ return null;
+ }
+ };
+ AccessController.doPrivileged(action);
}
/**
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java 2010-06-15 13:24:09 UTC (rev 2602)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java 2010-06-15 13:37:48 UTC (rev 2603)
@@ -36,8 +36,7 @@
import java.io.Serializable;
import java.security.AccessController;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
+import java.security.PrivilegedAction;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -216,34 +215,15 @@
*/
public void create() throws CacheException
{
- PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
+ PrivilegedAction<Object> action = new PrivilegedAction<Object>()
{
- public Object run() throws Exception
+ public Object run()
{
parentCache.create();
return null;
}
};
- try
- {
- AccessController.doPrivileged(action);
- }
- catch (PrivilegedActionException pae)
- {
- Throwable cause = pae.getCause();
- if (cause instanceof CacheException)
- {
- throw (CacheException)cause;
- }
- else if (cause instanceof RuntimeException)
- {
- throw (RuntimeException)cause;
- }
- else
- {
- throw new RuntimeException(cause);
- }
- }
+ AccessController.doPrivileged(action);
}
/* (non-Javadoc)
@@ -648,34 +628,15 @@
*/
public void start() throws CacheException
{
- PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
+ PrivilegedAction<Object> action = new PrivilegedAction<Object>()
{
- public Object run() throws Exception
+ public Object run()
{
parentCache.start();
return null;
}
};
- try
- {
- AccessController.doPrivileged(action);
- }
- catch (PrivilegedActionException pae)
- {
- Throwable cause = pae.getCause();
- if (cause instanceof CacheException)
- {
- throw (CacheException)cause;
- }
- else if (cause instanceof RuntimeException)
- {
- throw (RuntimeException)cause;
- }
- else
- {
- throw new RuntimeException(cause);
- }
- }
+ AccessController.doPrivileged(action);
}
/* (non-Javadoc)
@@ -691,7 +652,15 @@
*/
public void stop()
{
- parentCache.stop();
+ PrivilegedAction<Object> action = new PrivilegedAction<Object>()
+ {
+ public Object run()
+ {
+ parentCache.stop();
+ return null;
+ }
+ };
+ AccessController.doPrivileged(action);
}
public TransactionManager getTransactionManager()
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/SpoolFile.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/SpoolFile.java 2010-06-15 13:24:09 UTC (rev 2602)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/SpoolFile.java 2010-06-15 13:37:48 UTC (rev 2603)
@@ -77,7 +77,7 @@
public synchronized void acquire(Object holder) throws FileNotFoundException
{
if (users == null)
- throw new FileNotFoundException("File was deleted " + getAbsolutePath());
+ throw new FileNotFoundException("File was deleted " + PrivilegedFileHelper.getAbsolutePath(this));
users.put(holder, System.currentTimeMillis());
}
@@ -85,7 +85,7 @@
public synchronized void release(Object holder) throws FileNotFoundException
{
if (users == null)
- throw new FileNotFoundException("File was deleted " + getAbsolutePath());
+ throw new FileNotFoundException("File was deleted " + PrivilegedFileHelper.getAbsolutePath(this));
users.remove(holder);
}
@@ -93,7 +93,7 @@
public synchronized boolean inUse() throws FileNotFoundException
{
if (users == null)
- throw new FileNotFoundException("File was deleted " + getAbsolutePath());
+ throw new FileNotFoundException("File was deleted " + PrivilegedFileHelper.getAbsolutePath(this));
return users.size() > 0;
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/transaction/jbosscache/JBossTransactionsService.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/transaction/jbosscache/JBossTransactionsService.java 2010-06-15 13:24:09 UTC (rev 2602)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/transaction/jbosscache/JBossTransactionsService.java 2010-06-15 13:37:48 UTC (rev 2603)
@@ -23,6 +23,9 @@
import org.exoplatform.container.xml.InitParams;
import org.jboss.cache.transaction.TransactionManagerLookup;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
import javax.transaction.UserTransaction;
import javax.transaction.xa.Xid;
@@ -35,15 +38,15 @@
*/
public class JBossTransactionsService extends GenericTransactionService
{
-
+
public JBossTransactionsService(TransactionManagerLookup tmLookup)
{
super(tmLookup);
}
-
+
public JBossTransactionsService(TransactionManagerLookup tmLookup, InitParams params)
{
- super(tmLookup, params);
+ super(tmLookup, params);
}
/**
@@ -61,6 +64,13 @@
@Override
public UserTransaction getUserTransaction()
{
- return com.arjuna.ats.jta.UserTransaction.userTransaction();
+ PrivilegedAction<UserTransaction> action = new PrivilegedAction<UserTransaction>()
+ {
+ public UserTransaction run()
+ {
+ return com.arjuna.ats.jta.UserTransaction.userTransaction();
+ }
+ };
+ return AccessController.doPrivileged(action);
}
}
16 years, 1 month
exo-jcr SVN: r2602 - in jcr/trunk/exo.jcr.component.core: src/test/resources and 1 other directory.
by do-not-reply@jboss.org
Author: dkatayev
Date: 2010-06-15 09:24:09 -0400 (Tue, 15 Jun 2010)
New Revision: 2602
Modified:
jcr/trunk/exo.jcr.component.core/pom.xml
jcr/trunk/exo.jcr.component.core/src/test/resources/test.policy
Log:
EXOJCR-756 fileseparator added
Modified: jcr/trunk/exo.jcr.component.core/pom.xml
===================================================================
--- jcr/trunk/exo.jcr.component.core/pom.xml 2010-06-15 12:47:05 UTC (rev 2601)
+++ jcr/trunk/exo.jcr.component.core/pom.xml 2010-06-15 13:24:09 UTC (rev 2602)
@@ -479,9 +479,9 @@
<include name="test.policy"/>
</fileset>
<filterset>
- <filter token="MAVEN_REPO" value="${settings.localRepository}"/>
- <filter token="MAIN_CLASSES" value="${project.build.outputDirectory}"/>
- <filter token="TEST_CLASSES" value="${project.build.testOutputDirectory}"/>
+ <filter token="MAVEN_REPO" value="${settings.localRepository}${file.separator}"/>
+ <filter token="MAIN_CLASSES" value="${project.build.outputDirectory}${file.separator}"/>
+ <filter token="TEST_CLASSES" value="${project.build.testOutputDirectory}${file.separator}"/>
</filterset>
</copy>
</tasks>
Modified: jcr/trunk/exo.jcr.component.core/src/test/resources/test.policy
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/resources/test.policy 2010-06-15 12:47:05 UTC (rev 2601)
+++ jcr/trunk/exo.jcr.component.core/src/test/resources/test.policy 2010-06-15 13:24:09 UTC (rev 2602)
@@ -1,14 +1,14 @@
-grant codeBase "file:@MAVEN_REPO@/-"{
+grant codeBase "file:@MAVEN_REPO@-"{
permission java.security.AllPermission;
};
-grant codeBase "file:@MAIN_CLASSES@/-"{
+grant codeBase "file:@MAIN_CLASSES@-"{
permission java.security.AllPermission;
};
-grant codeBase "file:@TEST_CLASSES@/-"{
+grant codeBase "file:@TEST_CLASSES@-"{
permission java.lang.RuntimePermission "setSecurityManager";
permission java.lang.RuntimePermission "getJCRSystemSession";
permission java.lang.RuntimePermission "manageRepository";
16 years, 1 month
exo-jcr SVN: r2601 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr: impl/dataflow/persistent/jbosscache and 4 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-06-15 08:47:05 -0400 (Tue, 15 Jun 2010)
New Revision: 2601
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/SimpleFileIOChannel.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/TesterSecurityManager.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedFileHelper.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/jbosscache/ExoJBossCacheFactory.java
Log:
EXOJCR-756: fix
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java 2010-06-15 10:53:03 UTC (rev 2600)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java 2010-06-15 12:47:05 UTC (rev 2601)
@@ -56,6 +56,7 @@
import org.exoplatform.services.naming.InitialContextInitializer;
import org.exoplatform.services.transaction.TransactionService;
import org.jboss.cache.Cache;
+import org.jboss.cache.CacheException;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
@@ -68,8 +69,11 @@
import java.io.Serializable;
import java.math.BigInteger;
+import java.security.AccessController;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
@@ -254,11 +258,39 @@
cache = factory.createCache(config.getLockManager());
- cache.create();
- // Add the cache loader needed to prevent TimeoutException
- addCacheLoader();
- cache.start();
+ PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
+ {
+ public Object run() throws Exception
+ {
+ cache.create();
+ // Add the cache loader needed to prevent TimeoutException
+ addCacheLoader();
+ cache.start();
+ return null;
+ }
+ };
+ try
+ {
+ AccessController.doPrivileged(action);
+ }
+ catch (PrivilegedActionException pae)
+ {
+ Throwable cause = pae.getCause();
+ if (cause instanceof CacheException)
+ {
+ throw (CacheException)cause;
+ }
+ else if (cause instanceof RuntimeException)
+ {
+ throw (RuntimeException)cause;
+ }
+ else
+ {
+ throw new RuntimeException(cause);
+ }
+ }
+
createStructuredNode(lockRoot);
// Context recall is a workaround of JDBCCacheLoader starting.
@@ -285,7 +317,7 @@
// detect dialect of data-source
try
{
- DataSource dataSource = (DataSource)new InitialContext().lookup(dataSourceName);
+ final DataSource dataSource = (DataSource)new InitialContext().lookup(dataSourceName);
if (dataSource == null)
{
throw new RepositoryException("DataSource (" + dataSourceName + ") can't be null");
@@ -294,7 +326,34 @@
Connection jdbcConn = null;
try
{
- jdbcConn = dataSource.getConnection();
+ PrivilegedExceptionAction<Connection> action = new PrivilegedExceptionAction<Connection>()
+ {
+ public Connection run() throws Exception
+ {
+ return dataSource.getConnection();
+ }
+ };
+ try
+ {
+ jdbcConn = AccessController.doPrivileged(action);
+ }
+ catch (PrivilegedActionException pae)
+ {
+ Throwable cause = pae.getCause();
+ if (cause instanceof SQLException)
+ {
+ throw (SQLException)cause;
+ }
+ else if (cause instanceof RuntimeException)
+ {
+ throw (RuntimeException)cause;
+ }
+ else
+ {
+ throw new RuntimeException(cause);
+ }
+ }
+
dialect = DialectDetecter.detect(jdbcConn.getMetaData());
}
finally
@@ -489,7 +548,7 @@
}
return true;
}
-
+
/**
* Return new instance of session lock manager.
*/
@@ -912,7 +971,7 @@
{
return getExactNodeOrCloseParentLock(node, true);
}
-
+
private LockData getExactNodeOrCloseParentLock(NodeData node, boolean checkHasLocks) throws RepositoryException
{
@@ -953,7 +1012,7 @@
{
return getClosedChild(node, true);
}
-
+
private LockData getClosedChild(NodeData node, boolean checkHasLocks) throws RepositoryException
{
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java 2010-06-15 10:53:03 UTC (rev 2600)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java 2010-06-15 12:47:05 UTC (rev 2601)
@@ -18,14 +18,6 @@
*/
package org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache;
-import java.io.Serializable;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.transaction.TransactionManager;
-
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.jboss.cache.Cache;
@@ -42,6 +34,17 @@
import org.jboss.cache.interceptors.base.CommandInterceptor;
import org.jgroups.Address;
+import java.io.Serializable;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.transaction.TransactionManager;
+
/**
* Decorator over the JBossCache that stores changes in buffer, then sorts and applies to JBossCache.
*
@@ -60,9 +63,9 @@
private final ThreadLocal<CompressedChangesBuffer> changesList = new ThreadLocal<CompressedChangesBuffer>();
private ThreadLocal<Boolean> local = new ThreadLocal<Boolean>();
-
+
private final boolean useExpiration;
-
+
private final long expirationTimeOut;
protected static final Log LOG =
@@ -213,7 +216,34 @@
*/
public void create() throws CacheException
{
- parentCache.create();
+ PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
+ {
+ public Object run() throws Exception
+ {
+ parentCache.create();
+ return null;
+ }
+ };
+ try
+ {
+ AccessController.doPrivileged(action);
+ }
+ catch (PrivilegedActionException pae)
+ {
+ Throwable cause = pae.getCause();
+ if (cause instanceof CacheException)
+ {
+ throw (CacheException)cause;
+ }
+ else if (cause instanceof RuntimeException)
+ {
+ throw (RuntimeException)cause;
+ }
+ else
+ {
+ throw new RuntimeException(cause);
+ }
+ }
}
/* (non-Javadoc)
@@ -584,8 +614,8 @@
public boolean removeNode(Fqn fqn)
{
CompressedChangesBuffer changesContainer = getChangesBufferSafe();
- changesContainer.add(new RemoveNodeContainer(fqn, parentCache, changesContainer.getHistoryIndex(), local.get(),
- useExpiration, expirationTimeOut));
+ changesContainer.add(new RemoveNodeContainer(fqn, parentCache, changesContainer.getHistoryIndex(), local.get(),
+ useExpiration, expirationTimeOut));
return true;
}
@@ -618,7 +648,34 @@
*/
public void start() throws CacheException
{
- parentCache.start();
+ PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
+ {
+ public Object run() throws Exception
+ {
+ parentCache.start();
+ return null;
+ }
+ };
+ try
+ {
+ AccessController.doPrivileged(action);
+ }
+ catch (PrivilegedActionException pae)
+ {
+ Throwable cause = pae.getCause();
+ if (cause instanceof CacheException)
+ {
+ throw (CacheException)cause;
+ }
+ else if (cause instanceof RuntimeException)
+ {
+ throw (RuntimeException)cause;
+ }
+ else
+ {
+ throw new RuntimeException(cause);
+ }
+ }
}
/* (non-Javadoc)
@@ -691,9 +748,9 @@
protected final boolean localMode;
protected final boolean useExpiration;
-
+
protected final long timeOut;
-
+
public ChangesContainer(Fqn fqn, ChangesType changesType, Cache<Serializable, Object> cache, int historicalIndex,
boolean localMode, boolean useExpiration, long timeOut)
{
@@ -750,7 +807,7 @@
{
cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(localMode);
}
-
+
public final void putExpiration(Fqn efqn)
{
setCacheLocalMode();
@@ -780,7 +837,7 @@
{
setCacheLocalMode();
cache.put(fqn, data);
-
+
if (useExpiration)
{
putExpiration(fqn);
@@ -812,7 +869,7 @@
{
putExpiration(fqn);
}
-
+
setCacheLocalMode();
cache.put(fqn, key, value);
}
@@ -853,12 +910,12 @@
newSet.addAll((Set<Object>)existingObject);
}
newSet.add(value);
-
+
if (useExpiration)
{
putExpiration(fqn);
}
-
+
setCacheLocalMode();
cache.put(fqn, key, newSet);
}
@@ -900,12 +957,12 @@
{
Set<Object> newSet = new HashSet<Object>((Set<Object>)existingObject);
newSet.remove(value);
-
+
if (useExpiration)
{
putExpiration(fqn);
}
-
+
setCacheLocalMode();
cache.put(fqn, key, newSet);
}
@@ -941,8 +998,8 @@
public static class RemoveNodeContainer extends ChangesContainer
{
- public RemoveNodeContainer(Fqn fqn, Cache<Serializable, Object> cache, int historicalIndex, boolean local,
- boolean useExpiration, long timeOut)
+ public RemoveNodeContainer(Fqn fqn, Cache<Serializable, Object> cache, int historicalIndex, boolean local,
+ boolean useExpiration, long timeOut)
{
super(fqn, ChangesType.REMOVE, cache, historicalIndex, local, useExpiration, timeOut);
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/SimpleFileIOChannel.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/SimpleFileIOChannel.java 2010-06-15 10:53:03 UTC (rev 2600)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/SimpleFileIOChannel.java 2010-06-15 12:47:05 UTC (rev 2601)
@@ -20,6 +20,7 @@
import org.exoplatform.services.jcr.impl.storage.value.ValueDataResourceHolder;
import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
import java.io.File;
import java.io.FileFilter;
@@ -71,6 +72,6 @@
@Override
protected File[] getFiles(String propertyId) throws IOException
{
- return rootDir.listFiles(new PropertyIDFilter(propertyId));
+ return PrivilegedFileHelper.listFiles(rootDir, new PropertyIDFilter(propertyId));
}
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/TesterSecurityManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/TesterSecurityManager.java 2010-06-15 10:53:03 UTC (rev 2600)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/TesterSecurityManager.java 2010-06-15 12:47:05 UTC (rev 2601)
@@ -52,28 +52,24 @@
{
StackTraceElement el = traceElements[i];
String cl = el.getClassName();
+ String fn = el.getFileName();
if (cl.startsWith("org.exoplatform"))
{
- int p = cl.lastIndexOf('.');
- if (p != -1)
- {
- cl = cl.substring(p + 1);
- }
-
// TesterSecurityManager is not a part of source code
- if (cl.equals("TesterSecurityManager"))
+ if (fn.equals("TesterSecurityManager.java"))
{
continue;
}
// hide Exception
- if (cl.equals("BaseStandaloneTest"))
+ if (fn.equals("BaseStandaloneTest.java") || fn.equals("SLF4JExoLogFactory.java"))
{
return;
}
- if (cl.startsWith("Test") || cl.endsWith("Test") || cl.endsWith("TestBase"))
+ if (fn.startsWith("Test") || fn.endsWith("Test.java") || fn.endsWith("TestBase.java")
+ || fn.equals("Probe.java"))
{
testCode = true;
}
@@ -82,6 +78,19 @@
srcCode = true;
}
}
+ else if (cl.startsWith("org.apache.jackrabbit.test"))
+ {
+ // hide Exception
+ if (fn.equals("JCRTestResult.java"))
+ {
+ return;
+ }
+ }
+ else if (cl.startsWith("org.exoplatform.services.log.impl.SLF4JExoLogFactory"))
+ {
+ return;
+ }
+
}
e = e.getCause();
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedFileHelper.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedFileHelper.java 2010-06-15 10:53:03 UTC (rev 2600)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedFileHelper.java 2010-06-15 12:47:05 UTC (rev 2601)
@@ -19,6 +19,7 @@
package org.exoplatform.services.jcr.impl.util.io;
import java.io.File;
+import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@@ -569,4 +570,22 @@
return AccessController.doPrivileged(action);
}
+ /**
+ * Get file's list in privileged mode.
+ *
+ * @param file
+ * @return
+ */
+ public static File[] listFiles(final File file, final FileFilter filter)
+ {
+ PrivilegedAction<File[]> action = new PrivilegedAction<File[]>()
+ {
+ public File[] run()
+ {
+ return file.listFiles(filter);
+ }
+ };
+ return AccessController.doPrivileged(action);
+ }
+
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/jbosscache/ExoJBossCacheFactory.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/jbosscache/ExoJBossCacheFactory.java 2010-06-15 10:53:03 UTC (rev 2600)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/jbosscache/ExoJBossCacheFactory.java 2010-06-15 12:47:05 UTC (rev 2601)
@@ -31,6 +31,8 @@
import java.io.IOException;
import java.io.InputStream;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import javax.transaction.TransactionManager;
@@ -124,9 +126,18 @@
}
// create cache
- CacheFactory<K, V> factory = new DefaultCacheFactory<K, V>();
- Cache<K, V> cache = factory.createCache(configStream, false);
+ final CacheFactory<K, V> factory = new DefaultCacheFactory<K, V>();
+ final InputStream stream = configStream;
+ PrivilegedAction<Cache<K, V>> action = new PrivilegedAction<Cache<K, V>>()
+ {
+ public Cache<K, V> run()
+ {
+ return factory.createCache(stream, false);
+ }
+ };
+ Cache<K, V> cache = AccessController.doPrivileged(action);
+
// inject transaction manager if defined
if (transactionManager != null)
{
16 years, 1 month
exo-jcr SVN: r2600 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr: impl/storage/jdbc and 3 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-06-15 06:53:03 -0400 (Tue, 15 Jun 2010)
New Revision: 2600
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/BackupWorkspaceInitializer.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SysViewWorkspaceInitializer.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedFileHelper.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedSystemHelper.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/statistics/JCRStatisticsManager.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/storage/WorkspaceDataContainer.java
Log:
EXOJCR-756: small refactoring
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/BackupWorkspaceInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/BackupWorkspaceInitializer.java 2010-06-15 10:21:46 UTC (rev 2599)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/BackupWorkspaceInitializer.java 2010-06-15 10:53:03 UTC (rev 2600)
@@ -40,6 +40,7 @@
import org.exoplatform.services.jcr.impl.storage.JCRItemExistsException;
import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedSystemHelper;
import org.exoplatform.services.jcr.impl.util.io.SpoolFile;
import org.exoplatform.services.jcr.observation.ExtendedEvent;
@@ -99,7 +100,7 @@
else
restorePath = fullBackupPath;
- this.tempDir = new File(System.getProperty("java.io.tmpdir"));
+ this.tempDir = new File(PrivilegedSystemHelper.getProperty("java.io.tmpdir"));
}
@Override
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SysViewWorkspaceInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SysViewWorkspaceInitializer.java 2010-06-15 10:21:46 UTC (rev 2599)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SysViewWorkspaceInitializer.java 2010-06-15 10:53:03 UTC (rev 2600)
@@ -44,6 +44,7 @@
import org.exoplatform.services.jcr.impl.util.JCRDateFormat;
import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedSystemHelper;
import org.exoplatform.services.jcr.impl.util.io.SpoolFile;
import org.exoplatform.services.jcr.storage.WorkspaceDataContainer;
import org.exoplatform.services.log.ExoLogger;
@@ -416,7 +417,7 @@
+ ") RestoreIntializer should have mandatory parameter "
+ SysViewWorkspaceInitializer.RESTORE_PATH_PARAMETER);
- this.tempDir = new File(System.getProperty("java.io.tmpdir"));
+ this.tempDir = new File(PrivilegedSystemHelper.getProperty("java.io.tmpdir"));
}
/**
@@ -462,7 +463,7 @@
WorkspaceDataContainer.DEF_MAXBUFFERSIZE);
this.restorePath = restorePath;
- this.tempDir = new File(System.getProperty("java.io.tmpdir"));
+ this.tempDir = new File(PrivilegedSystemHelper.getProperty("java.io.tmpdir"));
}
/**
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java 2010-06-15 10:21:46 UTC (rev 2599)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java 2010-06-15 10:53:03 UTC (rev 2600)
@@ -35,6 +35,7 @@
import org.exoplatform.services.jcr.impl.storage.jdbc.update.StorageUpdateManager;
import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedSystemHelper;
import org.exoplatform.services.jcr.impl.util.jdbc.DBInitializerException;
import org.exoplatform.services.jcr.storage.WorkspaceDataContainer;
import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection;
@@ -70,7 +71,7 @@
* Indicates if the statistics has to be enabled.
*/
public static final boolean STATISTICS_ENABLED =
- Boolean.valueOf(System.getProperty("JDBCWorkspaceDataContainer.statistics.enabled"));
+ Boolean.valueOf(PrivilegedSystemHelper.getProperty("JDBCWorkspaceDataContainer.statistics.enabled"));
static
{
if (STATISTICS_ENABLED)
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedFileHelper.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedFileHelper.java 2010-06-15 10:21:46 UTC (rev 2599)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedFileHelper.java 2010-06-15 10:53:03 UTC (rev 2600)
@@ -39,6 +39,13 @@
public class PrivilegedFileHelper
{
+ /**
+ * Create FileOutputStream in privileged mode.
+ *
+ * @param file
+ * @return
+ * @throws FileNotFoundException
+ */
public static FileOutputStream fileOutputStream(final File file) throws FileNotFoundException
{
PrivilegedExceptionAction<FileOutputStream> action = new PrivilegedExceptionAction<FileOutputStream>()
@@ -70,6 +77,13 @@
}
}
+ /**
+ * Create FileOutputStream in privileged mode.
+ *
+ * @param name
+ * @return
+ * @throws FileNotFoundException
+ */
public static FileOutputStream fileOutputStream(final String name) throws FileNotFoundException
{
PrivilegedExceptionAction<FileOutputStream> action = new PrivilegedExceptionAction<FileOutputStream>()
@@ -101,6 +115,14 @@
}
}
+ /**
+ * Create FileOutputStream in privileged mode.
+ *
+ * @param file
+ * @param append
+ * @return
+ * @throws FileNotFoundException
+ */
public static FileOutputStream fileOutputStream(final File file, final boolean append) throws FileNotFoundException
{
PrivilegedExceptionAction<FileOutputStream> action = new PrivilegedExceptionAction<FileOutputStream>()
@@ -132,6 +154,13 @@
}
}
+ /**
+ * Create FileInputStream in privileged mode.
+ *
+ * @param file
+ * @return
+ * @throws FileNotFoundException
+ */
public static FileInputStream fileInputStream(final File file) throws FileNotFoundException
{
PrivilegedExceptionAction<FileInputStream> action = new PrivilegedExceptionAction<FileInputStream>()
@@ -163,6 +192,13 @@
}
}
+ /**
+ * Create FileInputStream in privileged mode.
+ *
+ * @param name
+ * @return
+ * @throws FileNotFoundException
+ */
public static FileInputStream fileInputStream(final String name) throws FileNotFoundException
{
PrivilegedExceptionAction<FileInputStream> action = new PrivilegedExceptionAction<FileInputStream>()
@@ -194,6 +230,16 @@
}
}
+ /**
+ * Create temporary file in privileged mode.
+ *
+ * @param prefix
+ * @param suffix
+ * @param directory
+ * @return
+ * @throws IllegalArgumentException
+ * @throws IOException
+ */
public static File createTempFile(final String prefix, final String suffix, final File directory)
throws IllegalArgumentException, IOException
{
@@ -230,6 +276,16 @@
}
}
+ /**
+ * Create teamporary file in privileged mode.
+ *
+ *
+ * @param prefix
+ * @param suffix
+ * @return
+ * @throws IllegalArgumentException
+ * @throws IOException
+ */
public static File createTempFile(final String prefix, final String suffix) throws IllegalArgumentException,
IOException
{
@@ -266,6 +322,15 @@
}
}
+ /**
+ * Create RandomAccessFile in privileged mode.
+ *
+ * @param file
+ * @param mode
+ * @return
+ * @throws IllegalArgumentException
+ * @throws IOException
+ */
public static RandomAccessFile randomAccessFile(final File file, final String mode) throws IllegalArgumentException,
IOException
{
@@ -302,6 +367,12 @@
}
}
+ /**
+ * Get file length in privileged mode.
+ *
+ * @param file
+ * @return
+ */
public static long length(final File file)
{
PrivilegedAction<Long> action = new PrivilegedAction<Long>()
@@ -314,6 +385,12 @@
return AccessController.doPrivileged(action);
}
+ /**
+ * Requests in privileged mode that the file or directory denoted by this abstract
+ * pathname be deleted when the virtual machine terminates.
+ *
+ * @param file
+ */
public static void deleteOnExit(final File file)
{
PrivilegedAction<Object> action = new PrivilegedAction<Object>()
@@ -327,6 +404,12 @@
AccessController.doPrivileged(action);
}
+ /**
+ * Get file absolute path in privileged mode.
+ *
+ * @param file
+ * @return
+ */
public static String getAbsolutePath(final File file)
{
PrivilegedAction<String> action = new PrivilegedAction<String>()
@@ -339,6 +422,12 @@
return AccessController.doPrivileged(action);
}
+ /**
+ * Delete file in privileged mode.
+ *
+ * @param file
+ * @return
+ */
public static boolean delete(final File file)
{
PrivilegedAction<Boolean> action = new PrivilegedAction<Boolean>()
@@ -351,6 +440,13 @@
return AccessController.doPrivileged(action);
}
+ /**
+ * Tests in privileged mode whether the file denoted by this abstract pathname is a
+ * directory.
+ *
+ * @param file
+ * @return
+ */
public static boolean isDirectory(final File file)
{
PrivilegedAction<Boolean> action = new PrivilegedAction<Boolean>()
@@ -363,6 +459,13 @@
return AccessController.doPrivileged(action);
}
+ /**
+ * Tests in privileged mode whether the file or directory denoted by this abstract pathname
+ * exists.
+ *
+ * @param file
+ * @return
+ */
public static boolean exists(final File file)
{
PrivilegedAction<Boolean> action = new PrivilegedAction<Boolean>()
@@ -375,6 +478,12 @@
return AccessController.doPrivileged(action);
}
+ /**
+ * Creates the directory in privileged mode.
+ *
+ * @param file
+ * @return
+ */
public static boolean mkdirs(final File file)
{
PrivilegedAction<Boolean> action = new PrivilegedAction<Boolean>()
@@ -387,6 +496,13 @@
return AccessController.doPrivileged(action);
}
+ /**
+ * Rename File in privileged mode.
+ *
+ * @param srcFile
+ * @param dstfile
+ * @return
+ */
public static boolean renameTo(final File srcFile, final File dstfile)
{
PrivilegedAction<Boolean> action = new PrivilegedAction<Boolean>()
@@ -399,6 +515,12 @@
return AccessController.doPrivileged(action);
}
+ /**
+ * Get file's list in privileged mode.
+ *
+ * @param file
+ * @return
+ */
public static String[] list(final File file)
{
PrivilegedAction<String[]> action = new PrivilegedAction<String[]>()
@@ -411,6 +533,12 @@
return AccessController.doPrivileged(action);
}
+ /**
+ * Get file's list in privileged mode.
+ *
+ * @param file
+ * @return
+ */
public static String[] list(final File file, final FilenameFilter filter)
{
PrivilegedAction<String[]> action = new PrivilegedAction<String[]>()
@@ -423,6 +551,12 @@
return AccessController.doPrivileged(action);
}
+ /**
+ * Get file's list in privileged mode.
+ *
+ * @param file
+ * @return
+ */
public static File[] listFiles(final File file)
{
PrivilegedAction<File[]> action = new PrivilegedAction<File[]>()
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedSystemHelper.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedSystemHelper.java 2010-06-15 10:21:46 UTC (rev 2599)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedSystemHelper.java 2010-06-15 10:53:03 UTC (rev 2600)
@@ -29,25 +29,38 @@
public class PrivilegedSystemHelper
{
- public static String getProperty(final String name)
+ /**
+ * Gets system property in privileged mode.
+ *
+ * @param key
+ * @return
+ */
+ public static String getProperty(final String key)
{
PrivilegedAction<String> action = new PrivilegedAction<String>()
{
public String run()
{
- return System.getProperty(name);
+ return System.getProperty(key);
}
};
return AccessController.doPrivileged(action);
}
- public static String getProperty(final String name, final String def)
+ /**
+ * Gets system property in privileged mode.
+ *
+ * @param key
+ * @param def
+ * @return
+ */
+ public static String getProperty(final String key, final String def)
{
PrivilegedAction<String> action = new PrivilegedAction<String>()
{
public String run()
{
- return System.getProperty(name, def);
+ return System.getProperty(key, def);
}
};
return AccessController.doPrivileged(action);
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/statistics/JCRStatisticsManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/statistics/JCRStatisticsManager.java 2010-06-15 10:21:46 UTC (rev 2599)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/statistics/JCRStatisticsManager.java 2010-06-15 10:53:03 UTC (rev 2600)
@@ -26,6 +26,7 @@
import org.exoplatform.management.jmx.annotations.Property;
import org.exoplatform.management.rest.annotations.RESTEndpoint;
import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedSystemHelper;
import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -80,13 +81,13 @@
* Indicates if the persistence of the statistics has to be enabled.
*/
public static final boolean PERSISTENCE_ENABLED =
- Boolean.valueOf(System.getProperty("JCRStatisticsManager.persistence.enabled", "true"));
+ Boolean.valueOf(PrivilegedSystemHelper.getProperty("JCRStatisticsManager.persistence.enabled", "true"));
/**
* The length of time in milliseconds after which the snapshot of the statistics is persisted.
*/
public static final long PERSISTENCE_TIMEOUT =
- Long.valueOf(System.getProperty("JCRStatisticsManager.persistence.timeout", "5000"));
+ Long.valueOf(PrivilegedSystemHelper.getProperty("JCRStatisticsManager.persistence.timeout", "5000"));
/**
* Default constructor.
@@ -148,8 +149,8 @@
try
{
file =
- new File(System.getProperty("user.dir"), "Statistics" + category + "-" + System.currentTimeMillis()
- + ".csv");
+ new File(PrivilegedSystemHelper.getProperty("user.dir"), "Statistics" + category + "-"
+ + System.currentTimeMillis() + ".csv");
file.createNewFile();
pw = new PrintWriter(file);
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/storage/WorkspaceDataContainer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/storage/WorkspaceDataContainer.java 2010-06-15 10:21:46 UTC (rev 2599)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/storage/WorkspaceDataContainer.java 2010-06-15 10:53:03 UTC (rev 2600)
@@ -18,6 +18,8 @@
*/
package org.exoplatform.services.jcr.storage;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedSystemHelper;
+
import java.util.Calendar;
import javax.jcr.RepositoryException;
@@ -45,7 +47,7 @@
public final static int DEF_MAXBUFFERSIZE = 1024 * 200; // 200k
- public final static String DEF_SWAPDIR = System.getProperty("java.io.tmpdir");
+ public final static String DEF_SWAPDIR = PrivilegedSystemHelper.getProperty("java.io.tmpdir");
public final static String CHECK_SNS_NEW_CONNECTION = "check-sns-new-connection";
16 years, 1 month
exo-jcr SVN: r2599 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl: core/query/lucene and 1 other directories.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2010-06-15 06:21:46 -0400 (Tue, 15 Jun 2010)
New Revision: 2599
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ErrorLog.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ConsistencyCheck.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/FileBasedNamespaceMappings.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexingQueue.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexingQueueStore.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/PersistentIndex.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/Util.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/VolatileIndex.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/SecurityHelper.java
Log:
EXOJCR-758: indexer updates
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ErrorLog.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ErrorLog.java 2010-06-15 09:58:52 UTC (rev 2598)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ErrorLog.java 2010-06-15 10:21:46 UTC (rev 2599)
@@ -17,6 +17,7 @@
package org.exoplatform.services.jcr.impl.core.query;
+import org.exoplatform.services.jcr.impl.util.SecurityHelper;
import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -30,6 +31,7 @@
import java.io.InputStreamReader;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
+import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -96,24 +98,31 @@
* @param log
* @throws IOException
*/
- private void openFile(File log) throws IOException
+ private void openFile(final File log) throws IOException
{
- // set file size;
- if (!log.exists())
+ SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
{
- log.getParentFile().mkdirs();
- log.createNewFile();
+ public Object run() throws Exception
+ {
+ // set file size;
+ if (!log.exists())
+ {
+ log.getParentFile().mkdirs();
+ log.createNewFile();
- out = PrivilegedFileHelper.fileOutputStream(log).getChannel();
- out.position(1024 * fileSize - 1);
- out.write(ByteBuffer.wrap(new byte[]{0}));
- out.position(0);
- out.force(false);
- }
- else
- {
- out = PrivilegedFileHelper.fileOutputStream(log, true).getChannel();
- }
+ out = PrivilegedFileHelper.fileOutputStream(log).getChannel();
+ out.position(1024 * fileSize - 1);
+ out.write(ByteBuffer.wrap(new byte[]{0}));
+ out.position(0);
+ out.force(false);
+ }
+ else
+ {
+ out = new FileOutputStream(log, true).getChannel();
+ }
+ return null;
+ }
+ });
}
/**
@@ -124,10 +133,17 @@
* @throws IOException
* if the node cannot be written to the redo log.
*/
- public void append(String action, String uuid) throws IOException
+ public void append(final String action, final String uuid) throws IOException
{
initOut();
- out.write(ByteBuffer.wrap((action + " " + uuid + "\n").getBytes()));
+ SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
+ {
+ public Object run() throws Exception
+ {
+ out.write(ByteBuffer.wrap((action + " " + uuid + "\n").getBytes()));
+ return null;
+ }
+ });
}
/**
@@ -138,10 +154,17 @@
*/
public void flush() throws IOException
{
- if (out != null)
+ SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
{
- out.force(false);
- }
+ public Object run() throws Exception
+ {
+ if (out != null)
+ {
+ out.force(false);
+ }
+ return null;
+ }
+ });
}
/**
@@ -152,16 +175,23 @@
*/
public void clear() throws IOException
{
- if (out != null)
+ SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
{
- out.truncate(0);
- out.close();
- out = PrivilegedFileHelper.fileOutputStream(logFile).getChannel();
- out.position(1024 * fileSize - 1);
- out.write(ByteBuffer.wrap(new byte[]{0}));
- out.position(0);
- out.force(false);
- }
+ public Object run() throws Exception
+ {
+ if (out != null)
+ {
+ out.truncate(0);
+ out.close();
+ out = new FileOutputStream(logFile).getChannel();
+ out.position(1024 * fileSize - 1);
+ out.write(ByteBuffer.wrap(new byte[]{0}));
+ out.position(0);
+ out.force(false);
+ }
+ return null;
+ }
+ });
}
/**
@@ -172,11 +202,18 @@
*/
private void initOut() throws IOException
{
- if (out == null)
+ SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
{
- FileOutputStream os = PrivilegedFileHelper.fileOutputStream(logFile, false);
- out = os.getChannel();
- }
+ public Object run() throws Exception
+ {
+ if (out == null)
+ {
+ FileOutputStream os = new FileOutputStream(logFile, false);
+ out = os.getChannel();
+ }
+ return null;
+ }
+ });
}
/**
@@ -187,36 +224,42 @@
*/
public List<String> readList() throws IOException
{
- InputStream in = PrivilegedFileHelper.fileInputStream(logFile);
- try
+ return SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<List<String>>()
{
- List<String> list = new ArrayList<String>();
- BufferedReader reader = new BufferedReader(new InputStreamReader(in));
- String line;
- while ((line = reader.readLine()) != null)
+ public List<String> run() throws Exception
{
- if (!line.matches("\\x00++"))
+ InputStream in = new FileInputStream(logFile);
+ try
{
- list.add(line);
- }
- }
- return list;
+ List<String> list = new ArrayList<String>();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(in));
+ String line;
+ while ((line = reader.readLine()) != null)
+ {
+ if (!line.matches("\\x00++"))
+ {
+ list.add(line);
+ }
+ }
+ return list;
- }
- finally
- {
- if (in != null)
- {
- try
- {
- in.close();
}
- catch (IOException e)
+ finally
{
- LOG.warn("Exception while closing error log: " + e.toString());
+ if (in != null)
+ {
+ try
+ {
+ in.close();
+ }
+ catch (IOException e)
+ {
+ LOG.warn("Exception while closing error log: " + e.toString());
+ }
+ }
}
}
- }
+ });
}
public void readChanges(Set<String> rem, Set<String> add) throws IOException
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ConsistencyCheck.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ConsistencyCheck.java 2010-06-15 09:58:52 UTC (rev 2598)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ConsistencyCheck.java 2010-06-15 10:21:46 UTC (rev 2599)
@@ -19,10 +19,12 @@
import org.apache.lucene.document.Document;
import org.exoplatform.services.jcr.dataflow.ItemDataConsumer;
import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.impl.util.SecurityHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
+import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
@@ -114,12 +116,20 @@
int notRepairable = 0;
for (Iterator<ConsistencyCheckError> it = errors.iterator(); it.hasNext();)
{
- ConsistencyCheckError error = it.next();
+ final ConsistencyCheckError error = it.next();
try
{
if (error.repairable())
{
- error.repair();
+ SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
+ {
+ public Object run() throws Exception
+ {
+ // running in privileged mode
+ error.repair();
+ return null;
+ }
+ });
}
else
{
@@ -170,21 +180,29 @@
Set multipleEntries = new HashSet();
// collect all documents UUIDs
documentUUIDs = new HashSet();
- CachingMultiIndexReader reader = index.getIndexReader();
+ final CachingMultiIndexReader reader = index.getIndexReader();
try
{
for (int i = 0; i < reader.maxDoc(); i++)
{
if (i > 10 && i % (reader.maxDoc() / 5) == 0)
{
- long progress = Math.round((100.0 * (float)i) / ((float)reader.maxDoc() * 2f));
+ long progress = Math.round((100.0 * i) / (reader.maxDoc() * 2f));
log.info("progress: " + progress + "%");
}
if (reader.isDeleted(i))
{
continue;
}
- Document d = reader.document(i, FieldSelectors.UUID);
+ final int currentIndex = i;
+ Document d = SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Document>()
+ {
+ public Document run() throws Exception
+ {
+ return reader.document(currentIndex, FieldSelectors.UUID);
+ }
+ });
+
String uuid = d.get(FieldNames.UUID);
if (stateMgr.getItemData(uuid) != null)
{
@@ -201,7 +219,14 @@
}
finally
{
- reader.release();
+ SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
+ {
+ public Object run() throws Exception
+ {
+ reader.release();
+ return null;
+ }
+ });
}
// create multiple entries errors
@@ -210,22 +235,30 @@
errors.add(new MultipleEntries((String)it.next()));
}
- reader = index.getIndexReader();
+ final CachingMultiIndexReader newReader = index.getIndexReader();
try
{
// run through documents again and check parent
- for (int i = 0; i < reader.maxDoc(); i++)
+ for (int i = 0; i < newReader.maxDoc(); i++)
{
- if (i > 10 && i % (reader.maxDoc() / 5) == 0)
+ if (i > 10 && i % (newReader.maxDoc() / 5) == 0)
{
- long progress = Math.round((100.0 * (float)i) / ((float)reader.maxDoc() * 2f));
+ long progress = Math.round((100.0 * i) / (newReader.maxDoc() * 2f));
log.info("progress: " + (progress + 50) + "%");
}
- if (reader.isDeleted(i))
+ if (newReader.isDeleted(i))
{
continue;
}
- Document d = reader.document(i, FieldSelectors.UUID_AND_PARENT);
+ final int currentIndex = i;
+ Document d = SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Document>()
+ {
+ public Document run() throws Exception
+ {
+ return newReader.document(currentIndex, FieldSelectors.UUID_AND_PARENT);
+ }
+ });
+
String uuid = d.get(FieldNames.UUID);
String parentUUIDString = d.get(FieldNames.PARENT);
@@ -248,7 +281,14 @@
}
finally
{
- reader.release();
+ SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
+ {
+ public Object run() throws Exception
+ {
+ newReader.release();
+ return null;
+ }
+ });
}
}
@@ -285,6 +325,7 @@
* Returns <code>true</code>.
* @return <code>true</code>.
*/
+ @Override
public boolean repairable()
{
return true;
@@ -294,6 +335,7 @@
* Repairs the missing node by indexing the missing ancestors.
* @throws IOException if an error occurs while repairing.
*/
+ @Override
public void repair() throws IOException
{
String parentId = parentUUID;
@@ -331,6 +373,7 @@
* Not reparable (yet).
* @return <code>false</code>.
*/
+ @Override
public boolean repairable()
{
return false;
@@ -339,6 +382,7 @@
/**
* No operation.
*/
+ @Override
public void repair() throws IOException
{
log.warn("Unknown parent for " + uuid + " cannot be repaired");
@@ -360,6 +404,7 @@
* Returns <code>true</code>.
* @return <code>true</code>.
*/
+ @Override
public boolean repairable()
{
return true;
@@ -370,6 +415,7 @@
* re-index the node.
* @throws IOException if an error occurs while repairing.
*/
+ @Override
public void repair() throws IOException
{
// first remove all occurrences
@@ -405,6 +451,7 @@
* Returns <code>true</code>.
* @return <code>true</code>.
*/
+ @Override
public boolean repairable()
{
return true;
@@ -414,6 +461,7 @@
* Deletes the nodes from the index.
* @throws IOException if an error occurs while repairing.
*/
+ @Override
public void repair() throws IOException
{
log.info("Removing deleted node from index: " + uuid);
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/FileBasedNamespaceMappings.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/FileBasedNamespaceMappings.java 2010-06-15 09:58:52 UTC (rev 2598)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/FileBasedNamespaceMappings.java 2010-06-15 10:21:46 UTC (rev 2599)
@@ -16,16 +16,17 @@
*/
package org.exoplatform.services.jcr.impl.core.query.lucene;
+import org.exoplatform.services.jcr.impl.util.SecurityHelper;
import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedOutputStream;
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.security.PrivilegedExceptionAction;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -148,33 +149,40 @@
*/
private void load() throws IOException
{
- if (storage.exists())
+ SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
{
- InputStream in = PrivilegedFileHelper.fileInputStream(storage);
- try
+ public Object run() throws Exception
{
- Properties props = new Properties();
- log.debug("loading namespace mappings...");
- props.load(in);
+ if (storage.exists())
+ {
+ InputStream in = PrivilegedFileHelper.fileInputStream(storage);
+ try
+ {
+ Properties props = new Properties();
+ log.debug("loading namespace mappings...");
+ props.load(in);
- // read mappings from properties
- Iterator iter = props.keySet().iterator();
- while (iter.hasNext())
- {
- String prefix = (String)iter.next();
- String uri = props.getProperty(prefix);
- log.debug(prefix + " -> " + uri);
- prefixToURI.put(prefix, uri);
- uriToPrefix.put(uri, prefix);
+ // read mappings from properties
+ Iterator iter = props.keySet().iterator();
+ while (iter.hasNext())
+ {
+ String prefix = (String)iter.next();
+ String uri = props.getProperty(prefix);
+ log.debug(prefix + " -> " + uri);
+ prefixToURI.put(prefix, uri);
+ uriToPrefix.put(uri, prefix);
+ }
+ prefixCount = props.size();
+ log.debug("namespace mappings loaded.");
+ }
+ finally
+ {
+ in.close();
+ }
}
- prefixCount = props.size();
- log.debug("namespace mappings loaded.");
+ return null;
}
- finally
- {
- in.close();
- }
- }
+ });
}
/**
@@ -184,28 +192,35 @@
*/
private void store() throws IOException
{
- Properties props = new Properties();
-
- // store mappings in properties
- Iterator iter = prefixToURI.keySet().iterator();
- while (iter.hasNext())
+ SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
{
- String prefix = (String)iter.next();
- String uri = (String)prefixToURI.get(prefix);
- props.setProperty(prefix, uri);
- }
+ public Object run() throws Exception
+ {
+ Properties props = new Properties();
- OutputStream out = PrivilegedFileHelper.fileOutputStream(storage);
- try
- {
- out = new BufferedOutputStream(out);
- props.store(out, null);
- }
- finally
- {
- // make sure stream is closed
- out.close();
- }
+ // store mappings in properties
+ Iterator iter = prefixToURI.keySet().iterator();
+ while (iter.hasNext())
+ {
+ String prefix = (String)iter.next();
+ String uri = (String)prefixToURI.get(prefix);
+ props.setProperty(prefix, uri);
+ }
+
+ OutputStream out = PrivilegedFileHelper.fileOutputStream(storage);
+ try
+ {
+ out = new BufferedOutputStream(out);
+ props.store(out, null);
+ }
+ finally
+ {
+ // make sure stream is closed
+ out.close();
+ }
+ return null;
+ }
+ });
}
public String[] getAllNamespacePrefixes() throws RepositoryException
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexingQueue.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexingQueue.java 2010-06-15 09:58:52 UTC (rev 2598)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexingQueue.java 2010-06-15 10:21:46 UTC (rev 2599)
@@ -19,10 +19,12 @@
import org.apache.lucene.document.Document;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermDocs;
+import org.exoplatform.services.jcr.impl.util.SecurityHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
+import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@@ -75,54 +77,62 @@
* @param index the multi index this indexing queue belongs to.
* @throws IOException if an error occurs while reading from the index.
*/
- void initialize(MultiIndex index) throws IOException
+ void initialize(final MultiIndex index) throws IOException
{
- if (initialized)
+ SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
{
- throw new IllegalStateException("already initialized");
- }
- // check index for nodes that need to be reindexed
- CachingMultiIndexReader reader = index.getIndexReader();
- try
- {
- TermDocs tDocs = reader.termDocs(new Term(FieldNames.REINDEXING_REQUIRED, ""));
- try
+ public Object run() throws Exception
{
- while (tDocs.next())
+ if (initialized)
{
- queueStore.addUUID(reader.document(tDocs.doc(), FieldSelectors.UUID).get(FieldNames.UUID));
+ throw new IllegalStateException("already initialized");
}
+ // check index for nodes that need to be reindexed
+ CachingMultiIndexReader reader = index.getIndexReader();
+ try
+ {
+ TermDocs tDocs = reader.termDocs(new Term(FieldNames.REINDEXING_REQUIRED, ""));
+ try
+ {
+ while (tDocs.next())
+ {
+ queueStore.addUUID(reader.document(tDocs.doc(), FieldSelectors.UUID).get(FieldNames.UUID));
+ }
+ }
+ finally
+ {
+ tDocs.close();
+ }
+ }
+ finally
+ {
+ reader.release();
+ }
+ String[] uuids = queueStore.getPending();
+ for (int i = 0; i < uuids.length; i++)
+ {
+ try
+ {
+ Document doc = index.createDocument(uuids[i]);
+ pendingDocuments.put(uuids[i], doc);
+ log.debug("added node {}. New size of indexing queue: {}", uuids[i], new Integer(pendingDocuments
+ .size()));
+ }
+ catch (IllegalArgumentException e)
+ {
+ log.warn("Invalid UUID in indexing queue store: " + uuids[i]);
+ }
+ catch (RepositoryException e)
+ {
+ // node does not exist anymore
+ log.debug("Node with uuid {} does not exist anymore", uuids[i]);
+ queueStore.removeUUID(uuids[i]);
+ }
+ }
+ initialized = true;
+ return null;
}
- finally
- {
- tDocs.close();
- }
- }
- finally
- {
- reader.release();
- }
- String[] uuids = queueStore.getPending();
- for (int i = 0; i < uuids.length; i++)
- {
- try
- {
- Document doc = index.createDocument(uuids[i]);
- pendingDocuments.put(uuids[i], doc);
- log.debug("added node {}. New size of indexing queue: {}", uuids[i], new Integer(pendingDocuments.size()));
- }
- catch (IllegalArgumentException e)
- {
- log.warn("Invalid UUID in indexing queue store: " + uuids[i]);
- }
- catch (RepositoryException e)
- {
- // node does not exist anymore
- log.debug("Node with uuid {} does not exist anymore", uuids[i]);
- queueStore.removeUUID(uuids[i]);
- }
- }
- initialized = true;
+ });
}
/**
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexingQueueStore.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexingQueueStore.java 2010-06-15 09:58:52 UTC (rev 2598)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexingQueueStore.java 2010-06-15 10:21:46 UTC (rev 2599)
@@ -18,6 +18,7 @@
import org.apache.lucene.store.Directory;
import org.exoplatform.services.jcr.impl.core.query.lucene.directory.IndexInputStream;
+import org.exoplatform.services.jcr.impl.util.SecurityHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -25,6 +26,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedExceptionAction;
import java.util.HashSet;
import java.util.Set;
@@ -118,20 +121,27 @@
*/
public void close()
{
- if (pending.isEmpty())
+ SecurityHelper.doPriviledgedAction(new PrivilegedAction<Object>()
{
- try
+ public Object run()
{
- if (dir.fileExists(INDEXING_QUEUE_FILE))
+ if (pending.isEmpty())
{
- dir.deleteFile(INDEXING_QUEUE_FILE);
+ try
+ {
+ if (dir.fileExists(INDEXING_QUEUE_FILE))
+ {
+ dir.deleteFile(INDEXING_QUEUE_FILE);
+ }
+ }
+ catch (IOException e)
+ {
+ log.warn("unable to delete " + INDEXING_QUEUE_FILE);
+ }
}
+ return null;
}
- catch (IOException e)
- {
- log.warn("unable to delete " + INDEXING_QUEUE_FILE);
- }
- }
+ });
}
//----------------------------< internal >----------------------------------
@@ -144,45 +154,52 @@
*/
private void readStore() throws IOException
{
- if (dir.fileExists(INDEXING_QUEUE_FILE))
+ SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
{
- InputStream in = new IndexInputStream(dir.openInput(INDEXING_QUEUE_FILE));
- BufferedReader reader = new BufferedReader(new InputStreamReader(in, ENCODING));
- try
+ public Object run() throws Exception
{
- String line;
- while ((line = reader.readLine()) != null)
+ if (dir.fileExists(INDEXING_QUEUE_FILE))
{
- int idx = line.indexOf(' ');
- if (idx == -1)
+ InputStream in = new IndexInputStream(dir.openInput(INDEXING_QUEUE_FILE));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(in, ENCODING));
+ try
{
- // invalid line
- log.warn("invalid line in {}: {}", INDEXING_QUEUE_FILE, line);
- }
- else
- {
- String cmd = line.substring(0, idx);
- String uuid = line.substring(idx + 1, line.length());
- if (ADD.equals(cmd))
+ String line;
+ while ((line = reader.readLine()) != null)
{
- pending.add(uuid);
+ int idx = line.indexOf(' ');
+ if (idx == -1)
+ {
+ // invalid line
+ log.warn("invalid line in {}: {}", INDEXING_QUEUE_FILE, line);
+ }
+ else
+ {
+ String cmd = line.substring(0, idx);
+ String uuid = line.substring(idx + 1, line.length());
+ if (ADD.equals(cmd))
+ {
+ pending.add(uuid);
+ }
+ else if (REMOVE.equals(cmd))
+ {
+ pending.remove(uuid);
+ }
+ else
+ {
+ // invalid line
+ log.warn("invalid line in {}: {}", INDEXING_QUEUE_FILE, line);
+ }
+ }
}
- else if (REMOVE.equals(cmd))
- {
- pending.remove(uuid);
- }
- else
- {
- // invalid line
- log.warn("invalid line in {}: {}", INDEXING_QUEUE_FILE, line);
- }
}
+ finally
+ {
+ in.close();
+ }
}
+ return null;
}
- finally
- {
- in.close();
- }
- }
+ });
}
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2010-06-15 09:58:52 UTC (rev 2598)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2010-06-15 10:21:46 UTC (rev 2599)
@@ -20,8 +20,6 @@
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.FSDirectory;
-import org.apache.lucene.store.NativeFSLockFactory;
import org.exoplatform.services.jcr.dataflow.ItemDataConsumer;
import org.exoplatform.services.jcr.datamodel.ItemData;
import org.exoplatform.services.jcr.datamodel.NodeData;
@@ -35,9 +33,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.security.PrivilegedAction;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.Arrays;
@@ -245,6 +243,7 @@
this.modeHandler = modeHandler;
this.indexUpdateMonitor = indexUpdateMonitor;
this.directoryManager = handler.getDirectoryManager();
+ // this method is run in privileged mode internally
this.indexDir = directoryManager.getDirectory(".");
this.handler = handler;
this.cache = new DocNumberCache(handler.getCacheSize());
@@ -253,10 +252,13 @@
this.flushTask = null;
this.indexNames = indexInfos;
this.indexNames.setDirectory(indexDir);
+ // this method is run in privileged mode internally
this.indexNames.read();
modeHandler.addIndexerIoModeListener(this);
indexUpdateMonitor.addIndexUpdateMonitorListener(this);
+
+ // this method is run in privileged mode internally
// as of 1.5 deletable file is not used anymore
removeDeletable();
@@ -266,6 +268,7 @@
merger.setMergeFactor(handler.getMergeFactor());
merger.setMinMergeDocs(handler.getMinMergeDocs());
+ // this method is run in privileged mode internally
IndexingQueueStore store = new IndexingQueueStore(indexDir);
// initialize indexing queue
@@ -301,14 +304,21 @@
// set index format version and at the same time
// initialize hierarchy cache if requested.
- CachingMultiIndexReader reader = getIndexReader(handler.isInitializeHierarchyCache());
+ final CachingMultiIndexReader reader = getIndexReader(handler.isInitializeHierarchyCache());
try
{
version = IndexFormatVersion.getVersion(reader);
}
finally
{
- reader.release();
+ SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
+ {
+ public Object run() throws Exception
+ {
+ reader.release();
+ return null;
+ }
+ });
}
indexingQueue.initialize(this);
if (modeHandler.getMode() == IndexerIoMode.READ_WRITE)
@@ -333,14 +343,21 @@
}
else
{
- CachingMultiIndexReader reader = getIndexReader();
+ final CachingMultiIndexReader reader = getIndexReader();
try
{
return reader.numDocs();
}
finally
{
- reader.release();
+ SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
+ {
+ public Object run() throws Exception
+ {
+ reader.release();
+ return null;
+ }
+ });
}
}
}
@@ -418,71 +435,78 @@
* @throws IOException
* if an error occurs while updating the index.
*/
- synchronized void update(Collection remove, Collection add) throws IOException
+ synchronized void update(final Collection remove, final Collection add) throws IOException
{
- // make sure a reader is available during long updates
- if (add.size() > handler.getBufferSize())
+ SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
{
- try
+ public Object run() throws Exception
{
- getIndexReader().release();
- }
- catch (IOException e)
- {
- // do not fail if an exception is thrown here
- log.warn("unable to prepare index reader " + "for queries during update", e);
- }
- }
-
- synchronized (updateMonitor)
- {
- //updateInProgress = true;
- indexUpdateMonitor.setUpdateInProgress(true, false);
- }
- boolean flush = false;
- try
- {
- long transactionId = nextTransactionId++;
- executeAndLog(new Start(transactionId));
-
- for (Iterator it = remove.iterator(); it.hasNext();)
- {
- executeAndLog(new DeleteNode(transactionId, (String)it.next()));
- }
- for (Iterator it = add.iterator(); it.hasNext();)
- {
- Document doc = (Document)it.next();
- if (doc != null)
+ // make sure a reader is available during long updates
+ if (add.size() > handler.getBufferSize())
{
- executeAndLog(new AddNode(transactionId, doc));
- // commit volatile index if needed
- flush |= checkVolatileCommit();
+ try
+ {
+ getIndexReader().release();
+ }
+ catch (IOException e)
+ {
+ // do not fail if an exception is thrown here
+ log.warn("unable to prepare index reader " + "for queries during update", e);
+ }
}
- }
- executeAndLog(new Commit(transactionId));
- // flush whole index when volatile index has been commited.
- if (flush)
- {
- // if we are going to flush, need to set persistent update
synchronized (updateMonitor)
{
- indexUpdateMonitor.setUpdateInProgress(true, true);
+ //updateInProgress = true;
+ indexUpdateMonitor.setUpdateInProgress(true, false);
}
- flush();
- }
- }
- finally
- {
- synchronized (updateMonitor)
- {
- //updateInProgress = false;
+ boolean flush = false;
+ try
+ {
+ long transactionId = nextTransactionId++;
+ executeAndLog(new Start(transactionId));
- indexUpdateMonitor.setUpdateInProgress(false, flush);
- updateMonitor.notifyAll();
- releaseMultiReader();
+ for (Iterator it = remove.iterator(); it.hasNext();)
+ {
+ executeAndLog(new DeleteNode(transactionId, (String)it.next()));
+ }
+ for (Iterator it = add.iterator(); it.hasNext();)
+ {
+ Document doc = (Document)it.next();
+ if (doc != null)
+ {
+ executeAndLog(new AddNode(transactionId, doc));
+ // commit volatile index if needed
+ flush |= checkVolatileCommit();
+ }
+ }
+ executeAndLog(new Commit(transactionId));
+
+ // flush whole index when volatile index has been commited.
+ if (flush)
+ {
+ // if we are going to flush, need to set persistent update
+ synchronized (updateMonitor)
+ {
+ indexUpdateMonitor.setUpdateInProgress(true, true);
+ }
+ flush();
+ }
+ }
+ finally
+ {
+ synchronized (updateMonitor)
+ {
+ //updateInProgress = false;
+
+ indexUpdateMonitor.setUpdateInProgress(false, flush);
+ updateMonitor.notifyAll();
+ releaseMultiReader();
+ }
+ }
+ return null;
}
- }
+ });
}
/**
@@ -606,10 +630,17 @@
for (Iterator it = indexReaders.entrySet().iterator(); it.hasNext();)
{
Map.Entry entry = (Map.Entry)it.next();
- ReadOnlyIndexReader reader = (ReadOnlyIndexReader)entry.getKey();
+ final ReadOnlyIndexReader reader = (ReadOnlyIndexReader)entry.getKey();
try
{
- reader.release();
+ SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
+ {
+ public Object run() throws Exception
+ {
+ reader.release();
+ return null;
+ }
+ });
}
catch (IOException ex)
{
@@ -727,14 +758,21 @@
* @throws IOException
* if an exception occurs while replacing the indexes.
*/
- void replaceIndexes(String[] obsoleteIndexes, PersistentIndex index, Collection deleted) throws IOException
+ void replaceIndexes(String[] obsoleteIndexes, final PersistentIndex index, Collection deleted) throws IOException
{
if (handler.isInitializeHierarchyCache())
{
// force initializing of caches
long time = System.currentTimeMillis();
- index.getReadOnlyIndexReader(true).release();
+ SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
+ {
+ public Object run() throws Exception
+ {
+ index.getReadOnlyIndexReader(true).release();
+ return null;
+ }
+ });
time = System.currentTimeMillis() - time;
log.debug("hierarchy cache initialized in {} ms", new Long(time));
}
@@ -1119,17 +1157,24 @@
*/
void releaseMultiReader() throws IOException
{
- if (multiReader != null)
+ SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
{
- try
+ public Object run() throws Exception
{
- multiReader.release();
+ if (multiReader != null)
+ {
+ try
+ {
+ multiReader.release();
+ }
+ finally
+ {
+ multiReader = null;
+ }
+ }
+ return null;
}
- finally
- {
- multiReader = null;
- }
- }
+ });
}
// -------------------------< internal
@@ -1161,28 +1206,35 @@
*/
private void scheduleFlushTask()
{
- // cancel task
- if (flushTask != null)
+ SecurityHelper.doPriviledgedAction(new PrivilegedAction<Object>()
{
- flushTask.cancel();
- }
- // clear canceled tasks
- FLUSH_TIMER.purge();
- // new flush task, cause canceled can't be re-used
- flushTask = new TimerTask()
- {
- @Override
- public void run()
+ public Object run()
{
- // check if there are any indexing jobs finished
- checkIndexingQueue();
- // check if volatile index should be flushed
- checkFlush();
+ // cancel task
+ if (flushTask != null)
+ {
+ flushTask.cancel();
+ }
+ // clear canceled tasks
+ FLUSH_TIMER.purge();
+ // new flush task, cause canceled can't be re-used
+ flushTask = new TimerTask()
+ {
+ @Override
+ public void run()
+ {
+ // check if there are any indexing jobs finished
+ checkIndexingQueue();
+ // check if volatile index should be flushed
+ checkFlush();
+ }
+ };
+ FLUSH_TIMER.schedule(flushTask, 0, 1000);
+ lastFlushTime = System.currentTimeMillis();
+ lastFileSystemFlushTime = System.currentTimeMillis();
+ return null;
}
- };
- FLUSH_TIMER.schedule(flushTask, 0, 1000);
- lastFlushTime = System.currentTimeMillis();
- lastFileSystemFlushTime = System.currentTimeMillis();
+ });
}
/**
@@ -1386,18 +1438,25 @@
*/
private void removeDeletable()
{
- String fileName = "deletable";
- try
+ SecurityHelper.doPriviledgedAction(new PrivilegedAction<Object>()
{
- if (indexDir.fileExists(fileName))
+ public Object run()
{
- indexDir.deleteFile(fileName);
+ String fileName = "deletable";
+ try
+ {
+ if (indexDir.fileExists(fileName))
+ {
+ indexDir.deleteFile(fileName);
+ }
+ }
+ catch (IOException e)
+ {
+ log.warn("Unable to remove file 'deletable'.", e);
+ }
+ return null;
}
- }
- catch (IOException e)
- {
- log.warn("Unable to remove file 'deletable'.", e);
- }
+ });
}
/**
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/PersistentIndex.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/PersistentIndex.java 2010-06-15 09:58:52 UTC (rev 2598)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/PersistentIndex.java 2010-06-15 10:21:46 UTC (rev 2599)
@@ -16,8 +16,6 @@
*/
package org.exoplatform.services.jcr.impl.core.query.lucene;
-import java.io.IOException;
-
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
@@ -26,149 +24,187 @@
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;
import org.exoplatform.services.jcr.impl.core.query.lucene.directory.DirectoryManager;
+import org.exoplatform.services.jcr.impl.util.SecurityHelper;
+import java.io.IOException;
+import java.security.PrivilegedExceptionAction;
-
/**
* Implements a lucene index which is based on a
* {@link org.apache.jackrabbit.core.fs.FileSystem}.
*/
-class PersistentIndex extends AbstractIndex {
+class PersistentIndex extends AbstractIndex
+{
- /** The name of this persistent index */
- private final String name;
+ /** The name of this persistent index */
+ private final String name;
- /**
- * If non <code>null</code>, <code>listener</code> needs to be informed
- * when a document is deleted.
- */
- private IndexListener listener;
+ /**
+ * If non <code>null</code>, <code>listener</code> needs to be informed
+ * when a document is deleted.
+ */
+ private IndexListener listener;
- /**
- * Creates a new <code>PersistentIndex</code>.
- *
- * @param name the name of this index.
- * @param analyzer the analyzer for text tokenizing.
- * @param similarity the similarity implementation.
- * @param cache the document number cache
- * @param indexingQueue the indexing queue.
- * @param directoryManager the directory manager.
- * @throws IOException if an error occurs while opening / creating the
- * index.
- */
- PersistentIndex(String name, Analyzer analyzer,
- Similarity similarity, DocNumberCache cache,
- IndexingQueue indexingQueue,
- DirectoryManager directoryManager)
- throws IOException {
- super(analyzer, similarity, directoryManager.getDirectory(name),
- cache, indexingQueue);
- this.name = name;
- if (isExisting()) {
- IndexMigration.migrate(this, directoryManager);
- }
- }
+ /**
+ * Creates a new <code>PersistentIndex</code>.
+ *
+ * @param name the name of this index.
+ * @param analyzer the analyzer for text tokenizing.
+ * @param similarity the similarity implementation.
+ * @param cache the document number cache
+ * @param indexingQueue the indexing queue.
+ * @param directoryManager the directory manager.
+ * @throws IOException if an error occurs while opening / creating the
+ * index.
+ */
+ PersistentIndex(String name, Analyzer analyzer, Similarity similarity, DocNumberCache cache,
+ IndexingQueue indexingQueue, final DirectoryManager directoryManager) throws IOException
+ {
+ super(analyzer, similarity, directoryManager.getDirectory(name), cache, indexingQueue);
+ this.name = name;
+ if (isExisting())
+ {
+ SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
+ {
+ public Object run() throws Exception
+ {
+ IndexMigration.migrate(PersistentIndex.this, directoryManager);
+ return null;
+ }
+ });
+ }
+ }
- /**
- * @inheritDoc
- */
- int removeDocument(Term idTerm) throws IOException {
- int num = super.removeDocument(idTerm);
- if (num > 0 && listener != null) {
- listener.documentDeleted(idTerm);
- }
- return num;
- }
+ /**
+ * @inheritDoc
+ */
+ @Override
+ int removeDocument(Term idTerm) throws IOException
+ {
+ int num = super.removeDocument(idTerm);
+ if (num > 0 && listener != null)
+ {
+ listener.documentDeleted(idTerm);
+ }
+ return num;
+ }
- /**
- * Merges the provided indexes into this index. After this completes, the
- * index is optimized.
- * <p/>
- * The provided IndexReaders are not closed.
- *
- * @param readers the readers of indexes to add.
- * @throws IOException if an error occurs while adding indexes.
- */
- void addIndexes(IndexReader[] readers) throws IOException {
- getIndexWriter().addIndexes(readers);
- getIndexWriter().optimize();
- }
+ /**
+ * Merges the provided indexes into this index. After this completes, the
+ * index is optimized.
+ * <p/>
+ * The provided IndexReaders are not closed.
+ *
+ * @param readers the readers of indexes to add.
+ * @throws IOException if an error occurs while adding indexes.
+ */
+ void addIndexes(final IndexReader[] readers) throws IOException
+ {
+ SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
+ {
+ public Object run() throws Exception
+ {
+ getIndexWriter().addIndexes(readers);
+ getIndexWriter().optimize();
+ return null;
+ }
+ });
+ }
- /**
- * Copies <code>index</code> into this persistent index. This method should
- * only be called when <code>this</code> index is empty otherwise the
- * behaviour is undefined.
- *
- * @param index the index to copy from.
- * @throws IOException if an error occurs while copying.
- */
- void copyIndex(AbstractIndex index) throws IOException {
- // commit changes to directory on other index.
- index.commit(true);
- // simply copy over the files
- byte[] buffer = new byte[1024];
- Directory dir = index.getDirectory();
- Directory dest = getDirectory();
- String[] files = dir.list();
- for (int i = 0; i < files.length; i++) {
- IndexInput in = dir.openInput(files[i]);
- try {
- IndexOutput out = dest.createOutput(files[i]);
- try {
- long remaining = in.length();
- while (remaining > 0) {
- int num = (int) Math.min(remaining, buffer.length);
+ /**
+ * Copies <code>index</code> into this persistent index. This method should
+ * only be called when <code>this</code> index is empty otherwise the
+ * behaviour is undefined.
+ *
+ * @param index the index to copy from.
+ * @throws IOException if an error occurs while copying.
+ */
+ void copyIndex(final AbstractIndex index) throws IOException
+ {
+ SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
+ {
+ public Object run() throws Exception
+ {
+ // commit changes to directory on other index.
+ index.commit(true);
+ // simply copy over the files
+ byte[] buffer = new byte[1024];
+ Directory dir = index.getDirectory();
+ Directory dest = getDirectory();
+ String[] files = dir.list();
+ for (int i = 0; i < files.length; i++)
+ {
+ IndexInput in = dir.openInput(files[i]);
+ try
+ {
+ IndexOutput out = dest.createOutput(files[i]);
+ try
+ {
+ long remaining = in.length();
+ while (remaining > 0)
+ {
+ int num = (int)Math.min(remaining, buffer.length);
in.readBytes(buffer, 0, num);
out.writeBytes(buffer, num);
remaining -= num;
- }
- } finally {
- out.close();
- }
- } finally {
- in.close();
+ }
+ }
+ finally
+ {
+ out.close();
+ }
+ }
+ finally
+ {
+ in.close();
+ }
}
- }
- }
+ return null;
+ }
+ });
+ }
- /**
- * Returns a <code>ReadOnlyIndexReader</code> and registeres
- * <code>listener</code> to send notifications when documents are deleted on
- * <code>this</code> index.
- *
- * @param listener the listener to notify when documents are deleted.
- * @return a <code>ReadOnlyIndexReader</code>.
- * @throws IOException if the reader cannot be obtained.
- */
- synchronized ReadOnlyIndexReader getReadOnlyIndexReader(IndexListener listener)
- throws IOException {
- ReadOnlyIndexReader reader = getReadOnlyIndexReader();
- this.listener = listener;
- return reader;
- }
+ /**
+ * Returns a <code>ReadOnlyIndexReader</code> and registeres
+ * <code>listener</code> to send notifications when documents are deleted on
+ * <code>this</code> index.
+ *
+ * @param listener the listener to notify when documents are deleted.
+ * @return a <code>ReadOnlyIndexReader</code>.
+ * @throws IOException if the reader cannot be obtained.
+ */
+ synchronized ReadOnlyIndexReader getReadOnlyIndexReader(IndexListener listener) throws IOException
+ {
+ ReadOnlyIndexReader reader = getReadOnlyIndexReader();
+ this.listener = listener;
+ return reader;
+ }
- /**
- * Removes a potentially registered {@link IndexListener}.
- */
- synchronized void resetListener() {
- this.listener = null;
- }
+ /**
+ * Removes a potentially registered {@link IndexListener}.
+ */
+ synchronized void resetListener()
+ {
+ this.listener = null;
+ }
- /**
- * Returns the number of documents in this persistent index.
- *
- * @return the number of documents in this persistent index.
- * @throws IOException if an error occurs while reading from the index.
- */
- int getNumDocuments() throws IOException {
- return getIndexReader().numDocs();
- }
+ /**
+ * Returns the number of documents in this persistent index.
+ *
+ * @return the number of documents in this persistent index.
+ * @throws IOException if an error occurs while reading from the index.
+ */
+ int getNumDocuments() throws IOException
+ {
+ return getIndexReader().numDocs();
+ }
- /**
- * Returns the name of this index.
- * @return the name of this index.
- */
- String getName() {
- return name;
- }
+ /**
+ * Returns the name of this index.
+ * @return the name of this index.
+ */
+ String getName()
+ {
+ return name;
+ }
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java 2010-06-15 09:58:52 UTC (rev 2598)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java 2010-06-15 10:21:46 UTC (rev 2599)
@@ -59,6 +59,7 @@
import org.exoplatform.services.jcr.impl.core.query.SearchIndexConfigurationHelper;
import org.exoplatform.services.jcr.impl.core.query.lucene.directory.DirectoryManager;
import org.exoplatform.services.jcr.impl.core.query.lucene.directory.FSDirectoryManager;
+import org.exoplatform.services.jcr.impl.util.SecurityHelper;
import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -69,6 +70,8 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -129,6 +132,7 @@
* calculated as follows: 2 *
* Runtime.getRuntime().availableProcessors().
*/
+ @Deprecated
public static final int DEFAULT_EXTRACTOR_POOL_SIZE = 0;
/**
@@ -493,18 +497,24 @@
throw new IOException("SearchIndex requires 'path' parameter in configuration!");
}
- File indexDirectory;
+ final File indexDirectory;
if (path != null)
{
-
indexDirectory = new File(path);
- if (!indexDirectory.exists())
+ SecurityHelper.doPriviledgedRepositoryExceptionAction(new PrivilegedExceptionAction<Object>()
{
- if (!indexDirectory.mkdirs())
+ public Object run() throws Exception
{
- throw new RepositoryException("fail to create index dir " + path);
+ if (!indexDirectory.exists())
+ {
+ if (!indexDirectory.mkdirs())
+ {
+ throw new RepositoryException("fail to create index dir " + path);
+ }
+ }
+ return null;
}
- }
+ });
}
else
{
@@ -531,9 +541,16 @@
else
{
// read local namespace mappings
- File mapFile = new File(indexDirectory, NS_MAPPING_FILE);
- if (mapFile.exists())
+ final File mapFile = new File(indexDirectory, NS_MAPPING_FILE);
+ boolean fileExists = SecurityHelper.doPriviledgedAction(new PrivilegedAction<Boolean>()
{
+ public Boolean run()
+ {
+ return mapFile.exists();
+ }
+ });
+ if (fileExists)
+ {
// be backward compatible and use ns_mappings.properties from
// index folder
nsMappings = new FileBasedNamespaceMappings(mapFile);
@@ -1376,8 +1393,15 @@
{
try
{
- spCheck = spellCheckerClass.newInstance();
- spCheck.init(this, spellCheckerMinDistance, spellCheckerMorePopular);
+ spCheck = SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<SpellChecker>()
+ {
+ public SpellChecker run() throws Exception
+ {
+ SpellChecker spCheck = spellCheckerClass.newInstance();
+ spCheck.init(SearchIndex.this, spellCheckerMinDistance, spellCheckerMorePopular);
+ return spCheck;
+ }
+ });
}
catch (Exception e)
{
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/Util.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/Util.java 2010-06-15 09:58:52 UTC (rev 2598)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/Util.java 2010-06-15 10:21:46 UTC (rev 2599)
@@ -25,11 +25,14 @@
import org.exoplatform.services.jcr.datamodel.QPathEntry;
import org.exoplatform.services.jcr.datamodel.ValueData;
import org.exoplatform.services.jcr.impl.dataflow.ValueDataConvertor;
+import org.exoplatform.services.jcr.impl.util.SecurityHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedExceptionAction;
import java.util.Iterator;
import java.util.regex.Pattern;
@@ -55,28 +58,35 @@
*
* @param old the document to dispose.
*/
- public static void disposeDocument(Document old)
+ public static void disposeDocument(final Document old)
{
- for (Iterator it = old.getFields().iterator(); it.hasNext();)
+ SecurityHelper.doPriviledgedAction(new PrivilegedAction<Object>()
{
- Fieldable f = (Fieldable)it.next();
- try
+ public Object run()
{
- if (f.readerValue() != null)
+ for (Iterator it = old.getFields().iterator(); it.hasNext();)
{
- f.readerValue().close();
+ Fieldable f = (Fieldable)it.next();
+ try
+ {
+ if (f.readerValue() != null)
+ {
+ f.readerValue().close();
+ }
+ else if (f instanceof LazyTextExtractorField)
+ {
+ LazyTextExtractorField field = (LazyTextExtractorField)f;
+ field.dispose();
+ }
+ }
+ catch (IOException ex)
+ {
+ log.warn("Exception while disposing index document: " + ex);
+ }
}
- else if (f instanceof LazyTextExtractorField)
- {
- LazyTextExtractorField field = (LazyTextExtractorField)f;
- field.dispose();
- }
+ return null;
}
- catch (IOException ex)
- {
- log.warn("Exception while disposing index document: " + ex);
- }
- }
+ });
}
/**
@@ -147,16 +157,23 @@
* @throws IOException if an error occurs while closing or releasing the
* index reader.
*/
- public static void closeOrRelease(IndexReader reader) throws IOException
+ public static void closeOrRelease(final IndexReader reader) throws IOException
{
- if (reader instanceof ReleaseableIndexReader)
+ SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
{
- ((ReleaseableIndexReader)reader).release();
- }
- else
- {
- reader.close();
- }
+ public Object run() throws Exception
+ {
+ if (reader instanceof ReleaseableIndexReader)
+ {
+ ((ReleaseableIndexReader)reader).release();
+ }
+ else
+ {
+ reader.close();
+ }
+ return null;
+ }
+ });
}
/**
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/VolatileIndex.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/VolatileIndex.java 2010-06-15 09:58:52 UTC (rev 2598)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/VolatileIndex.java 2010-06-15 10:21:46 UTC (rev 2599)
@@ -29,147 +29,166 @@
/**
* Implements an in-memory index with a pending buffer.
*/
-class VolatileIndex extends AbstractIndex {
+class VolatileIndex extends AbstractIndex
+{
- /**
- * Default value for {@link #bufferSize}.
- */
- private static final int DEFAULT_BUFFER_SIZE = 10;
+ /**
+ * Default value for {@link #bufferSize}.
+ */
+ private static final int DEFAULT_BUFFER_SIZE = 10;
- /**
- * Map of pending documents to add to the index
- */
- private final Map pending = new LinkedMap();
+ /**
+ * Map of pending documents to add to the index
+ */
+ private final Map pending = new LinkedMap();
- /**
- * Number of documents that are buffered before they are added to the index.
- */
- private int bufferSize = DEFAULT_BUFFER_SIZE;
+ /**
+ * Number of documents that are buffered before they are added to the index.
+ */
+ private int bufferSize = DEFAULT_BUFFER_SIZE;
- /**
- * The number of documents in this index.
- */
- private int numDocs = 0;
+ /**
+ * The number of documents in this index.
+ */
+ private int numDocs = 0;
- /**
- * Creates a new <code>VolatileIndex</code> using an <code>analyzer</code>.
- *
- * @param analyzer the analyzer to use.
- * @param similarity the similarity implementation.
- * @param indexingQueue the indexing queue.
- * @throws IOException if an error occurs while opening the index.
- */
- VolatileIndex(Analyzer analyzer,
- Similarity similarity,
- IndexingQueue indexingQueue) throws IOException {
- super(analyzer, similarity, new RAMDirectory(), null, indexingQueue);
- }
+ /**
+ * Creates a new <code>VolatileIndex</code> using an <code>analyzer</code>.
+ *
+ * @param analyzer the analyzer to use.
+ * @param similarity the similarity implementation.
+ * @param indexingQueue the indexing queue.
+ * @throws IOException if an error occurs while opening the index.
+ */
+ VolatileIndex(Analyzer analyzer, Similarity similarity, IndexingQueue indexingQueue) throws IOException
+ {
+ super(analyzer, similarity, new RAMDirectory(), null, indexingQueue);
+ }
- /**
- * Overwrites the default implementation by adding the documents to a
- * pending list and commits the pending list if needed.
- *
- * @param docs the documents to add to the index.
- * @throws IOException if an error occurs while writing to the index.
- */
- void addDocuments(Document[] docs) throws IOException {
- for (int i = 0; i < docs.length; i++) {
- Document old = (Document) pending.put(docs[i].get(FieldNames.UUID), docs[i]);
- if (old != null) {
- Util.disposeDocument(old);
- }
- if (pending.size() >= bufferSize) {
- commitPending();
- }
- numDocs++;
- }
- invalidateSharedReader();
- }
+ /**
+ * Overwrites the default implementation by adding the documents to a
+ * pending list and commits the pending list if needed.
+ *
+ * @param docs the documents to add to the index.
+ * @throws IOException if an error occurs while writing to the index.
+ */
+ @Override
+ void addDocuments(Document[] docs) throws IOException
+ {
+ for (int i = 0; i < docs.length; i++)
+ {
+ Document old = (Document)pending.put(docs[i].get(FieldNames.UUID), docs[i]);
+ if (old != null)
+ {
+ Util.disposeDocument(old);
+ }
+ if (pending.size() >= bufferSize)
+ {
+ commitPending();
+ }
+ numDocs++;
+ }
+ invalidateSharedReader();
+ }
- /**
- * Overwrites the default implementation to remove the document from the
- * pending list if it is present or simply calls <code>super.removeDocument()</code>.
- *
- * @param idTerm the uuid term of the document to remove.
- * @return the number of deleted documents
- * @throws IOException if an error occurs while removing the document from
- * the index.
- */
- int removeDocument(Term idTerm) throws IOException {
- Document doc = (Document) pending.remove(idTerm.text());
- int num;
- if (doc != null) {
- Util.disposeDocument(doc);
- // pending document has been removed
- num = 1;
- } else {
- // remove document from index
- num = super.getIndexReader().deleteDocuments(idTerm);
- }
- numDocs -= num;
- return num;
- }
+ /**
+ * Overwrites the default implementation to remove the document from the
+ * pending list if it is present or simply calls <code>super.removeDocument()</code>.
+ *
+ * @param idTerm the uuid term of the document to remove.
+ * @return the number of deleted documents
+ * @throws IOException if an error occurs while removing the document from
+ * the index.
+ */
+ @Override
+ int removeDocument(Term idTerm) throws IOException
+ {
+ Document doc = (Document)pending.remove(idTerm.text());
+ int num;
+ if (doc != null)
+ {
+ Util.disposeDocument(doc);
+ // pending document has been removed
+ num = 1;
+ }
+ else
+ {
+ // remove document from index
+ num = super.removeDocument(idTerm);
+ }
+ numDocs -= num;
+ return num;
+ }
- /**
- * Returns the number of valid documents in this index.
- *
- * @return the number of valid documents in this index.
- */
- int getNumDocuments() {
- return numDocs;
- }
+ /**
+ * Returns the number of valid documents in this index.
+ *
+ * @return the number of valid documents in this index.
+ */
+ int getNumDocuments()
+ {
+ return numDocs;
+ }
- /**
- * Overwrites the implementation in {@link AbstractIndex} to trigger
- * commit of pending documents to index.
- * @return the index reader for this index.
- * @throws IOException if an error occurs building a reader.
- */
- protected synchronized CommittableIndexReader getIndexReader() throws IOException {
- commitPending();
- return super.getIndexReader();
- }
+ /**
+ * Overwrites the implementation in {@link AbstractIndex} to trigger
+ * commit of pending documents to index.
+ * @return the index reader for this index.
+ * @throws IOException if an error occurs building a reader.
+ */
+ @Override
+ protected synchronized CommittableIndexReader getIndexReader() throws IOException
+ {
+ commitPending();
+ return super.getIndexReader();
+ }
- /**
- * Overwrites the implementation in {@link AbstractIndex} to commit
- * pending documents.
- * @param optimize if <code>true</code> the index is optimized after the
- * commit.
- */
- protected synchronized void commit(boolean optimize) throws IOException {
- commitPending();
- super.commit(optimize);
- }
+ /**
+ * Overwrites the implementation in {@link AbstractIndex} to commit
+ * pending documents.
+ * @param optimize if <code>true</code> the index is optimized after the
+ * commit.
+ */
+ @Override
+ protected synchronized void commit(boolean optimize) throws IOException
+ {
+ commitPending();
+ super.commit(optimize);
+ }
- /**
- * {@inheritDoc}
- */
- long getRamSizeInBytes() {
- return super.getRamSizeInBytes() + ((RAMDirectory) getDirectory()).sizeInBytes();
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ long getRamSizeInBytes()
+ {
+ return super.getRamSizeInBytes() + ((RAMDirectory)getDirectory()).sizeInBytes();
+ }
- /**
- * Sets a new buffer size for pending documents to add to the index.
- * Higher values consume more memory, but help to avoid multiple index
- * cycles when a node is changed / saved multiple times.
- *
- * @param size the new buffer size.
- */
- void setBufferSize(int size) {
- bufferSize = size;
- }
+ /**
+ * Sets a new buffer size for pending documents to add to the index.
+ * Higher values consume more memory, but help to avoid multiple index
+ * cycles when a node is changed / saved multiple times.
+ *
+ * @param size the new buffer size.
+ */
+ void setBufferSize(int size)
+ {
+ bufferSize = size;
+ }
- /**
- * Commits pending documents to the index.
- *
- * @throws IOException if committing pending documents fails.
- */
- private void commitPending() throws IOException {
- if (pending.isEmpty()) {
- return;
- }
- super.addDocuments((Document[]) pending.values().toArray(
- new Document[pending.size()]));
- pending.clear();
- }
+ /**
+ * Commits pending documents to the index.
+ *
+ * @throws IOException if committing pending documents fails.
+ */
+ private void commitPending() throws IOException
+ {
+ if (pending.isEmpty())
+ {
+ return;
+ }
+ super.addDocuments((Document[])pending.values().toArray(new Document[pending.size()]));
+ pending.clear();
+ }
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/SecurityHelper.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/SecurityHelper.java 2010-06-15 09:58:52 UTC (rev 2598)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/SecurityHelper.java 2010-06-15 10:21:46 UTC (rev 2599)
@@ -18,13 +18,14 @@
*/
package org.exoplatform.services.jcr.impl.util;
-import java.io.File;
import java.io.IOException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
+import javax.jcr.RepositoryException;
+
/**
* Helps running code in privileged
*
@@ -68,33 +69,50 @@
}
/**
- * Launches action in privileged mode. Can throw only runtime exceptions.
+ * Launches action in privileged mode. Can throw only repository exception.
*
* @param <E>
* @param action
* @return
- * @throws IOException
+ * @throws RepositoryException
*/
- public static <E> E doPriviledgedAction(PrivilegedAction<E> action)
+ public static <E> E doPriviledgedRepositoryExceptionAction(PrivilegedExceptionAction<E> action)
+ throws RepositoryException
{
- return AccessController.doPrivileged(action);
+ try
+ {
+ return AccessController.doPrivileged(action);
+ }
+ catch (PrivilegedActionException pae)
+ {
+ Throwable cause = pae.getCause();
+ if (cause instanceof RepositoryException)
+ {
+ throw (RepositoryException)cause;
+ }
+ else if (cause instanceof RuntimeException)
+ {
+ throw (RuntimeException)cause;
+ }
+ else
+ {
+ throw new RuntimeException(cause);
+ }
+ }
}
+
/**
- * Gets system property in privileged mode
+ * Launches action in privileged mode. Can throw only runtime exceptions.
*
- * @param name
+ * @param <E>
+ * @param action
* @return
+ * @throws IOException
*/
- public static String getSystemProperty(final String name)
+ public static <E> E doPriviledgedAction(PrivilegedAction<E> action)
{
- return SecurityHelper.doPriviledgedAction(new PrivilegedAction<String>()
- {
- public String run()
- {
- return System.getProperty(name);
- }
- });
+ return AccessController.doPrivileged(action);
}
}
16 years, 1 month
exo-jcr SVN: r2598 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services: jcr/impl/storage/value/fs/operations and 2 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-06-15 05:58:52 -0400 (Tue, 15 Jun 2010)
New Revision: 2598
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/GenericCQConnectionFactory.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/ValueFileOperation.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializer.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/transaction/jbosscache/GenericTransactionService.java
Log:
EXOJCR-756: small refactoring
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/GenericCQConnectionFactory.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/GenericCQConnectionFactory.java 2010-06-15 09:42:31 UTC (rev 2597)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/GenericCQConnectionFactory.java 2010-06-15 09:58:52 UTC (rev 2598)
@@ -197,6 +197,8 @@
{
try
{
+ Connection conn = null;
+
PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
{
public Object run() throws Exception
@@ -207,15 +209,7 @@
};
try
{
- final Connection conn = (Connection)AccessController.doPrivileged(action);
-
- if (readOnly)
- {
- // set this feature only if it asked
- conn.setReadOnly(readOnly);
- }
-
- return conn;
+ conn = (Connection)AccessController.doPrivileged(action);
}
catch (PrivilegedActionException pae)
{
@@ -233,6 +227,14 @@
throw new RuntimeException(cause);
}
}
+
+ if (readOnly)
+ {
+ // set this feature only if it asked
+ conn.setReadOnly(readOnly);
+ }
+
+ return conn;
}
catch (SQLException e)
{
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/ValueFileOperation.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/ValueFileOperation.java 2010-06-15 09:42:31 UTC (rev 2597)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/ValueFileOperation.java 2010-06-15 09:58:52 UTC (rev 2598)
@@ -31,9 +31,6 @@
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
-import java.security.AccessController;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
/**
* Created by The eXo Platform SAS.
@@ -155,46 +152,16 @@
*/
public void unlock() throws IOException
{
+ if (lockFileStream != null)
+ lockFileStream.close();
- PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
- {
- public Object run() throws Exception
- {
- if (lockFileStream != null)
- lockFileStream.close();
-
- if (!PrivilegedFileHelper.delete(lockFile))
- { // TODO don't use FileCleaner, delete should be enough
- LOG.warn("Cannot delete lock file " + PrivilegedFileHelper.getAbsolutePath(lockFile)
- + ". Add to the FileCleaner");
- cleaner.addFile(lockFile);
- }
-
- return null;
- }
- };
- try
- {
- AccessController.doPrivileged(action);
+ if (!PrivilegedFileHelper.delete(lockFile))
+ { // TODO don't use FileCleaner, delete should be enough
+ LOG.warn("Cannot delete lock file " + PrivilegedFileHelper.getAbsolutePath(lockFile)
+ + ". Add to the FileCleaner");
+ cleaner.addFile(lockFile);
}
- catch (PrivilegedActionException pae)
- {
- Throwable cause = pae.getCause();
- if (cause instanceof IOException)
- {
- throw (IOException)cause;
- }
- else if (cause instanceof RuntimeException)
- {
- throw (RuntimeException)cause;
- }
- else
- {
- throw new RuntimeException(cause);
- }
- }
}
-
}
/**
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializer.java 2010-06-15 09:42:31 UTC (rev 2597)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializer.java 2010-06-15 09:58:52 UTC (rev 2598)
@@ -120,14 +120,14 @@
};
final InputStream is = AccessController.doPrivileged(action);
- PrivilegedAction<InputStreamReader> action_ = new PrivilegedAction<InputStreamReader>()
+ PrivilegedAction<InputStreamReader> actionGetReader = new PrivilegedAction<InputStreamReader>()
{
public InputStreamReader run()
{
return new InputStreamReader(is);
}
};
- InputStreamReader isr = AccessController.doPrivileged(action_);
+ InputStreamReader isr = AccessController.doPrivileged(actionGetReader);
try
{
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/transaction/jbosscache/GenericTransactionService.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/transaction/jbosscache/GenericTransactionService.java 2010-06-15 09:42:31 UTC (rev 2597)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/transaction/jbosscache/GenericTransactionService.java 2010-06-15 09:58:52 UTC (rev 2598)
@@ -363,7 +363,42 @@
*/
public void rollback() throws IllegalStateException, SecurityException, SystemException
{
- tm.rollback();
+ PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
+ {
+ public Object run() throws Exception
+ {
+ tm.rollback();
+ return null;
+ }
+ };
+ try
+ {
+ AccessController.doPrivileged(action);
+ }
+ catch (PrivilegedActionException pae)
+ {
+ Throwable cause = pae.getCause();
+ if (cause instanceof SecurityException)
+ {
+ throw (SecurityException)cause;
+ }
+ else if (cause instanceof IllegalStateException)
+ {
+ throw (IllegalStateException)cause;
+ }
+ else if (cause instanceof SystemException)
+ {
+ throw (SystemException)cause;
+ }
+ else if (cause instanceof RuntimeException)
+ {
+ throw (RuntimeException)cause;
+ }
+ else
+ {
+ throw new RuntimeException(cause);
+ }
+ }
}
/**
16 years, 1 month
exo-jcr SVN: r2597 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr: impl/core and 4 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-06-15 05:42:31 -0400 (Tue, 15 Jun 2010)
New Revision: 2597
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedSystemHelper.java
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/serialization/SerializationConstants.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionFactory.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/value/ValueFactoryImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/serialization/PersistedValueDataReader.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/ValueFileIOHelper.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/ValueFileOperation.java
Log:
EXOJCR-756: small refactoring, add PrivilegedSystemHelper
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/serialization/SerializationConstants.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/serialization/SerializationConstants.java 2010-06-15 09:34:19 UTC (rev 2596)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/serialization/SerializationConstants.java 2010-06-15 09:42:31 UTC (rev 2597)
@@ -18,6 +18,8 @@
*/
package org.exoplatform.services.jcr.dataflow.serialization;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedSystemHelper;
+
import java.io.File;
/**
@@ -33,7 +35,8 @@
/**
* Serialization temp dir.
*/
- public static final String TEMP_DIR = System.getProperty("java.io.tmpdir") + File.separator + "_jcrser.tmp";
+ public static final String TEMP_DIR =
+ PrivilegedSystemHelper.getProperty("java.io.tmpdir") + File.separator + "_jcrser.tmp";
/**
* TransientValueData class.
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionFactory.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionFactory.java 2010-06-15 09:34:19 UTC (rev 2596)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionFactory.java 2010-06-15 09:42:31 UTC (rev 2597)
@@ -22,14 +22,12 @@
import org.exoplatform.container.ExoContainerContext;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
import org.exoplatform.services.jcr.impl.dataflow.session.TransactionableResourceManager;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedSystemHelper;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.exoplatform.services.security.ConversationState;
import org.exoplatform.services.transaction.TransactionService;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
import javax.jcr.LoginException;
import javax.jcr.RepositoryException;
@@ -67,47 +65,40 @@
this.tService = tService;
this.txResourceManager = new TransactionableResourceManager();
- PrivilegedAction<Object> action = new PrivilegedAction<Object>()
+ boolean tracking =
+ "true".equalsIgnoreCase(PrivilegedSystemHelper.getProperty("exo.jcr.session.tracking.active", "false"));
+
+ if (tracking)
{
- public Object run()
+ long maxAgeMillis = 0;
+
+ String maxagevalue = PrivilegedSystemHelper.getProperty("exo.jcr.jcr.session.tracking.maxage");
+ if (maxagevalue != null)
{
- boolean tracking = "true".equalsIgnoreCase(System.getProperty("exo.jcr.session.tracking.active", "false"));
- if (tracking)
+ try
{
- long maxAgeMillis = 0;
-
- String maxagevalue = System.getProperty("exo.jcr.jcr.session.tracking.maxage");
- if (maxagevalue != null)
- {
- try
- {
- maxAgeMillis = Long.parseLong(maxagevalue) * 1000;
- }
- catch (NumberFormatException e)
- {
- //
- }
- }
- if (maxAgeMillis <= 0)
- {
- maxAgeMillis = 1000 * 60 * 2; // 2 mns
- }
-
+ maxAgeMillis = Long.parseLong(maxagevalue) * 1000;
+ }
+ catch (NumberFormatException e)
+ {
//
- try
- {
- SessionReference.start(maxAgeMillis);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
}
+ }
+ if (maxAgeMillis <= 0)
+ {
+ maxAgeMillis = 1000 * 60 * 2; // 2 mns
+ }
- return null;
+ //
+ try
+ {
+ SessionReference.start(maxAgeMillis);
}
- };
- AccessController.doPrivileged(action);
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
}
/**
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/value/ValueFactoryImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/value/ValueFactoryImpl.java 2010-06-15 09:34:19 UTC (rev 2596)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/value/ValueFactoryImpl.java 2010-06-15 09:42:31 UTC (rev 2597)
@@ -30,6 +30,7 @@
import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
import org.exoplatform.services.jcr.impl.util.JCRDateFormat;
import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedSystemHelper;
import org.exoplatform.services.jcr.impl.util.io.WorkspaceFileCleanerHolder;
import org.exoplatform.services.jcr.storage.WorkspaceDataContainer;
import org.exoplatform.services.log.ExoLogger;
@@ -40,8 +41,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
import java.util.Calendar;
import javax.jcr.Node;
@@ -78,17 +77,8 @@
this.locationFactory = locationFactory;
this.fileCleaner = cleanerHolder.getFileCleaner();
+ this.tempDirectory = new File(PrivilegedSystemHelper.getProperty("java.io.tmpdir"));
- PrivilegedAction<Object> action = new PrivilegedAction<Object>()
- {
- public Object run()
- {
- tempDirectory = new File(System.getProperty("java.io.tmpdir"));
- return null;
- }
- };
- AccessController.doPrivileged(action);
-
// TODO we use WorkspaceDataContainer constants but is it ok?
this.maxBufferSize =
workspaceConfig.getContainer().getParameterInteger(WorkspaceDataContainer.MAXBUFFERSIZE_PROP,
@@ -99,16 +89,7 @@
{
this.locationFactory = locationFactory;
this.maxBufferSize = WorkspaceDataContainer.DEF_MAXBUFFERSIZE;
-
- PrivilegedAction<Object> action = new PrivilegedAction<Object>()
- {
- public Object run()
- {
- tempDirectory = new File(System.getProperty("java.io.tmpdir"));
- return null;
- }
- };
- AccessController.doPrivileged(action);
+ this.tempDirectory = new File(PrivilegedSystemHelper.getProperty("java.io.tmpdir"));
}
/**
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/serialization/PersistedValueDataReader.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/serialization/PersistedValueDataReader.java 2010-06-15 09:34:19 UTC (rev 2596)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/serialization/PersistedValueDataReader.java 2010-06-15 09:42:31 UTC (rev 2597)
@@ -31,8 +31,6 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
/**
* Created by The eXo Platform SAS. <br/>
@@ -89,14 +87,7 @@
*/
public AbstractPersistedValueData read(ObjectReader in) throws UnknownClassIdException, IOException
{
- PrivilegedAction<String> action = new PrivilegedAction<String>()
- {
- public String run()
- {
- return SerializationConstants.TEMP_DIR;
- }
- };
- File tempDirectory = new File(AccessController.doPrivileged(action));
+ File tempDirectory = new File(SerializationConstants.TEMP_DIR);
PrivilegedFileHelper.mkdirs(tempDirectory);
// read id
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/ValueFileIOHelper.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/ValueFileIOHelper.java 2010-06-15 09:34:19 UTC (rev 2596)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/ValueFileIOHelper.java 2010-06-15 09:42:31 UTC (rev 2597)
@@ -37,9 +37,6 @@
import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
-import java.security.AccessController;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
/**
* Created by The eXo Platform SAS.
@@ -78,59 +75,33 @@
*/
protected ValueData readValue(final File file, final int orderNum, final int maxBufferSize) throws IOException
{
- PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
- {
- public Object run() throws Exception
- {
- long fileSize = PrivilegedFileHelper.length(file);
+ long fileSize = PrivilegedFileHelper.length(file);
- if (fileSize > maxBufferSize)
- {
- return new FilePersistedValueData(orderNum, file);
- }
- else
- {
- FileInputStream is = PrivilegedFileHelper.fileInputStream(file);
- try
- {
- int buffSize = (int)fileSize;
- byte[] res = new byte[buffSize];
- int rpos = 0;
- int r = -1;
- byte[] buff = new byte[IOBUFFER_SIZE > buffSize ? IOBUFFER_SIZE : buffSize];
- while ((r = is.read(buff)) >= 0)
- {
- System.arraycopy(buff, 0, res, rpos, r);
- rpos += r;
- }
- return new ByteArrayPersistedValueData(orderNum, res);
- }
- finally
- {
- is.close();
- }
- }
- }
- };
- try
+ if (fileSize > maxBufferSize)
{
- return (ValueData)AccessController.doPrivileged(action);
+ return new FilePersistedValueData(orderNum, file);
}
- catch (PrivilegedActionException pae)
+ else
{
- Throwable cause = pae.getCause();
- if (cause instanceof IOException)
+ FileInputStream is = PrivilegedFileHelper.fileInputStream(file);
+ try
{
- throw (IOException)cause;
+ int buffSize = (int)fileSize;
+ byte[] res = new byte[buffSize];
+ int rpos = 0;
+ int r = -1;
+ byte[] buff = new byte[IOBUFFER_SIZE > buffSize ? IOBUFFER_SIZE : buffSize];
+ while ((r = is.read(buff)) >= 0)
+ {
+ System.arraycopy(buff, 0, res, rpos, r);
+ rpos += r;
+ }
+ return new ByteArrayPersistedValueData(orderNum, res);
}
- else if (cause instanceof RuntimeException)
+ finally
{
- throw (RuntimeException)cause;
+ is.close();
}
- else
- {
- throw new RuntimeException(cause);
- }
}
}
@@ -168,42 +139,14 @@
*/
protected void writeByteArrayValue(final File file, final ValueData value) throws IOException
{
- PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
- {
- public Object run() throws Exception
- {
- OutputStream out = PrivilegedFileHelper.fileOutputStream(file);
- try
- {
- out.write(value.getAsByteArray());
- }
- finally
- {
- out.close();
- }
-
- return null;
- }
- };
+ OutputStream out = PrivilegedFileHelper.fileOutputStream(file);
try
{
- AccessController.doPrivileged(action);
+ out.write(value.getAsByteArray());
}
- catch (PrivilegedActionException pae)
+ finally
{
- Throwable cause = pae.getCause();
- if (cause instanceof IOException)
- {
- throw (IOException)cause;
- }
- else if (cause instanceof RuntimeException)
- {
- throw (RuntimeException)cause;
- }
- else
- {
- throw new RuntimeException(cause);
- }
+ out.close();
}
}
@@ -219,82 +162,53 @@
*/
protected void writeStreamedValue(final File file, final ValueData value) throws IOException
{
- PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
+ // do what you want
+ // stream Value
+ if (value instanceof StreamPersistedValueData)
{
- public Object run() throws Exception
+ StreamPersistedValueData streamed = (StreamPersistedValueData)value;
+
+ if (streamed.isPersisted())
{
- // do what you want
- // stream Value
- if (value instanceof StreamPersistedValueData)
+ // already persisted in another Value, copy it to this Value
+ copyClose(streamed.getAsStream(), PrivilegedFileHelper.fileOutputStream(file));
+ }
+ else
+ {
+ // the Value not yet persisted, i.e. or in client stream or spooled to a temp file
+ File tempFile;
+ if ((tempFile = streamed.getTempFile()) != null)
{
- StreamPersistedValueData streamed = (StreamPersistedValueData)value;
-
- if (streamed.isPersisted())
+ // it's spooled Value, try move its file to VS
+ if (!PrivilegedFileHelper.renameTo(tempFile, file))
{
- // already persisted in another Value, copy it to this Value
- copyClose(streamed.getAsStream(), PrivilegedFileHelper.fileOutputStream(file));
- }
- else
- {
- // the Value not yet persisted, i.e. or in client stream or spooled to a temp file
- File tempFile;
- if ((tempFile = streamed.getTempFile()) != null)
+ // not succeeded - copy bytes, temp file will be deleted by transient ValueData
+ if (LOG.isDebugEnabled())
{
- // it's spooled Value, try move its file to VS
- if (!PrivilegedFileHelper.renameTo(tempFile, file))
- {
- // not succeeded - copy bytes, temp file will be deleted by transient ValueData
- if (LOG.isDebugEnabled())
- {
- LOG
- .debug("Value spool file move (rename) to Values Storage is not succeeded. Trying bytes copy. Spool file: "
- + PrivilegedFileHelper.getAbsolutePath(tempFile)
- + ". Destination: "
- + PrivilegedFileHelper.getAbsolutePath(file));
- }
-
- copyClose(PrivilegedFileHelper.fileInputStream(tempFile), PrivilegedFileHelper
- .fileOutputStream(file));
- }
+ LOG
+ .debug("Value spool file move (rename) to Values Storage is not succeeded. Trying bytes copy. Spool file: "
+ + PrivilegedFileHelper.getAbsolutePath(tempFile)
+ + ". Destination: "
+ + PrivilegedFileHelper.getAbsolutePath(file));
}
- else
- {
- // not spooled, use client InputStream
- copyClose(streamed.getStream(), PrivilegedFileHelper.fileOutputStream(file));
- }
- // link this Value to file in VS
- streamed.setPersistedFile(file);
+ copyClose(PrivilegedFileHelper.fileInputStream(tempFile), PrivilegedFileHelper.fileOutputStream(file));
}
}
else
{
- // copy from Value stream to the file, e.g. from FilePersistedValueData to this Value
- copyClose(value.getAsStream(), PrivilegedFileHelper.fileOutputStream(file));
+ // not spooled, use client InputStream
+ copyClose(streamed.getStream(), PrivilegedFileHelper.fileOutputStream(file));
}
- return null;
+ // link this Value to file in VS
+ streamed.setPersistedFile(file);
}
- };
- try
- {
- AccessController.doPrivileged(action);
}
- catch (PrivilegedActionException pae)
+ else
{
- Throwable cause = pae.getCause();
- if (cause instanceof IOException)
- {
- throw (IOException)cause;
- }
- else if (cause instanceof RuntimeException)
- {
- throw (RuntimeException)cause;
- }
- else
- {
- throw new RuntimeException(cause);
- }
+ // copy from Value stream to the file, e.g. from FilePersistedValueData to this Value
+ copyClose(value.getAsStream(), PrivilegedFileHelper.fileOutputStream(file));
}
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/ValueFileOperation.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/ValueFileOperation.java 2010-06-15 09:34:19 UTC (rev 2596)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/ValueFileOperation.java 2010-06-15 09:42:31 UTC (rev 2597)
@@ -125,40 +125,14 @@
*/
public void lock() throws IOException
{
- PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
- {
- public Object run() throws Exception
- {
- // lock file in temp directory
- lockFile = new File(tempDir, targetFile.getName() + LOCK_FILE_EXTENSION);
+ // lock file in temp directory
+ lockFile = new File(tempDir, targetFile.getName() + LOCK_FILE_EXTENSION);
- FileOutputStream lout = PrivilegedFileHelper.fileOutputStream(lockFile, true);
- lout.write(operationInfo.getBytes()); // TODO write info
- lout.getChannel().lock(); // wait for unlock (on Windows will wait for this JVM too)
+ FileOutputStream lout = PrivilegedFileHelper.fileOutputStream(lockFile, true);
+ lout.write(operationInfo.getBytes()); // TODO write info
+ lout.getChannel().lock(); // wait for unlock (on Windows will wait for this JVM too)
- return lout;
- }
- };
- try
- {
- lockFileStream = (FileOutputStream)AccessController.doPrivileged(action);
- }
- catch (PrivilegedActionException pae)
- {
- Throwable cause = pae.getCause();
- if (cause instanceof IOException)
- {
- throw (IOException)cause;
- }
- else if (cause instanceof RuntimeException)
- {
- throw (RuntimeException)cause;
- }
- else
- {
- throw new RuntimeException(cause);
- }
- }
+ lockFileStream = lout;
}
/**
Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedSystemHelper.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedSystemHelper.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedSystemHelper.java 2010-06-15 09:42:31 UTC (rev 2597)
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2010 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.util.io;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * @author <a href="anatoliy.bazko(a)exoplatform.org">Anatoliy Bazko</a>
+ * @version $Id: PrivilegedSystemHelper.java 111 2010-11-11 11:11:11Z tolusha $
+ *
+ */
+public class PrivilegedSystemHelper
+{
+
+ public static String getProperty(final String name)
+ {
+ PrivilegedAction<String> action = new PrivilegedAction<String>()
+ {
+ public String run()
+ {
+ return System.getProperty(name);
+ }
+ };
+ return AccessController.doPrivileged(action);
+ }
+
+ public static String getProperty(final String name, final String def)
+ {
+ PrivilegedAction<String> action = new PrivilegedAction<String>()
+ {
+ public String run()
+ {
+ return System.getProperty(name, def);
+ }
+ };
+ return AccessController.doPrivileged(action);
+ }
+}
16 years, 1 month