1717package com .esri .samples .localserver .local_server_services ;
1818
1919import java .io .File ;
20+ import java .io .IOException ;
21+ import java .nio .file .Files ;
22+ import java .nio .file .Path ;
2023
2124import javafx .application .HostServices ;
2225import javafx .application .Platform ;
3134import javafx .scene .control .TextField ;
3235import javafx .stage .FileChooser ;
3336import javafx .stage .FileChooser .ExtensionFilter ;
37+ import org .apache .commons .io .FileUtils ;
3438
3539import com .esri .arcgisruntime .localserver .LocalFeatureService ;
3640import com .esri .arcgisruntime .localserver .LocalGeoprocessingService ;
@@ -50,12 +54,25 @@ public class LocalServerServicesController {
5054
5155 private HostServices hostServices ;
5256 private FileChooser packageChooser ;
57+ private Path appDataPath ;
5358
5459 @ FXML
5560 private void initialize () {
5661
5762 if (LocalServer .INSTANCE .checkInstallValid ()) {
5863 LocalServer server = LocalServer .INSTANCE ;
64+
65+ // configure app data path (path length must be short for some services)
66+ appDataPath = Path .of (System .getProperty ("user.home" ), "EsriSamples" );
67+ if (!appDataPath .toFile ().exists ()) {
68+ try {
69+ Files .createDirectory (appDataPath );
70+ } catch (IOException ex ) {
71+ new Alert (AlertType .ERROR , "Failed to set local server app data path. Some processes may not work." ).show ();
72+ }
73+ }
74+ LocalServer .INSTANCE .setAppDataPath (appDataPath .toFile ().getAbsolutePath ());
75+
5976 // log the server status
6077 server .addStatusChangedListener (status -> statusLog .appendText ("Server Status: " + status .getNewStatus ()
6178 .toString () + "\n " ));
@@ -87,17 +104,15 @@ private void initialize() {
87104 serviceOptions .getSelectionModel ().selectedItemProperty ().addListener (o -> {
88105 packageChooser .setInitialFileName (null );
89106 packageChooser .getExtensionFilters ().clear ();
90- switch (serviceOptions .getSelectionModel ().getSelectedItem ()) {
91- case "Geoprocessing Service" :
92- packageChooser .getExtensionFilters ().add (gpkFilter );
93- break ;
94- default :
95- packageChooser .getExtensionFilters ().add (mpkFilter );
107+ if ("Geoprocessing Service" .equals (serviceOptions .getSelectionModel ().getSelectedItem ())) {
108+ packageChooser .getExtensionFilters ().add (gpkFilter );
109+ } else {
110+ packageChooser .getExtensionFilters ().add (mpkFilter );
96111 }
97112 });
98113
99114 // create list view representation of running services
100- runningServices .setCellFactory (list -> new ListCell <LocalService >() {
115+ runningServices .setCellFactory (list -> new ListCell <>() {
101116
102117 @ Override
103118 protected void updateItem (LocalService service , boolean bln ) {
@@ -196,4 +211,22 @@ void setHostServices(HostServices hostServices) {
196211
197212 this .hostServices = hostServices ;
198213 }
214+
215+ /**
216+ * Stops and releases all resources used in application.
217+ */
218+ void terminate () {
219+
220+ // make sure all services are stopped before deleting app data
221+ LocalServer .INSTANCE .stopAsync ().addDoneListener (() -> {
222+ if (appDataPath != null ) {
223+ try {
224+ // delete the app data
225+ FileUtils .deleteDirectory (appDataPath .toFile ());
226+ } catch (IOException ex ) {
227+ ex .printStackTrace ();
228+ }
229+ }
230+ });
231+ }
199232}
0 commit comments