├── .gitignore ├── LICENSE ├── MANIFEST.MF ├── README.md ├── concurrent-util.iml ├── out └── artifacts │ └── concurrent_util_0_1 │ └── javadoc │ ├── allclasses-frame.html │ ├── allclasses-noframe.html │ ├── com │ └── hybhub │ │ └── util │ │ └── concurrent │ │ ├── AbstractConcurrentSet.html │ │ ├── ConcurrentSetBlockingQueue.html │ │ ├── ConcurrentSetCollection.html │ │ ├── ConcurrentSetQueue.html │ │ ├── SetBlockingQueueMultiThreadTest.html │ │ ├── SetBlockingQueueUnitTest.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ └── package-tree.html │ ├── constant-values.html │ ├── deprecated-list.html │ ├── help-doc.html │ ├── index-files │ ├── index-1.html │ ├── index-10.html │ ├── index-11.html │ ├── index-12.html │ ├── index-2.html │ ├── index-3.html │ ├── index-4.html │ ├── index-5.html │ ├── index-6.html │ ├── index-7.html │ ├── index-8.html │ └── index-9.html │ ├── index.html │ ├── overview-tree.html │ ├── package-list │ ├── script.js │ └── stylesheet.css ├── pom.xml ├── src └── main │ └── java │ └── com │ └── hybhub │ └── util │ └── concurrent │ ├── AbstractConcurrentSet.java │ ├── ConcurrentSetBlockingQueue.java │ ├── ConcurrentSetCollection.java │ └── ConcurrentSetQueue.java └── testsrc └── com └── hybhub └── util └── concurrent ├── ConcurrentSetBlockingQueueMultiThreadTest.java ├── ConcurrentSetBlockingQueueThreadPoolExecutorTest.java ├── ConcurrentSetBlockingQueueUnitTest.java └── ConcurrentSetQueueUnitTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Mobile Tools for Java (J2ME) 4 | .mtj.tmp/ 5 | 6 | # Package Files # 7 | *.jar 8 | *.war 9 | *.ear 10 | 11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 12 | hs_err_pid* 13 | 14 | # Workspace 15 | .DS_Store 16 | .idea/ 17 | target/ 18 | concurrent.iml 19 | pom.xml.releaseBackup 20 | release.properties 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 0.2 2 | Created-By: Hybhub 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # concurrent-unique-queue 2 | A Java concurrent unique queue backed by a Set (LinkedHashSet), for when you need to have a Queue with unique elements. 3 | The ConcurrentSetBlockingQueue will behave the same way if the queue is full or if a duplicate entry already exists in the Queue. 4 | 5 | **Your element needs to have a proper hash and equals implementations !** 6 | 7 | ```xml 8 | 9 | com.hybhub 10 | concurrent-util 11 | 0.3.0 12 | 13 | ``` 14 | 15 | # Usage 16 | 17 | ```java 18 | #ConcurrentSetBlockingQueue implements BlockingQueue 19 | BlockingQueue queue = new ConcurrentSetBlockingQueue<>(); 20 | 21 | queue.offer(1); # True 22 | queue.offer(2); # True 23 | queue.offer(2); # False 24 | ``` -------------------------------------------------------------------------------- /concurrent-util.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | -------------------------------------------------------------------------------- /out/artifacts/concurrent_util_0_1/javadoc/allclasses-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | All Classes 7 | 8 | 9 | 10 | 11 | 12 |

All Classes

13 |
14 | 22 |
23 | 24 | 25 | -------------------------------------------------------------------------------- /out/artifacts/concurrent_util_0_1/javadoc/allclasses-noframe.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | All Classes 7 | 8 | 9 | 10 | 11 | 12 |

All Classes

13 |
14 | 22 |
23 | 24 | 25 | -------------------------------------------------------------------------------- /out/artifacts/concurrent_util_0_1/javadoc/com/hybhub/util/concurrent/SetBlockingQueueMultiThreadTest.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | SetBlockingQueueMultiThreadTest 7 | 8 | 9 | 10 | 11 | 12 | 28 | 31 | 32 |
33 | 34 | 35 | 36 | 37 | 38 | 39 | 47 |
48 | 90 | 91 | 92 |
93 |
com.hybhub.util.concurrent
94 |

Class SetBlockingQueueMultiThreadTest

95 |
96 |
97 | 105 |
106 |
    107 |
  • 108 |
    109 |
    110 |
    public class SetBlockingQueueMultiThreadTest
    111 | extends java.lang.Object
    112 |
  • 113 |
114 |
115 |
116 | 175 |
176 |
177 |
    178 |
  • 179 | 180 |
      181 |
    • 182 | 183 | 184 |

      Constructor Detail

      185 | 186 | 187 | 188 |
        189 |
      • 190 |

        SetBlockingQueueMultiThreadTest

        191 |
        public SetBlockingQueueMultiThreadTest()
        192 |
      • 193 |
      194 |
    • 195 |
    196 | 197 |
      198 |
    • 199 | 200 | 201 |

      Method Detail

      202 | 203 | 204 | 205 |
        206 |
      • 207 |

        testTwoThreadsOfferTake

        208 |
        public void testTwoThreadsOfferTake()
        209 |                              throws java.lang.InterruptedException
        210 |
        211 |
        Throws:
        212 |
        java.lang.InterruptedException
        213 |
        214 |
      • 215 |
      216 | 217 | 218 | 219 |
        220 |
      • 221 |

        testTenThreadsOffer

        222 |
        public void testTenThreadsOffer()
        223 |                          throws java.lang.InterruptedException
        224 |
        225 |
        Throws:
        226 |
        java.lang.InterruptedException
        227 |
        228 |
      • 229 |
      230 | 231 | 232 | 233 |
        234 |
      • 235 |

        testOfferWithTimeout

        236 |
        public void testOfferWithTimeout()
        237 |                           throws java.lang.InterruptedException
        238 |
        239 |
        Throws:
        240 |
        java.lang.InterruptedException
        241 |
        242 |
      • 243 |
      244 | 245 | 246 | 247 |
        248 |
      • 249 |

        testFiftyThreadsPutPoll

        250 |
        public void testFiftyThreadsPutPoll()
        251 |                              throws java.lang.InterruptedException
        252 |
        253 |
        Throws:
        254 |
        java.lang.InterruptedException
        255 |
        256 |
      • 257 |
      258 |
    • 259 |
    260 |
  • 261 |
262 |
263 |
264 | 265 | 266 |
267 | 268 | 269 | 270 | 271 | 272 | 273 | 281 |
282 | 324 | 325 | 326 | 327 | -------------------------------------------------------------------------------- /out/artifacts/concurrent_util_0_1/javadoc/com/hybhub/util/concurrent/SetBlockingQueueUnitTest.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | SetBlockingQueueUnitTest 7 | 8 | 9 | 10 | 11 | 12 | 28 | 31 | 32 |
33 | 34 | 35 | 36 | 37 | 38 | 39 | 47 |
48 | 90 | 91 | 92 |
93 |
com.hybhub.util.concurrent
94 |

Class SetBlockingQueueUnitTest

95 |
96 |
97 | 105 |
106 |
    107 |
  • 108 |
    109 |
    110 |
    public class SetBlockingQueueUnitTest
    111 | extends java.lang.Object
    112 |
  • 113 |
114 |
115 |
116 | 175 |
176 |
177 |
    178 |
  • 179 | 180 |
      181 |
    • 182 | 183 | 184 |

      Constructor Detail

      185 | 186 | 187 | 188 |
        189 |
      • 190 |

        SetBlockingQueueUnitTest

        191 |
        public SetBlockingQueueUnitTest()
        192 |
      • 193 |
      194 |
    • 195 |
    196 | 197 |
      198 |
    • 199 | 200 | 201 |

      Method Detail

      202 | 203 | 204 | 205 |
        206 |
      • 207 |

        testOfferThenPoll

        208 |
        public void testOfferThenPoll()
        209 |
      • 210 |
      211 | 212 | 213 | 214 |
        215 |
      • 216 |

        testOfferDuplicates

        217 |
        public void testOfferDuplicates()
        218 |
      • 219 |
      220 | 221 | 222 | 223 |
        224 |
      • 225 |

        testRemainingCapacity

        226 |
        public void testRemainingCapacity()
        227 |                            throws java.lang.InterruptedException
        228 |
        229 |
        Throws:
        230 |
        java.lang.InterruptedException
        231 |
        232 |
      • 233 |
      234 | 235 | 236 | 237 |
        238 |
      • 239 |

        testFullCapacity

        240 |
        public void testFullCapacity()
        241 |                       throws java.lang.InterruptedException
        242 |
        243 |
        Throws:
        244 |
        java.lang.InterruptedException
        245 |
        246 |
      • 247 |
      248 |
    • 249 |
    250 |
  • 251 |
252 |
253 |
254 | 255 | 256 |
257 | 258 | 259 | 260 | 261 | 262 | 263 | 271 |
272 | 314 | 315 | 316 | 317 | -------------------------------------------------------------------------------- /out/artifacts/concurrent_util_0_1/javadoc/com/hybhub/util/concurrent/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | com.hybhub.util.concurrent 7 | 8 | 9 | 10 | 11 | 12 |

com.hybhub.util.concurrent

13 |
14 |

Classes

15 | 23 |
24 | 25 | 26 | -------------------------------------------------------------------------------- /out/artifacts/concurrent_util_0_1/javadoc/com/hybhub/util/concurrent/package-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | com.hybhub.util.concurrent 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
71 |

Package com.hybhub.util.concurrent

72 |
73 |
74 | 117 |
118 | 119 |
120 | 121 | 122 | 123 | 124 | 125 | 126 | 134 |
135 | 162 | 163 | 164 | 165 | -------------------------------------------------------------------------------- /out/artifacts/concurrent_util_0_1/javadoc/com/hybhub/util/concurrent/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | com.hybhub.util.concurrent Class Hierarchy 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
71 |

