├── .gitignore ├── LICENSE.txt ├── NOTICE.txt ├── README.adoc ├── pom.xml └── src ├── main ├── java │ └── org │ │ └── tomitribe │ │ └── jcache │ │ └── cdi │ │ ├── AnyLiteral.java │ │ ├── CacheManagerBean.java │ │ ├── CacheProviderBean.java │ │ ├── DefaultLiteral.java │ │ └── ExtraJCacheExtension.java └── resources │ └── META-INF │ ├── beans.xml │ └── services │ └── javax.enterprise.inject.spi.Extension └── test ├── java └── org │ └── tomitribe │ └── jcache │ └── cdi │ └── ExtraJCacheExtensionTest.java └── resources ├── META-INF └── beans.xml └── hazelcast-client.xml /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | *.iml 3 | .project 4 | .classpath 5 | .settings/ 6 | target/ 7 | 8 | 9 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | JCache CDI Extensions 2 | Copyright 2001-2015 The Apache Software Foundation. 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | 7 | -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | = JCache-CDI 2 | 3 | == JCache 4 | 5 | JCache (https://github.com/jsr107/jsr107spec[JSR-107]) defines a standard Java Caching API for use by developers and a standard SPI ("Service Provider Interface") for use by implementers. 6 | 7 | The key concepts in JCache are: 8 | 9 | * +CachingProvider+ 10 | 11 | This is the entry point for using JCache. The default CachingProvider can be accessed via +Caching.getCachingProvider()+. This interface provides access to a number of +CacheManager+s. 12 | 13 | * +CacheManager+ 14 | 15 | A +CacheManager+ provides access to a number of named +Cache+s. 16 | 17 | * +Cache+ 18 | 19 | A temporary key-based store, similar to a +Map+. A cache can store a number of entries for fast lookup for a period of time until the entry expires. 20 | 21 | Using JCache in a Java SE way is shown in the "Hello world" example below. 22 | 23 | [source,java,numbered] 24 | ---- 25 | CachingProvider provider = Caching.getCachingProvider(); 26 | CacheManager manager = provider.getCacheManager(); 27 | 28 | Configuration configuration = new MutableConfiguration().setTypes(String.class, String.class); 29 | Cache cache = manager.createCache("simpleCache", configuration); 30 | 31 | cache.put("phrase", "Hello, world!"); 32 | 33 | String value = cache.get("phrase"); 34 | System.out.println("Value: " + value); 35 | ---- 36 | 37 | There's nothing wrong with taking this approach within a Java EE application, but notice that this example has a reasonable amount of 38 | boilerplate code, and the JCache objects created aren't managed by the Java EE container - we cannot inject them into EJB or CDI beans 39 | for example. 40 | 41 | Java EE doesn't include JCache as yet, although hopefully that will change in future Java EE specifications. In the meantime though, we 42 | can use a little of CDI fairy dust to start using JCache in a Java EE application with minimal fuss. 43 | 44 | == CDI 45 | 46 | Contexts and Dependency Injection (https://jcp.org/en/jsr/detail?id=346[JSR-346]) first arrived in Java EE in version 6, and is a 47 | required part of the Web Profile as well as the Full Profile. CDI provides the container with the capability to manage the lifecycle of a 48 | bean and the ability to inject beans into other managed components. 49 | 50 | CDI includes support for: 51 | 52 | * Injection (with scoping, names, qualifiers, stereotypes and alternatives) 53 | 54 | * Producers (factory methods) 55 | 56 | * Interceptors 57 | 58 | * Observers 59 | 60 | In addition, you can define your own CDI extensions which allow a great deal of flexibility within the CDI container. We'll specifically 61 | focus on Producers and Interceptors here. There are some easy to follow CDI examples on the TomEE website (http://tomee.apache.org/examples-trunk/index.html) 62 | and some great YouTube videos on CDI presented by Alex Soto (https://www.youtube.com/user/lordofthejars/videos). 63 | 64 | == About this library 65 | 66 | This library is made up from the interceptors and annotations from the JCache reference implementation (https://github.com/jsr107/RI/tree/master/cache-annotations-ri/cache-annotations-ri-cdi) 67 | and an additional extension that will load the JCache provider at deployment time and create CachingProvider and CacheManager CDI beans that 68 | can be directly injected into managed beans. 69 | 70 | In effect that means the code above, can now become: 71 | 72 | [source,java,numbered] 73 | ---- 74 | public class MyBean { 75 | 76 | @Inject 77 | private CacheManager mgr; 78 | 79 | public void doSomething() { 80 | 81 | final Configuration configuration = new MutableConfiguration().setTypes(String.class, String.class); 82 | final Cache cache = mgr.createCache("simpleCache", configuration); 83 | 84 | cache.put("phrase", "Hello, world!"); 85 | 86 | final String value = cache.get("phrase"); 87 | System.out.println("Value: " + value); 88 | } 89 | } 90 | ---- 91 | 92 | Note that +CacheManager+ does not need to be created any more, it is injected straight in. 93 | 94 | == Using JCache with CDI in your Java EE application 95 | 96 | To use this library in your Java EE application, include the following dependencies in your pom.xml (I'm using Hazelcast 97 | as the JCache implementation here): 98 | 99 | [source,xml,numbered] 100 | ---- 101 | 102 | javax.cache 103 | cache-api 104 | 1.0.0 105 | 106 | 107 | com.hazelcast 108 | hazelcast 109 | 3.4.1 110 | 111 | 112 | org.tomitribe 113 | jcache-cdi 114 | 0.1-SNAPSHOT 115 | 116 | ---- 117 | 118 | and you will need to add an empty +beans.xml+ file. 119 | 120 | [source,xml,numbered] 121 | ---- 122 | 126 | ---- 127 | 128 | This is everything you need to add JCache to your existing project. This library has been tested with Hazelcast on TomEE, but 129 | should be portable in work in different application servers and with different JCache implementations. 130 | 131 | === Producer 132 | 133 | You've already seen the example above, where +CachingProvider+ and +CacheManager+ can be directly injected into beans 134 | managed by the container. But, wouldn't it be nice if we could eliminate the configuration and +CacheManager.createCache()+ call, and just 135 | inject +Cache+ straight into our beans? Well, with a little work with CDI, we can. The solution here is to use a producer. 136 | 137 | At a very simple producer would look like this: 138 | 139 | [source,java,numbered] 140 | ---- 141 | public class CacheProducer { 142 | 143 | @Inject 144 | private CacheManager mgr; 145 | 146 | @Produces 147 | @Singleton 148 | public Cache createCache() { 149 | final Configuration configuration = new MutableConfiguration().setTypes(String.class, String.class); 150 | final Cache cache = mgr.createCache("simpleCache", configuration); 151 | 152 | return cache; 153 | } 154 | } 155 | ---- 156 | 157 | Notice that we simply moved the configuration and +createCache+ call into a factory method. Now we can use +@Inject Cache+ in 158 | our application code. This has some limitations though - for example we cannot use this to create different caches with different names. 159 | 160 | We could take this one step further, and use a qualifier to define different caches. To use a qualifier, you need to define an annotation. 161 | For example: 162 | 163 | [source,java,numbered] 164 | ---- 165 | @Retention(RetentionPolicy.RUNTIME) 166 | @Inherited 167 | @Target({ElementType.METHOD, ElementType.FIELD}) 168 | public @interface DefaultCache { 169 | } 170 | 171 | @Retention(RetentionPolicy.RUNTIME) 172 | @Inherited 173 | @Target({ElementType.METHOD, ElementType.FIELD}) 174 | public @interface AnotherCache { 175 | } 176 | ---- 177 | 178 | and then define different producers: 179 | 180 | [source,java,numbered] 181 | ---- 182 | @Produces 183 | @Singleton 184 | @DefaultCache 185 | public Cache createCache() { 186 | // create the cache 187 | } 188 | 189 | @Produces 190 | @Singleton 191 | @AnotherCache 192 | public Cache createCache() { 193 | // create the cache 194 | } 195 | ---- 196 | 197 | This provides us with a little more flexibility, but could become unwieldy down the line. Another approach is to define some options 198 | on the annotation that we create, and then use these within our Producer method to control the configuration and creation of the cache. 199 | 200 | For example - add a name option to the annotation 201 | 202 | [source,java,numbered] 203 | ---- 204 | @Retention(RetentionPolicy.RUNTIME) 205 | @Inherited 206 | @Target({ElementType.METHOD, ElementType.FIELD}) 207 | public @interface MyCache { 208 | String name() default "default"; 209 | } 210 | ---- 211 | 212 | and access the annotation added to the field using an InjectionPoint parameter on the Producer. Note that this does not 213 | include the +@Singleton+ annotation. 214 | 215 | [source,java,numbered] 216 | ---- 217 | @Produces 218 | @MyCache 219 | public Cache createCache(final InjectionPoint injectionPoint) { 220 | 221 | final MyCache cache = injectionPoint.getAnnotated().getAnnotation(MyCache.class); 222 | 223 | Cache cache = mgr.getCache(cache.name()); 224 | if (cache == null) { 225 | final MutableConfiguration config = new MutableConfiguration() 226 | .setTypes(Object.class, Object.class); 227 | 228 | cache = mgr.createCache(cache.name(), config); 229 | } 230 | 231 | return cache; 232 | } 233 | ---- 234 | 235 | === Built-in Interceptors 236 | 237 | Being able to create your own producer is great, but you still need to do all the work of figuring out when to add objects to the cache, 238 | when to remove invalid objects and when to fetch objects from the cache. 239 | 240 | Fortunately the JCache specification defines a set of annotations specifically for implementations to provide interceptors to do the heavy 241 | lifting for you. The JCache reference implementation provides a default implementation of these interceptors and these have been 242 | shaded into this library. 243 | 244 | These built in interceptors can be used by annotating the methods to you want to be intercepted with the appropriate annotation. 245 | 246 | The interceptors are outlined briefly below, and full Javadoc can be found here: https://github.com/jsr107/jsr107spec/tree/master/src/main/java/javax/cache/annotation 247 | 248 | ==== +@CacheResult+ 249 | 250 | +CacheResult+ will cache the result of a method call, using specified parameters as the key, using the +@CacheKey+ annotation below. 251 | Subsequent calls to the method will be checked against the cache, and the result returned from cache if available. +CacheResult+ provides 252 | some simple options, including: 253 | 254 | +cacheName+: The name of the cache to use for the result 255 | +skipGet+: Always caches the result, but does not use the value in the cache to return from the method. 256 | 257 | In a very simple case, the result of method could be cached simply by adding +@CacheResult(cacheName="myCache")+: 258 | 259 | [source,java,numbered] 260 | ---- 261 | @CacheResult(cacheName = "results") 262 | public List getResults(final Integer firstResult, final Integer maxResults, final String field, final String searchTerm) { 263 | // TODO: search code here... 264 | } 265 | ---- 266 | 267 | ==== +@CacheKey / @CacheValue+ 268 | 269 | +@CacheKey+ and +@CacheValue+ should be specified on method parameters when using any of these interceptors. +@CacheValue+ identifies the object that should 270 | be cached, and +@CacheKey+ identifies the objects that should make up the key for the for cache entry. 271 | 272 | +@CacheKey+ can be used in conjunction with +CacheKeyGenerator+ (below) to apply some logic to generate the actual key to use for the cache from the parameters 273 | annotated with +@CacheKey+. 274 | 275 | ==== +CacheKeyGenerator+ 276 | 277 | Your method may accept a domain object as a parameter, but you may not wish to use the domain object itself as the key for the cache, instead you may just wish 278 | to use an id field, for example. The +CacheKeyGenerator+ allows you to provide a class that can apply this logic. 279 | 280 | For example, a +@CachePut+ method such as 281 | 282 | [source,java,numbered] 283 | ---- 284 | @CachePut(cacheName = "domainCache", cacheKeyGenerator = DomainObjectCacheKeyGenerator.class) 285 | public void addObject(@CacheKey @CacheValue final DomainObject domObj) { 286 | entityManager.persist(domObj); 287 | } 288 | ---- 289 | 290 | could use a +CacheKeyGenerator+ like this: 291 | 292 | [source,java,numbered] 293 | ---- 294 | public class DomainObjectCacheKeyGenerator implements CacheKeyGenerator { 295 | @Override 296 | public GeneratedCacheKey generateCacheKey(final CacheKeyInvocationContext cacheKeyInvocationContext) { 297 | 298 | final CacheInvocationParameter[] allParameters = cacheKeyInvocationContext.getAllParameters(); 299 | for (final CacheInvocationParameter parameter : allParameters) { 300 | if (DomainObject.class.equals(parameter.getRawType())) { 301 | final DomainObject domObj = DomainObject.class.cast(parameter.getValue()); 302 | return new DefaultGeneratedCacheKey(new Object[] { domObj.getId() }); 303 | } 304 | } 305 | 306 | throw new IllegalArgumentException("No domain object argument found in method signature"); 307 | } 308 | } 309 | ---- 310 | 311 | ==== +@CachePut+ 312 | 313 | +@CachePut+ allows you to add or update a value in the cache with a value passed into the method as a parameter. The parameter to cache 314 | should be annotated with +@CacheValue+ and the parameters that make up the key, should be annotated with +@CacheKey+. +@CacheKey+ can be used in conjunction with 315 | a +CacheKeyGenerator+ and +@CacheKey+ and +@CacheValue+ can be applied to the same parameter if appropriate. For example, to cache an entity that is being added 316 | to the database, the following code could be used: 317 | 318 | [source,java,numbered] 319 | ---- 320 | @CachePut(cacheName = "domainById", cacheKeyGenerator = DomainObjectCacheKeyGenerator.class) 321 | public void addObject(@CacheKey @CacheValue final DomainObject domObj) { 322 | entityManager.persist(domObj); 323 | } 324 | ---- 325 | 326 | ==== +@CacheRemove+ 327 | 328 | +@CacheRemove+ can be used to remove a specific +@CacheKey+ from the cache. This might be particularly useful when the method called removes an entity from the system. 329 | For example: 330 | 331 | [source,java,numbered] 332 | ---- 333 | @CacheRemove(cacheName = "domainCache") 334 | public void deleteById(final long id) { 335 | final DomainObject domObj = entityManager.find(DomainObject.class, id); 336 | entityManager.remove(movie); 337 | } 338 | ---- 339 | 340 | ==== +@CacheRemoveAll+ 341 | 342 | +@CacheRemoveAll+ is similar to +@CacheRemove+ but will remove *all entries* from the specified cache. 343 | 344 | ==== +@CacheDefaults+ 345 | 346 | The +@CacheDefaults+ annotation can be applied at class level to provide a set of defaults for the method-level annotations. For example, you can save yourself 347 | specifying +cacheName+ and +cacheKeyGenerator+ on each method annotation by providing a +@CacheDefaults(cacheName = "domainCache", cacheKeyGenerator = DomainObjectCacheKeyGenerator.class)+ 348 | on the class itself. 349 | 350 | ==== Some limitations 351 | 352 | These annotations and interceptors can provide a really simple way to introduce JCache into your application. One specific limitation to be aware of though, is that 353 | only one +Cache+ annotation can be used on a method. So you can't for example, do this: 354 | 355 | [source,java,numbered] 356 | ---- 357 | @CachePut(cacheName = "domainById", cacheKeyGenerator = DomainObjectCacheKeyGenerator.class) 358 | @CacheRemoveAll(cacheName = "searchResults") // this is now invalid because we added an new object 359 | public void addDomainObject(@CacheKey @CacheValue final DomainObject movie) { 360 | entityManager.persist(movie); 361 | } 362 | ---- 363 | 364 | You'd need to either work with the caches manually, or define your own interceptor. 365 | 366 | === Creating your own 367 | 368 | Creating your own interceptor with CDI is really easy. Firstly, define a "marker" annotation: 369 | 370 | [source,java,numbered] 371 | ---- 372 | @InterceptorBinding 373 | @Target({ TYPE, METHOD }) 374 | @Retention(RUNTIME) 375 | public @interface MyCacheAnnotation { 376 | } 377 | ---- 378 | 379 | Next, create the interceptor. The key here is the +@AroundInvoke+ annotation and the +InvocationContext+ parameter. 380 | 381 | [source,java,numbered] 382 | ---- 383 | @Interceptor 384 | @MyCacheAnnotation 385 | public class CacheInterceptor { 386 | 387 | @Inject // use your Producer to create this 388 | private Cache cache; 389 | 390 | @AroundInvoke 391 | public Object cache(final InvocationContext ctx) throws Exception { 392 | 393 | final Object[] parameters = ctx.getParameters(); 394 | final Object result = ctx.proceed(); 395 | 396 | // TODO: your code here to work with the cache 397 | 398 | return result; 399 | } 400 | } 401 | ---- 402 | 403 | Now, you can use your interceptor in your code: 404 | 405 | [source,java,numbered] 406 | ---- 407 | @MyCacheAnnotation 408 | public void addDomainObject(@CacheKey @CacheValue final DomainObject movie) { 409 | entityManager.persist(movie); 410 | } 411 | ---- 412 | 413 | Finally, you need to enable interceptors in your +beans.xml+ file: 414 | 415 | [source,xml,numbered] 416 | ---- 417 | 421 | 422 | 423 | org.superbiz.jcache.interceptors.CacheInterceptor 424 | 425 | 426 | ---- 427 | 428 | NOTE: As well as enabling interceptors, +beans.xml+ also defines the order the interceptors run in. -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.tomitribe 25 | oss-parent 26 | 2 27 | 28 | 29 | jcache-cdi 30 | 0.1-SNAPSHOT 31 | jar 32 | 33 | Tomitribe :: JCache CDI 34 | 35 | 36 | UTF-8 37 | 38 | 39 | 40 | scm:git:git@github.com:tomitribe/jcache-cdi.git 41 | scm:git:git@github.com:tomitribe/jcache-cdi.git 42 | scm:git:git@github.com:tomitribe/jcache-cdi.git 43 | HEAD 44 | 45 | 46 | 47 | 48 | snapshots 49 | http://repository.tomitribe.com/content/repositories/snapshots 50 | 51 | true 52 | 53 | 54 | 55 | Sonatype-public 56 | Sonatype snapshot and release 57 | https://oss.sonatype.org/content/groups/public/ 58 | 59 | true 60 | 61 | 62 | true 63 | 64 | 65 | 66 | 67 | 68 | 69 | org.jsr107.ri 70 | cache-annotations-ri-cdi 71 | 1.0.0 72 | 73 | 74 | junit 75 | junit 76 | 4.11 77 | test 78 | 79 | 80 | org.apache.openejb 81 | javaee-api 82 | 6.0-6 83 | provided 84 | 85 | 86 | javax.cache 87 | cache-api 88 | 1.0.0 89 | provided 90 | 91 | 92 | org.apache.openejb 93 | openejb-core 94 | 4.7.1 95 | test 96 | 97 | 98 | 99 | 100 | com.hazelcast 101 | hazelcast 102 | 3.4.1 103 | test 104 | 105 | 106 | 107 | 108 | 109 | 110 | org.apache.rat 111 | apache-rat-plugin 112 | 0.10 113 | 114 | 115 | src/**/* 116 | pom.xml 117 | 118 | 119 | **/*/MANIFEST.MF 120 | .git 121 | .gitignore 122 | derby.log 123 | **/META-INF/services/* 124 | **/bootstrap-* 125 | **/js/jquery-* 126 | **/*.json 127 | src/test/resources/**/*.txt 128 | **/src/main/resources/archetype-resources/**/* 129 | **/javax.enterprise.inject.spi.Extension 130 | 131 | 132 | 133 | 134 | validate 135 | 136 | check 137 | 138 | 139 | 140 | 141 | 142 | org.apache.maven.plugins 143 | maven-compiler-plugin 144 | 3.1 145 | 146 | 1.6 147 | 1.6 148 | 149 | 150 | 151 | org.apache.maven.plugins 152 | maven-shade-plugin 153 | 2.3 154 | 155 | 156 | package 157 | 158 | shade 159 | 160 | 161 | true 162 | true 163 | false 164 | 165 | 166 | javax.enterprise:cdi-api 167 | org.jboss.spec.javax.interceptor:jboss-interceptors-api_1.1_spec 168 | javax.annotation:jsr250-api 169 | javax.inject:javax.inject 170 | 171 | 172 | 173 | 174 | org.jsr107.ri:cache-annotations-ri-cdi 175 | 176 | META-INF/services/javax.enterprise.inject.spi.Extension 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | -------------------------------------------------------------------------------- /src/main/java/org/tomitribe/jcache/cdi/AnyLiteral.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.tomitribe.jcache.cdi; 20 | 21 | import javax.enterprise.inject.Any; 22 | import javax.enterprise.util.AnnotationLiteral; 23 | 24 | public class AnyLiteral extends AnnotationLiteral implements Any 25 | { 26 | public static final AnyLiteral INSTANCE = new AnyLiteral(); 27 | 28 | @Override 29 | public String toString() 30 | { 31 | return "@javax.enterprise.inject.Any()"; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/tomitribe/jcache/cdi/CacheManagerBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.tomitribe.jcache.cdi; 20 | 21 | import javax.cache.CacheManager; 22 | import javax.enterprise.context.ApplicationScoped; 23 | import javax.enterprise.context.spi.CreationalContext; 24 | import javax.enterprise.inject.spi.Bean; 25 | import javax.enterprise.inject.spi.InjectionPoint; 26 | import javax.enterprise.inject.spi.PassivationCapable; 27 | import java.lang.annotation.Annotation; 28 | import java.lang.reflect.Type; 29 | import java.util.HashSet; 30 | import java.util.Set; 31 | 32 | import static java.util.Collections.emptySet; 33 | 34 | public class CacheManagerBean implements Bean, PassivationCapable 35 | { 36 | private final Set types; 37 | private final Set qualifiers; 38 | private final CacheManager manager; 39 | private final String id; 40 | 41 | public CacheManagerBean(final CacheManager cacheManager) 42 | { 43 | manager = cacheManager; 44 | id = getClass().getName() + "-" + hashCode(); 45 | 46 | types = new HashSet(); 47 | types.add(CacheManager.class); 48 | types.add(Object.class); 49 | 50 | qualifiers = new HashSet(); 51 | qualifiers.add(DefaultLiteral.INSTANCE); 52 | qualifiers.add(AnyLiteral.INSTANCE); 53 | } 54 | 55 | @Override 56 | public Set getTypes() 57 | { 58 | return types; 59 | } 60 | 61 | @Override 62 | public Set getQualifiers() 63 | { 64 | return qualifiers; 65 | } 66 | 67 | @Override 68 | public Class getScope() 69 | { 70 | return ApplicationScoped.class; 71 | } 72 | 73 | @Override 74 | public String getName() 75 | { 76 | return null; 77 | } 78 | 79 | @Override 80 | public boolean isNullable() 81 | { 82 | return false; 83 | } 84 | 85 | @Override 86 | public Set getInjectionPoints() 87 | { 88 | return emptySet(); 89 | } 90 | 91 | @Override 92 | public Class getBeanClass() 93 | { 94 | return CacheManager.class; 95 | } 96 | 97 | @Override 98 | public Set> getStereotypes() 99 | { 100 | return emptySet(); 101 | } 102 | 103 | @Override 104 | public boolean isAlternative() 105 | { 106 | return false; 107 | } 108 | 109 | @Override 110 | public CacheManager create(CreationalContext cacheManagerCreationalContext) 111 | { 112 | return manager; 113 | } 114 | 115 | @Override 116 | public void destroy(CacheManager cacheManager, CreationalContext cacheManagerCreationalContext) 117 | { 118 | manager.close(); 119 | } 120 | 121 | @Override 122 | public String getId() 123 | { 124 | return id; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /src/main/java/org/tomitribe/jcache/cdi/CacheProviderBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.tomitribe.jcache.cdi; 20 | 21 | import javax.cache.spi.CachingProvider; 22 | import javax.enterprise.context.ApplicationScoped; 23 | import javax.enterprise.context.spi.CreationalContext; 24 | import javax.enterprise.inject.spi.Bean; 25 | import javax.enterprise.inject.spi.InjectionPoint; 26 | import javax.enterprise.inject.spi.PassivationCapable; 27 | import java.lang.annotation.Annotation; 28 | import java.lang.reflect.Type; 29 | import java.util.HashSet; 30 | import java.util.Set; 31 | 32 | import static java.util.Collections.emptySet; 33 | 34 | public class CacheProviderBean implements Bean, PassivationCapable 35 | { 36 | private final Set types; 37 | private final Set qualifiers; 38 | private final CachingProvider provider; 39 | private final String id; 40 | 41 | public CacheProviderBean(final CachingProvider cacheManager) 42 | { 43 | provider = cacheManager; 44 | id = getClass().getName() + "-" + hashCode(); 45 | 46 | types = new HashSet(); 47 | types.add(CachingProvider.class); 48 | types.add(Object.class); 49 | 50 | qualifiers = new HashSet(); 51 | qualifiers.add(DefaultLiteral.INSTANCE); 52 | qualifiers.add(AnyLiteral.INSTANCE); 53 | } 54 | 55 | @Override 56 | public Set getTypes() 57 | { 58 | return types; 59 | } 60 | 61 | @Override 62 | public Set getQualifiers() 63 | { 64 | return qualifiers; 65 | } 66 | 67 | @Override 68 | public Class getScope() 69 | { 70 | return ApplicationScoped.class; 71 | } 72 | 73 | @Override 74 | public String getName() 75 | { 76 | return null; 77 | } 78 | 79 | @Override 80 | public boolean isNullable() 81 | { 82 | return false; 83 | } 84 | 85 | @Override 86 | public Set getInjectionPoints() 87 | { 88 | return emptySet(); 89 | } 90 | 91 | @Override 92 | public Class getBeanClass() 93 | { 94 | return CachingProvider.class; 95 | } 96 | 97 | @Override 98 | public Set> getStereotypes() 99 | { 100 | return emptySet(); 101 | } 102 | 103 | @Override 104 | public boolean isAlternative() 105 | { 106 | return false; 107 | } 108 | 109 | @Override 110 | public CachingProvider create(final CreationalContext cacheManagerCreationalContext) 111 | { 112 | return provider; 113 | } 114 | 115 | @Override 116 | public void destroy(final CachingProvider cacheProvider, final CreationalContext cacheManagerCreationalContext) 117 | { 118 | provider.close(); 119 | } 120 | 121 | @Override 122 | public String getId() 123 | { 124 | return id; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /src/main/java/org/tomitribe/jcache/cdi/DefaultLiteral.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.tomitribe.jcache.cdi; 20 | 21 | import javax.enterprise.inject.Default; 22 | import javax.enterprise.util.AnnotationLiteral; 23 | 24 | public class DefaultLiteral extends AnnotationLiteral implements Default 25 | { 26 | public static final DefaultLiteral INSTANCE = new DefaultLiteral(); 27 | 28 | @Override 29 | public String toString() 30 | { 31 | return "@javax.enterprise.inject.Default()"; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/tomitribe/jcache/cdi/ExtraJCacheExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.tomitribe.jcache.cdi; 20 | 21 | import javax.cache.CacheManager; 22 | import javax.cache.Caching; 23 | import javax.cache.spi.CachingProvider; 24 | import javax.enterprise.event.Observes; 25 | import javax.enterprise.inject.spi.AfterBeanDiscovery; 26 | import javax.enterprise.inject.spi.Bean; 27 | import javax.enterprise.inject.spi.BeforeShutdown; 28 | import javax.enterprise.inject.spi.Extension; 29 | import javax.enterprise.inject.spi.ProcessBean; 30 | import java.util.Properties; 31 | 32 | // add default CacheProvider and CacheManager 33 | public class ExtraJCacheExtension implements Extension 34 | { 35 | private static final boolean ACTIVATED = "true".equals(System.getProperty("org.apache.jcs.extra.cdi", "true")); 36 | 37 | private boolean cacheManagerFound = false; 38 | private boolean cacheProviderFound = false; 39 | private CacheManager cacheManager; 40 | private CachingProvider cachingProvider; 41 | 42 | public void processBean(final @Observes ProcessBean processBeanEvent) 43 | { 44 | if (!ACTIVATED) 45 | { 46 | return; 47 | } 48 | 49 | if (cacheManagerFound && cacheProviderFound) 50 | { 51 | return; 52 | } 53 | 54 | final Bean bean = processBeanEvent.getBean(); 55 | if (CacheManagerBean.class.isInstance(bean) || CacheProviderBean.class.isInstance(bean)) 56 | { 57 | return; 58 | } 59 | 60 | if (!cacheManagerFound) 61 | { 62 | cacheManagerFound = bean.getTypes().contains(CacheManager.class); 63 | } 64 | if (!cacheProviderFound) 65 | { 66 | cacheProviderFound = bean.getTypes().contains(CachingProvider.class); 67 | } 68 | } 69 | 70 | public void addJCacheBeans(final @Observes AfterBeanDiscovery afterBeanDiscovery) 71 | { 72 | if (!ACTIVATED) 73 | { 74 | return; 75 | } 76 | 77 | if (cacheManagerFound && cacheProviderFound) { 78 | return; 79 | } 80 | 81 | cachingProvider = Caching.getCachingProvider(); 82 | if (!cacheManagerFound) 83 | { 84 | cacheManager = cachingProvider.getCacheManager( 85 | cachingProvider.getDefaultURI(), 86 | cachingProvider.getDefaultClassLoader(), 87 | new Properties()); 88 | afterBeanDiscovery.addBean(new CacheManagerBean(cacheManager)); 89 | } 90 | if (!cacheProviderFound) 91 | { 92 | afterBeanDiscovery.addBean(new CacheProviderBean(cachingProvider)); 93 | } 94 | } 95 | 96 | public void destroyIfCreated(final @Observes BeforeShutdown beforeShutdown) 97 | { 98 | if (cacheManager != null) 99 | { 100 | cacheManager.close(); 101 | } 102 | if (cachingProvider != null) 103 | { 104 | cachingProvider.close(); 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension: -------------------------------------------------------------------------------- 1 | org.tomitribe.jcache.cdi.ExtraJCacheExtension 2 | org.jsr107.ri.annotations.cdi.InterceptorExtension 3 | 4 | -------------------------------------------------------------------------------- /src/test/java/org/tomitribe/jcache/cdi/ExtraJCacheExtensionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.tomitribe.jcache.cdi; 20 | 21 | import org.junit.After; 22 | import org.junit.Before; 23 | import org.junit.Test; 24 | 25 | import javax.cache.CacheManager; 26 | import javax.cache.spi.CachingProvider; 27 | import javax.ejb.embeddable.EJBContainer; 28 | import javax.inject.Inject; 29 | import java.util.Random; 30 | 31 | import static org.junit.Assert.assertNotNull; 32 | 33 | public class ExtraJCacheExtensionTest 34 | { 35 | public ExtraJCacheExtensionTest() { 36 | final String logging = "hazelcast.logging.type"; 37 | if (System.getProperty(logging) == null) { 38 | System.setProperty(logging, "jdk"); 39 | } 40 | 41 | System.setProperty("hazelcast.version.check.enabled", "false"); 42 | System.setProperty("hazelcast.mancenter.enabled", "false"); 43 | System.setProperty("hazelcast.wait.seconds.before.join", "1"); 44 | System.setProperty("hazelcast.local.localAddress", "127.0.0.1"); 45 | System.setProperty("java.net.preferIPv4Stack", "true"); 46 | System.setProperty("hazelcast.jmx", "true"); 47 | 48 | // randomize multicast group... 49 | Random rand = new Random(); 50 | int g1 = rand.nextInt(255); 51 | int g2 = rand.nextInt(255); 52 | int g3 = rand.nextInt(255); 53 | System.setProperty("hazelcast.multicast.group", "224." + g1 + "." + g2 + "." + g3); 54 | System.setProperty("hazelcast.jcache.provider.type", "server"); 55 | } 56 | 57 | private EJBContainer container; 58 | 59 | @Before 60 | public void setUp() { 61 | try { 62 | container = EJBContainer.createEJBContainer(); 63 | container.getContext().bind("inject", this); 64 | } catch (Exception e) { 65 | e.printStackTrace(); 66 | } 67 | } 68 | 69 | @After 70 | public void cleanUp() { 71 | try { 72 | container.getContext().unbind("inject"); 73 | container.close(); 74 | } catch (Exception e) { 75 | e.printStackTrace(); 76 | } 77 | } 78 | 79 | @Inject 80 | private BeanWithInjections bean; 81 | 82 | @Test 83 | public void defaultCacheManager() 84 | { 85 | assertNotNull(bean.getMgr()); 86 | } 87 | 88 | @Test 89 | public void defaultCacheProvider() 90 | { 91 | assertNotNull(bean.getProvider()); 92 | } 93 | 94 | public static class BeanWithInjections { 95 | @Inject 96 | private CacheManager mgr; 97 | 98 | @Inject 99 | private CachingProvider provider; 100 | 101 | public CacheManager getMgr() 102 | { 103 | return mgr; 104 | } 105 | 106 | public CachingProvider getProvider() 107 | { 108 | return provider; 109 | } 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /src/test/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/test/resources/hazelcast-client.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 22 | 23 | cluster1 24 | cluster1pass 25 | 26 | 27 | 28 | 29 |
127.0.0.1:5701
30 |
31 |
32 | 33 |
--------------------------------------------------------------------------------