001/* 002 * Copyright 2009-2019 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright (C) 2009-2019 Ping Identity Corporation 007 * 008 * This program is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU General Public License (GPLv2 only) 010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 011 * as published by the Free Software Foundation. 012 * 013 * This program is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU General Public License for more details. 017 * 018 * You should have received a copy of the GNU General Public License 019 * along with this program; if not, see <http://www.gnu.org/licenses>. 020 */ 021package com.unboundid.util; 022 023 024 025/** 026 * This enumeration defines a set of thread safety levels that may be used to 027 * indicate whether the associated code is safe to be accessed concurrently 028 * by multiple threads. 029 */ 030public enum ThreadSafetyLevel 031{ 032 /** 033 * The associated code is completely threadsafe and may be accessed 034 * concurrently by any number of threads, subject to the constraints described 035 * in the {@link ThreadSafety} documentation. 036 */ 037 COMPLETELY_THREADSAFE, 038 039 040 041 /** 042 * The associated code is mostly threadsafe, but there may be some methods 043 * which are not safe to be invoked when multiple threads are accessing an 044 * instance concurrently. The class-level documentation for a class including 045 * this thread safety level should include comments indicating which methods 046 * are not threadsafe, and those methods should also be marked with their own 047 * {@code ThreadSafety} annotations using the {@link #METHOD_NOT_THREADSAFE} 048 * level. 049 */ 050 MOSTLY_THREADSAFE, 051 052 053 054 /** 055 * The associated code is mostly not threadsafe, but there may be some methods 056 * which are safe to be invoked concurrently by multiple threads. The 057 * class-level documentation for a class including this thread safety level 058 * should include comments indicating which methods are threadsafe, and those 059 * methods should also be marked with their own {@code ThreadSafety} 060 * annotations using the {@link #METHOD_THREADSAFE} level. 061 */ 062 MOSTLY_NOT_THREADSAFE, 063 064 065 066 /** 067 * The associated code is not threadsafe. Unless otherwise noted, multiple 068 * threads may not attempt to invoke methods on the same instance of objects 069 * of this type without external synchronization. 070 */ 071 NOT_THREADSAFE, 072 073 074 075 /** 076 * Methods declared in the associated interface or abstract class must be 077 * threadsafe in classes which implement that interface or extend that 078 * abstract class. No guarantees will be made about the thread safety of 079 * other methods contained in that class which are not declared in the parent 080 * interface or superclass. 081 */ 082 INTERFACE_THREADSAFE, 083 084 085 086 /** 087 * Methods declared in the associated interface or abstract class are not 088 * required to be threadsafe and classes which call them must not rely on the 089 * ability to concurrently invoke those methods on the same object instance 090 * without any external synchronization. 091 */ 092 INTERFACE_NOT_THREADSAFE, 093 094 095 096 /** 097 * The associated method may be considered threadsafe and may be invoked 098 * concurrently by multiple threads, subject to the constraints described in 099 * the {@link ThreadSafety} documentation, and in any additional notes 100 * contained in the method-level javadoc. 101 */ 102 METHOD_THREADSAFE, 103 104 105 106 /** 107 * The associated method may not be considered threadsafe and should not be 108 * invoked concurrently by multiple threads. 109 */ 110 METHOD_NOT_THREADSAFE; 111 112 113 114 /** 115 * Retrieves the thread safety level with the specified name. 116 * 117 * @param name The name of the thread safety level to retrieve. It must not 118 * be {@code null}. 119 * 120 * @return The requested thread safety level, or {@code null} if no such 121 * level is defined. 122 */ 123 public static ThreadSafetyLevel forName(final String name) 124 { 125 switch (StaticUtils.toLowerCase(name)) 126 { 127 case "completelythreadsafe": 128 case "completely-threadsafe": 129 case "completely_threadsafe": 130 return COMPLETELY_THREADSAFE; 131 case "mostlythreadsafe": 132 case "mostly-threadsafe": 133 case "mostly_threadsafe": 134 return MOSTLY_THREADSAFE; 135 case "mostlynotthreadsafe": 136 case "mostly-not-threadsafe": 137 case "mostly_not_threadsafe": 138 return MOSTLY_NOT_THREADSAFE; 139 case "notthreadsafe": 140 case "not-threadsafe": 141 case "not_threadsafe": 142 return NOT_THREADSAFE; 143 case "interfacethreadsafe": 144 case "interface-threadsafe": 145 case "interface_threadsafe": 146 return INTERFACE_THREADSAFE; 147 case "interfacenotthreadsafe": 148 case "interface-not-threadsafe": 149 case "interface_not_threadsafe": 150 return INTERFACE_NOT_THREADSAFE; 151 case "methodthreadsafe": 152 case "method-threadsafe": 153 case "method_threadsafe": 154 return METHOD_THREADSAFE; 155 case "methodnotthreadsafe": 156 case "method-not-threadsafe": 157 case "method_not_threadsafe": 158 return METHOD_NOT_THREADSAFE; 159 default: 160 return null; 161 } 162 } 163}