Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.

Commit 7f322de

Browse files
committed
Reload charts in mapcache on restart of server
1 parent 16a5615 commit 7f322de

File tree

4 files changed

+55
-8
lines changed

4 files changed

+55
-8
lines changed

pom.xml

+14-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<jetty.version>8.1.16.v20140903</jetty.version>
1515
<!-- <jetty.version>9.2.9.v20150224</jetty.version> -->
1616

17-
<camel.version>2.15.2</camel.version>
18-
<camel.core.version>2.15.2</camel.core.version>
17+
<camel.version>2.15.6</camel.version>
18+
<camel.core.version>2.15.6</camel.core.version>
1919
<jna.version>4.0.0</jna.version>
2020
<apollo.version>1.7.1</apollo.version>
2121
<activemq.version>5.11.1</activemq.version>
@@ -262,6 +262,12 @@
262262
<groupId>org.apache.camel</groupId>
263263
<artifactId>camel-ahc-ws</artifactId>
264264
<version>${camel.version}</version>
265+
<exclusions>
266+
<exclusion>
267+
<artifactId>netty</artifactId>
268+
<groupId>io.netty</groupId>
269+
</exclusion>
270+
</exclusions>
265271
</dependency>
266272
<dependency>
267273
<groupId>org.apache.camel</groupId>
@@ -417,6 +423,12 @@
417423
<artifactId>async-http-client</artifactId>
418424
<version>1.8.14</version>
419425
<scope>test</scope>
426+
<!-- <exclusions> -->
427+
<!-- <exclusion> -->
428+
<!-- <artifactId>netty</artifactId> -->
429+
<!-- <groupId>io.netty</groupId> -->
430+
<!-- </exclusion> -->
431+
<!-- </exclusions> -->
420432
</dependency>
421433
<dependency>
422434
<groupId>org.fusesource.mqtt-client</groupId>

src/main/java/nz/co/fortytwo/signalk/processor/UploadProcessor.java

+15-3
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,24 @@ private void install(Path destination) throws Exception {
159159
ZipUtils.unzip(destDir, zipFile);
160160
logger.debug("Unzipped file:"+destDir);
161161
//now add a reference in resources
162-
162+
loadChart(f);
163+
}catch(Exception e){
164+
logger.error(e.getMessage(),e);
165+
throw e;
166+
}
167+
}
168+
169+
public void loadChart(String chartName) throws Exception{
170+
try{
171+
File destDir = new File(Util.getConfigProperty(STATIC_DIR)+Util.getConfigProperty(MAP_DIR)+chartName);
163172
SAXReader reader = new SAXReader();
164173
Document document = reader.read(new File(destDir, "tilemapresource.xml"));
165174

166175
String title = document.getRootElement().element("Title").getText();
167-
String scale = document.getRootElement().element("Metadata").attribute("scale").getText();
176+
String scale = "250000";
177+
if(document.getRootElement().element("Metadata")!=null){
178+
scale = document.getRootElement().element("Metadata").attribute("scale").getText();
179+
}
168180
double maxRes = 0.0;
169181
double minRes = Double.MAX_VALUE;
170182
int maxZoom = 0;
@@ -180,7 +192,7 @@ private void install(Path destination) throws Exception {
180192
minRes=Math.min(units, minRes);
181193
}
182194
//now make an entry in resources
183-
Json resource = createChartMsg(f, title, scale);
195+
Json resource = createChartMsg(chartName, title, scale);
184196
inProducer.asyncSendBody(inProducer.getDefaultEndpoint(),resource);
185197
}catch(Exception e){
186198
logger.error(e.getMessage(),e);

src/main/java/nz/co/fortytwo/signalk/server/RouteManager.java

+25-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
*/
2424
package nz.co.fortytwo.signalk.server;
2525

26+
import static nz.co.fortytwo.signalk.util.ConfigConstants.MAP_DIR;
2627
import static nz.co.fortytwo.signalk.util.ConfigConstants.OUTPUT_XMPP;
28+
import static nz.co.fortytwo.signalk.util.ConfigConstants.STATIC_DIR;
2729
import static nz.co.fortytwo.signalk.util.SignalKConstants.DEMO;
2830
//import static nz.co.fortytwo.signalk.util.ConfigConstants.UUID;
2931
import static nz.co.fortytwo.signalk.util.SignalKConstants.FORMAT_DELTA;
@@ -77,6 +79,7 @@
7779
import mjson.Json;
7880
import nz.co.fortytwo.signalk.model.SignalKModel;
7981
import nz.co.fortytwo.signalk.model.impl.SignalKModelFactory;
82+
import nz.co.fortytwo.signalk.processor.UploadProcessor;
8083
import nz.co.fortytwo.signalk.util.ConfigConstants;
8184
import nz.co.fortytwo.signalk.util.Util;
8285

@@ -350,10 +353,10 @@ public void configure0() throws Exception {
350353
//start any clients if they exist
351354
//WS
352355
Json wsClients = Util.getConfigJsonArray(ConfigConstants.CLIENT_WS);
353-
logger.info(" Starting WS connection to url:"+wsClients);
356+
logger.info(" WS client connections : "+wsClients);
354357
if(wsClients!=null){
355358
for(Object client: wsClients.asList()){
356-
logger.info(" Starting WS connection to url:ahc-ws://"+client);
359+
logger.info(" Starting WS client connection to url:ahc-ws://"+client);
357360
WsEndpoint wsEndpoint = (WsEndpoint)getContext().getEndpoint("ahc-ws://"+client);
358361
setupClient("ahc-ws://"+client,client.toString(),"ws");
359362
wsEndpoint.connect();
@@ -410,6 +413,9 @@ public void configure0() throws Exception {
410413
}
411414
}
412415
}
416+
//reload charts into resources
417+
reloadCharts();
418+
413419
//restart support
414420
from(JETTY_HTTP_0_0_0_0 + restPort + SIGNALK_RESTART).id("Restart route")
415421
.setExchangePattern(ExchangePattern.InOut)
@@ -448,6 +454,23 @@ public void configure0() throws Exception {
448454
}
449455
}
450456

457+
private void reloadCharts() {
458+
File mapDir = new File(Util.getConfigProperty(STATIC_DIR)+Util.getConfigProperty(MAP_DIR));
459+
logger.debug("Reloading charts from: "+mapDir.getAbsolutePath());
460+
UploadProcessor processor = new UploadProcessor();
461+
for(File chart:mapDir.listFiles()){
462+
if(chart.isDirectory()){
463+
logger.debug("Reloading: "+chart.getName());
464+
try {
465+
processor.loadChart(chart.getName());
466+
} catch (Exception e) {
467+
logger.warn(e.getMessage());
468+
}
469+
}
470+
}
471+
472+
}
473+
451474
private void setupClient(String endpoint, String client, String serviceName) {
452475
setupClient(getContext().getEndpoint(endpoint), client, serviceName);
453476
}

src/test/java/nz/co/fortytwo/signalk/server/SubcribeWsTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public void shouldGetSubscribeWsResponse() throws Exception {
105105
latch2.await(3, TimeUnit.SECONDS);
106106
//await messages
107107
String restUrl = json.at("endpoints").at("v1").at(websocketUrl).asString();
108-
logger.debug("Open websocket at :"+restUrl);
108+
logger.debug("Open websocket at: "+restUrl);
109109
WebSocket websocket = c.prepareGet(restUrl).setCookies(r1.getCookies()).execute(
110110
new WebSocketUpgradeHandler.Builder()
111111
.addWebSocketListener(new DefaultWebSocketListener() {

0 commit comments

Comments
 (0)