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; 020 021import javax.annotation.concurrent.NotThreadSafe; 022 023import static java.util.Objects.requireNonNull; 024 025/** 026 * Indicates that a transport lifecycle graph is already owned by another 027 * Soklet lifecycle. Ownership is committed by reference identity and is not 028 * released when that lifecycle terminates; construct a fresh transport graph 029 * with a fresh {@link TransportIdentity} for each generation. 030 * 031 * @author <a href="https://www.revetkn.com">Mark Allen</a> 032 */ 033@NotThreadSafe 034public final class TransportOwnershipException extends IllegalStateException { 035 @NonNull 036 private final ShutdownComponentType shutdownComponentType; 037 @NonNull 038 private final Class<?> transportClass; 039 040 TransportOwnershipException( 041 @NonNull InternalLifecycleComponentType shutdownComponentType, 042 @NonNull Class<?> transportClass) { 043 this(ShutdownComponentType.valueOf( 044 requireNonNull(shutdownComponentType).name()), 045 transportClass); 046 } 047 048 TransportOwnershipException( 049 @NonNull ShutdownComponentType shutdownComponentType, 050 @NonNull Class<?> transportClass) { 051 super("The " + requireNonNull(shutdownComponentType) 052 + " transport identity for " 053 + requireNonNull(transportClass).getName() 054 + " is already owned by another lifecycle"); 055 this.shutdownComponentType = shutdownComponentType; 056 this.transportClass = transportClass; 057 } 058 059 /** @return the type of shutdown component whose identity is already owned */ 060 @NonNull 061 public ShutdownComponentType getShutdownComponentType() { 062 return this.shutdownComponentType; 063 } 064 065 /** @return the configured transport implementation class */ 066 @NonNull 067 public Class<?> getTransportClass() { 068 return this.transportClass; 069 } 070}