ArcGIS Runtime SDK for Java

Local Server Services

Demonstrates how to start and stop a map, feature, and geoprocessing services on the Local Server.

Note: Local Server is not supported on MacOS

How it works

To start a LocalServer and start a LocalService to it:

  1. Create and run a local server.

    • LocalServer.INSTANCE creates a local server
    • Server.startAsync() starts the server asynchronously

  2. Wait for server to be in the LocalServerStatus.STARTED state.

    • Server.addStatusChangedListener() fires whenever the running status of the local server has changed.

  3. Create and run a local service, example of running aLocalMapService.

    • new LocalMapService(Url), creates a local map service with the given url path to mpk file
    • Service.startAsync(), starts the service asynchronously
    • service will be added to the local server automatically

To stop a LocalServer and stop any LocalServices that are added to it:

  1. Get any services that are currently running on the local server, Server.getServices().
  2. Loop through all services and stop any that are currently started.

    • check service is started, Service.getStatus()equals LocalServerStatus.STARTED
    • Service.stopAsync(), stops the service asynchronously

  3. Wait for all services to be in the LocalServerStatus.STOPPED state.

    • Service.addStatusChangedListener() fires whenever the running status of the local service has changed.

  4. Stop the local server, Server.stopAsync().

Code

/*
 * Copyright 2017 Esri.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.esri.samples.localserver.local_server_services;

import java.io.IOException;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class LocalServerServicesSample extends Application {

  @Override
  public void start(Stage stage) throws IOException {
    // set up the scene
    FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/local_server_services.fxml"));
    Parent root = loader.load();
    LocalServerServicesController controller = loader.getController();
    controller.setHostServices(getHostServices());
    Scene scene = new Scene(root);

    // set up the stage
    stage.setTitle("Local Server Services Sample");
    stage.setWidth(800);
    stage.setHeight(400);
    stage.setScene(scene);
    stage.show();
  }

  /**
   * Opens and runs application.
   *
   * @param args arguments passed to this application
   */
  public static void main(String[] args) {

    Application.launch(args);
  }
}


In this topic
  1. How it works
  2. Code