1 /* 2 * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package de.smartics.properties.spi.config.cache; 17 18 import de.smartics.properties.core.services.AbstractJndiBackedServiceFactory; 19 20 /** 21 * Creates instances of the {@link CacheManager}. 22 * <p> 23 * Returns the manager for caches. The manager class is registered in 24 * <code>META-INF/services/de.smartics.properties.spi.config.cache.CacheManager</code> 25 * . 26 * </p> 27 * <p> 28 * Issues a warning if more than one implementation is found. Returns an 29 * instance of the first implementation found. If no type is specified, returns 30 * an instance of {@link AmnesiaCacheManager} per default. 31 * </p> 32 */ 33 public final class CacheManagerFactory extends 34 AbstractJndiBackedServiceFactory<CacheManager> 35 { 36 // ********************************* Fields ********************************* 37 38 // --- constants ------------------------------------------------------------ 39 40 /** 41 * The singleton. 42 */ 43 private static final CacheManagerFactory INSTANCE = new CacheManagerFactory(); 44 45 // --- members -------------------------------------------------------------- 46 47 // ****************************** Initializer ******************************* 48 49 // ****************************** Constructors ****************************** 50 51 /** 52 * Default constructor. 53 */ 54 private CacheManagerFactory() 55 { 56 super(CacheManager.class); 57 } 58 59 // ****************************** Inner Classes ***************************** 60 61 // ********************************* Methods ******************************** 62 63 // --- init ----------------------------------------------------------------- 64 65 // --- get&set -------------------------------------------------------------- 66 67 /** 68 * Returns the singleton instance for this factory. 69 * 70 * @return the singleton instance. 71 */ 72 public static CacheManagerFactory getInstance() 73 { 74 return INSTANCE; 75 } 76 77 // --- business ------------------------------------------------------------- 78 79 /** 80 * Returns the a new instance of a cache manager. 81 * 82 * @return a new instance of a cache manager. Never <code>null</code>. 83 */ 84 public CacheManager createManager() 85 { 86 return INSTANCE.create(InMemoryCacheManager.class); 87 } 88 89 /** 90 * Returns the an instance of a cache manager for a given id or create a new 91 * one on first request. 92 * 93 * @param id fetch the cache manager for the given id or create a new one on 94 * first request. 95 * @return an instance of a cache manager. Never <code>null</code>. 96 */ 97 public CacheManager getManager(final String id) 98 { 99 return INSTANCE.create(InMemoryCacheManager.class); 100 } 101 // --- object basics -------------------------------------------------------- 102 103 }