Hierarchy For Package com.hybhub.util.concurrent

72 |
73 |
74 |

Class Hierarchy

75 | 96 |
97 | 98 |
99 | 100 | 101 | 102 | 103 | 104 | 105 | 113 |
114 | 141 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /out/artifacts/concurrent_util_0_1/javadoc/constant-values.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Constant Field Values 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
71 |

Constant Field Values

72 |

Contents

73 |
74 | 75 |
76 | 77 | 78 | 79 | 80 | 81 | 82 | 90 |
91 | 118 | 119 | 120 | 121 | -------------------------------------------------------------------------------- /out/artifacts/concurrent_util_0_1/javadoc/deprecated-list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Deprecated List 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
71 |

Deprecated API

72 |

Contents

73 |
74 | 75 |
76 | 77 | 78 | 79 | 80 | 81 | 82 | 90 |
91 | 118 | 119 | 120 | 121 | -------------------------------------------------------------------------------- /out/artifacts/concurrent_util_0_1/javadoc/help-doc.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | API Help 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
71 |

How This API Document Is Organized

72 |
This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.
73 |
74 |
75 | 170 | This help file applies to API documentation generated using the standard doclet.
171 | 172 |
173 | 174 | 175 | 176 | 177 | 178 | 179 | 187 |
188 | 215 | 216 | 217 | 218 | -------------------------------------------------------------------------------- /out/artifacts/concurrent_util_0_1/javadoc/index-files/index-1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | A-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
A C D E F I N O P R S T  71 | 72 | 73 |

A

74 |
75 |
AbstractConcurrentSet<E> - Class in com.hybhub.util.concurrent
76 |
77 |
Abstract concurrent class holding a set a method to handle take and put lock.
78 |
79 |
AbstractConcurrentSet(int) - Constructor for class com.hybhub.util.concurrent.AbstractConcurrentSet
80 |
 
81 |
add(E) - Method in class com.hybhub.util.concurrent.ConcurrentSetCollection
82 |
 
83 |
addAll(Collection<? extends E>) - Method in class com.hybhub.util.concurrent.ConcurrentSetCollection
84 |
 
85 |
86 | A C D E F I N O P R S T 
87 | 88 |
89 | 90 | 91 | 92 | 93 | 94 | 95 | 103 |
104 | 131 | 132 | 133 | 134 | -------------------------------------------------------------------------------- /out/artifacts/concurrent_util_0_1/javadoc/index-files/index-10.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | R-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
A C D E F I N O P R S T  71 | 72 | 73 |

R

74 |
75 |
remainingCapacity() - Method in class com.hybhub.util.concurrent.ConcurrentSetBlockingQueue
76 |
 
77 |
remove(Object) - Method in class com.hybhub.util.concurrent.ConcurrentSetCollection
78 |
 
79 |
remove() - Method in class com.hybhub.util.concurrent.ConcurrentSetQueue
80 |
 
81 |
removeAll(Collection<?>) - Method in class com.hybhub.util.concurrent.ConcurrentSetCollection
82 |
 
83 |
retainAll(Collection<?>) - Method in class com.hybhub.util.concurrent.ConcurrentSetCollection
84 |
 
85 |
86 | A C D E F I N O P R S T 
87 | 88 |
89 | 90 | 91 | 92 | 93 | 94 | 95 | 103 |
104 | 131 | 132 | 133 | 134 | -------------------------------------------------------------------------------- /out/artifacts/concurrent_util_0_1/javadoc/index-files/index-11.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | S-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
A C D E F I N O P R S T  71 | 72 | 73 |

S

74 |
75 |
set - Variable in class com.hybhub.util.concurrent.AbstractConcurrentSet
76 |
77 |
Set backing the queue
78 |
79 |
SetBlockingQueueMultiThreadTest - Class in com.hybhub.util.concurrent
80 |
 
81 |
SetBlockingQueueMultiThreadTest() - Constructor for class com.hybhub.util.concurrent.SetBlockingQueueMultiThreadTest
82 |
 
83 |
SetBlockingQueueUnitTest - Class in com.hybhub.util.concurrent
84 |
 
85 |
SetBlockingQueueUnitTest() - Constructor for class com.hybhub.util.concurrent.SetBlockingQueueUnitTest
86 |
 
87 |
signalNotEmpty() - Method in class com.hybhub.util.concurrent.AbstractConcurrentSet
88 |
89 |
Signals a waiting take.
90 |
91 |
signalNotFull() - Method in class com.hybhub.util.concurrent.AbstractConcurrentSet
92 |
93 |
Signals a waiting put.
94 |
95 |
size() - Method in class com.hybhub.util.concurrent.ConcurrentSetCollection
96 |
 
97 |
98 | A C D E F I N O P R S T 
99 | 100 |
101 | 102 | 103 | 104 | 105 | 106 | 107 | 115 |
116 | 143 | 144 | 145 | 146 | -------------------------------------------------------------------------------- /out/artifacts/concurrent_util_0_1/javadoc/index-files/index-12.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | T-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
A C D E F I N O P R S T  71 | 72 | 73 |

T

74 |
75 |
take() - Method in class com.hybhub.util.concurrent.ConcurrentSetBlockingQueue
76 |
 
77 |
takeLock - Variable in class com.hybhub.util.concurrent.AbstractConcurrentSet
78 |
79 |
Lock held by take, poll, etc
80 |
81 |
testFiftyThreadsPutPoll() - Method in class com.hybhub.util.concurrent.SetBlockingQueueMultiThreadTest
82 |
 
83 |
testFullCapacity() - Method in class com.hybhub.util.concurrent.SetBlockingQueueUnitTest
84 |
 
85 |
testOfferDuplicates() - Method in class com.hybhub.util.concurrent.SetBlockingQueueUnitTest
86 |
 
87 |
testOfferThenPoll() - Method in class com.hybhub.util.concurrent.SetBlockingQueueUnitTest
88 |
 
89 |
testOfferWithTimeout() - Method in class com.hybhub.util.concurrent.SetBlockingQueueMultiThreadTest
90 |
 
91 |
testRemainingCapacity() - Method in class com.hybhub.util.concurrent.SetBlockingQueueUnitTest
92 |
 
93 |
testTenThreadsOffer() - Method in class com.hybhub.util.concurrent.SetBlockingQueueMultiThreadTest
94 |
 
95 |
testTwoThreadsOfferTake() - Method in class com.hybhub.util.concurrent.SetBlockingQueueMultiThreadTest
96 |
 
97 |
toArray() - Method in class com.hybhub.util.concurrent.ConcurrentSetCollection
98 |
 
99 |
toArray(T[]) - Method in class com.hybhub.util.concurrent.ConcurrentSetCollection
100 |
 
101 |
102 | A C D E F I N O P R S T 
103 | 104 |
105 | 106 | 107 | 108 | 109 | 110 | 111 | 119 |
120 | 147 | 148 | 149 | 150 | -------------------------------------------------------------------------------- /out/artifacts/concurrent_util_0_1/javadoc/index-files/index-2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | C-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
A C D E F I N O P R S T  71 | 72 | 73 |

C

74 |
75 |
capacity - Variable in class com.hybhub.util.concurrent.AbstractConcurrentSet
76 |
77 |
Maximum capacity of the queue
78 |
79 |
clear() - Method in class com.hybhub.util.concurrent.ConcurrentSetCollection
80 |
 
81 |
com.hybhub.util.concurrent - package com.hybhub.util.concurrent
82 |
 
83 |
ConcurrentSetBlockingQueue<E> - Class in com.hybhub.util.concurrent
84 |
85 |
A blocking queue backed by a set so duplicates inside the queue are not allowed.
86 |
87 |
ConcurrentSetBlockingQueue(int) - Constructor for class com.hybhub.util.concurrent.ConcurrentSetBlockingQueue
88 |
 
89 |
ConcurrentSetBlockingQueue() - Constructor for class com.hybhub.util.concurrent.ConcurrentSetBlockingQueue
90 |
 
91 |
ConcurrentSetCollection<E> - Class in com.hybhub.util.concurrent
92 |
 
93 |
ConcurrentSetQueue<E> - Class in com.hybhub.util.concurrent
94 |
95 |
Queue backed by a set so duplicate elements are not allowed.
96 |
97 |
ConcurrentSetQueue() - Constructor for class com.hybhub.util.concurrent.ConcurrentSetQueue
98 |
 
99 |
ConcurrentSetQueue(int) - Constructor for class com.hybhub.util.concurrent.ConcurrentSetQueue
100 |
 
101 |
contains(Object) - Method in class com.hybhub.util.concurrent.ConcurrentSetCollection
102 |
 
103 |
containsAll(Collection<?>) - Method in class com.hybhub.util.concurrent.ConcurrentSetCollection
104 |
 
105 |
count - Variable in class com.hybhub.util.concurrent.AbstractConcurrentSet
106 |
107 |
Current number of elements
108 |
109 |
110 | A C D E F I N O P R S T 
111 | 112 |
113 | 114 | 115 | 116 | 117 | 118 | 119 | 127 |
128 | 155 | 156 | 157 | 158 | -------------------------------------------------------------------------------- /out/artifacts/concurrent_util_0_1/javadoc/index-files/index-3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | D-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
A C D E F I N O P R S T  71 | 72 | 73 |

D

74 |
75 |
drainTo(Collection<? super E>) - Method in class com.hybhub.util.concurrent.ConcurrentSetBlockingQueue
76 |
 
77 |
drainTo(Collection<? super E>, int) - Method in class com.hybhub.util.concurrent.ConcurrentSetBlockingQueue
78 |
 
