mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
IOC for scheduling
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2696 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
<!-- Scheduled jobs -->
|
<!-- Scheduled jobs -->
|
||||||
<!-- -->
|
<!-- -->
|
||||||
|
|
||||||
<bean id="ftsIndexerTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
|
<bean id="ftsIndexerTrigger" class="org.alfresco.util.TriggerBean">
|
||||||
<property name="jobDetail">
|
<property name="jobDetail">
|
||||||
<bean id="ftsIndexerJobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
|
<bean id="ftsIndexerJobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
|
||||||
<property name="jobClass">
|
<property name="jobClass">
|
||||||
@@ -21,15 +21,19 @@
|
|||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
</property>
|
</property>
|
||||||
|
<!-- Try and do some indexing every minute after starting up -->
|
||||||
<property name="startDelay">
|
<property name="startDelay">
|
||||||
<value>60000</value>
|
<value>60000</value>
|
||||||
</property>
|
</property>
|
||||||
<property name="repeatInterval">
|
<property name="repeatInterval">
|
||||||
<value>60000</value>
|
<value>60000</value>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="scheduler">
|
||||||
|
<ref bean="schedulerFactory" />
|
||||||
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="tempFileCleanerTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
|
<bean id="tempFileCleanerTrigger" class="org.alfresco.util.TriggerBean">
|
||||||
<property name="jobDetail">
|
<property name="jobDetail">
|
||||||
<bean id="tempFileCleanerJobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
|
<bean id="tempFileCleanerJobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
|
||||||
<property name="jobClass">
|
<property name="jobClass">
|
||||||
@@ -50,9 +54,12 @@
|
|||||||
<property name="repeatInterval">
|
<property name="repeatInterval">
|
||||||
<value>3600000</value><!-- repeat every hour -->
|
<value>3600000</value><!-- repeat every hour -->
|
||||||
</property>
|
</property>
|
||||||
|
<property name="scheduler">
|
||||||
|
<ref bean="schedulerFactory" />
|
||||||
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="contentStoreCleanerTrigger" class="org.alfresco.util.TriggerBean">
|
<bean id="contentStoreCleanerTrigger" class="org.alfresco.util.CronTriggerBean">
|
||||||
<property name="jobDetail">
|
<property name="jobDetail">
|
||||||
<bean id="fileContentStoreCleanerJobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
|
<bean id="fileContentStoreCleanerJobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
|
||||||
<property name="jobClass">
|
<property name="jobClass">
|
||||||
@@ -67,19 +74,17 @@
|
|||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
</property>
|
</property>
|
||||||
<!-- trigger at 4am -->
|
<property name="scheduler">
|
||||||
<property name="hour">
|
<ref bean="schedulerFactory" />
|
||||||
<value>04</value>
|
|
||||||
</property>
|
</property>
|
||||||
<property name="minute">
|
<!-- trigger at 4am each day -->
|
||||||
<value>00</value>
|
<property name="cronExpression">
|
||||||
</property>
|
<value>0 0 4 * * ?</value>
|
||||||
<property name="repeatInterval">
|
|
||||||
<value>86400000</value> <!-- repeat daily -->
|
|
||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="indexRecoveryTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
|
|
||||||
|
<bean id="indexRecoveryTrigger" class="org.alfresco.util.TriggerBean">
|
||||||
<property name="jobDetail">
|
<property name="jobDetail">
|
||||||
<bean id="IndexRecoveryJobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
|
<bean id="IndexRecoveryJobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
|
||||||
<property name="jobClass">
|
<property name="jobClass">
|
||||||
@@ -100,9 +105,12 @@
|
|||||||
<property name="repeatCount">
|
<property name="repeatCount">
|
||||||
<value>0</value> <!-- DO NOT REPEAT !!!!! -->
|
<value>0</value> <!-- DO NOT REPEAT !!!!! -->
|
||||||
</property>
|
</property>
|
||||||
|
<property name="scheduler">
|
||||||
|
<ref bean="schedulerFactory" />
|
||||||
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="indexBackupTrigger" class="org.alfresco.util.TriggerBean">
|
<bean id="indexBackupTrigger" class="org.alfresco.util.CronTriggerBean">
|
||||||
<property name="jobDetail">
|
<property name="jobDetail">
|
||||||
<bean id="IndexBackupJobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
|
<bean id="IndexBackupJobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
|
||||||
<property name="jobClass">
|
<property name="jobClass">
|
||||||
@@ -117,20 +125,17 @@
|
|||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
</property>
|
</property>
|
||||||
<!-- trigger at 3am -->
|
<property name="scheduler">
|
||||||
<property name="hour">
|
<ref bean="schedulerFactory" />
|
||||||
<value>03</value>
|
|
||||||
</property>
|
</property>
|
||||||
<property name="minute">
|
<!-- trigger at 3am each day -->
|
||||||
<value>00</value>
|
<property name="cronExpression">
|
||||||
</property>
|
<value>0 0 3 * * ?</value>
|
||||||
<property name="repeatInterval">
|
|
||||||
<value>86400000</value> <!-- repeat daily -->
|
|
||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<!-- enable DEBUG for 'org.alfresco.repo.cache.EhCacheTracerJob' to activate -->
|
<!-- enable DEBUG for 'org.alfresco.repo.cache.EhCacheTracerJob' to activate -->
|
||||||
<bean id="ehCacheTracerJob" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
|
<bean id="ehCacheTracerJob" class="org.alfresco.util.TriggerBean">
|
||||||
<property name="jobDetail">
|
<property name="jobDetail">
|
||||||
<bean id="ehCacheTracerJobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
|
<bean id="ehCacheTracerJobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
|
||||||
<property name="jobClass">
|
<property name="jobClass">
|
||||||
@@ -147,29 +152,18 @@
|
|||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<!-- Scheduled tasks -->
|
<!-- Scheduled tasks -->
|
||||||
|
<!-- Triggers should not appear here - the scheduler should be injected into the trigger definition -->
|
||||||
|
<!-- This bean should not need to apear else where in extension configuration -->
|
||||||
<bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
|
<bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
|
||||||
<property name="triggers">
|
|
||||||
<list>
|
|
||||||
<ref bean="tempFileCleanerTrigger" />
|
|
||||||
<ref bean="contentStoreCleanerTrigger"/>
|
|
||||||
<ref bean="ftsIndexerTrigger" />
|
|
||||||
<ref bean="indexRecoveryTrigger" />
|
|
||||||
<ref bean="indexBackupTrigger" />
|
|
||||||
<!--
|
|
||||||
<ref bean="ldapGroupTrigger" />
|
|
||||||
<ref bean="ldapPeopleTrigger" />
|
|
||||||
-->
|
|
||||||
<!--
|
|
||||||
<ref bean="ehCacheTracerJob" />
|
|
||||||
-->
|
|
||||||
</list>
|
|
||||||
</property>
|
|
||||||
<property name="waitForJobsToCompleteOnShutdown">
|
<property name="waitForJobsToCompleteOnShutdown">
|
||||||
<value>true</value>
|
<value>true</value>
|
||||||
</property>
|
</property>
|
||||||
<property name="configLocation">
|
<property name="configLocation">
|
||||||
<value>classpath:alfresco/domain/quartz.properties</value>
|
<value>classpath:alfresco/domain/quartz.properties</value>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="schedulerName">
|
||||||
|
<value>DefaultScheduler</value>
|
||||||
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
@@ -0,0 +1,241 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005 Alfresco, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Mozilla Public License version 1.1
|
||||||
|
* with a permitted attribution clause. You may obtain a
|
||||||
|
* copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.alfresco.org/legal/license.txt
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||||
|
* either express or implied. See the License for the specific
|
||||||
|
* language governing permissions and limitations under the
|
||||||
|
* License.
|
||||||
|
*/
|
||||||
|
package org.alfresco.repo.node;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.transaction.UserTransaction;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.alfresco.repo.dictionary.DictionaryDAO;
|
||||||
|
import org.alfresco.repo.dictionary.M2Model;
|
||||||
|
import org.alfresco.repo.search.impl.lucene.fts.FullTextSearchIndexer;
|
||||||
|
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||||
|
import org.alfresco.service.ServiceRegistry;
|
||||||
|
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
|
import org.alfresco.service.cmr.repository.StoreRef;
|
||||||
|
import org.alfresco.service.cmr.search.ResultSet;
|
||||||
|
import org.alfresco.service.cmr.search.SearchService;
|
||||||
|
import org.alfresco.service.namespace.DynamicNamespacePrefixResolver;
|
||||||
|
import org.alfresco.service.namespace.NamespacePrefixResolver;
|
||||||
|
import org.alfresco.service.namespace.NamespaceService;
|
||||||
|
import org.alfresco.service.namespace.QName;
|
||||||
|
import org.alfresco.service.transaction.TransactionService;
|
||||||
|
import org.alfresco.util.ApplicationContextHelper;
|
||||||
|
import org.apache.lucene.index.IndexWriter;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
|
||||||
|
public class ConcurrentNodeServiceSearchTest extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
public static final String NAMESPACE = "http://www.alfresco.org/test/BaseNodeServiceTest";
|
||||||
|
|
||||||
|
public static final String TEST_PREFIX = "test";
|
||||||
|
|
||||||
|
public static final QName TYPE_QNAME_TEST_CONTENT = QName.createQName(NAMESPACE, "content");
|
||||||
|
|
||||||
|
public static final QName ASPECT_QNAME_TEST_TITLED = QName.createQName(NAMESPACE, "titled");
|
||||||
|
|
||||||
|
public static final QName PROP_QNAME_TEST_TITLE = QName.createQName(NAMESPACE, "title");
|
||||||
|
|
||||||
|
public static final QName PROP_QNAME_TEST_MIMETYPE = QName.createQName(NAMESPACE, "mimetype");
|
||||||
|
|
||||||
|
static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
|
||||||
|
|
||||||
|
private NodeService nodeService;
|
||||||
|
|
||||||
|
private TransactionService transactionService;
|
||||||
|
|
||||||
|
private NodeRef rootNodeRef;
|
||||||
|
|
||||||
|
private FullTextSearchIndexer luceneFTS;
|
||||||
|
|
||||||
|
private AuthenticationComponent authenticationComponent;
|
||||||
|
|
||||||
|
public ConcurrentNodeServiceSearchTest()
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setUp() throws Exception
|
||||||
|
{
|
||||||
|
DictionaryDAO dictionaryDao = (DictionaryDAO) ctx.getBean("dictionaryDAO");
|
||||||
|
// load the system model
|
||||||
|
ClassLoader cl = BaseNodeServiceTest.class.getClassLoader();
|
||||||
|
InputStream modelStream = cl.getResourceAsStream("alfresco/model/systemModel.xml");
|
||||||
|
assertNotNull(modelStream);
|
||||||
|
M2Model model = M2Model.createModel(modelStream);
|
||||||
|
dictionaryDao.putModel(model);
|
||||||
|
// load the test model
|
||||||
|
modelStream = cl.getResourceAsStream("org/alfresco/repo/node/BaseNodeServiceTest_model.xml");
|
||||||
|
assertNotNull(modelStream);
|
||||||
|
model = M2Model.createModel(modelStream);
|
||||||
|
dictionaryDao.putModel(model);
|
||||||
|
|
||||||
|
nodeService = (NodeService) ctx.getBean("dbNodeService");
|
||||||
|
transactionService = (TransactionService) ctx.getBean("transactionComponent");
|
||||||
|
luceneFTS = (FullTextSearchIndexer) ctx.getBean("LuceneFullTextSearchIndexer");
|
||||||
|
this.authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
|
||||||
|
|
||||||
|
this.authenticationComponent.setSystemUserAsCurrentUser();
|
||||||
|
|
||||||
|
// create a first store directly
|
||||||
|
UserTransaction tx = transactionService.getUserTransaction();
|
||||||
|
tx.begin();
|
||||||
|
StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
|
||||||
|
rootNodeRef = nodeService.getRootNode(storeRef);
|
||||||
|
tx.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void tearDown() throws Exception
|
||||||
|
{
|
||||||
|
authenticationComponent.clearCurrentSecurityContext();
|
||||||
|
super.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Map<QName, ChildAssociationRef> buildNodeGraph() throws Exception
|
||||||
|
{
|
||||||
|
return BaseNodeServiceTest.buildNodeGraph(nodeService, rootNodeRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Map<QName, ChildAssociationRef> commitNodeGraph() throws Exception
|
||||||
|
{
|
||||||
|
UserTransaction tx = transactionService.getUserTransaction();
|
||||||
|
tx.begin();
|
||||||
|
Map<QName, ChildAssociationRef> answer = buildNodeGraph();
|
||||||
|
tx.commit();
|
||||||
|
|
||||||
|
return null;// answer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testConcurrent() throws Exception
|
||||||
|
{
|
||||||
|
luceneFTS.pause();
|
||||||
|
IndexWriter.COMMIT_LOCK_TIMEOUT = 100000;
|
||||||
|
int count = 10;
|
||||||
|
int repeats = 10;
|
||||||
|
|
||||||
|
SearchService searcher = (SearchService) ctx.getBean(ServiceRegistry.SEARCH_SERVICE.getLocalName());
|
||||||
|
|
||||||
|
Map<QName, ChildAssociationRef> assocRefs = commitNodeGraph();
|
||||||
|
Thread runner = null;
|
||||||
|
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
runner = new Nester("Concurrent-" + i, runner, repeats, searcher);
|
||||||
|
}
|
||||||
|
if (runner != null)
|
||||||
|
{
|
||||||
|
runner.start();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
runner.join();
|
||||||
|
}
|
||||||
|
catch (InterruptedException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(2, searcher.selectNodes(rootNodeRef, "/*", null,
|
||||||
|
getNamespacePrefixReolsver(""), false).size());
|
||||||
|
ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*\"");
|
||||||
|
// n6 has root aspect - there are three things at the root level in the
|
||||||
|
// index
|
||||||
|
assertEquals(3, results.length());
|
||||||
|
results.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Daemon thread
|
||||||
|
*/
|
||||||
|
class Nester extends Thread
|
||||||
|
{
|
||||||
|
Thread waiter;
|
||||||
|
|
||||||
|
int repeats;
|
||||||
|
|
||||||
|
SearchService searcher;
|
||||||
|
|
||||||
|
Nester(String name, Thread waiter, int repeats, SearchService searcher)
|
||||||
|
{
|
||||||
|
super(name);
|
||||||
|
this.setDaemon(true);
|
||||||
|
this.waiter = waiter;
|
||||||
|
this.repeats = repeats;
|
||||||
|
this.searcher = searcher;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
authenticationComponent.setSystemUserAsCurrentUser();
|
||||||
|
|
||||||
|
if (waiter != null)
|
||||||
|
{
|
||||||
|
waiter.start();
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
System.out.println("Start " + this.getName());
|
||||||
|
for (int i = 0; i < repeats; i++)
|
||||||
|
{
|
||||||
|
// Map<QName, ChildAssociationRef> assocRefs = commitNodeGraph();
|
||||||
|
if (i % 50 == 0)
|
||||||
|
{
|
||||||
|
System.out.println(" " + this.getName() + " " + i);
|
||||||
|
}
|
||||||
|
ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*\"");
|
||||||
|
results.close();
|
||||||
|
}
|
||||||
|
System.out.println("End " + this.getName());
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
System.exit(12);
|
||||||
|
}
|
||||||
|
if (waiter != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
waiter.join();
|
||||||
|
}
|
||||||
|
catch (InterruptedException e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private NamespacePrefixResolver getNamespacePrefixReolsver(String defaultURI)
|
||||||
|
{
|
||||||
|
DynamicNamespacePrefixResolver nspr = new DynamicNamespacePrefixResolver(null);
|
||||||
|
nspr.registerNamespace(NamespaceService.SYSTEM_MODEL_PREFIX, NamespaceService.SYSTEM_MODEL_1_0_URI);
|
||||||
|
nspr.registerNamespace(NamespaceService.CONTENT_MODEL_PREFIX, NamespaceService.CONTENT_MODEL_1_0_URI);
|
||||||
|
nspr.registerNamespace(NamespaceService.APP_MODEL_PREFIX, NamespaceService.APP_MODEL_1_0_URI);
|
||||||
|
nspr.registerNamespace("namespace", "namespace");
|
||||||
|
nspr.registerNamespace(NamespaceService.DEFAULT_PREFIX, defaultURI);
|
||||||
|
return nspr;
|
||||||
|
}
|
||||||
|
}
|
@@ -522,6 +522,7 @@ public class LuceneTest extends TestCase
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
authenticationComponent.setSystemUserAsCurrentUser();
|
||||||
UserTransaction tx = transactionService.getUserTransaction();
|
UserTransaction tx = transactionService.getUserTransaction();
|
||||||
tx = transactionService.getUserTransaction();
|
tx = transactionService.getUserTransaction();
|
||||||
tx.begin();
|
tx.begin();
|
||||||
@@ -559,7 +560,7 @@ public class LuceneTest extends TestCase
|
|||||||
|
|
||||||
tx.rollback();
|
tx.rollback();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Throwable e)
|
||||||
{
|
{
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
@@ -160,14 +160,14 @@ public class FullTextSearchIndexerImpl implements FTSIndexerAware, FullTextSearc
|
|||||||
StoreRef toIndex = getNextRef();
|
StoreRef toIndex = getNextRef();
|
||||||
if (toIndex != null)
|
if (toIndex != null)
|
||||||
{
|
{
|
||||||
//System.out.println("Indexing "+toIndex+" id is "+this);
|
//System.out.println("Indexing "+toIndex+" at "+(new java.util.Date()));
|
||||||
LuceneIndexer indexer = luceneIndexerAndSearcherFactory.getIndexer(toIndex);
|
LuceneIndexer indexer = luceneIndexerAndSearcherFactory.getIndexer(toIndex);
|
||||||
indexer.registerCallBack(this);
|
indexer.registerCallBack(this);
|
||||||
indexer.updateFullTextSearch(1000);
|
indexer.updateFullTextSearch(1000);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//System.out.println("Nothing to index"+" id is "+this);
|
//System.out.println("Nothing to Indexing at "+(new java.util.Date()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user