Permalink
Browse files

Some try/catch more just in case and we don't create the MoNaV connector

unless we really need it. (Will anyone use it instead of OSRM? Is that
even possible?)
  • Loading branch information...
1 parent 9e173a4 commit fe47e8d86c1313dfc61fb3c8fe7e538d8e885259 @Delawen Delawen committed Jul 17, 2012
@@ -105,7 +105,7 @@ public void setConfiguration(
this.configuration = configuration;
}
- private MoNaVConnector monavConnector = new MoNaVConnector();
+ private MoNaVConnector monavConnector = new MoNaVConnector();
/**
* Stupid test to see if the Server is alive.
@@ -130,71 +130,77 @@ public String test() {
@Consumes({ MediaType.APPLICATION_XML, MediaType.TEXT_XML,
MediaType.APPLICATION_ATOM_XML })
public XLSType openLS(JAXBElement<XLSType> jaxbelement) {
- final XLSType parameter = jaxbelement.getValue();
- LOG.trace("openLS(" + parameter + ")");
- Locale localetmp = Locale.ROOT;
-
- if (parameter.getLang() != null && !parameter.getLang().isEmpty()) {
- LOG.trace("Language detected: " + parameter.getLang());
- localetmp = new Locale(parameter.getLang());
- }
- final Locale locale = localetmp;
- localetmp = null;
- final List<List<AbstractResponseParametersType>> resultado = new LinkedList<List<AbstractResponseParametersType>>();
-
- ExecutorService executor = Executors.newFixedThreadPool(3);
-
- for (JAXBElement<? extends AbstractBodyType> jaxbbody : parameter
- .getBody()) {
-
- AbstractBodyType body = jaxbbody.getValue();
-
- if (body instanceof RequestType) {
-
- final AbstractRequestParametersType request = ((RequestType) body)
- .getRequestParameters().getValue();
-
- FutureTask<List<AbstractResponseParametersType>> thread = new FutureTask<List<AbstractResponseParametersType>>(
- new Callable<List<AbstractResponseParametersType>>() {
-
- public List<AbstractResponseParametersType> call()
- throws Exception {
- List<AbstractResponseParametersType> response = null;
-
- try {
- if (request instanceof DetermineRouteRequestType)
- response = routePlan(
- (DetermineRouteRequestType) request,
- locale);
- else if (request instanceof ReverseGeocodeRequestType)
- response = reverseGeocoding((ReverseGeocodeRequestType) request);
- else if (request instanceof GeocodeRequestType)
- response = geocoding((GeocodeRequestType) request);
- else if (request instanceof DirectoryRequestType)
- response = directory((DirectoryRequestType) request);
+ try {
+ final XLSType parameter = jaxbelement.getValue();
+ LOG.trace("openLS(" + parameter + ")");
+ Locale localetmp = Locale.ROOT;
- synchronized (resultado) {
- resultado.add(response);
+ if (parameter.getLang() != null && !parameter.getLang().isEmpty()) {
+ LOG.trace("Language detected: " + parameter.getLang());
+ localetmp = new Locale(parameter.getLang());
+ }
+ final Locale locale = localetmp;
+ localetmp = null;
+ final List<List<AbstractResponseParametersType>> resultado = new LinkedList<List<AbstractResponseParametersType>>();
+
+ ExecutorService executor = Executors.newFixedThreadPool(3);
+
+ for (JAXBElement<? extends AbstractBodyType> jaxbbody : parameter
+ .getBody()) {
+
+ AbstractBodyType body = jaxbbody.getValue();
+
+ if (body instanceof RequestType) {
+
+ final AbstractRequestParametersType request = ((RequestType) body)
+ .getRequestParameters().getValue();
+
+ FutureTask<List<AbstractResponseParametersType>> thread = new FutureTask<List<AbstractResponseParametersType>>(
+ new Callable<List<AbstractResponseParametersType>>() {
+
+ public List<AbstractResponseParametersType> call()
+ throws Exception {
+ List<AbstractResponseParametersType> response = null;
+
+ try {
+ if (request instanceof DetermineRouteRequestType)
+ response = routePlan(
+ (DetermineRouteRequestType) request,
+ locale);
+ else if (request instanceof ReverseGeocodeRequestType)
+ response = reverseGeocoding((ReverseGeocodeRequestType) request);
+ else if (request instanceof GeocodeRequestType)
+ response = geocoding((GeocodeRequestType) request);
+ else if (request instanceof DirectoryRequestType)
+ response = directory((DirectoryRequestType) request);
+
+ synchronized (resultado) {
+ resultado.add(response);
+ }
+ } catch (Throwable e) {
+ LOG.error("Error answering request", e);
+ throw new RuntimeException(e);
}
- } catch (Throwable e) {
- LOG.error("Error answering request", e);
- throw new RuntimeException(e);
+ return response;
}
- return response;
- }
- });
- executor.execute(thread);
+ });
+ executor.execute(thread);
+ }
}
- }
- executor.shutdown();
+ executor.shutdown();
- try {
- executor.awaitTermination(10, TimeUnit.SECONDS);
- } catch (InterruptedException e) {
- LOG.error(e, e);
+ try {
+ executor.awaitTermination(10, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ LOG.error(e, e);
+ }
+ return Utils.envelop(resultado, locale).getValue();
+ } catch (Throwable t) {
+ LOG.error("Unexpected error. Help!", t);
+
+ return null;
}
- return Utils.envelop(resultado, locale).getValue();
}
@@ -215,9 +221,11 @@ else if (request instanceof DirectoryRequestType)
String conn = configuration.get("RoutingConnector", "default");
if (conn.equals("PGROUTING"))
arpt = routingController.routePlan(param);
- else if (conn.equals("MONAV"))
+ else if (conn.equals("MONAV")) {
+ if (monavConnector == null)
+ monavConnector = new MoNaVConnector();
arpt = monavConnector.routePlan(param);
- else {
+ } else {
String host_port = configuration.get("OSRM_HOST",
"localhost:5000");
String http = "http";
@@ -84,8 +84,8 @@ public MoNaVConnector() {
.createUnmarshaller();
context = JAXBContext.newInstance("org.jvnet.ogc.gml.v_3_1_1.jts");
marshaller = context.createMarshaller();
- } catch (JAXBException e) {
- LOG.error(e, e);
+ } catch (Throwable e) {
+ LOG.error("Unable to load MoNaV connector" , e);
}
}

0 comments on commit fe47e8d

Please sign in to comment.