79 |
80 | A C D E F I N O P R S T 
81 | 82 |
83 | 84 | 85 | 86 | 87 | 88 | 89 | 97 |
98 | 125 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /out/artifacts/concurrent_util_0_1/javadoc/index-files/index-4.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | E-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
A C D E F I N O P R S T  71 | 72 | 73 |

E

74 |
75 |
element() - Method in class com.hybhub.util.concurrent.ConcurrentSetQueue
76 |
 
77 |
78 | A C D E F I N O P R S T 
79 | 80 |
81 | 82 | 83 | 84 | 85 | 86 | 87 | 95 |
96 | 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /out/artifacts/concurrent_util_0_1/javadoc/index-files/index-5.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | F-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
A C D E F I N O P R S T  71 | 72 | 73 |

F

74 |
75 |
fullyLock() - Method in class com.hybhub.util.concurrent.AbstractConcurrentSet
76 |
77 |
Locks to prevent both puts and takes.
78 |
79 |
fullyUnlock() - Method in class com.hybhub.util.concurrent.AbstractConcurrentSet
80 |
81 |
Unlocks to allow both puts and takes.
82 |
83 |
84 | A C D E F I N O P R S T 
85 | 86 |
87 | 88 | 89 | 90 | 91 | 92 | 93 | 101 |
102 | 129 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /out/artifacts/concurrent_util_0_1/javadoc/index-files/index-6.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | I-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
A C D E F I N O P R S T  71 | 72 | 73 |

I

74 |
75 |
isEmpty() - Method in class com.hybhub.util.concurrent.ConcurrentSetCollection
76 |
 
77 |
iterator() - Method in class com.hybhub.util.concurrent.ConcurrentSetCollection
78 |
 
79 |
80 | A C D E F I N O P R S T 
81 | 82 |
83 | 84 | 85 | 86 | 87 | 88 | 89 | 97 |
98 | 125 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /out/artifacts/concurrent_util_0_1/javadoc/index-files/index-7.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | N-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
A C D E F I N O P R S T  71 | 72 | 73 |

N

74 |
75 |
notEmpty - Variable in class com.hybhub.util.concurrent.AbstractConcurrentSet
76 |
77 |
Wait queue for waiting takes
78 |
79 |
notFull - Variable in class com.hybhub.util.concurrent.AbstractConcurrentSet
80 |
81 |
Wait queue for waiting puts
82 |
83 |
84 | A C D E F I N O P R S T 
85 | 86 |
87 | 88 | 89 | 90 | 91 | 92 | 93 | 101 |
102 | 129 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /out/artifacts/concurrent_util_0_1/javadoc/index-files/index-8.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | O-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
A C D E F I N O P R S T  71 | 72 | 73 |

O

74 |
75 |
offer(E, long, TimeUnit) - Method in class com.hybhub.util.concurrent.ConcurrentSetBlockingQueue
76 |
 
77 |
offer(E) - Method in class com.hybhub.util.concurrent.ConcurrentSetCollection
78 |
 
79 |
offer(E) - Method in class com.hybhub.util.concurrent.ConcurrentSetQueue
80 |
 
81 |
82 | A C D E F I N O P R S T 
83 | 84 |
85 | 86 | 87 | 88 | 89 | 90 | 91 | 99 |
100 | 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /out/artifacts/concurrent_util_0_1/javadoc/index-files/index-9.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | P-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
A C D E F I N O P R S T  71 | 72 | 73 |

P

74 |
75 |
peek() - Method in class com.hybhub.util.concurrent.ConcurrentSetQueue
76 |
 
77 |
poll(long, TimeUnit) - Method in class com.hybhub.util.concurrent.ConcurrentSetBlockingQueue
78 |
 
79 |
poll() - Method in class com.hybhub.util.concurrent.ConcurrentSetQueue
80 |
 
81 |
put(E) - Method in class com.hybhub.util.concurrent.ConcurrentSetBlockingQueue
82 |
 
83 |
putLock - Variable in class com.hybhub.util.concurrent.AbstractConcurrentSet
84 |
85 |
Lock held by put, offer, etc
86 |
87 |
88 | A C D E F I N O P R S T 
89 | 90 |
91 | 92 | 93 | 94 | 95 | 96 | 97 | 105 |
106 | 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /out/artifacts/concurrent_util_0_1/javadoc/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Generated Documentation (Untitled) 7 | 59 | 60 | 61 | 62 | 63 | 64 | <noscript> 65 | <div>JavaScript is disabled on your browser.</div> 66 | </noscript> 67 | <h2>Frame Alert</h2> 68 | <p>This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to <a href="com/hybhub/util/concurrent/package-summary.html">Non-frame version</a>.</p> 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /out/artifacts/concurrent_util_0_1/javadoc/overview-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Class Hierarchy 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 41 |
42 | 69 | 70 |
71 |

Hierarchy For All Packages

72 | Package Hierarchies: 73 | 76 |
77 |
78 |

Class Hierarchy

79 | 100 |
101 | 102 |
103 | 104 | 105 | 106 | 107 | 108 | 109 | 117 |
118 | 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /out/artifacts/concurrent_util_0_1/javadoc/package-list: -------------------------------------------------------------------------------- 1 | com.hybhub.util.concurrent 2 | -------------------------------------------------------------------------------- /out/artifacts/concurrent_util_0_1/javadoc/script.js: -------------------------------------------------------------------------------- 1 | function show(type) 2 | { 3 | count = 0; 4 | for (var key in methods) { 5 | var row = document.getElementById(key); 6 | if ((methods[key] & type) != 0) { 7 | row.style.display = ''; 8 | row.className = (count++ % 2) ? rowColor : altColor; 9 | } 10 | else 11 | row.style.display = 'none'; 12 | } 13 | updateTabs(type); 14 | } 15 | 16 | function updateTabs(type) 17 | { 18 | for (var value in tabs) { 19 | var sNode = document.getElementById(tabs[value][0]); 20 | var spanNode = sNode.firstChild; 21 | if (value == type) { 22 | sNode.className = activeTableTab; 23 | spanNode.innerHTML = tabs[value][1]; 24 | } 25 | else { 26 | sNode.className = tableTab; 27 | spanNode.innerHTML = "" + tabs[value][1] + ""; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /out/artifacts/concurrent_util_0_1/javadoc/stylesheet.css: -------------------------------------------------------------------------------- 1 | /* Javadoc style sheet */ 2 | /* 3 | Overall document style 4 | */ 5 | 6 | @import url('resources/fonts/dejavu.css'); 7 | 8 | body { 9 | background-color:#ffffff; 10 | color:#353833; 11 | font-family:'DejaVu Sans', Arial, Helvetica, sans-serif; 12 | font-size:14px; 13 | margin:0; 14 | } 15 | a:link, a:visited { 16 | text-decoration:none; 17 | color:#4A6782; 18 | } 19 | a:hover, a:focus { 20 | text-decoration:none; 21 | color:#bb7a2a; 22 | } 23 | a:active { 24 | text-decoration:none; 25 | color:#4A6782; 26 | } 27 | a[name] { 28 | color:#353833; 29 | } 30 | a[name]:hover { 31 | text-decoration:none; 32 | color:#353833; 33 | } 34 | pre { 35 | font-family:'DejaVu Sans Mono', monospace; 36 | font-size:14px; 37 | } 38 | h1 { 39 | font-size:20px; 40 | } 41 | h2 { 42 | font-size:18px; 43 | } 44 | h3 { 45 | font-size:16px; 46 | font-style:italic; 47 | } 48 | h4 { 49 | font-size:13px; 50 | } 51 | h5 { 52 | font-size:12px; 53 | } 54 | h6 { 55 | font-size:11px; 56 | } 57 | ul { 58 | list-style-type:disc; 59 | } 60 | code, tt { 61 | font-family:'DejaVu Sans Mono', monospace; 62 | font-size:14px; 63 | padding-top:4px; 64 | margin-top:8px; 65 | line-height:1.4em; 66 | } 67 | dt code { 68 | font-family:'DejaVu Sans Mono', monospace; 69 | font-size:14px; 70 | padding-top:4px; 71 | } 72 | table tr td dt code { 73 | font-family:'DejaVu Sans Mono', monospace; 74 | font-size:14px; 75 | vertical-align:top; 76 | padding-top:4px; 77 | } 78 | sup { 79 | font-size:8px; 80 | } 81 | /* 82 | Document title and Copyright styles 83 | */ 84 | .clear { 85 | clear:both; 86 | height:0px; 87 | overflow:hidden; 88 | } 89 | .aboutLanguage { 90 | float:right; 91 | padding:0px 21px; 92 | font-size:11px; 93 | z-index:200; 94 | margin-top:-9px; 95 | } 96 | .legalCopy { 97 | margin-left:.5em; 98 | } 99 | .bar a, .bar a:link, .bar a:visited, .bar a:active { 100 | color:#FFFFFF; 101 | text-decoration:none; 102 | } 103 | .bar a:hover, .bar a:focus { 104 | color:#bb7a2a; 105 | } 106 | .tab { 107 | background-color:#0066FF; 108 | color:#ffffff; 109 | padding:8px; 110 | width:5em; 111 | font-weight:bold; 112 | } 113 | /* 114 | Navigation bar styles 115 | */ 116 | .bar { 117 | background-color:#4D7A97; 118 | color:#FFFFFF; 119 | padding:.8em .5em .4em .8em; 120 | height:auto;/*height:1.8em;*/ 121 | font-size:11px; 122 | margin:0; 123 | } 124 | .topNav { 125 | background-color:#4D7A97; 126 | color:#FFFFFF; 127 | float:left; 128 | padding:0; 129 | width:100%; 130 | clear:right; 131 | height:2.8em; 132 | padding-top:10px; 133 | overflow:hidden; 134 | font-size:12px; 135 | } 136 | .bottomNav { 137 | margin-top:10px; 138 | background-color:#4D7A97; 139 | color:#FFFFFF; 140 | float:left; 141 | padding:0; 142 | width:100%; 143 | clear:right; 144 | height:2.8em; 145 | padding-top:10px; 146 | overflow:hidden; 147 | font-size:12px; 148 | } 149 | .subNav { 150 | background-color:#dee3e9; 151 | float:left; 152 | width:100%; 153 | overflow:hidden; 154 | font-size:12px; 155 | } 156 | .subNav div { 157 | clear:left; 158 | float:left; 159 | padding:0 0 5px 6px; 160 | text-transform:uppercase; 161 | } 162 | ul.navList, ul.subNavList { 163 | float:left; 164 | margin:0 25px 0 0; 165 | padding:0; 166 | } 167 | ul.navList li{ 168 | list-style:none; 169 | float:left; 170 | padding: 5px 6px; 171 | text-transform:uppercase; 172 | } 173 | ul.subNavList li{ 174 | list-style:none; 175 | float:left; 176 | } 177 | .topNav a:link, .topNav a:active, .topNav a:visited, .bottomNav a:link, .bottomNav a:active, .bottomNav a:visited { 178 | color:#FFFFFF; 179 | text-decoration:none; 180 | text-transform:uppercase; 181 | } 182 | .topNav a:hover, .bottomNav a:hover { 183 | text-decoration:none; 184 | color:#bb7a2a; 185 | text-transform:uppercase; 186 | } 187 | .navBarCell1Rev { 188 | background-color:#F8981D; 189 | color:#253441; 190 | margin: auto 5px; 191 | } 192 | .skipNav { 193 | position:absolute; 194 | top:auto; 195 | left:-9999px; 196 | overflow:hidden; 197 | } 198 | /* 199 | Page header and footer styles 200 | */ 201 | .header, .footer { 202 | clear:both; 203 | margin:0 20px; 204 | padding:5px 0 0 0; 205 | } 206 | .indexHeader { 207 | margin:10px; 208 | position:relative; 209 | } 210 | .indexHeader span{ 211 | margin-right:15px; 212 | } 213 | .indexHeader h1 { 214 | font-size:13px; 215 | } 216 | .title { 217 | color:#2c4557; 218 | margin:10px 0; 219 | } 220 | .subTitle { 221 | margin:5px 0 0 0; 222 | } 223 | .header ul { 224 | margin:0 0 15px 0; 225 | padding:0; 226 | } 227 | .footer ul { 228 | margin:20px 0 5px 0; 229 | } 230 | .header ul li, .footer ul li { 231 | list-style:none; 232 | font-size:13px; 233 | } 234 | /* 235 | Heading styles 236 | */ 237 | div.details ul.blockList ul.blockList ul.blockList li.blockList h4, div.details ul.blockList ul.blockList ul.blockListLast li.blockList h4 { 238 | background-color:#dee3e9; 239 | border:1px solid #d0d9e0; 240 | margin:0 0 6px -8px; 241 | padding:7px 5px; 242 | } 243 | ul.blockList ul.blockList ul.blockList li.blockList h3 { 244 | background-color:#dee3e9; 245 | border:1px solid #d0d9e0; 246 | margin:0 0 6px -8px; 247 | padding:7px 5px; 248 | } 249 | ul.blockList ul.blockList li.blockList h3 { 250 | padding:0; 251 | margin:15px 0; 252 | } 253 | ul.blockList li.blockList h2 { 254 | padding:0px 0 20px 0; 255 | } 256 | /* 257 | Page layout container styles 258 | */ 259 | .contentContainer, .sourceContainer, .classUseContainer, .serializedFormContainer, .constantValuesContainer { 260 | clear:both; 261 | padding:10px 20px; 262 | position:relative; 263 | } 264 | .indexContainer { 265 | margin:10px; 266 | position:relative; 267 | font-size:12px; 268 | } 269 | .indexContainer h2 { 270 | font-size:13px; 271 | padding:0 0 3px 0; 272 | } 273 | .indexContainer ul { 274 | margin:0; 275 | padding:0; 276 | } 277 | .indexContainer ul li { 278 | list-style:none; 279 | padding-top:2px; 280 | } 281 | .contentContainer .description dl dt, .contentContainer .details dl dt, .serializedFormContainer dl dt { 282 | font-size:12px; 283 | font-weight:bold; 284 | margin:10px 0 0 0; 285 | color:#4E4E4E; 286 | } 287 | .contentContainer .description dl dd, .contentContainer .details dl dd, .serializedFormContainer dl dd { 288 | margin:5px 0 10px 0px; 289 | font-size:14px; 290 | font-family:'DejaVu Sans Mono',monospace; 291 | } 292 | .serializedFormContainer dl.nameValue dt { 293 | margin-left:1px; 294 | font-size:1.1em; 295 | display:inline; 296 | font-weight:bold; 297 | } 298 | .serializedFormContainer dl.nameValue dd { 299 | margin:0 0 0 1px; 300 | font-size:1.1em; 301 | display:inline; 302 | } 303 | /* 304 | List styles 305 | */ 306 | ul.horizontal li { 307 | display:inline; 308 | font-size:0.9em; 309 | } 310 | ul.inheritance { 311 | margin:0; 312 | padding:0; 313 | } 314 | ul.inheritance li { 315 | display:inline; 316 | list-style:none; 317 | } 318 | ul.inheritance li ul.inheritance { 319 | margin-left:15px; 320 | padding-left:15px; 321 | padding-top:1px; 322 | } 323 | ul.blockList, ul.blockListLast { 324 | margin:10px 0 10px 0; 325 | padding:0; 326 | } 327 | ul.blockList li.blockList, ul.blockListLast li.blockList { 328 | list-style:none; 329 | margin-bottom:15px; 330 | line-height:1.4; 331 | } 332 | ul.blockList ul.blockList li.blockList, ul.blockList ul.blockListLast li.blockList { 333 | padding:0px 20px 5px 10px; 334 | border:1px solid #ededed; 335 | background-color:#f8f8f8; 336 | } 337 | ul.blockList ul.blockList ul.blockList li.blockList, ul.blockList ul.blockList ul.blockListLast li.blockList { 338 | padding:0 0 5px 8px; 339 | background-color:#ffffff; 340 | border:none; 341 | } 342 | ul.blockList ul.blockList ul.blockList ul.blockList li.blockList { 343 | margin-left:0; 344 | padding-left:0; 345 | padding-bottom:15px; 346 | border:none; 347 | } 348 | ul.blockList ul.blockList ul.blockList ul.blockList li.blockListLast { 349 | list-style:none; 350 | border-bottom:none; 351 | padding-bottom:0; 352 | } 353 | table tr td dl, table tr td dl dt, table tr td dl dd { 354 | margin-top:0; 355 | margin-bottom:1px; 356 | } 357 | /* 358 | Table styles 359 | */ 360 | .overviewSummary, .memberSummary, .typeSummary, .useSummary, .constantsSummary, .deprecatedSummary { 361 | width:100%; 362 | border-left:1px solid #EEE; 363 | border-right:1px solid #EEE; 364 | border-bottom:1px solid #EEE; 365 | } 366 | .overviewSummary, .memberSummary { 367 | padding:0px; 368 | } 369 | .overviewSummary caption, .memberSummary caption, .typeSummary caption, 370 | .useSummary caption, .constantsSummary caption, .deprecatedSummary caption { 371 | position:relative; 372 | text-align:left; 373 | background-repeat:no-repeat; 374 | color:#253441; 375 | font-weight:bold; 376 | clear:none; 377 | overflow:hidden; 378 | padding:0px; 379 | padding-top:10px; 380 | padding-left:1px; 381 | margin:0px; 382 | white-space:pre; 383 | } 384 | .overviewSummary caption a:link, .memberSummary caption a:link, .typeSummary caption a:link, 385 | .useSummary caption a:link, .constantsSummary caption a:link, .deprecatedSummary caption a:link, 386 | .overviewSummary caption a:hover, .memberSummary caption a:hover, .typeSummary caption a:hover, 387 | .useSummary caption a:hover, .constantsSummary caption a:hover, .deprecatedSummary caption a:hover, 388 | .overviewSummary caption a:active, .memberSummary caption a:active, .typeSummary caption a:active, 389 | .useSummary caption a:active, .constantsSummary caption a:active, .deprecatedSummary caption a:active, 390 | .overviewSummary caption a:visited, .memberSummary caption a:visited, .typeSummary caption a:visited, 391 | .useSummary caption a:visited, .constantsSummary caption a:visited, .deprecatedSummary caption a:visited { 392 | color:#FFFFFF; 393 | } 394 | .overviewSummary caption span, .memberSummary caption span, .typeSummary caption span, 395 | .useSummary caption span, .constantsSummary caption span, .deprecatedSummary caption span { 396 | white-space:nowrap; 397 | padding-top:5px; 398 | padding-left:12px; 399 | padding-right:12px; 400 | padding-bottom:7px; 401 | display:inline-block; 402 | float:left; 403 | background-color:#F8981D; 404 | border: none; 405 | height:16px; 406 | } 407 | .memberSummary caption span.activeTableTab span { 408 | white-space:nowrap; 409 | padding-top:5px; 410 | padding-left:12px; 411 | padding-right:12px; 412 | margin-right:3px; 413 | display:inline-block; 414 | float:left; 415 | background-color:#F8981D; 416 | height:16px; 417 | } 418 | .memberSummary caption span.tableTab span { 419 | white-space:nowrap; 420 | padding-top:5px; 421 | padding-left:12px; 422 | padding-right:12px; 423 | margin-right:3px; 424 | display:inline-block; 425 | float:left; 426 | background-color:#4D7A97; 427 | height:16px; 428 | } 429 | .memberSummary caption span.tableTab, .memberSummary caption span.activeTableTab { 430 | padding-top:0px; 431 | padding-left:0px; 432 | padding-right:0px; 433 | background-image:none; 434 | float:none; 435 | display:inline; 436 | } 437 | .overviewSummary .tabEnd, .memberSummary .tabEnd, .typeSummary .tabEnd, 438 | .useSummary .tabEnd, .constantsSummary .tabEnd, .deprecatedSummary .tabEnd { 439 | display:none; 440 | width:5px; 441 | position:relative; 442 | float:left; 443 | background-color:#F8981D; 444 | } 445 | .memberSummary .activeTableTab .tabEnd { 446 | display:none; 447 | width:5px; 448 | margin-right:3px; 449 | position:relative; 450 | float:left; 451 | background-color:#F8981D; 452 | } 453 | .memberSummary .tableTab .tabEnd { 454 | display:none; 455 | width:5px; 456 | margin-right:3px; 457 | position:relative; 458 | background-color:#4D7A97; 459 | float:left; 460 | 461 | } 462 | .overviewSummary td, .memberSummary td, .typeSummary td, 463 | .useSummary td, .constantsSummary td, .deprecatedSummary td { 464 | text-align:left; 465 | padding:0px 0px 12px 10px; 466 | } 467 | th.colOne, th.colFirst, th.colLast, .useSummary th, .constantsSummary th, 468 | td.colOne, td.colFirst, td.colLast, .useSummary td, .constantsSummary td{ 469 | vertical-align:top; 470 | padding-right:0px; 471 | padding-top:8px; 472 | padding-bottom:3px; 473 | } 474 | th.colFirst, th.colLast, th.colOne, .constantsSummary th { 475 | background:#dee3e9; 476 | text-align:left; 477 | padding:8px 3px 3px 7px; 478 | } 479 | td.colFirst, th.colFirst { 480 | white-space:nowrap; 481 | font-size:13px; 482 | } 483 | td.colLast, th.colLast { 484 | font-size:13px; 485 | } 486 | td.colOne, th.colOne { 487 | font-size:13px; 488 | } 489 | .overviewSummary td.colFirst, .overviewSummary th.colFirst, 490 | .useSummary td.colFirst, .useSummary th.colFirst, 491 | .overviewSummary td.colOne, .overviewSummary th.colOne, 492 | .memberSummary td.colFirst, .memberSummary th.colFirst, 493 | .memberSummary td.colOne, .memberSummary th.colOne, 494 | .typeSummary td.colFirst{ 495 | width:25%; 496 | vertical-align:top; 497 | } 498 | td.colOne a:link, td.colOne a:active, td.colOne a:visited, td.colOne a:hover, td.colFirst a:link, td.colFirst a:active, td.colFirst a:visited, td.colFirst a:hover, td.colLast a:link, td.colLast a:active, td.colLast a:visited, td.colLast a:hover, .constantValuesContainer td a:link, .constantValuesContainer td a:active, .constantValuesContainer td a:visited, .constantValuesContainer td a:hover { 499 | font-weight:bold; 500 | } 501 | .tableSubHeadingColor { 502 | background-color:#EEEEFF; 503 | } 504 | .altColor { 505 | background-color:#FFFFFF; 506 | } 507 | .rowColor { 508 | background-color:#EEEEEF; 509 | } 510 | /* 511 | Content styles 512 | */ 513 | .description pre { 514 | margin-top:0; 515 | } 516 | .deprecatedContent { 517 | margin:0; 518 | padding:10px 0; 519 | } 520 | .docSummary { 521 | padding:0; 522 | } 523 | 524 | ul.blockList ul.blockList ul.blockList li.blockList h3 { 525 | font-style:normal; 526 | } 527 | 528 | div.block { 529 | font-size:14px; 530 | font-family:'DejaVu Serif', Georgia, "Times New Roman", Times, serif; 531 | } 532 | 533 | td.colLast div { 534 | padding-top:0px; 535 | } 536 | 537 | 538 | td.colLast a { 539 | padding-bottom:3px; 540 | } 541 | /* 542 | Formatting effect styles 543 | */ 544 | .sourceLineNo { 545 | color:green; 546 | padding:0 30px 0 0; 547 | } 548 | h1.hidden { 549 | visibility:hidden; 550 | overflow:hidden; 551 | font-size:10px; 552 | } 553 | .block { 554 | display:block; 555 | margin:3px 10px 2px 0px; 556 | color:#474747; 557 | } 558 | .deprecatedLabel, .descfrmTypeLabel, .memberNameLabel, .memberNameLink, 559 | .overrideSpecifyLabel, .packageHierarchyLabel, .paramLabel, .returnLabel, 560 | .seeLabel, .simpleTagLabel, .throwsLabel, .typeNameLabel, .typeNameLink { 561 | font-weight:bold; 562 | } 563 | .deprecationComment, .emphasizedPhrase, .interfaceName { 564 | font-style:italic; 565 | } 566 | 567 | div.block div.block span.deprecationComment, div.block div.block span.emphasizedPhrase, 568 | div.block div.block span.interfaceName { 569 | font-style:normal; 570 | } 571 | 572 | div.contentContainer ul.blockList li.blockList h2{ 573 | padding-bottom:0px; 574 | } 575 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | 6 | org.sonatype.oss 7 | oss-parent 8 | 9 9 | 10 | 11 | com.hybhub 12 | concurrent-util 13 | 0.3.0 14 | 15 | 16 | 1.8 17 | 1.8 18 | 19 | 20 | 21 | 22 | ossrh 23 | https://oss.sonatype.org/content/repositories/snapshots 24 | 25 | 26 | ossrh 27 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 28 | 29 | 30 | 31 | 32 | org.testng 33 | testng 34 | 6.8 35 | test 36 | 37 | 38 | 39 | 40 | 41 | org.apache.maven.plugins 42 | maven-source-plugin 43 | 2.2.1 44 | 45 | 46 | attach-sources 47 | 48 | jar-no-fork 49 | 50 | 51 | 52 | 53 | 54 | org.apache.maven.plugins 55 | maven-javadoc-plugin 56 | 2.9.1 57 | 58 | 59 | attach-javadocs 60 | 61 | jar 62 | 63 | 64 | 65 | 66 | 67 | org.apache.maven.plugins 68 | maven-gpg-plugin 69 | 1.5 70 | 71 | 72 | sign-artifacts 73 | verify 74 | 75 | sign 76 | 77 | 78 | 79 | 80 | 81 | org.sonatype.plugins 82 | nexus-staging-maven-plugin 83 | 1.6.7 84 | true 85 | 86 | ossrh 87 | https://oss.sonatype.org/ 88 | true 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /src/main/java/com/hybhub/util/concurrent/AbstractConcurrentSet.java: -------------------------------------------------------------------------------- 1 | package com.hybhub.util.concurrent; 2 | 3 | import java.util.LinkedHashSet; 4 | import java.util.concurrent.atomic.AtomicInteger; 5 | import java.util.concurrent.locks.Condition; 6 | import java.util.concurrent.locks.ReentrantLock; 7 | 8 | /** 9 | * Abstract concurrent class holding a set and methods to handle concurrent locks. 10 | * The {@link java.util.Set} is a {@link LinkedHashSet}, it guaranties that there are no duplicates, 11 | * and is aware of the order of insertion inside the {@link java.util.Set}, 12 | * so we are able to simulate a "first in first out" strategy. 13 | * Inspired by {@link java.util.concurrent.LinkedBlockingQueue} 14 | * @param 15 | */ 16 | abstract class AbstractConcurrentSet { 17 | 18 | /** Maximum capacity of the queue */ 19 | final int capacity; 20 | 21 | /** Current number of elements */ 22 | final AtomicInteger count = new AtomicInteger(); 23 | 24 | /** Lock held by take, poll, etc */ 25 | final ReentrantLock takeLock = new ReentrantLock(); 26 | 27 | /** Wait queue for waiting takes */ 28 | final Condition notEmpty = takeLock.newCondition(); 29 | 30 | /** Lock held by put, offer, etc */ 31 | final ReentrantLock putLock = new ReentrantLock(); 32 | 33 | /** Wait queue for waiting puts */ 34 | final Condition notFull = putLock.newCondition(); 35 | 36 | /** Set backing the queue */ 37 | final LinkedHashSet set; 38 | 39 | /** 40 | * Instantiate a concurrent set with a maximum capacity of capacity 41 | */ 42 | AbstractConcurrentSet(final int capacity) { 43 | this.capacity = capacity; 44 | this.set = new LinkedHashSet<>(); 45 | } 46 | 47 | /** 48 | * Signals a waiting take. Called only from put/offer (which do not 49 | * otherwise ordinarily lock takeLock.) 50 | */ 51 | void signalNotEmpty() { 52 | takeLock.lock(); 53 | try { 54 | notEmpty.signal(); 55 | } finally { 56 | takeLock.unlock(); 57 | } 58 | } 59 | 60 | /** 61 | * Signals a waiting put. Called only from take/poll. 62 | */ 63 | void signalNotFull() { 64 | putLock.lock(); 65 | try { 66 | notFull.signal(); 67 | } finally { 68 | putLock.unlock(); 69 | } 70 | } 71 | 72 | /** 73 | * Locks to prevent both puts and takes. 74 | */ 75 | void fullyLock() { 76 | putLock.lock(); 77 | takeLock.lock(); 78 | } 79 | 80 | /** 81 | * Unlocks to allow both puts and takes. 82 | */ 83 | void fullyUnlock() { 84 | takeLock.unlock(); 85 | putLock.unlock(); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/com/hybhub/util/concurrent/ConcurrentSetBlockingQueue.java: -------------------------------------------------------------------------------- 1 | package com.hybhub.util.concurrent; 2 | 3 | import java.util.Collection; 4 | import java.util.concurrent.BlockingQueue; 5 | import java.util.concurrent.TimeUnit; 6 | import java.util.concurrent.atomic.AtomicInteger; 7 | import java.util.concurrent.locks.ReentrantLock; 8 | 9 | /** 10 | * A blocking queue backed by a set so duplicates inside the queue are not allowed. 11 | * @param 12 | */ 13 | public class ConcurrentSetBlockingQueue extends ConcurrentSetQueue implements BlockingQueue { 14 | 15 | 16 | public ConcurrentSetBlockingQueue(final int capacity) { 17 | super(capacity); 18 | } 19 | 20 | public ConcurrentSetBlockingQueue() { 21 | this(Integer.MAX_VALUE); 22 | } 23 | 24 | @Override 25 | public int remainingCapacity() { 26 | return ( capacity - count.get() ); 27 | } 28 | 29 | @Override 30 | public E poll(final long timeout, final TimeUnit unit) throws InterruptedException { 31 | E x; 32 | int c; 33 | long nanos = unit.toNanos(timeout); 34 | final AtomicInteger count = this.count; 35 | final ReentrantLock takeLock = this.takeLock; 36 | takeLock.lockInterruptibly(); 37 | try { 38 | while (count.get() == 0) { 39 | if (nanos <= 0) { 40 | return null; 41 | } 42 | nanos = notEmpty.awaitNanos(nanos); 43 | } 44 | x = set.iterator().next(); 45 | set.remove(x); 46 | c = count.getAndDecrement(); 47 | if (c > 1) { 48 | notEmpty.signal(); 49 | } 50 | } finally { 51 | takeLock.unlock(); 52 | } 53 | if (c == capacity) { 54 | signalNotFull(); 55 | } 56 | return x; 57 | } 58 | 59 | @Override 60 | public void put(final E e) throws InterruptedException { 61 | if (e == null) { 62 | throw new NullPointerException(); 63 | } 64 | 65 | int c; 66 | final ReentrantLock putLock = this.putLock; 67 | final AtomicInteger count = this.count; 68 | fullyLock(); 69 | try { 70 | if (set.contains(e)) { 71 | return; 72 | } 73 | 74 | while (count.get() == capacity) { 75 | notFull.await(); 76 | } 77 | set.add(e); 78 | c = count.getAndIncrement(); 79 | if (c + 1 < capacity) { 80 | notFull.signal(); 81 | } 82 | } finally { 83 | fullyUnlock(); 84 | } 85 | if (c == 0) { 86 | signalNotEmpty(); 87 | } 88 | } 89 | 90 | @Override 91 | public boolean offer(final E e, final long timeout, final TimeUnit unit) throws InterruptedException { 92 | if (e == null) { 93 | throw new NullPointerException(); 94 | } 95 | long nanos = unit.toNanos(timeout); 96 | int c; 97 | final ReentrantLock putLock = this.putLock; 98 | final AtomicInteger count = this.count; 99 | putLock.lockInterruptibly(); 100 | try { 101 | if (set.contains(e)) { 102 | return false; 103 | } 104 | 105 | while (count.get() == capacity) { 106 | if (nanos <= 0) { 107 | return false; 108 | } 109 | nanos = notFull.awaitNanos(nanos); 110 | } 111 | set.add(e); 112 | c = count.getAndIncrement(); 113 | if (c + 1 < capacity) { 114 | notFull.signal(); 115 | } 116 | } finally { 117 | putLock.unlock(); 118 | } 119 | if (c == 0) { 120 | signalNotEmpty(); 121 | } 122 | return true; 123 | } 124 | 125 | @Override 126 | public E take() throws InterruptedException { 127 | E x; 128 | int c; 129 | final AtomicInteger count = this.count; 130 | final ReentrantLock takeLock = this.takeLock; 131 | takeLock.lockInterruptibly(); 132 | try { 133 | while (count.get() == 0) { 134 | notEmpty.await(); 135 | } 136 | x = set.iterator().next(); 137 | set.remove(x); 138 | c = count.getAndDecrement(); 139 | if (c > 1) { 140 | notEmpty.signal(); 141 | } 142 | } finally { 143 | takeLock.unlock(); 144 | } 145 | if (c == capacity) { 146 | signalNotFull(); 147 | } 148 | return x; 149 | } 150 | 151 | @Override 152 | public int drainTo(final Collection c) { 153 | return drainTo(c, Integer.MAX_VALUE); 154 | } 155 | 156 | @Override 157 | public int drainTo(final Collection c, final int maxElements) { 158 | if (c == null) { 159 | throw new NullPointerException(); 160 | } 161 | if (c == this) { 162 | throw new IllegalArgumentException(); 163 | } 164 | if (maxElements <= 0) { 165 | return 0; 166 | } 167 | boolean signalNotFull = false; 168 | final ReentrantLock takeLock = this.takeLock; 169 | takeLock.lock(); 170 | try { 171 | int n = Math.min(maxElements, count.get()); 172 | int i = 0; 173 | try { 174 | while (i < n) { 175 | E e = set.iterator().next(); 176 | set.remove(e); 177 | c.add(e); 178 | ++i; 179 | } 180 | return n; 181 | } finally { 182 | if (i > 0) { 183 | signalNotFull = (count.getAndAdd(-i) == capacity); 184 | } 185 | } 186 | } finally { 187 | takeLock.unlock(); 188 | if (signalNotFull) { 189 | signalNotFull(); 190 | } 191 | } 192 | } 193 | } 194 | -------------------------------------------------------------------------------- /src/main/java/com/hybhub/util/concurrent/ConcurrentSetCollection.java: -------------------------------------------------------------------------------- 1 | package com.hybhub.util.concurrent; 2 | 3 | 4 | import java.util.Collection; 5 | import java.util.Iterator; 6 | import java.util.concurrent.CopyOnWriteArrayList; 7 | import java.util.concurrent.atomic.AtomicInteger; 8 | 9 | public class ConcurrentSetCollection extends AbstractConcurrentSet implements Collection { 10 | 11 | ConcurrentSetCollection(final int capacity) { 12 | super(capacity); 13 | } 14 | 15 | @Override 16 | public int size() { 17 | return count.get(); 18 | } 19 | 20 | @Override 21 | public void clear() { 22 | fullyLock(); 23 | try { 24 | set.clear(); 25 | } 26 | finally { 27 | fullyUnlock(); 28 | } 29 | 30 | } 31 | 32 | @Override 33 | public boolean isEmpty() { 34 | return count.get() == 0; 35 | } 36 | 37 | public boolean offer(final E e) { 38 | if (e == null) { 39 | throw new NullPointerException(); 40 | } 41 | final AtomicInteger count = this.count; 42 | if (count.get() == capacity) { 43 | return false; 44 | } 45 | int c = -1; 46 | fullyLock(); 47 | try { 48 | if (count.get() < capacity && ! set.contains(e)) { 49 | set.add(e); 50 | c = count.getAndIncrement(); 51 | if (c + 1 < capacity) { 52 | notFull.signal(); 53 | } 54 | } 55 | } finally { 56 | fullyUnlock(); 57 | } 58 | if (c == 0) { 59 | signalNotEmpty(); 60 | } 61 | return c >= 0; 62 | } 63 | 64 | @Override 65 | public boolean add(final E e) { 66 | if (this.offer(e)) { 67 | return true; 68 | } 69 | else { 70 | throw new IllegalStateException("Queue full"); 71 | } 72 | } 73 | 74 | @Override 75 | public boolean remove(final Object o) { 76 | if (o == null) { 77 | return false; 78 | } 79 | fullyLock(); 80 | try { 81 | if(set.remove(o)){ 82 | count.decrementAndGet(); 83 | return true; 84 | } 85 | return false; 86 | } finally { 87 | fullyUnlock(); 88 | } 89 | } 90 | 91 | @Override 92 | public boolean contains(final Object o) { 93 | if(o == null) { 94 | return false; 95 | } 96 | fullyLock(); 97 | try { 98 | return set.contains(o); 99 | } 100 | finally { 101 | fullyUnlock(); 102 | } 103 | } 104 | 105 | @Override 106 | public boolean containsAll(final Collection c) { 107 | for (Object o : c){ 108 | if(!this.contains(o)){ 109 | return false; 110 | } 111 | } 112 | return true; 113 | } 114 | 115 | @Override 116 | public Iterator iterator() { 117 | return new CopyOnWriteArrayList<>(set).iterator(); 118 | } 119 | 120 | @Override 121 | public Object[] toArray() { 122 | fullyLock(); 123 | try { 124 | return set.toArray(); 125 | } 126 | finally { 127 | fullyUnlock(); 128 | } 129 | } 130 | 131 | @Override 132 | public T[] toArray(final T[] a) { 133 | fullyLock(); 134 | try { 135 | return set.toArray(a); 136 | } 137 | finally { 138 | fullyUnlock(); 139 | } 140 | } 141 | 142 | @Override 143 | public boolean addAll(final Collection c) { 144 | throw new UnsupportedOperationException(); 145 | } 146 | 147 | @Override 148 | public boolean removeAll(final Collection c) { 149 | throw new UnsupportedOperationException(); 150 | } 151 | 152 | @Override 153 | public boolean retainAll(final Collection c) { 154 | throw new UnsupportedOperationException(); 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /src/main/java/com/hybhub/util/concurrent/ConcurrentSetQueue.java: -------------------------------------------------------------------------------- 1 | package com.hybhub.util.concurrent; 2 | 3 | import java.util.NoSuchElementException; 4 | import java.util.Queue; 5 | import java.util.concurrent.atomic.AtomicInteger; 6 | import java.util.concurrent.locks.ReentrantLock; 7 | 8 | /** 9 | * Queue backed by a set so duplicate elements are not allowed. 10 | * @param 11 | */ 12 | public abstract class ConcurrentSetQueue extends ConcurrentSetCollection implements Queue { 13 | 14 | ConcurrentSetQueue(final int capacity) { 15 | super(capacity); 16 | } 17 | 18 | @Override 19 | public boolean offer(final E e) { 20 | return super.offer(e); 21 | } 22 | 23 | @Override 24 | public E poll() { 25 | final AtomicInteger count = this.count; 26 | if (count.get() == 0) { 27 | return null; 28 | } 29 | E x = null; 30 | int c = -1; 31 | final ReentrantLock takeLock = this.takeLock; 32 | takeLock.lock(); 33 | try { 34 | if (count.get() > 0) { 35 | x = set.iterator().next(); 36 | set.spliterator(); 37 | set.remove(x); 38 | c = count.getAndDecrement(); 39 | if (c > 1) { 40 | notEmpty.signal(); 41 | } 42 | } 43 | } finally { 44 | takeLock.unlock(); 45 | } 46 | if (c == capacity) { 47 | signalNotFull(); 48 | } 49 | return x; } 50 | 51 | @Override 52 | public E element() { 53 | E x = peek(); 54 | if (x != null) { 55 | return x; 56 | } 57 | else { 58 | throw new NoSuchElementException(); 59 | } 60 | } 61 | 62 | @Override 63 | public E peek() { 64 | if (count.get() == 0) { 65 | return null; 66 | } 67 | final ReentrantLock takeLock = this.takeLock; 68 | takeLock.lock(); 69 | try { 70 | return set.iterator().next(); 71 | } finally { 72 | takeLock.unlock(); 73 | } 74 | } 75 | 76 | @Override 77 | public E remove() { 78 | E x = poll(); 79 | if (x != null) { 80 | return x; 81 | } 82 | else { 83 | throw new NoSuchElementException(); 84 | } 85 | 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /testsrc/com/hybhub/util/concurrent/ConcurrentSetBlockingQueueMultiThreadTest.java: -------------------------------------------------------------------------------- 1 | package com.hybhub.util.concurrent; 2 | 3 | import org.testng.Assert; 4 | import org.testng.annotations.Test; 5 | 6 | import java.util.ArrayList; 7 | import java.util.Collection; 8 | import java.util.List; 9 | import java.util.UUID; 10 | import java.util.concurrent.BlockingQueue; 11 | import java.util.concurrent.Callable; 12 | import java.util.concurrent.ExecutorService; 13 | import java.util.concurrent.Executors; 14 | import java.util.concurrent.Future; 15 | import java.util.concurrent.TimeUnit; 16 | import java.util.stream.Collectors; 17 | import java.util.stream.IntStream; 18 | import java.util.stream.Stream; 19 | 20 | @Test 21 | public class ConcurrentSetBlockingQueueMultiThreadTest { 22 | 23 | private static class OfferGiver implements Callable { 24 | private BlockingQueue queue; 25 | 26 | public OfferGiver(final BlockingQueue queue) { 27 | this.queue = queue; 28 | } 29 | 30 | @Override 31 | public Boolean call() { 32 | for ( int ignored : IntStream.range(0,1_000).toArray()) { 33 | queue.offer(UUID.randomUUID()); 34 | } 35 | return Boolean.TRUE; 36 | } 37 | } 38 | 39 | private static class PutGiver implements Callable { 40 | private BlockingQueue queue; 41 | 42 | public PutGiver(final BlockingQueue queue) { 43 | this.queue = queue; 44 | } 45 | 46 | @Override 47 | public Boolean call() throws InterruptedException { 48 | for ( int ignored : IntStream.range(0,1_000).toArray()) { 49 | queue.put(UUID.randomUUID()); 50 | } 51 | return Boolean.TRUE; 52 | } 53 | } 54 | 55 | private static class Consumer implements Callable { 56 | private BlockingQueue queue; 57 | 58 | public Consumer(final BlockingQueue queue) { 59 | this.queue = queue; 60 | } 61 | 62 | @Override 63 | public Boolean call() throws InterruptedException { 64 | for ( int ignored : IntStream.range(0,8_000).toArray()) { 65 | queue.take(); 66 | } 67 | return Boolean.TRUE; 68 | } 69 | } 70 | 71 | public void testTwoThreadsOfferTake() throws InterruptedException { 72 | //Arrange 73 | BlockingQueue queue = new ConcurrentSetBlockingQueue<>(); 74 | ExecutorService exec = Executors.newFixedThreadPool(16); 75 | 76 | //Act 77 | exec.invokeAll((Collection>) Stream.of( 78 | new OfferGiver(queue), 79 | new OfferGiver(queue), 80 | new OfferGiver(queue), 81 | new OfferGiver(queue), 82 | new OfferGiver(queue), 83 | new OfferGiver(queue), 84 | new OfferGiver(queue), 85 | new PutGiver(queue), 86 | new Consumer(queue)) 87 | .collect(Collectors.toCollection(ArrayList::new))); 88 | 89 | exec.awaitTermination(5, TimeUnit.SECONDS); 90 | exec.shutdown(); 91 | 92 | //Test 93 | System.out.println(queue.size()); 94 | Assert.assertTrue(queue.isEmpty()); 95 | } 96 | 97 | public void testTenThreadsOffer() throws InterruptedException { 98 | //Arrange 99 | BlockingQueue queue = new ConcurrentSetBlockingQueue<>(); 100 | List> consumers = new ArrayList<>(); 101 | for ( int ignored : IntStream.range(0,10).toArray() ){ 102 | consumers.add(() -> { 103 | for ( int ignored2 : IntStream.range(0,15).toArray() ) { 104 | queue.offer(UUID.randomUUID()); 105 | } 106 | return Boolean.TRUE; 107 | }); 108 | } 109 | ExecutorService exec = Executors.newFixedThreadPool(5); 110 | 111 | //Act 112 | exec.invokeAll(consumers); 113 | exec.shutdown(); 114 | exec.awaitTermination(1, TimeUnit.SECONDS); 115 | 116 | //Test 117 | Assert.assertEquals(queue.size(), 150); 118 | Assert.assertFalse(queue.isEmpty()); 119 | } 120 | 121 | public void testOfferWithTimeout() throws InterruptedException { 122 | //Arrange 123 | BlockingQueue queue = new ConcurrentSetBlockingQueue<>(1); 124 | List> consumers = new ArrayList<>(); 125 | for ( int ignored : IntStream.range(0,20).toArray() ){ 126 | consumers.add(() -> queue.offer(UUID.randomUUID(), 10, TimeUnit.SECONDS) && queue.offer(UUID.randomUUID(), 10, TimeUnit.SECONDS)); 127 | } 128 | consumers.add(() -> { IntStream.range(0,40).parallel().forEach((i) -> { 129 | try { 130 | queue.take(); 131 | } catch (InterruptedException e) { 132 | e.printStackTrace(); 133 | } 134 | }); 135 | return Boolean.TRUE; } 136 | ); 137 | ExecutorService exec = Executors.newFixedThreadPool(21); 138 | 139 | //Act 140 | exec.invokeAll(consumers); 141 | exec.shutdown(); 142 | exec.awaitTermination(1, TimeUnit.SECONDS); 143 | 144 | //Test 145 | Assert.assertEquals(queue.size(), 0); 146 | Assert.assertTrue(queue.isEmpty()); 147 | } 148 | 149 | public void testFiftyThreadsPutPoll() throws InterruptedException { 150 | //Arrange 151 | BlockingQueue queue = new ConcurrentSetBlockingQueue<>(30); 152 | List> consumers = new ArrayList<>(); 153 | for (int ignored : IntStream.range(0, 20).toArray()) { 154 | consumers.add(() -> { 155 | queue.put(UUID.randomUUID()); 156 | queue.put(UUID.randomUUID()); 157 | return Boolean.TRUE; 158 | }); 159 | consumers.add(queue::poll); 160 | consumers.add(queue::poll); 161 | } 162 | ExecutorService exec = Executors.newFixedThreadPool(50); 163 | 164 | //Act 165 | final List> results = exec.invokeAll(consumers); 166 | exec.shutdown(); 167 | exec.awaitTermination(1, TimeUnit.SECONDS); 168 | 169 | //Test 170 | final long failedPolls = results.stream().filter((o) -> { 171 | try { 172 | return o.get() == null; 173 | } catch (Exception e) { 174 | return true; 175 | } 176 | }).count(); 177 | Assert.assertTrue((failedPolls == 0) == queue.isEmpty()); 178 | Assert.assertEquals(failedPolls, queue.size()); 179 | } 180 | 181 | } 182 | -------------------------------------------------------------------------------- /testsrc/com/hybhub/util/concurrent/ConcurrentSetBlockingQueueThreadPoolExecutorTest.java: -------------------------------------------------------------------------------- 1 | package com.hybhub.util.concurrent; 2 | 3 | import org.testng.Assert; 4 | import org.testng.annotations.Test; 5 | 6 | import java.util.concurrent.ThreadPoolExecutor; 7 | import java.util.concurrent.TimeUnit; 8 | 9 | @Test 10 | public class ConcurrentSetBlockingQueueThreadPoolExecutorTest { 11 | 12 | /** 13 | * IMPORTANT : The ThreadPoolExecutor won't add the first Runnable inside the queue, that's the reason why I execute it with Integer 1 three times first. 14 | * @throws InterruptedException 15 | */ 16 | @Test 17 | public void testBLockingQueueInsideThreadPoolExecutor() throws InterruptedException { 18 | //Arrange 19 | final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1,1,20, TimeUnit.SECONDS, 20 | new ConcurrentSetBlockingQueue<>(100), new ThreadPoolExecutor.DiscardPolicy()); 21 | 22 | //Act 23 | threadPoolExecutor.execute(new SimpleRunnable(1)); 24 | final int shouldBeZero = threadPoolExecutor.getQueue().size(); 25 | 26 | threadPoolExecutor.execute(new SimpleRunnable(1)); 27 | final int shouldBeOne = threadPoolExecutor.getQueue().size(); 28 | 29 | threadPoolExecutor.execute(new SimpleRunnable(1)); 30 | final int shouldBeOneStill = threadPoolExecutor.getQueue().size(); 31 | 32 | threadPoolExecutor.execute(new SimpleRunnable(2)); 33 | final int shouldBeTwo = threadPoolExecutor.getQueue().size(); 34 | 35 | threadPoolExecutor.execute(new SimpleRunnable(1)); 36 | final int shouldBeTwoStill = threadPoolExecutor.getQueue().size(); 37 | 38 | threadPoolExecutor.awaitTermination(4, TimeUnit.SECONDS); 39 | Thread.sleep(2_000); 40 | final long shouldBeThree = threadPoolExecutor.getCompletedTaskCount(); 41 | 42 | //Test 43 | Assert.assertEquals(shouldBeZero, 0); 44 | Assert.assertEquals(shouldBeOne, 1); 45 | Assert.assertEquals(shouldBeOneStill, 1); 46 | Assert.assertEquals(shouldBeTwo, 2); 47 | Assert.assertEquals(shouldBeTwoStill, 2); 48 | Assert.assertEquals(shouldBeThree, 3); 49 | } 50 | 51 | private class SimpleRunnable implements Runnable { 52 | 53 | private Integer uid; 54 | 55 | public SimpleRunnable(final Integer uid) { 56 | this.uid = uid; 57 | } 58 | 59 | @Override 60 | public void run() { 61 | try { 62 | Thread.sleep(1_000); 63 | } catch (InterruptedException e) { 64 | e.printStackTrace(); 65 | } 66 | } 67 | 68 | @Override 69 | public int hashCode() { 70 | return this.uid.hashCode(); 71 | } 72 | 73 | @Override 74 | public boolean equals(Object obj) { 75 | if(obj instanceof SimpleRunnable){ 76 | return this.uid.equals(((SimpleRunnable) obj).uid); 77 | } 78 | return false; 79 | } 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /testsrc/com/hybhub/util/concurrent/ConcurrentSetBlockingQueueUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.hybhub.util.concurrent; 2 | 3 | import java.util.ArrayList; 4 | import java.util.concurrent.BlockingQueue; 5 | import java.util.concurrent.TimeUnit; 6 | 7 | import org.testng.Assert; 8 | import org.testng.annotations.Test; 9 | 10 | @Test 11 | public class ConcurrentSetBlockingQueueUnitTest { 12 | 13 | public void testRemainingCapacity() throws InterruptedException { 14 | //Arrange 15 | final BlockingQueue queue = new ConcurrentSetBlockingQueue<>(5); 16 | 17 | //Act 18 | final int initialCapacity = queue.remainingCapacity(); 19 | queue.offer(1); 20 | final int capacityOne = queue.remainingCapacity(); 21 | queue.offer(1); 22 | final int capacityOneRepeated = queue.remainingCapacity(); 23 | queue.offer(2); 24 | final int capacityTwo = queue.remainingCapacity(); 25 | queue.peek(); 26 | final int capacityThree = queue.remainingCapacity(); 27 | queue.put(3); 28 | final int capacityFour = queue.remainingCapacity(); 29 | queue.remove(3); 30 | final int capacityFive = queue.remainingCapacity(); 31 | queue.add(4); 32 | final int capacitySix = queue.remainingCapacity(); 33 | queue.element(); 34 | final int capacitySeven = queue.remainingCapacity(); 35 | queue.remove(); 36 | final int capacityEight = queue.remainingCapacity(); 37 | queue.take(); 38 | final int capacityNine = queue.remainingCapacity(); 39 | queue.offer(5, 1, TimeUnit.SECONDS); 40 | final int capacityTen = queue.remainingCapacity(); 41 | queue.drainTo(new ArrayList<>()); 42 | final int capacityEleven = queue.remainingCapacity(); 43 | 44 | //Test 45 | Assert.assertEquals(initialCapacity, 5); 46 | Assert.assertEquals(capacityOne, 4); 47 | Assert.assertEquals(capacityOneRepeated, 4); 48 | Assert.assertEquals(capacityTwo, 3); 49 | Assert.assertEquals(capacityThree, 3); 50 | Assert.assertEquals(capacityFour, 2); 51 | Assert.assertEquals(capacityFive, 3); 52 | Assert.assertEquals(capacitySix, 2); 53 | Assert.assertEquals(capacitySeven, 2); 54 | Assert.assertEquals(capacityEight, 3); 55 | Assert.assertEquals(capacityNine, 4); 56 | Assert.assertEquals(capacityTen, 3); 57 | Assert.assertEquals(capacityEleven, 5); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /testsrc/com/hybhub/util/concurrent/ConcurrentSetQueueUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.hybhub.util.concurrent; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.NoSuchElementException; 6 | import java.util.Queue; 7 | 8 | import org.testng.Assert; 9 | import org.testng.annotations.Test; 10 | 11 | @Test 12 | public class ConcurrentSetQueueUnitTest { 13 | 14 | public void testFullCapacityOffer() throws InterruptedException { 15 | //Arrange 16 | final Queue queue = new ConcurrentSetBlockingQueue<>(1); 17 | 18 | //Act 19 | final boolean acceptedOffer = queue.offer(1); 20 | final boolean rejectedOffer1 = queue.offer(2); 21 | final boolean rejectedOffer2 = queue.offer(2); 22 | boolean rejectedException = false; 23 | try{ 24 | queue.add(2); 25 | } 26 | catch (IllegalStateException ex){ 27 | rejectedException = true; 28 | } 29 | 30 | //Test 31 | Assert.assertTrue(acceptedOffer); 32 | Assert.assertFalse(rejectedOffer1); 33 | Assert.assertFalse(rejectedOffer2); 34 | Assert.assertTrue(rejectedException); 35 | } 36 | 37 | public void testOfferThenPoll(){ 38 | //Arrange 39 | final Queue queue = new ConcurrentSetBlockingQueue<>(); 40 | final List dataSet = Arrays.asList("1","3","6","10","4"); 41 | 42 | //Act 43 | dataSet.forEach(queue::offer); 44 | 45 | //Test 46 | for(String s : dataSet){ 47 | Assert.assertEquals(queue.poll(), s, "Polled String is incorrect"); 48 | } 49 | Assert.assertTrue(queue.isEmpty()); 50 | } 51 | 52 | public void testOfferDuplicates(){ 53 | //Arrange 54 | final Queue queue = new ConcurrentSetBlockingQueue<>(); 55 | 56 | //Act 57 | final boolean firstOffer = queue.offer(1); 58 | final boolean secondOffer = queue.offer(1); 59 | 60 | //Test 61 | Assert.assertTrue(firstOffer); 62 | Assert.assertFalse(secondOffer); 63 | } 64 | 65 | public void testPeek(){ 66 | //Arrange 67 | final Queue queue = new ConcurrentSetBlockingQueue<>(); 68 | 69 | //Act 70 | final Integer shouldBeNull = queue.peek(); 71 | final boolean shouldBeTrue = queue.offer(1); 72 | final Integer shouldBeNonNull = queue.peek(); 73 | final int shouldBeOne = queue.size(); 74 | 75 | //Test 76 | Assert.assertNull(shouldBeNull); 77 | Assert.assertTrue(shouldBeTrue); 78 | Assert.assertNotNull(shouldBeNonNull); 79 | Assert.assertEquals(1, shouldBeOne); 80 | } 81 | 82 | public void testRemove(){ 83 | //Arrange 84 | final Queue queue = new ConcurrentSetBlockingQueue<>(); 85 | 86 | //Act 87 | Exception expectedException = null; 88 | try { 89 | queue.remove(); 90 | } 91 | catch (NoSuchElementException noSuchElementException){ 92 | expectedException = noSuchElementException; 93 | } 94 | final boolean addedFirst = queue.offer(3); 95 | final boolean addedSecond = queue.offer(1); 96 | final boolean addedThird = queue.offer(2); 97 | final Integer integerRemoved = queue.remove(); 98 | final int finalQueueSize = queue.size(); 99 | 100 | //Test 101 | Assert.assertNotNull(expectedException); 102 | Assert.assertTrue(addedFirst); 103 | Assert.assertTrue(addedSecond); 104 | Assert.assertTrue(addedThird); 105 | Assert.assertEquals(integerRemoved, new Integer(3)); 106 | Assert.assertEquals(finalQueueSize, 2); 107 | } 108 | 109 | public void testElement(){ 110 | //Arrange 111 | final Queue queue = new ConcurrentSetBlockingQueue<>(); 112 | 113 | //Act 114 | Exception expectedException = null; 115 | try { 116 | queue.element(); 117 | } 118 | catch (NoSuchElementException noSuchElementException){ 119 | expectedException = noSuchElementException; 120 | } 121 | final boolean addedFirst = queue.offer(4); 122 | final boolean addedSecond = queue.offer(1); 123 | final Integer shouldBeNonNull = queue.element(); 124 | final int shouldBeTwo = queue.size(); 125 | 126 | //Test 127 | Assert.assertNotNull(expectedException); 128 | Assert.assertTrue(addedFirst); 129 | Assert.assertTrue(addedSecond); 130 | Assert.assertNotNull(shouldBeNonNull); 131 | Assert.assertEquals(2, shouldBeTwo); 132 | } 133 | } 134 | --------------------------------------------------------------------------------