|
From: <dav...@us...> - 2010-03-18 17:15:48
|
Revision: 2387
http://qtitools.svn.sourceforge.net/qtitools/?rev=2387&view=rev
Author: davemckain
Date: 2010-03-18 17:15:41 +0000 (Thu, 18 Mar 2010)
Log Message:
-----------
Now uses JacomaxSimpleConfigurator to attempt to configure Maxima, meaning that the engine can be deployed to "most" platforms without requiring an explicit jacomax.properties.
If a MaximaConfiguration can't be created (e.g. because Maxima isn't installed!) then the engine will now work, but throws a QTIEvaluationException if any MathAssess-enabled question is played.
Modified Paths:
--------------
branches/mathassess/QTIEngine/grails-app/conf/spring/resources.groovy
branches/mathassess/QTIEngine/src/java/org/qtitools/mathassess/DefaultQTIMaximaSessionHolder.java
branches/mathassess/QTIEngine/src/java/org/qtitools/mathassess/PooledQTIMaximaSessionHolder.java
branches/mathassess/QTIEngine/src/java/org/qtitools/mathassess/QTIMaximaSessionHolder.java
Modified: branches/mathassess/QTIEngine/grails-app/conf/spring/resources.groovy
===================================================================
--- branches/mathassess/QTIEngine/grails-app/conf/spring/resources.groovy 2010-03-18 17:03:04 UTC (rev 2386)
+++ branches/mathassess/QTIEngine/grails-app/conf/spring/resources.groovy 2010-03-18 17:15:41 UTC (rev 2387)
@@ -3,19 +3,10 @@
stylesheetCache(uk.ac.ed.ph.snuggletex.utilities.SimpleStylesheetCache)
- maximaPropertiesConfigurer(uk.ac.ed.ph.jacomax.MaximaPropertiesConfigurer)
-
- maximaConfiguration(maximaPropertiesConfigurer:'configure')
-
- pooledQTIMaximaSessionManager(org.qtitools.mathassess.tools.glue.extras.pooling.PooledQTIMaximaSessionManager) { bean ->
+ pooledQTIMaximaSessionHolder(org.qtitools.mathassess.PooledQTIMaximaSessionHolder) { bean ->
stylesheetCache = ref('stylesheetCache')
- maximaConfiguration = ref('maximaConfiguration')
bean.initMethod = 'init'
bean.destroyMethod = 'shutdown'
}
- pooledQTIMaximaSessionHolder(org.qtitools.mathassess.PooledQTIMaximaSessionHolder) {
- pooledQTIMaximaSessionManager = ref('pooledQTIMaximaSessionManager')
- }
-
}
\ No newline at end of file
Modified: branches/mathassess/QTIEngine/src/java/org/qtitools/mathassess/DefaultQTIMaximaSessionHolder.java
===================================================================
--- branches/mathassess/QTIEngine/src/java/org/qtitools/mathassess/DefaultQTIMaximaSessionHolder.java 2010-03-18 17:03:04 UTC (rev 2386)
+++ branches/mathassess/QTIEngine/src/java/org/qtitools/mathassess/DefaultQTIMaximaSessionHolder.java 2010-03-18 17:15:41 UTC (rev 2387)
@@ -1,3 +1,8 @@
+/* $Id$
+ *
+ * Copyright (c) 2010, The University of Edinburgh.
+ * All Rights Reserved
+ */
package org.qtitools.mathassess;
import org.qtitools.mathassess.tools.qticasbridge.maxima.QTIMaximaSession;
@@ -3,4 +8,11 @@
import org.qtitools.mathassess.tools.qticasbridge.maxima.SimpleQTIMaximaSessionManager;
+/**
+ * Trivial implementation of {@link QTIMaximaSessionHolder} that uses a
+ * {@link SimpleQTIMaximaSessionManager}.
+ *
+ * @author David McKain
+ * @version $Revision$
+ */
public final class DefaultQTIMaximaSessionHolder implements QTIMaximaSessionHolder {
Modified: branches/mathassess/QTIEngine/src/java/org/qtitools/mathassess/PooledQTIMaximaSessionHolder.java
===================================================================
--- branches/mathassess/QTIEngine/src/java/org/qtitools/mathassess/PooledQTIMaximaSessionHolder.java 2010-03-18 17:03:04 UTC (rev 2386)
+++ branches/mathassess/QTIEngine/src/java/org/qtitools/mathassess/PooledQTIMaximaSessionHolder.java 2010-03-18 17:15:41 UTC (rev 2387)
@@ -1,3 +1,8 @@
+/* $Id$
+ *
+ * Copyright (c) 2010, The University of Edinburgh.
+ * All Rights Reserved
+ */
package org.qtitools.mathassess;
import org.qtitools.mathassess.tools.glue.extras.pooling.PooledQTIMaximaSessionManager;
@@ -2,2 +7,3 @@
import org.qtitools.mathassess.tools.qticasbridge.maxima.QTIMaximaSession;
+import org.qtitools.qti.exception.QTIEvaluationException;
import org.qtitools.qti.ext.LifecycleEventType;
@@ -7,8 +13,19 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import uk.ac.ed.ph.jacomax.JacomaxConfigurationException;
+import uk.ac.ed.ph.jacomax.JacomaxSimpleConfigurator;
+import uk.ac.ed.ph.jacomax.MaximaConfiguration;
+import uk.ac.ed.ph.snuggletex.utilities.StylesheetCache;
+
/**
- * FIXME: Document this!
+ * Implementation of {@link QTIMaximaSessionHolder} that uses the
+ * {@link PooledQTIMaximaSessionManager} from MathAssessTools.
+ * <p>
+ * This implements {@link LifecycleListener} and is registered with an item/test
+ * in the appropriate place in MathAssessEngine itself. The {@link MaximaEngine}
+ * can then discover the (normally shared) instance of this by searching the
+ * {@link LifecycleListener}s. This is a bit nasty but avoids evil singletons.
*
* @author David McKain
* @version $Revision$
@@ -19,6 +36,7 @@
private final ThreadLocal<QTIMaximaSession> sessionThreadLocal;
+ private StylesheetCache stylesheetCache;
private PooledQTIMaximaSessionManager pooledQTIMaximaSessionManager;
//---------------------------------------------------------
@@ -27,14 +45,39 @@
this.sessionThreadLocal = new ThreadLocal<QTIMaximaSession>();
}
- public PooledQTIMaximaSessionManager getPooledQTIMaximaSessionManager() {
- return pooledQTIMaximaSessionManager;
+
+ public StylesheetCache getStylesheetCache() {
+ return stylesheetCache;
}
- public void setPooledQTIMaximaSessionManager(PooledQTIMaximaSessionManager pooledQTIMaximaSessionManager) {
- this.pooledQTIMaximaSessionManager = pooledQTIMaximaSessionManager;
+ public void setStylesheetCache(StylesheetCache stylesheetCache) {
+ this.stylesheetCache = stylesheetCache;
}
+
+ public void init() {
+ MaximaConfiguration maximaConfiguration = null;
+ try {
+ maximaConfiguration = JacomaxSimpleConfigurator.configure();
+
+ logger.info("Created MaximaConfiguration, so creating a PooledQTIMaximaSessionManager to support questions authored with MathAssess extensions");
+ pooledQTIMaximaSessionManager = new PooledQTIMaximaSessionManager();
+ pooledQTIMaximaSessionManager.setMaximaConfiguration(maximaConfiguration);
+ pooledQTIMaximaSessionManager.setStylesheetCache(stylesheetCache);
+ pooledQTIMaximaSessionManager.init();
+ }
+ catch (JacomaxConfigurationException e) {
+ pooledQTIMaximaSessionManager = null;
+ logger.warn("Could not obtain a MaximaConfiguration, so no Maxima pool will be created and questions using MathAssess extensions will not be supported");
+ }
+ }
+
+ public void shutdown() {
+ if (pooledQTIMaximaSessionManager!=null) {
+ pooledQTIMaximaSessionManager.shutdown();
+ }
+ }
+
//---------------------------------------------------------
public void lifecycleEvent(LifecycleEventType eventType) {
@@ -63,17 +106,22 @@
private QTIMaximaSession obtainSessionForLifecycle() {
QTIMaximaSession session = sessionThreadLocal.get();
if (session==null) {
- logger.info("Obtaining new maxima session from pool for this request");
- /* Need to get a new session from pool */
- session = pooledQTIMaximaSessionManager.obtainSession();
- sessionThreadLocal.set(session);
+ if (pooledQTIMaximaSessionManager!=null) {
+ logger.info("Obtaining new maxima session from pool for this request");
+ /* Need to get a new session from pool */
+ session = pooledQTIMaximaSessionManager.obtainSession();
+ sessionThreadLocal.set(session);
+ }
+ else {
+ throw new QTIEvaluationException("Maxima is available on this engine, so questions authored with MathAssess extensions are not supported");
+ }
}
return session;
}
private void releaseSessionForLifecycle() {
QTIMaximaSession session = sessionThreadLocal.get();
- if (session!=null) {
+ if (session!=null && pooledQTIMaximaSessionManager!=null) {
logger.info("Finished with maxima session for this request - returning to pool");
pooledQTIMaximaSessionManager.returnSession(session);
sessionThreadLocal.set(null);
Modified: branches/mathassess/QTIEngine/src/java/org/qtitools/mathassess/QTIMaximaSessionHolder.java
===================================================================
--- branches/mathassess/QTIEngine/src/java/org/qtitools/mathassess/QTIMaximaSessionHolder.java 2010-03-18 17:03:04 UTC (rev 2386)
+++ branches/mathassess/QTIEngine/src/java/org/qtitools/mathassess/QTIMaximaSessionHolder.java 2010-03-18 17:15:41 UTC (rev 2387)
@@ -1,3 +1,8 @@
+/* $Id$
+ *
+ * Copyright (c) 2010, The University of Edinburgh.
+ * All Rights Reserved
+ */
package org.qtitools.mathassess;
import org.qtitools.mathassess.tools.qticasbridge.maxima.QTIMaximaSession;
@@ -2,2 +7,12 @@
+/**
+ * Provides a handle on a {@link QTIMaximaSession} for the duration of a single
+ * "call" made by {@link MaximaEngine}.
+ * <p>
+ * There are currently 2 implementations of this - one trivial and one with pooling.
+ * We'll probably just settle on pooling if everything goes well.
+ *
+ * @author David McKain
+ * @version $Revision$
+ */
public interface QTIMaximaSessionHolder {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|