Author: skabashnyuk
Date: 2009-12-23 11:05:41 -0500 (Wed, 23 Dec 2009)
New Revision: 1156
Added:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexUpdateMonitor.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/DefaultIndexUpdateMonitor.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexUpdateMonitor.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestIndexUpdateMonitor.java
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/AbstractQueryHandler.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/QueryHandler.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexChangesFilter.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jcr-config.xml
Log:
EXOJCR-331 : initial implementation of IndexUpdateMonitor
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/AbstractQueryHandler.java
===================================================================
---
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/AbstractQueryHandler.java 2009-12-23
13:42:22 UTC (rev 1155)
+++
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/AbstractQueryHandler.java 2009-12-23
16:05:41 UTC (rev 1156)
@@ -16,18 +16,20 @@
*/
package org.exoplatform.services.jcr.impl.core.query;
-import java.io.IOException;
-import java.util.Iterator;
-
-import javax.jcr.RepositoryException;
-
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.impl.core.query.lucene.DefaultIndexUpdateMonitor;
import org.exoplatform.services.jcr.impl.core.query.lucene.IndexInfos;
+import org.exoplatform.services.jcr.impl.core.query.lucene.IndexUpdateMonitor;
import org.exoplatform.services.jcr.impl.core.query.lucene.MultiIndex;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.IOException;
+import java.util.Iterator;
+
+import javax.jcr.RepositoryException;
+
/**
* Implements default behaviour for some methods of {@link QueryHandler}.
*/
@@ -70,8 +72,10 @@
/**
* {@link IndexInfos} instance that is passed to {@link MultiIndex}
*/
- private IndexInfos indexInfos;
+ protected IndexInfos indexInfos;
+ private IndexUpdateMonitor indexUpdateMonitor;
+
public boolean isInitialized()
{
return initialized;
@@ -228,4 +232,19 @@
return indexInfos == null ? new IndexInfos() : indexInfos;
}
+ /**
+ * @return the indexUpdateMonitor
+ */
+ public IndexUpdateMonitor getIndexUpdateMonitor()
+ {
+ return indexUpdateMonitor == null ? new DefaultIndexUpdateMonitor() :
indexUpdateMonitor;
+ }
+
+ /**
+ * @param indexUpdateMonitor the indexUpdateMonitor to set
+ */
+ public void setIndexUpdateMonitor(IndexUpdateMonitor indexUpdateMonitor)
+ {
+ this.indexUpdateMonitor = indexUpdateMonitor;
+ }
}
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/QueryHandler.java
===================================================================
---
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/QueryHandler.java 2009-12-23
13:42:22 UTC (rev 1155)
+++
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/QueryHandler.java 2009-12-23
16:05:41 UTC (rev 1156)
@@ -21,7 +21,9 @@
import org.exoplatform.services.jcr.datamodel.NodeData;
import org.exoplatform.services.jcr.impl.core.SessionDataManager;
import org.exoplatform.services.jcr.impl.core.SessionImpl;
+import org.exoplatform.services.jcr.impl.core.query.lucene.DefaultIndexUpdateMonitor;
import org.exoplatform.services.jcr.impl.core.query.lucene.IndexInfos;
+import org.exoplatform.services.jcr.impl.core.query.lucene.IndexUpdateMonitor;
import org.exoplatform.services.jcr.impl.core.query.lucene.MultiIndex;
import org.exoplatform.services.jcr.impl.core.query.lucene.QueryHits;
@@ -167,4 +169,14 @@
*/
public IndexInfos getIndexInfos();
+ /**
+ * @return the indexUpdateMonitor
+ */
+ public IndexUpdateMonitor getIndexUpdateMonitor();
+
+ /**
+ * @param indexUpdateMonitor the indexUpdateMonitor to set
+ */
+ public void setIndexUpdateMonitor(IndexUpdateMonitor indexUpdateMonitor);
+
}
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexChangesFilter.java
===================================================================
---
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexChangesFilter.java 2009-12-23
13:42:22 UTC (rev 1155)
+++
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexChangesFilter.java 2009-12-23
16:05:41 UTC (rev 1156)
@@ -119,13 +119,17 @@
if (!parentHandler.isInitialized())
{
// TODO: uncomment it, when JbossCacheIndexInfos is finished.
- // parentHandler.setIndexInfos(new JbossCacheIndexInfos(cache, true, ioMode));
+ //parentHandler.setIndexInfos(new JbossCacheIndexInfos(cache, true, ioMode));
+ //parentHandler.setIndexInfos(new IndexInfos());
+ parentHandler.setIndexUpdateMonitor(new JbossCacheIndexUpdateMonitor(cache));
parentHandler.init();
}
if (!handler.isInitialized())
{
// TODO: uncomment it, when JbossCacheIndexInfos is finished.
- // handler.setIndexInfos(new JbossCacheIndexInfos(cache, false, ioMode));
+ //handler.setIndexInfos(new JbossCacheIndexInfos(cache, false, ioMode));
+ //handler.setIndexInfos(new IndexInfos());
+ handler.setIndexUpdateMonitor(new JbossCacheIndexUpdateMonitor(cache));
handler.init();
}
Added:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexUpdateMonitor.java
===================================================================
---
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexUpdateMonitor.java
(rev 0)
+++
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexUpdateMonitor.java 2009-12-23
16:05:41 UTC (rev 1156)
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.core.query.jbosscache;
+
+import org.exoplatform.services.jcr.impl.core.query.lucene.IndexUpdateMonitor;
+import org.jboss.cache.Cache;
+import org.jboss.cache.Fqn;
+
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:Sergey.Kabashnyuk@exoplatform.org">Sergey
Kabashnyuk</a>
+ * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
+ *
+ */
+public class JbossCacheIndexUpdateMonitor implements IndexUpdateMonitor
+{
+
+ private final Cache<Serializable, Object> cache;
+
+ private final static Fqn PARAMETER_ROOT =
Fqn.fromString("INDEX_UPDATE_MONITOR");
+
+ private final static String PARAMETER_NAME = "index-update-in-progress";
+
+ /**
+ * @param cache instance of JbossCache that is used to deliver index names
+ */
+ public JbossCacheIndexUpdateMonitor(Cache<Serializable, Object> cache)
+ {
+ this.cache = cache;
+ setUpdateInProgress(false);
+
+ }
+
+ /**
+ * @see
org.exoplatform.services.jcr.impl.core.query.lucene.IndexUpdateMonitor#getUpdateInProgress()
+ */
+ public boolean getUpdateInProgress()
+ {
+ Object value = cache.get(PARAMETER_ROOT, PARAMETER_NAME);
+ return value != null ? (Boolean)value : false;
+ }
+
+ /**
+ * @see
org.exoplatform.services.jcr.impl.core.query.lucene.IndexUpdateMonitor#setUpdateInProgress(boolean)
+ */
+ public void setUpdateInProgress(boolean updateInProgress)
+ {
+ cache.put(PARAMETER_ROOT, PARAMETER_NAME, new Boolean(updateInProgress));
+ }
+
+}
Property changes on:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexUpdateMonitor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/DefaultIndexUpdateMonitor.java
===================================================================
---
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/DefaultIndexUpdateMonitor.java
(rev 0)
+++
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/DefaultIndexUpdateMonitor.java 2009-12-23
16:05:41 UTC (rev 1156)
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.core.query.lucene;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * @author <a href="mailto:Sergey.Kabashnyuk@exoplatform.org">Sergey
Kabashnyuk</a>
+ * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
+ *
+ */
+public class DefaultIndexUpdateMonitor implements IndexUpdateMonitor
+{
+ private AtomicBoolean updateInProgress;
+
+ /**
+ * @param semaphore
+ */
+ public DefaultIndexUpdateMonitor()
+ {
+ super();
+ this.updateInProgress = new AtomicBoolean();
+ this.updateInProgress.set(false);
+ }
+
+ /**
+ *
+ * @see
org.exoplatform.services.jcr.impl.core.query.lucene.IndexUpdateMonitor#getUpdateInProgress()
+ */
+ public boolean getUpdateInProgress()
+ {
+ return updateInProgress.get();
+ }
+
+ /**
+ *
+ * @see
org.exoplatform.services.jcr.impl.core.query.lucene.IndexUpdateMonitor#setUpdateInProgress(boolean)
+ */
+ public void setUpdateInProgress(boolean updateInProgress)
+ {
+ this.updateInProgress.set(updateInProgress);
+ }
+}
Property changes on:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/DefaultIndexUpdateMonitor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexUpdateMonitor.java
===================================================================
---
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexUpdateMonitor.java
(rev 0)
+++
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexUpdateMonitor.java 2009-12-23
16:05:41 UTC (rev 1156)
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.core.query.lucene;
+
+/**
+ * @author <a href="mailto:Sergey.Kabashnyuk@exoplatform.org">Sergey
Kabashnyuk</a>
+ * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
+ *
+ */
+public interface IndexUpdateMonitor
+{
+ /**
+ * @return the updateInProgress
+ */
+ boolean getUpdateInProgress();
+
+ /**
+ * @param updateInProgress the updateInProgress to set
+ */
+ void setUpdateInProgress(boolean updateInProgress);
+
+}
\ No newline at end of file
Property changes on:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexUpdateMonitor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
===================================================================
---
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2009-12-23
13:42:22 UTC (rev 1155)
+++
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2009-12-23
16:05:41 UTC (rev 1156)
@@ -129,8 +129,10 @@
/**
* Flag indicating whether an update operation is in progress.
*/
- private boolean updateInProgress = false;
+ // private boolean updateInProgress = false;
+ private final IndexUpdateMonitor indexUpdateMonitor;
+
/**
* If not <code>null</code> points to a valid
<code>IndexReader</code> that
* reads from all indexes, including volatile and persistent indexes.
@@ -225,10 +227,11 @@
* @throws IOException
* if an error occurs
*/
- MultiIndex(SearchIndex handler, IndexingTree indexingTree, IndexerIoMode ioMode,
IndexInfos indexInfos)
- throws IOException
+ MultiIndex(SearchIndex handler, IndexingTree indexingTree, IndexerIoMode ioMode,
IndexInfos indexInfos,
+ IndexUpdateMonitor indexUpdateMonitor) throws IOException
{
this.ioMode = ioMode;
+ this.indexUpdateMonitor = indexUpdateMonitor;
this.directoryManager = handler.getDirectoryManager();
this.indexDir = directoryManager.getDirectory(".");
this.handler = handler;
@@ -420,7 +423,8 @@
synchronized (updateMonitor)
{
- updateInProgress = true;
+ //updateInProgress = true;
+ indexUpdateMonitor.setUpdateInProgress(true);
}
try
{
@@ -454,7 +458,8 @@
{
synchronized (updateMonitor)
{
- updateInProgress = false;
+ //updateInProgress = false;
+ indexUpdateMonitor.setUpdateInProgress(false);
updateMonitor.notifyAll();
releaseMultiReader();
}
@@ -500,7 +505,8 @@
{
synchronized (updateMonitor)
{
- updateInProgress = true;
+ //updateInProgress = true;
+ indexUpdateMonitor.setUpdateInProgress(true);
}
int num;
try
@@ -532,7 +538,8 @@
{
synchronized (updateMonitor)
{
- updateInProgress = false;
+ //updateInProgress = false;
+ indexUpdateMonitor.setUpdateInProgress(false);
updateMonitor.notifyAll();
releaseMultiReader();
}
@@ -717,7 +724,8 @@
{
synchronized (updateMonitor)
{
- updateInProgress = true;
+ //updateInProgress = true;
+ indexUpdateMonitor.setUpdateInProgress(true);
}
try
{
@@ -764,7 +772,8 @@
{
synchronized (updateMonitor)
{
- updateInProgress = false;
+ //updateInProgress = false;
+ indexUpdateMonitor.setUpdateInProgress(false);
updateMonitor.notifyAll();
releaseMultiReader();
}
@@ -819,7 +828,7 @@
}
// no reader available
// wait until no update is in progress
- while (updateInProgress)
+ while (indexUpdateMonitor.getUpdateInProgress())
{
try
{
@@ -1369,7 +1378,8 @@
log.debug("Flushing index after being idle for " + idleTime +
" ms.");
synchronized (updateMonitor)
{
- updateInProgress = true;
+ //updateInProgress = true;
+ indexUpdateMonitor.setUpdateInProgress(true);
}
try
{
@@ -1379,7 +1389,8 @@
{
synchronized (updateMonitor)
{
- updateInProgress = false;
+ //updateInProgress = false;
+ indexUpdateMonitor.setUpdateInProgress(false);
updateMonitor.notifyAll();
releaseMultiReader();
}
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java
===================================================================
---
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java 2009-12-23
13:42:22 UTC (rev 1155)
+++
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java 2009-12-23
16:05:41 UTC (rev 1156)
@@ -515,7 +515,7 @@
indexingConfig = createIndexingConfiguration(nsMappings);
analyzer.setIndexingConfig(indexingConfig);
- index = new MultiIndex(this, context.getIndexingTree(), ioMode, getIndexInfos());
+ index = new MultiIndex(this, context.getIndexingTree(), ioMode, getIndexInfos(),
getIndexUpdateMonitor());
// if RW mode, create initial index and start check
if (ioMode == IndexerIoMode.READ_WRITE)
{
Added:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestIndexUpdateMonitor.java
===================================================================
---
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestIndexUpdateMonitor.java
(rev 0)
+++
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestIndexUpdateMonitor.java 2009-12-23
16:05:41 UTC (rev 1156)
@@ -0,0 +1,208 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.lab.cluster.prepare;
+
+import junit.framework.TestCase;
+
+import
org.exoplatform.services.jcr.impl.core.query.jbosscache.JbossCacheIndexUpdateMonitor;
+import org.exoplatform.services.jcr.impl.core.query.lucene.IndexUpdateMonitor;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheFactory;
+import org.jboss.cache.DefaultCacheFactory;
+
+import java.io.Serializable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * @author <a href="mailto:Sergey.Kabashnyuk@exoplatform.org">Sergey
Kabashnyuk</a>
+ * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
+ *
+ */
+public class TestIndexUpdateMonitor extends TestCase
+{
+ /**
+ * Logger instance for this class
+ */
+ private final Log log = ExoLogger.getLogger(TestIndexUpdateMonitor.class);
+
+ private IndexUpdateMonitor indexUpdateMonitor;
+
+ /**
+ * @see org.exoplatform.services.jcr.BaseStandaloneTest#setUp()
+ */
+ @Override
+ public void setUp() throws Exception
+ {
+ // TODO Auto-generated method stub
+ super.setUp();
+ indexUpdateMonitor = new JbossCacheIndexUpdateMonitor(createCache());
+ }
+
+ public void testSimpleBoolean() throws Exception
+ {
+ //test default
+ assertFalse(indexUpdateMonitor.getUpdateInProgress());
+
+ //test set false
+ indexUpdateMonitor.setUpdateInProgress(false);
+ assertFalse(indexUpdateMonitor.getUpdateInProgress());
+
+ //test set true
+ indexUpdateMonitor.setUpdateInProgress(true);
+ assertTrue(indexUpdateMonitor.getUpdateInProgress());
+
+ //test set false
+ indexUpdateMonitor.setUpdateInProgress(false);
+ assertFalse(indexUpdateMonitor.getUpdateInProgress());
+
+ }
+
+ public void testMultiThread() throws Exception
+ {
+ AtomicBoolean atomicBoolean = new AtomicBoolean();
+ ThreadGroup chengers = new ThreadGroup("Changers");
+ ThreadGroup checkers = new ThreadGroup("Checkers");
+ Thread[] changersArray = new Thread[10];
+ Thread[] checkerArray = new Thread[10];
+
+ for (int i = 0; i < changersArray.length; i++)
+ {
+ changersArray[i] = new Thread(chengers, new
UpdateMonitorChanger(atomicBoolean));
+ changersArray[i].start();
+ }
+
+ for (int i = 0; i < checkerArray.length; i++)
+ {
+ checkerArray[i] = new Thread(checkers, new
UpdateMonitorChecker(atomicBoolean));
+ checkerArray[i].start();
+ }
+
+ // Thread changer = new Thread(new UpdateMonitorChanger(atomicBoolean));
+ // changer.start();
+ // Thread checker = new Thread(new UpdateMonitorChecker(atomicBoolean));
+ // checker.start();
+
+ Thread.sleep(4 * 60 * 1000);
+ chengers.destroy();
+ checkers.destroy();
+ }
+
+ private class UpdateMonitorChanger implements Runnable
+ {
+ private AtomicBoolean atomicBoolean;
+
+ /**
+ * @param atomicBoolean
+ */
+ public UpdateMonitorChanger(AtomicBoolean atomicBoolean)
+ {
+ super();
+ this.atomicBoolean = atomicBoolean;
+ }
+
+ /**
+ * @see java.lang.Runnable#run()
+ */
+ public void run()
+ {
+ while (!Thread.currentThread().isInterrupted())
+ {
+
+ synchronized (atomicBoolean)
+ {
+ assertEquals(atomicBoolean.get(),
indexUpdateMonitor.getUpdateInProgress());
+ boolean oldValue = atomicBoolean.get();
+
+ indexUpdateMonitor.setUpdateInProgress(!oldValue);
+
+ if (!atomicBoolean.compareAndSet(oldValue, !oldValue))
+ {
+ log.warn("Fail to change monitor");
+ }
+ }
+ }
+
+ }
+ }
+
+ private class UpdateMonitorChecker implements Runnable
+ {
+
+ /**
+ * @param atomicBoolean
+ */
+ public UpdateMonitorChecker(AtomicBoolean atomicBoolean)
+ {
+ super();
+ this.atomicBoolean = atomicBoolean;
+ }
+
+ private final AtomicBoolean atomicBoolean;
+
+ /**
+ * @see java.lang.Runnable#run()
+ */
+ public void run()
+ {
+
+ while (!Thread.currentThread().isInterrupted())
+ {
+
+ synchronized (atomicBoolean)
+ {
+ //assertEquals(atomicBoolean.get(),
indexUpdateMonitor.getUpdateInProgress());
+ if (atomicBoolean.get() == indexUpdateMonitor.getUpdateInProgress())
+ {
+ System.out.println("check ok");
+ }
+ else
+ {
+ System.out.println("check fail");
+ }
+
+ }
+
+ try
+ {
+ Thread.sleep(100);
+ }
+ catch (InterruptedException e)
+ {
+ return;
+ }
+ }
+
+ }
+ }
+
+ private Cache<Serializable, Object> createCache()
+ {
+ String jbcConfig = "conf/standalone/test-jbosscache-config.xml";
+ CacheFactory<Serializable, Object> factory = new
DefaultCacheFactory<Serializable, Object>();
+ log.info("JBoss Cache configuration used: " + jbcConfig);
+ Cache<Serializable, Object> cache = factory.createCache(jbcConfig, false);
+
+ cache.create();
+ cache.start();
+ return cache;
+ }
+
+}
Property changes on:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestIndexUpdateMonitor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jcr-config.xml
===================================================================
---
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jcr-config.xml 2009-12-23
13:42:22 UTC (rev 1155)
+++
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jcr-config.xml 2009-12-23
16:05:41 UTC (rev 1156)
@@ -74,6 +74,9 @@
<query-handler
class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
<properties>
<property name="index-dir"
value="target/temp/index/db1/ws" />
+ <!-- property name="changesfilter-class"
value="org.exoplatform.services.jcr.impl.core.query.jbosscache.JbossCacheIndexChangesFilter"
/>
+ <property name="changesfilter-config-path"
value="conf/standalone/test-jbosscache-config.xml" /-->
+
</properties>
</query-handler>
<lock-manager>