001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.rest.server;
018
019import static java.lang.annotation.ElementType.*;
020import static java.lang.annotation.RetentionPolicy.*;
021
022import java.lang.annotation.*;
023
024import jakarta.servlet.*;
025
026/**
027 * Identifies a method that gets called during servlet destroy.
028 *
029 * <p>
030 * This method is called from within the {@link Servlet#destroy()}.
031 *
032 * <p>
033 * The only valid parameter type for this method is {@link RestContext}, although typically no arguments will
034 * be specified.
035 *
036 * <h5 class='figure'>Example:</h5>
037 * <p class='bjava'>
038 *    <ja>@Rest</ja>(...)
039 *    <jk>public class</jk> PetStoreResource <jk>extends</jk> BasicRestServlet <jk>implements</jk> BasicUniversalJenaConfig {
040 *
041 *       <jc>// Our database.</jc>
042 *       <jk>private</jk> Map&lt;Integer,Pet&gt; <jf>petDB</jf>;
043 *
044 *       <ja>@RestDestroy</ja>
045 *       <jk>public void</jk> onDestroy() {
046 *          <jf>petDB</jf> = <jk>null</jk>;
047 *       }
048 *    }
049 * </p>
050 *
051 * <h5 class='section'>Notes:</h5><ul>
052 *    <li class='note'>
053 *       The method should return <jk>void</jk> although if it does return any value, the value will be ignored.
054 *    <li class='note'>
055 *       The method should be <jk>public</jk> although other visibilities are valid if the security manager allows it.
056 *    <li class='note'>
057 *       Static methods can be used.
058 *    <li class='note'>
059 *       Multiple destroy methods can be defined on a class.
060 *       <br>Destroy methods on child classes are invoked before destroy methods on parent classes.
061 *       <br>The order of destroy method invocations within a class is alphabetical, then by parameter count, then by parameter types.
062 *    <li class='note'>
063 *       In general, destroy methods should not throw any exceptions, although if any are thrown, the stack trace will be
064 *       printed to <c>System.err</c>.
065 *    <li class='note'>
066 *       Note that if you override a parent method, you probably need to call <code><jk>super</jk>.parentMethod(...)</code>.
067 *       <br>The method is still considered part of the parent class for ordering purposes even though it's
068 *       overridden by the child class.
069 * </ul>
070 *
071 * <h5 class='section'>See Also:</h5><ul>
072 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/LifecycleHooks">Lifecycle Hooks</a>
073 * </ul>
074 */
075@Target({ METHOD })
076@Retention(RUNTIME)
077@Inherited
078public @interface RestDestroy {
079
080   /**
081    * Optional description for the exposed API.
082    *
083    * @return The annotation value.
084    * @since 9.2.0
085    */
086   String[] description() default {};
087}