Skip to content

Commit

Permalink
Merge pull request #72 from nicolasmoreau/master
Browse files Browse the repository at this point in the history
improve concurrent processes management
  • Loading branch information
nicolasmoreau authored Jun 28, 2017
2 parents 2324759 + 9b5a8b1 commit bf24f7f
Show file tree
Hide file tree
Showing 31 changed files with 643 additions and 471 deletions.
7 changes: 5 additions & 2 deletions portal.ejb/src/main/java/org/vamdc/portal/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ public enum Settings {
HTTP_DATA_TIMEOUT("HTTPDataTimeout","30000"),
REGISTRY_URL("registryURL","http://registry.vamdc.eu/registry-12.07/services/RegistryQueryv1_0"),
REGISTRY_UPDATE_INTERVAL("registryUpdateInterval","300000"),
QUERYSTORE_ASSOCIATION_URL("querystoreAssociationUrl","http://querystore.vamdc.eu/PortalAssociationService?"),
QUERYSTORE_ASSOCIATION_URL("querystoreAssociationUrl","https://querystore.vamdc.eu/PortalAssociationService?"),
AVAILABILITY_MONITOR_INTERVAL("availabilityMonitorInterval","300000"),
REGISTRY_RETRY_INTERVAL("registryRetryInterval","10000"),
HTTP_HEAD_TIMEOUT("HTTPHeadTimeout","60000"),
PDL_SERVER_URL("pdlServerURL", "http://vm-euhoutestc62.obspm.fr/vamdc/OnlineCode?"),
PORTAL_USER_AGENT("userAgent", "VAMDC Portal Dev"),
PORTAL_VERSION("version", "2017_02")
PORTAL_VERSION("version", "2017_06"),
QUERYSTORE_MAX_RETRY("querystoreMaxRetry", "10"),
QUERYSTORE_RETRY_TIMER("querystoreRetryTimer", "3000"),
DEFAULT_USER_MAIL("defaultUserMail", "[email protected]");
;


Expand Down
10 changes: 10 additions & 0 deletions portal.ejb/src/main/java/org/vamdc/portal/async/FutureTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.vamdc.portal.async;

public interface FutureTask {
public void process();
public boolean isDone();
public boolean isProcessing();
public boolean isOk();
public boolean isErrorHappened();
public String getError();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import javax.persistence.EntityManager;

import org.vamdc.portal.entity.constant.Species;
import org.vamdc.portal.entity.species.VamdcSpecies;
import org.vamdc.portal.session.queryBuilder.forms.MoleculesForm.MoleculeInfo;

Expand Down Expand Up @@ -50,23 +51,23 @@ public static List<MoleculeInfo> loadMoleculesFromName(EntityManager em,String v
String query = "SELECT distinct vs FROM VamdcSpecies vs " +
"INNER JOIN vs.vamdcSpeciesNameses vsn " +
"WHERE vsn.name = :Value " +
"AND vs.speciesType = 2 ";
"AND vs.speciesType = " + Species.MOLECULE.getId();
return loadElements(em,query,value);
}


public static List<MoleculeInfo> loadMoleculesFromStoichForm(EntityManager em,String value){
String query = "SELECT distinct vs FROM VamdcSpecies vs " +
"WHERE vs.stoichiometricFormula = :Value " +
"AND vs.speciesType = 2";
"AND vs.speciesType = "+ Species.MOLECULE.getId();
return loadElements(em,query,value);
}

public static List<MoleculeInfo> loadMoleculesFromOrdForm(EntityManager em, String value) {
String query = "SELECT distinct vs FROM VamdcSpecies vs " +
"INNER JOIN vs.vamdcSpeciesStructFormulaes vsf " +
"WHERE vsf.formula = :Value " +
"AND vs.speciesType = 2";
"AND vs.speciesType = " + Species.MOLECULE.getId();
return loadElements(em,query,value);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package org.vamdc.portal.entity;

import java.util.Collection;

import javax.persistence.EntityManager;

import org.vamdc.portal.entity.constant.Species;

/**
* Collection of static methods to get some species objects
* @author doronin
Expand All @@ -25,13 +28,13 @@ static Collection<String> suggestSpeciesName(EntityManager em,

static Collection<String> suggestAtomName(EntityManager em,
String name) {
return suggestRestrictedSpeciesName(em, name, 1);
return suggestRestrictedSpeciesName(em, name, Species.ATOM.getId());

}

static Collection<String> suggestMoleculeName(EntityManager em,
String name) {
return suggestRestrictedSpeciesName(em, name, 2);
return suggestRestrictedSpeciesName(em, name, Species.MOLECULE.getId());
}

@SuppressWarnings("unchecked")
Expand All @@ -58,7 +61,7 @@ static Collection<String> suggestStoichForm(EntityManager em, String formula){


static Collection<String> suggestMoleculeStoichForm(EntityManager em, String formula){
return suggestRestrictedStoichForm(em, formula, 2);
return suggestRestrictedStoichForm(em, formula, Species.MOLECULE.getId());
}

@SuppressWarnings("unchecked")
Expand All @@ -72,7 +75,7 @@ private static Collection<String> suggestRestrictedStoichForm(EntityManager em,
}

static Collection<String> suggestMoleculeStructForm(EntityManager em, String formula){
return suggestRestrictedStructForm(em, formula, 2);
return suggestRestrictedStructForm(em, formula, Species.MOLECULE.getId());
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.vamdc.portal.entity;

import org.vamdc.portal.entity.constant.Markup;
import org.vamdc.portal.entity.species.VamdcSpecies;
import org.vamdc.portal.entity.species.VamdcSpeciesNames;
import org.vamdc.portal.entity.species.VamdcSpeciesStructFormulae;
Expand All @@ -16,7 +17,7 @@ public VamdcSpeciesFacade(VamdcSpecies element){
@Override
public String getName() {
for (VamdcSpeciesNames vsn:element.getVamdcSpeciesNameses()){
if (vsn.getVamdcMarkupTypes().getId()==1)
if (vsn.getVamdcMarkupTypes().getId() == Markup.TEXT.getId())
return vsn.getName();
}
return "";
Expand All @@ -28,7 +29,7 @@ public String getName() {
@Override
public String getOrdinaryFormula() {
for (VamdcSpeciesStructFormulae vsff:element.getVamdcSpeciesStructFormulaes()){
if (vsff.getVamdcMarkupTypes().getId()==1)
if (vsff.getVamdcMarkupTypes().getId() == Markup.TEXT.getId())
return vsff.getFormula();
}
return "";
Expand All @@ -46,7 +47,7 @@ public String getDescription() {
String result = "";
for(VamdcSpeciesStructFormulae vsff: element.getVamdcSpeciesStructFormulaes()){
result=vsff.getFormula();
if (vsff.getVamdcMarkupTypes().getId()==2)
if (vsff.getVamdcMarkupTypes().getId() == Markup.HTML.getId())
break;
}
return appendName(result);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.vamdc.portal.entity.constant;

public enum Markup {
TEXT(1),
HTML(2),
RST(3),
LATEX(4);

private Integer id;

Markup(Integer id){
this.id = id;
}

public Integer getId(){
return this.id;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.vamdc.portal.entity.constant;

public enum Species {
ATOM(1),
MOLECULE(2);

private Integer id;

Species(Integer id){
this.id = id;
}

public Integer getId(){
return this.id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import javax.persistence.Table;

import org.hibernate.validator.NotNull;
import org.vamdc.portal.Settings;

/**
* VamdcInchikeyExceptions generated by hbm2java
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.vamdc.portal.session.consumers;

public interface Consumer {
public void process();
public String getLocation();
public boolean isDone();
public boolean isProcessing();
public boolean isOk();
public boolean isErrorHappened();
public String getError();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package org.vamdc.portal.session.consumers;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import org.jboss.seam.Component;
import org.vamdc.portal.async.FutureTask;
import org.vamdc.portal.registry.RegistryFacade;

public class ConsumerProcessor implements Consumer, FutureTask{

RegistryFacade registryFacade;
private URL consumer;
private URL data;
private Future<URL> location;


public ConsumerProcessor(String consumer, String data){
registryFacade = (RegistryFacade) Component.getInstance("registryFacade");
try {
this.consumer = registryFacade.getConsumerServiceURL(consumer);
this.data = new URL(data);
} catch (MalformedURLException e) {
e.printStackTrace();
}

}

/**
* execute consumer
*/
public void process() {
List<URL> nodes = new ArrayList<URL>();
nodes.add(data);
if (consumer != null) {
ExecutorService executor = Executors.newSingleThreadExecutor();
location = executor
.submit(new PostRequest(consumer, nodes));
executor.shutdown();
}
}

/**
* return consumer result url as a string
*/
public String getLocation(){
String result = "";
try {
result = this.location.get().toExternalForm();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}

return result;
}

public boolean isDone() {
return (location != null && location.isDone() && !location
.isCancelled());
}

public boolean isProcessing() {
return (location != null && !location.isDone());
}

public boolean isOk() {
return (isDone() && !isErrorHappened());
}

public boolean isErrorHappened() {
if (isDone()) {
try {
location.get();
} catch (Exception e) {
return true;
}
}
return false;
}

public String getError() {
if (isDone()) {
try {
location.get();
} catch (Exception e) {
return e.getMessage();
}
}
return "";
}
}
Loading

0 comments on commit bf24f7f

Please sign in to comment.