Skip to content
Snippets Groups Projects
Commit 4bf1b794 authored by buczekp's avatar buczekp
Browse files

[LMS-1858] fixed dependencies (broken cyclic dependency in spring by...

[LMS-1858] fixed dependencies (broken cyclic dependency in spring by introducing an encapsulation of a queue without evaluation thread logic)

SVN: 18821
parent 5b32de55
No related branches found
No related tags found
No related merge requests found
......@@ -16,7 +16,6 @@
package ch.systemsx.cisd.openbis.generic.server.dataaccess.db.dynamic_property;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
......@@ -26,11 +25,9 @@ import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import ch.systemsx.cisd.common.collections.ExtendedBlockingQueueFactory;
import ch.systemsx.cisd.common.collections.IExtendedBlockingQueue;
import ch.systemsx.cisd.common.logging.LogCategory;
import ch.systemsx.cisd.common.logging.LogFactory;
import ch.systemsx.cisd.openbis.generic.server.CommonServiceProvider;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.db.search.IFullTextIndexUpdateScheduler;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.db.search.IndexUpdateOperation;
import ch.systemsx.cisd.openbis.generic.shared.dto.IEntityInformationWithPropertiesHolder;
......@@ -39,79 +36,32 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.IEntityInformationWithPropert
* @author Piotr Buczek
*/
public final class DynamicPropertyEvaluationRunnable extends HibernateDaoSupport implements
IDynamicPropertyEvaluationScheduler, Runnable
Runnable
{
private static final int BATCH_SIZE = 1000;
public final static String DYNAMIC_PROPERTY_EVALUATOR_QUEUE_FILENAME =
".dynamic_property_evaluator_queue";
private static final Logger operationLog = LogFactory.getLogger(LogCategory.OPERATION,
DynamicPropertyEvaluationRunnable.class);
private static final Logger notificationLog = LogFactory.getLogger(LogCategory.NOTIFY,
DynamicPropertyEvaluationRunnable.class);
private final IExtendedBlockingQueue<DynamicPropertyEvaluationOperation> evaluatorQueue;
private final IFullTextIndexUpdateScheduler fullTextIndexUpdateScheduler;
private final IDynamicPropertyEvaluationSchedulerWithQueue evaluationQueue;
private final IBatchDynamicPropertyEvaluator evaluator;
public DynamicPropertyEvaluationRunnable(final SessionFactory sessionFactory,
final IFullTextIndexUpdateScheduler fullTextIndexUpdateScheduler)
final IDAOFactory daoFactory,
final IFullTextIndexUpdateScheduler fullTextIndexUpdateScheduler,
final IDynamicPropertyEvaluationSchedulerWithQueue evaluationQueue)
{
this.fullTextIndexUpdateScheduler = fullTextIndexUpdateScheduler;
this.evaluationQueue = evaluationQueue;
setSessionFactory(sessionFactory);
final File queueFile = getEvaluatorQueueFile();
operationLog.info(String.format("Evaluator queue file: %s.", queueFile.getAbsolutePath()));
evaluatorQueue = createEvaluatorQueue(queueFile);
}
private static IExtendedBlockingQueue<DynamicPropertyEvaluationOperation> createEvaluatorQueue(
final File queueFile)
{
try
{
return ExtendedBlockingQueueFactory
.<DynamicPropertyEvaluationOperation> createPersistRecordBased(queueFile);
} catch (RuntimeException e)
{
// don't fail if e.g. deserialization of the queue fails (see SE-286)
String newFileName =
DYNAMIC_PROPERTY_EVALUATOR_QUEUE_FILENAME + "_" + System.currentTimeMillis();
notificationLog.error(String.format("%s.\n "
+ "Renaming '%s' to '%s' and using an empty queue file. "
+ "Restart server with the queue that caused the problem or "
+ "wait for maintenance task to reevaluate all properties.", e.getMessage(),
queueFile, newFileName));
queueFile.renameTo(new File(newFileName));
return ExtendedBlockingQueueFactory
.<DynamicPropertyEvaluationOperation> createPersistRecordBased(queueFile);
}
}
private static File getEvaluatorQueueFile()
{
return new File(DYNAMIC_PROPERTY_EVALUATOR_QUEUE_FILENAME);
}
public void clear()
{
evaluatorQueue.clear();
if (operationLog.isInfoEnabled())
{
operationLog.info("Cleared evaluator queue.");
}
}
public void scheduleUpdate(DynamicPropertyEvaluationOperation operation)
{
if (operationLog.isDebugEnabled())
{
operationLog.debug("Scheduling update: " + operation);
}
evaluatorQueue.add(operation);
evaluator = new DefaultBatchDynamicPropertyEvaluator(BATCH_SIZE, daoFactory);
}
//
......@@ -123,14 +73,9 @@ public final class DynamicPropertyEvaluationRunnable extends HibernateDaoSupport
{
try
{
// WORKAROUND to cyclic dependencies between beans
// (can't pass IDaoFactory throuhg constructor)
final IBatchDynamicPropertyEvaluator evaluator =
new DefaultBatchDynamicPropertyEvaluator(BATCH_SIZE,
CommonServiceProvider.getDAOFactory());
while (true)
{
final DynamicPropertyEvaluationOperation operation = evaluatorQueue.peekWait();
final DynamicPropertyEvaluationOperation operation = evaluationQueue.peekWait();
if (operationLog.isInfoEnabled())
{
operationLog.info("Update: " + operation);
......@@ -185,7 +130,7 @@ public final class DynamicPropertyEvaluationRunnable extends HibernateDaoSupport
}
}
}
evaluatorQueue.take();
evaluationQueue.take();
}
} catch (final Throwable th)
{
......
/*
* Copyright 2008 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.generic.server.dataaccess.db.dynamic_property;
import java.io.File;
import org.apache.log4j.Logger;
import ch.systemsx.cisd.common.collections.ExtendedBlockingQueueFactory;
import ch.systemsx.cisd.common.collections.IExtendedBlockingQueue;
import ch.systemsx.cisd.common.logging.LogCategory;
import ch.systemsx.cisd.common.logging.LogFactory;
/**
* @author Piotr Buczek
*/
public final class DynamicPropertyEvaluationScheduler implements
IDynamicPropertyEvaluationSchedulerWithQueue
{
public final static String DYNAMIC_PROPERTY_EVALUATOR_QUEUE_FILENAME =
".dynamic_property_evaluator_queue";
private static final Logger operationLog = LogFactory.getLogger(LogCategory.OPERATION,
DynamicPropertyEvaluationScheduler.class);
private static final Logger notificationLog = LogFactory.getLogger(LogCategory.NOTIFY,
DynamicPropertyEvaluationScheduler.class);
private final IExtendedBlockingQueue<DynamicPropertyEvaluationOperation> evaluatorQueue;
public DynamicPropertyEvaluationScheduler()
{
final File queueFile = getEvaluatorQueueFile();
operationLog.info(String.format("Evaluator queue file: %s.", queueFile.getAbsolutePath()));
evaluatorQueue = createEvaluatorQueue(queueFile);
}
private static IExtendedBlockingQueue<DynamicPropertyEvaluationOperation> createEvaluatorQueue(
final File queueFile)
{
try
{
return ExtendedBlockingQueueFactory
.<DynamicPropertyEvaluationOperation> createPersistRecordBased(queueFile);
} catch (RuntimeException e)
{
// don't fail if e.g. deserialization of the queue fails (see SE-286)
String newFileName =
DYNAMIC_PROPERTY_EVALUATOR_QUEUE_FILENAME + "_" + System.currentTimeMillis();
notificationLog.error(String.format("%s.\n "
+ "Renaming '%s' to '%s' and using an empty queue file. "
+ "Restart server with the queue that caused the problem or "
+ "wait for maintenance task to reevaluate all properties.", e.getMessage(),
queueFile, newFileName));
queueFile.renameTo(new File(newFileName));
return ExtendedBlockingQueueFactory
.<DynamicPropertyEvaluationOperation> createPersistRecordBased(queueFile);
}
}
private static File getEvaluatorQueueFile()
{
return new File(DYNAMIC_PROPERTY_EVALUATOR_QUEUE_FILENAME);
}
public void clear()
{
evaluatorQueue.clear();
if (operationLog.isInfoEnabled())
{
operationLog.info("Cleared evaluator queue.");
}
}
public void scheduleUpdate(DynamicPropertyEvaluationOperation operation)
{
if (operationLog.isDebugEnabled())
{
operationLog.debug("Scheduling update: " + operation);
}
evaluatorQueue.add(operation);
}
public DynamicPropertyEvaluationOperation peekWait() throws InterruptedException
{
return evaluatorQueue.peekWait();
}
public DynamicPropertyEvaluationOperation take() throws InterruptedException
{
return evaluatorQueue.take();
}
}
/*
* Copyright 2008 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.generic.server.dataaccess.db.dynamic_property;
/**
* {@link IDynamicPropertyEvaluationScheduler} extension with methods for reading from the queue.
*
* @author Piotr Buczek
*/
public interface IDynamicPropertyEvaluationSchedulerWithQueue extends
IDynamicPropertyEvaluationScheduler
{
/**
* Retrieves, but does not remove, an operation from the head of this queue, waiting if no
* elements are present on this queue.
*
* @return an operation from the head of this queue
* @throws InterruptedException if interrupted while waiting.
*/
DynamicPropertyEvaluationOperation peekWait() throws InterruptedException;
/**
* Retrieves and removes an operation from the head of this queue, waiting if no elements are
* present on this queue.
*
* @return an operation from the head of this queue
* @throws InterruptedException if interrupted while waiting.
*/
DynamicPropertyEvaluationOperation take() throws InterruptedException;
}
\ No newline at end of file
......@@ -37,7 +37,7 @@
<constructor-arg ref="hibernate-session-factory" />
<constructor-arg ref="hibernate-search-context" />
<constructor-arg ref="full-text-index-updater" />
<constructor-arg ref="dynamic-property-evaluator" />
<constructor-arg ref="dynamic-property-scheduler" />
</bean>
<bean id="dss-factory" class="ch.systemsx.cisd.openbis.generic.server.business.DataStoreServiceFactory"/>
......
......@@ -153,10 +153,16 @@
<constructor-arg ref="full-text-index-updater" />
</bean>
<bean id="dynamic-property-scheduler"
class="ch.systemsx.cisd.openbis.generic.server.dataaccess.db.dynamic_property.DynamicPropertyEvaluationScheduler">
</bean>
<bean id="dynamic-property-evaluator"
class="ch.systemsx.cisd.openbis.generic.server.dataaccess.db.dynamic_property.DynamicPropertyEvaluationRunnable">
<constructor-arg ref="hibernate-session-factory" />
<constructor-arg ref="dao-factory" />
<constructor-arg ref="full-text-index-updater" />
<constructor-arg ref="dynamic-property-scheduler" />
</bean>
<bean id="maintenance-task-starter"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment