forked from misdoro/VAMDC-Portal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from nicolasmoreau/master
improve concurrent processes management
- Loading branch information
Showing
31 changed files
with
643 additions
and
471 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]"); | ||
; | ||
|
||
|
||
|
10 changes: 10 additions & 0 deletions
10
portal.ejb/src/main/java/org/vamdc/portal/async/FutureTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
portal.ejb/src/main/java/org/vamdc/portal/entity/constant/Markup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
portal.ejb/src/main/java/org/vamdc/portal/entity/constant/Species.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
portal.ejb/src/main/java/org/vamdc/portal/session/consumers/Consumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
99 changes: 99 additions & 0 deletions
99
portal.ejb/src/main/java/org/vamdc/portal/session/consumers/ConsumerProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ""; | ||
} | ||
} |
Oops, something went wrong.