Merge pull request #3 from mchid/develop
Adding fix for Map of science visualization problem
This commit is contained in:
commit
9ada4eb84f
2 changed files with 58 additions and 15 deletions
|
@ -9,9 +9,14 @@ import edu.cornell.mannlib.vitro.webapp.visualization.modelconstructor.Organizat
|
|||
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.ConstructedModelTracker;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.ModelConstructor;
|
||||
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.commons.logging.Log;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.CustomLock;
|
||||
|
||||
public class OrganizationToPublicationsForSubOrganizationsFactory implements
|
||||
ModelFactoryInterface {
|
||||
|
||||
private static final Log log = LogFactory.getLog(OrganizationToPublicationsForSubOrganizationsFactory.class.getName());
|
||||
@Override
|
||||
public Model getOrCreateModel(String uri, Dataset dataset)
|
||||
throws MalformedQueryParametersException {
|
||||
|
@ -27,7 +32,10 @@ public class OrganizationToPublicationsForSubOrganizationsFactory implements
|
|||
return candidateModel;
|
||||
|
||||
} else {
|
||||
|
||||
Lock customLock = CustomLock.getInstance().getLock();
|
||||
if (customLock.tryLock()) //Acquiring lock if available to construct the model
|
||||
{
|
||||
customLock.lock();
|
||||
ModelConstructor model = new OrganizationToPublicationsForSubOrganizationsModelConstructor(uri, dataset);
|
||||
|
||||
Model constructedModel = model.getConstructedModel();
|
||||
|
@ -37,10 +45,17 @@ public class OrganizationToPublicationsForSubOrganizationsFactory implements
|
|||
uri,
|
||||
OrganizationToPublicationsForSubOrganizationsModelConstructor.MODEL_TYPE),
|
||||
constructedModel);
|
||||
|
||||
customLock.unlock();
|
||||
return constructedModel;
|
||||
}
|
||||
else
|
||||
{
|
||||
log.info("The Model construction process is going on");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.visualization.visutils;
|
||||
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
|
||||
|
||||
/* This class is a singleton implementation for locking the concurrent
|
||||
construction of the models to resolve concurrency issue*/
|
||||
|
||||
public final class CustomLock{
|
||||
private static final CustomLock instance = new CustomLock();
|
||||
private static Lock lock;
|
||||
private CustomLock()
|
||||
{
|
||||
this.lock = new ReentrantLock();
|
||||
|
||||
}
|
||||
|
||||
public static CustomLock getInstance()
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static Lock getLock()
|
||||
{
|
||||
return lock;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue