--- /dev/null
+package org.simantics.maps.server.ui;
+
+import java.util.Optional;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.simantics.district.maps.server.TileserverMapnik.TileserverStartListener;
+import org.simantics.district.maps.server.TileserverMapnikInstance;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TileserverMapnikStartJob extends Job {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(TileserverMapnikStartJob.class);
+
+ public TileserverMapnikStartJob() {
+ super("Tileserver start job");
+ }
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ monitor.beginTask("Starting tileserver", 100);
+ try {
+ StartListener startListener = new StartListener(monitor);
+ TileserverMapnikInstance.get().start(Optional.of(startListener));
+ if (startListener.module != null || startListener.returnValue != 0)
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Could not install " + String.valueOf(startListener.module) + " with returnValue " + startListener.returnValue);
+ return Status.OK_STATUS;
+ } catch (Exception e) {
+ LOGGER.error("Could not start tileserver-mapnik", e);
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Could not start tileserver-mapnik: " + e.getMessage());
+ }
+ }
+
+ private class StartListener implements TileserverStartListener {
+
+ private IProgressMonitor monitor;
+ private String module;
+ private int returnValue;
+
+ public StartListener(IProgressMonitor monitor) {
+ this.monitor = monitor;
+ }
+
+ @Override
+ public void installing(String module) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Installing module ");
+ if (module == null)
+ module = "tileserver-mapnik";
+ sb.append(module);
+ monitor.subTask(sb.toString());
+ monitor.worked(30);
+ }
+
+ @Override
+ public void installationFailed(String module, int returnValue) {
+ // set as failed
+ this.module = module;
+ this.returnValue = returnValue;
+ LOGGER.warn("Installation of module {} failed with returnValue ", String.valueOf(module), returnValue);
+ }
+
+ @Override
+ public void started() {
+ monitor.subTask("Finished");
+ monitor.worked(10);
+ monitor.done();
+ if (LOGGER.isDebugEnabled())
+ LOGGER.debug("Tileserver started succesfully");
+ }
+ }
+}