|
5 | 5 |
|
6 | 6 | /** |
7 | 7 | * The service cache implementation which will cache services that are being created. |
8 | | - * On first hit, the cache will be empty and thus any service that is being requested, will be |
| 8 | + * On first hit, the cache will be empty and thus any service that is being requested, will be |
9 | 9 | * created fresh and then placed into the cache map. On next hit, if same service name will |
10 | | - * be requested, it will be returned from the cache |
11 | | - * @author saifasif |
| 10 | + * be requested, it will be returned from the cache |
12 | 11 | * |
| 12 | + * @author saifasif |
13 | 13 | */ |
14 | 14 | public class ServiceCache { |
15 | | - |
16 | | - private Map<String, Service> serviceCache; |
17 | 15 |
|
18 | | - public ServiceCache() { |
19 | | - serviceCache = new HashMap<String, Service>(); |
20 | | - } |
| 16 | + private final Map<String, Service> serviceCache; |
| 17 | + |
| 18 | + public ServiceCache() { |
| 19 | + serviceCache = new HashMap<String, Service>(); |
| 20 | + } |
21 | 21 |
|
22 | | - /** |
23 | | - * Get the service from the cache. null if no service is found matching the |
24 | | - * name |
25 | | - * @param serviceName |
26 | | - * @return {@link Service} |
27 | | - */ |
28 | | - public Service getService(String serviceName){ |
29 | | - Service cachedService = null; |
30 | | - for (String serviceJndiName : serviceCache.keySet()){ |
31 | | - if( serviceJndiName.equals( serviceName ) ){ |
32 | | - cachedService = serviceCache.get(serviceJndiName); |
33 | | - System.out.println("(cache call) Fetched service " + cachedService.getName() + "("+cachedService.getId()+") from cache... !"); |
34 | | - } |
35 | | - } |
36 | | - return cachedService; |
37 | | - } |
| 22 | + /** |
| 23 | + * Get the service from the cache. null if no service is found matching the name |
| 24 | + * |
| 25 | + * @param serviceName a string |
| 26 | + * @return {@link Service} |
| 27 | + */ |
| 28 | + public Service getService(String serviceName) { |
| 29 | + Service cachedService = null; |
| 30 | + for (String serviceJndiName : serviceCache.keySet()) { |
| 31 | + if (serviceJndiName.equals(serviceName)) { |
| 32 | + cachedService = serviceCache.get(serviceJndiName); |
| 33 | + System.out.println("(cache call) Fetched service " + cachedService.getName() + "(" + cachedService.getId() + ") from cache... !"); |
| 34 | + } |
| 35 | + } |
| 36 | + return cachedService; |
| 37 | + } |
38 | 38 |
|
39 | | - /** |
40 | | - * Adds the service into the cache map |
41 | | - * @param newService |
42 | | - */ |
43 | | - public void addService(Service newService){ |
44 | | - serviceCache.put(newService.getName(), newService); |
45 | | - } |
| 39 | + /** |
| 40 | + * Adds the service into the cache map |
| 41 | + * |
| 42 | + * @param newService a {@link Service} |
| 43 | + */ |
| 44 | + public void addService(Service newService) { |
| 45 | + serviceCache.put(newService.getName(), newService); |
| 46 | + } |
46 | 47 | } |
0 commit comments