001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.microservice.resources;
014
015import org.apache.juneau.rest.annotation.*;
016import org.apache.juneau.rest.servlet.*;
017
018/**
019 * Provides the capability to shut down this REST microservice through a REST call.
020 *
021 * <h5 class='section'>See Also:</h5><ul>
022 *    <li class='link'><a class="doclink" href="../../../../../index.html#juneau-microservice-core">juneau-microservice-core</a>
023 * </ul>
024 *
025 * @serial exclude
026 */
027@Rest(
028   path="/shutdown",
029   title="Shut down this resource"
030)
031public class ShutdownResource extends BasicRestServlet {
032
033   private static final long serialVersionUID = 1L;
034
035   /**
036    * [GET /] - Shutdown this resource.
037    *
038    * @return The string <js>"OK"</js>.
039    */
040   @RestGet(path="/", description="Show contents of config file.")
041   public String shutdown() {
042      new Thread(
043         new Runnable() {
044            @Override /* Runnable */
045            public void run() {
046               try {
047                  Thread.sleep(1000);
048                  System.exit(0);
049               } catch (InterruptedException e) {
050                  e.printStackTrace();
051               }
052            }
053         }
054      ).start();
055      return "OK";
056   }
057}