001/* 002 * Copyright 2022-2026 Revetware LLC. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package com.soklet; 018 019import org.jspecify.annotations.NonNull; 020import org.jspecify.annotations.Nullable; 021 022import javax.annotation.concurrent.NotThreadSafe; 023 024import static java.util.Objects.requireNonNull; 025 026/** 027 * Sealed base class for exceptions that carry an immutable lifecycle result. 028 * Exception instances retain {@link Throwable}'s mutable state and are not 029 * thread-safe; their {@link ShutdownResult} values remain immutable. 030 * <p> 031 * This type may gain reviewed permitted subtypes in Soklet 4.x; use a forward-compatible default when switching over its values. 032 * 033 */ 034@NotThreadSafe 035public abstract sealed class SokletLifecycleException extends RuntimeException 036 permits SokletShutdownCleanupException, 037 SokletShutdownIncompleteException, SokletStartupException, 038 SokletUnexpectedTerminationException { 039 @NonNull 040 private final ShutdownResult shutdownResult; 041 042 SokletLifecycleException(@NonNull String message, 043 @NonNull ShutdownResult shutdownResult) { 044 super(requireNonNull(message)); 045 this.shutdownResult = requireNonNull(shutdownResult); 046 } 047 048 SokletLifecycleException(@NonNull String message, 049 @NonNull ShutdownResult shutdownResult, 050 @Nullable Throwable cause) { 051 super(requireNonNull(message), cause); 052 this.shutdownResult = requireNonNull(shutdownResult); 053 } 054 055 /** @return the exact immutable result for the failed lifecycle attempt */ 056 @NonNull 057 public ShutdownResult getShutdownResult() { 058 return this.shutdownResult; 059 } 060 061 @NonNull 062 InternalShutdownResult getInternalShutdownResult() { 063 return this.shutdownResult.internalResult(); 064 } 065}