Advertisement
ggregory

Apache Commons Lang concurrency annotations

Nov 22nd, 2016
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 15.70 KB | None | 0 0
  1. diff --git a/src/main/java/org/apache/commons/lang3/annotation/concurrent/clazz/GuardedBy.java b/src/main/java/org/apache/commons/lang3/annotation/concurrent/clazz/GuardedBy.java
  2. new file mode 100644
  3. index 0000000..74d3492
  4. --- /dev/null
  5. +++ b/src/main/java/org/apache/commons/lang3/annotation/concurrent/clazz/GuardedBy.java
  6. @@ -0,0 +1,59 @@
  7. +package org.apache.commons.lang3.annotation.concurrent.clazz;
  8. +
  9. +import java.lang.annotation.ElementType;
  10. +import java.lang.annotation.Retention;
  11. +import java.lang.annotation.RetentionPolicy;
  12. +import java.lang.annotation.Target;
  13. +
  14. +/*
  15. + * Copyright (c) 2005 Brian Goetz
  16. + * Released under the Creative Commons Attribution License
  17. + *   (http://creativecommons.org/licenses/by/2.5)
  18. + * Official home: http://www.jcip.net
  19. + */
  20. +
  21. +/**
  22. + * GuardedBy
  23. + *
  24. + * The field or method to which this annotation is applied can only be accessed
  25. + * when holding a particular lock, which may be a built-in (synchronization)
  26. + * lock, or may be an explicit java.util.concurrent.Lock.
  27. + *
  28. + * The argument determines which lock guards the annotated field or method: this
  29. + * : The string literal "this" means that this field is guarded by the class in
  30. + * which it is defined. class-name.this : For inner classes, it may be necessary
  31. + * to disambiguate 'this'; the class-name.this designation allows you to specify
  32. + * which 'this' reference is intended itself : For reference fields only; the
  33. + * object to which the field refers. field-name : The lock object is referenced
  34. + * by the (instance or static) field specified by field-name.
  35. + * class-name.field-name : The lock object is reference by the static field
  36. + * specified by class-name.field-name. method-name() : The lock object is
  37. + * returned by calling the named nil-ary method. class-name.class : The Class
  38. + * object for the specified class should be used as the lock object.
  39. + */
  40. +@Target({ ElementType.FIELD, ElementType.METHOD })
  41. +@Retention(RetentionPolicy.CLASS)
  42. +public @interface GuardedBy {
  43. +
  44. +    /**
  45. +     * The field or method to which this annotation is applied can only be
  46. +     * accessed when holding a particular lock, which may be a built-in
  47. +     * (synchronization) lock, or may be an explicit java.util.concurrent.Lock.
  48. +     *
  49. +     * The argument determines which lock guards the annotated field or method:
  50. +     * this : The string literal "this" means that this field is guarded by the
  51. +     * class in which it is defined. class-name.this : For inner classes, it may
  52. +     * be necessary to disambiguate 'this'; the class-name.this designation
  53. +     * allows you to specify which 'this' reference is intended itself : For
  54. +     * reference fields only; the object to which the field refers. field-name :
  55. +     * The lock object is referenced by the (instance or static) field specified
  56. +     * by field-name. class-name.field-name : The lock object is reference by
  57. +     * the static field specified by class-name.field-name. method-name() : The
  58. +     * lock object is returned by calling the named nil-ary method.
  59. +     * class-name.class : The Class object for the specified class should be
  60. +     * used as the lock object.
  61. +     *
  62. +     * @return see description
  63. +     */
  64. +    String value();
  65. +}
  66. diff --git a/src/main/java/org/apache/commons/lang3/annotation/concurrent/clazz/Immutable.java b/src/main/java/org/apache/commons/lang3/annotation/concurrent/clazz/Immutable.java
  67. new file mode 100644
  68. index 0000000..129d7fb
  69. --- /dev/null
  70. +++ b/src/main/java/org/apache/commons/lang3/annotation/concurrent/clazz/Immutable.java
  71. @@ -0,0 +1,38 @@
  72. +package org.apache.commons.lang3.annotation.concurrent.clazz;
  73. +
  74. +
  75. +import java.lang.annotation.Documented;
  76. +import java.lang.annotation.ElementType;
  77. +import java.lang.annotation.Retention;
  78. +import java.lang.annotation.RetentionPolicy;
  79. +import java.lang.annotation.Target;
  80. +
  81. +/*
  82. + * Copyright (c) 2005 Brian Goetz
  83. + * Released under the Creative Commons Attribution License
  84. + *   (http://creativecommons.org/licenses/by/2.5)
  85. + * Official home: http://www.jcip.net
  86. + */
  87. +
  88. +/**
  89. + * Immutable
  90. + *
  91. + * The class to which this annotation is applied is immutable. This means that
  92. + * its state cannot be seen to change by callers. Of necessity this means that
  93. + * all public fields are final, and that all public final reference fields refer
  94. + * to other immutable objects, and that methods do not publish references to any
  95. + * internal state which is mutable by implementation even if not by design.
  96. + * Immutable objects may still have internal mutable state for purposes of
  97. + * performance optimization; some state variables may be lazily computed, so
  98. + * long as they are computed from immutable state and that callers cannot tell
  99. + * the difference.
  100. + *
  101. + * Immutable objects are inherently thread-safe; they may be passed between
  102. + * threads or published without synchronization.
  103. + */
  104. +@Documented
  105. +@Target(ElementType.TYPE)
  106. +@Retention(RetentionPolicy.CLASS)
  107. +public @interface Immutable {
  108. +    // marker annotation, empty body
  109. +}
  110. diff --git a/src/main/java/org/apache/commons/lang3/annotation/concurrent/clazz/NotThreadSafe.java b/src/main/java/org/apache/commons/lang3/annotation/concurrent/clazz/NotThreadSafe.java
  111. new file mode 100644
  112. index 0000000..26552af
  113. --- /dev/null
  114. +++ b/src/main/java/org/apache/commons/lang3/annotation/concurrent/clazz/NotThreadSafe.java
  115. @@ -0,0 +1,31 @@
  116. +package org.apache.commons.lang3.annotation.concurrent.clazz;
  117. +
  118. +import java.lang.annotation.Documented;
  119. +import java.lang.annotation.ElementType;
  120. +import java.lang.annotation.Retention;
  121. +import java.lang.annotation.RetentionPolicy;
  122. +import java.lang.annotation.Target;
  123. +
  124. +/*
  125. + * Copyright (c) 2005 Brian Goetz
  126. + * Released under the Creative Commons Attribution License
  127. + *   (http://creativecommons.org/licenses/by/2.5)
  128. + * Official home: http://www.jcip.net
  129. + */
  130. +
  131. +/**
  132. + * NotThreadSafe
  133. + *
  134. + * The class to which this annotation is applied is not thread-safe. This
  135. + * annotation primarily exists for clarifying the non-thread-safety of a class
  136. + * that might otherwise be assumed to be thread-safe, despite the fact that it
  137. + * is a bad idea to assume a class is thread-safe without good reason.
  138. + *
  139. + * @see ThreadSafe
  140. + */
  141. +@Documented
  142. +@Target(ElementType.TYPE)
  143. +@Retention(RetentionPolicy.CLASS)
  144. +public @interface NotThreadSafe {
  145. +    // marker annotation, empty body
  146. +}
  147. diff --git a/src/main/java/org/apache/commons/lang3/annotation/concurrent/clazz/ThreadSafe.java b/src/main/java/org/apache/commons/lang3/annotation/concurrent/clazz/ThreadSafe.java
  148. new file mode 100644
  149. index 0000000..f0f0ef4
  150. --- /dev/null
  151. +++ b/src/main/java/org/apache/commons/lang3/annotation/concurrent/clazz/ThreadSafe.java
  152. @@ -0,0 +1,31 @@
  153. +package org.apache.commons.lang3.annotation.concurrent.clazz;
  154. +
  155. +import java.lang.annotation.Documented;
  156. +import java.lang.annotation.ElementType;
  157. +import java.lang.annotation.Retention;
  158. +import java.lang.annotation.RetentionPolicy;
  159. +import java.lang.annotation.Target;
  160. +
  161. +/*
  162. + * Copyright (c) 2005 Brian Goetz and Tim Peierls
  163. + * Released under the Creative Commons Attribution License
  164. + *   (http://creativecommons.org/licenses/by/2.5)
  165. + * Official home: http://www.jcip.net
  166. + *
  167. + * Any republication or derived work distributed in source code form
  168. + * must include this copyright and license notice.
  169. + */
  170. +
  171. +/**
  172. + * The class to which this annotation is applied is thread-safe.  This means that
  173. + * no sequences of accesses (reads and writes to public fields, calls to public methods)
  174. + * may put the object into an invalid state, regardless of the interleaving of those actions
  175. + * by the runtime, and without requiring any additional synchronization or coordination on the
  176. + * part of the caller.
  177. + */
  178. +@Documented
  179. +@Target(ElementType.TYPE)
  180. +@Retention(RetentionPolicy.CLASS)
  181. +public @interface ThreadSafe {
  182. +    // marker annotation, empty body
  183. +}
  184. diff --git a/src/main/java/org/apache/commons/lang3/annotation/concurrent/runtime/GuardedBy.java b/src/main/java/org/apache/commons/lang3/annotation/concurrent/runtime/GuardedBy.java
  185. new file mode 100644
  186. index 0000000..41a90ac
  187. --- /dev/null
  188. +++ b/src/main/java/org/apache/commons/lang3/annotation/concurrent/runtime/GuardedBy.java
  189. @@ -0,0 +1,59 @@
  190. +package org.apache.commons.lang3.annotation.concurrent.runtime;
  191. +
  192. +import java.lang.annotation.ElementType;
  193. +import java.lang.annotation.Retention;
  194. +import java.lang.annotation.RetentionPolicy;
  195. +import java.lang.annotation.Target;
  196. +
  197. +/*
  198. + * Copyright (c) 2005 Brian Goetz
  199. + * Released under the Creative Commons Attribution License
  200. + *   (http://creativecommons.org/licenses/by/2.5)
  201. + * Official home: http://www.jcip.net
  202. + */
  203. +
  204. +/**
  205. + * GuardedBy
  206. + *
  207. + * The field or method to which this annotation is applied can only be accessed
  208. + * when holding a particular lock, which may be a built-in (synchronization)
  209. + * lock, or may be an explicit java.util.concurrent.Lock.
  210. + *
  211. + * The argument determines which lock guards the annotated field or method: this
  212. + * : The string literal "this" means that this field is guarded by the class in
  213. + * which it is defined. class-name.this : For inner classes, it may be necessary
  214. + * to disambiguate 'this'; the class-name.this designation allows you to specify
  215. + * which 'this' reference is intended itself : For reference fields only; the
  216. + * object to which the field refers. field-name : The lock object is referenced
  217. + * by the (instance or static) field specified by field-name.
  218. + * class-name.field-name : The lock object is reference by the static field
  219. + * specified by class-name.field-name. method-name() : The lock object is
  220. + * returned by calling the named nil-ary method. class-name.class : The Class
  221. + * object for the specified class should be used as the lock object.
  222. + */
  223. +@Target({ ElementType.FIELD, ElementType.METHOD })
  224. +@Retention(RetentionPolicy.RUNTIME)
  225. +public @interface GuardedBy {
  226. +
  227. +    /**
  228. +     * The field or method to which this annotation is applied can only be
  229. +     * accessed when holding a particular lock, which may be a built-in
  230. +     * (synchronization) lock, or may be an explicit java.util.concurrent.Lock.
  231. +     *
  232. +     * The argument determines which lock guards the annotated field or method:
  233. +     * this : The string literal "this" means that this field is guarded by the
  234. +     * class in which it is defined. class-name.this : For inner classes, it may
  235. +     * be necessary to disambiguate 'this'; the class-name.this designation
  236. +     * allows you to specify which 'this' reference is intended itself : For
  237. +     * reference fields only; the object to which the field refers. field-name :
  238. +     * The lock object is referenced by the (instance or static) field specified
  239. +     * by field-name. class-name.field-name : The lock object is reference by
  240. +     * the static field specified by class-name.field-name. method-name() : The
  241. +     * lock object is returned by calling the named nil-ary method.
  242. +     * class-name.class : The Class object for the specified class should be
  243. +     * used as the lock object.
  244. +     *
  245. +     * @return see description
  246. +     */
  247. +    String value();
  248. +}
  249. diff --git a/src/main/java/org/apache/commons/lang3/annotation/concurrent/runtime/Immutable.java b/src/main/java/org/apache/commons/lang3/annotation/concurrent/runtime/Immutable.java
  250. new file mode 100644
  251. index 0000000..74b89e7
  252. --- /dev/null
  253. +++ b/src/main/java/org/apache/commons/lang3/annotation/concurrent/runtime/Immutable.java
  254. @@ -0,0 +1,38 @@
  255. +package org.apache.commons.lang3.annotation.concurrent.runtime;
  256. +
  257. +
  258. +import java.lang.annotation.Documented;
  259. +import java.lang.annotation.ElementType;
  260. +import java.lang.annotation.Retention;
  261. +import java.lang.annotation.RetentionPolicy;
  262. +import java.lang.annotation.Target;
  263. +
  264. +/*
  265. + * Copyright (c) 2005 Brian Goetz
  266. + * Released under the Creative Commons Attribution License
  267. + *   (http://creativecommons.org/licenses/by/2.5)
  268. + * Official home: http://www.jcip.net
  269. + */
  270. +
  271. +/**
  272. + * Immutable
  273. + *
  274. + * The class to which this annotation is applied is immutable. This means that
  275. + * its state cannot be seen to change by callers. Of necessity this means that
  276. + * all public fields are final, and that all public final reference fields refer
  277. + * to other immutable objects, and that methods do not publish references to any
  278. + * internal state which is mutable by implementation even if not by design.
  279. + * Immutable objects may still have internal mutable state for purposes of
  280. + * performance optimization; some state variables may be lazily computed, so
  281. + * long as they are computed from immutable state and that callers cannot tell
  282. + * the difference.
  283. + *
  284. + * Immutable objects are inherently thread-safe; they may be passed between
  285. + * threads or published without synchronization.
  286. + */
  287. +@Documented
  288. +@Target(ElementType.TYPE)
  289. +@Retention(RetentionPolicy.RUNTIME)
  290. +public @interface Immutable {
  291. +    // marker annotation, empty body
  292. +}
  293. diff --git a/src/main/java/org/apache/commons/lang3/annotation/concurrent/runtime/NotThreadSafe.java b/src/main/java/org/apache/commons/lang3/annotation/concurrent/runtime/NotThreadSafe.java
  294. new file mode 100644
  295. index 0000000..cc5d018
  296. --- /dev/null
  297. +++ b/src/main/java/org/apache/commons/lang3/annotation/concurrent/runtime/NotThreadSafe.java
  298. @@ -0,0 +1,31 @@
  299. +package org.apache.commons.lang3.annotation.concurrent.runtime;
  300. +
  301. +import java.lang.annotation.Documented;
  302. +import java.lang.annotation.ElementType;
  303. +import java.lang.annotation.Retention;
  304. +import java.lang.annotation.RetentionPolicy;
  305. +import java.lang.annotation.Target;
  306. +
  307. +/*
  308. + * Copyright (c) 2005 Brian Goetz
  309. + * Released under the Creative Commons Attribution License
  310. + *   (http://creativecommons.org/licenses/by/2.5)
  311. + * Official home: http://www.jcip.net
  312. + */
  313. +
  314. +/**
  315. + * NotThreadSafe
  316. + *
  317. + * The class to which this annotation is applied is not thread-safe. This
  318. + * annotation primarily exists for clarifying the non-thread-safety of a class
  319. + * that might otherwise be assumed to be thread-safe, despite the fact that it
  320. + * is a bad idea to assume a class is thread-safe without good reason.
  321. + *
  322. + * @see ThreadSafe
  323. + */
  324. +@Documented
  325. +@Target(ElementType.TYPE)
  326. +@Retention(RetentionPolicy.RUNTIME)
  327. +public @interface NotThreadSafe {
  328. +    // marker annotation, empty body
  329. +}
  330. diff --git a/src/main/java/org/apache/commons/lang3/annotation/concurrent/runtime/ThreadSafe.java b/src/main/java/org/apache/commons/lang3/annotation/concurrent/runtime/ThreadSafe.java
  331. new file mode 100644
  332. index 0000000..927111a
  333. --- /dev/null
  334. +++ b/src/main/java/org/apache/commons/lang3/annotation/concurrent/runtime/ThreadSafe.java
  335. @@ -0,0 +1,31 @@
  336. +package org.apache.commons.lang3.annotation.concurrent.runtime;
  337. +
  338. +import java.lang.annotation.Documented;
  339. +import java.lang.annotation.ElementType;
  340. +import java.lang.annotation.Retention;
  341. +import java.lang.annotation.RetentionPolicy;
  342. +import java.lang.annotation.Target;
  343. +
  344. +/*
  345. + * Copyright (c) 2005 Brian Goetz and Tim Peierls
  346. + * Released under the Creative Commons Attribution License
  347. + *   (http://creativecommons.org/licenses/by/2.5)
  348. + * Official home: http://www.jcip.net
  349. + *
  350. + * Any republication or derived work distributed in source code form
  351. + * must include this copyright and license notice.
  352. + */
  353. +
  354. +/**
  355. + * The class to which this annotation is applied is thread-safe.  This means that
  356. + * no sequences of accesses (reads and writes to public fields, calls to public methods)
  357. + * may put the object into an invalid state, regardless of the interleaving of those actions
  358. + * by the runtime, and without requiring any additional synchronization or coordination on the
  359. + * part of the caller.
  360. + */
  361. +@Documented
  362. +@Target(ElementType.TYPE)
  363. +@Retention(RetentionPolicy.RUNTIME)
  364. +public @interface ThreadSafe {
  365. +    // marker annotation, empty body
  366. +}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement