/** * Creates a new class instance with the given loader. Logs errors along the way. * * @param loader the classloader to load the class * @param className a fully qualified class name * @return the newly created instance * @throws CacheException if instance cannot be created due to a missing class or exception */ public static Object createNewInstance(ClassLoader loader, String className) throws CacheException { return createNewInstance(loader, className, new Class[0], new Object[0]); }
/** * Get (and potentially) instantiate the instance * * @param cacheConfiguration the cache configuration * @param loader classloader to use to create the instance * @return the instance */ public ElementValueComparator createElementComparatorInstance(CacheConfiguration cacheConfiguration, ClassLoader loader) { try { if (DEFAULT_IMPL.equals(className)) { loader = getClass().getClassLoader(); } return (ElementValueComparator) ClassLoaderUtil.createNewInstance( loader, className, new Class[] {CacheConfiguration.class}, new Object[] {cacheConfiguration} ); } catch (ClassCastException cce) { throw new CacheException(className + " must implement " + ElementValueComparator.class.getName(), cce); } }
/** * Construct the extractor for this attribute configuration */ public AttributeExtractor constructExtractor(ClassLoader loader) { if (name == null) { throw new InvalidConfigurationException("search attribute has no name"); } if (expression != null) { return new ReflectionAttributeExtractor(expression); } else if (className != null) { if (properties != null) { return (AttributeExtractor) ClassLoaderUtil.createNewInstance(loader, className, new Class[] {Properties.class}, new Object[] {PropertyUtil.parseProperties(properties, propertySeparator)}); } else { return (AttributeExtractor) ClassLoaderUtil.createNewInstance(loader, className); } } else { return new JavaBeanAttributeExtractor(name); } }
/** * Tries to load the class specified. * * @return If there is none returns null. * @param cacheManager */ public final CacheManagerEventListener createCacheManagerEventListener(CacheManager cacheManager) throws CacheException { String className = null; FactoryConfiguration cacheManagerEventListenerFactoryConfiguration = configuration.getCacheManagerEventListenerFactoryConfiguration(); if (cacheManagerEventListenerFactoryConfiguration != null) { className = cacheManagerEventListenerFactoryConfiguration.getFullyQualifiedClassPath(); } if (className == null || className.length() == 0) { LOG.debug("No CacheManagerEventListenerFactory class specified. Skipping..."); return null; } else { CacheManagerEventListenerFactory factory = (CacheManagerEventListenerFactory) ClassLoaderUtil.createNewInstance(loader, className); Properties properties = PropertyUtil.parseProperties(cacheManagerEventListenerFactoryConfiguration.properties, cacheManagerEventListenerFactoryConfiguration.getPropertySeparator()); return factory.createCacheManagerEventListener(cacheManager, properties); } }
/** * Tries to create a CacheLoader from the configuration using the factory * specified. * * @return The CacheExceptionHandler, or null if it could not be found. */ public static CacheExceptionHandler createCacheExceptionHandler( CacheConfiguration.CacheExceptionHandlerFactoryConfiguration factoryConfiguration, ClassLoader loader) throws CacheException { String className = null; CacheExceptionHandler cacheExceptionHandler = null; if (factoryConfiguration != null) { className = factoryConfiguration.getFullyQualifiedClassPath(); } if (className == null || className.length() == 0) { LOG.debug("No CacheExceptionHandlerFactory class specified. Skipping..."); } else { CacheExceptionHandlerFactory factory = (CacheExceptionHandlerFactory) ClassLoaderUtil.createNewInstance(loader, className); Properties properties = PropertyUtil.parseProperties(factoryConfiguration.getProperties(), factoryConfiguration.getPropertySeparator()); return factory.createExceptionHandler(properties); } return cacheExceptionHandler; }
/** * Tries to load a BootstrapCacheLoader from the class specified. * @param loader * * @return If there is none returns null. */ private static final BootstrapCacheLoader createBootstrapCacheLoader( CacheConfiguration.BootstrapCacheLoaderFactoryConfiguration factoryConfiguration, ClassLoader loader) throws CacheException { String className = null; BootstrapCacheLoader bootstrapCacheLoader = null; if (factoryConfiguration != null) { className = factoryConfiguration.getFullyQualifiedClassPath(); } if (className == null || className.length() == 0) { LOG.debug("No BootstrapCacheLoaderFactory class specified. Skipping..."); } else { BootstrapCacheLoaderFactory factory = (BootstrapCacheLoaderFactory) ClassLoaderUtil.createNewInstance(loader, className); Properties properties = PropertyUtil.parseProperties(factoryConfiguration.getProperties(), factoryConfiguration.getPropertySeparator()); return factory.createBootstrapCacheLoader(properties); } return bootstrapCacheLoader; }
/** * Tries to load the class specified otherwise defaults to null. * * @param factoryConfiguration * @param loader */ private static CacheLoader createCacheLoader( CacheConfiguration.CacheLoaderFactoryConfiguration factoryConfiguration, Ehcache cache, ClassLoader loader) { String className = null; CacheLoader cacheLoader = null; if (factoryConfiguration != null) { className = factoryConfiguration.getFullyQualifiedClassPath(); } if (className == null) { LOG.debug("CacheLoader factory not configured. Skipping..."); } else { CacheLoaderFactory factory = (CacheLoaderFactory) ClassLoaderUtil.createNewInstance(loader, className); Properties properties = PropertyUtil.parseProperties(factoryConfiguration.getProperties(), factoryConfiguration.getPropertySeparator()); cacheLoader = factory.createCacheLoader(cache, properties); } return cacheLoader; }
/** * Tries to load the class specified otherwise defaults to null */ public Map<String, CacheManagerPeerListener> createCachePeerListeners() { String className = null; Map<String, CacheManagerPeerListener> cacheManagerPeerListeners = new HashMap<String, CacheManagerPeerListener>(); List<FactoryConfiguration> cacheManagerPeerListenerFactoryConfigurations = configuration.getCacheManagerPeerListenerFactoryConfigurations(); boolean first = true; for (FactoryConfiguration factoryConfiguration : cacheManagerPeerListenerFactoryConfigurations) { if (factoryConfiguration != null) { className = factoryConfiguration.getFullyQualifiedClassPath(); } if (className == null) { LOG.debug("No CachePeerListenerFactoryConfiguration specified. Not configuring a CacheManagerPeerListener."); return null; } else { CacheManagerPeerListenerFactory cacheManagerPeerListenerFactory = (CacheManagerPeerListenerFactory) ClassLoaderUtil.createNewInstance(loader, className); Properties properties = PropertyUtil.parseProperties(factoryConfiguration.getProperties(), factoryConfiguration.getPropertySeparator()); CacheManagerPeerListener cacheManagerPeerListener = cacheManagerPeerListenerFactory.createCachePeerListener(cacheManager, properties); cacheManagerPeerListeners.put(cacheManagerPeerListener.getScheme(), cacheManagerPeerListener); } } return cacheManagerPeerListeners; }
/** * Tries to load the class specified otherwise defaults to null. * * @param factoryConfiguration * @param loader */ private static CacheExtension createCacheExtension( CacheConfiguration.CacheExtensionFactoryConfiguration factoryConfiguration, Ehcache cache, ClassLoader loader) { String className = null; CacheExtension cacheExtension = null; if (factoryConfiguration != null) { className = factoryConfiguration.getFullyQualifiedClassPath(); } if (className == null) { LOG.debug("CacheExtension factory not configured. Skipping..."); } else { CacheExtensionFactory factory = (CacheExtensionFactory) ClassLoaderUtil.createNewInstance(loader, className); Properties properties = PropertyUtil.parseProperties(factoryConfiguration.getProperties(), factoryConfiguration.getPropertySeparator()); cacheExtension = factory.createCacheExtension(cache, properties); } return cacheExtension; }
/** * Tries to load the class specified otherwise defaults to null. * * @param config * @param loader */ private static CacheWriter createCacheWriter(CacheWriterConfiguration config, Ehcache cache, ClassLoader loader) { String className = null; CacheWriter cacheWriter = null; CacheWriterConfiguration.CacheWriterFactoryConfiguration factoryConfiguration = config.getCacheWriterFactoryConfiguration(); if (factoryConfiguration != null) { className = factoryConfiguration.getFullyQualifiedClassPath(); } if (null == className) { LOG.debug("CacheWriter factory not configured. Skipping..."); } else { CacheWriterFactory factory = (CacheWriterFactory) ClassLoaderUtil.createNewInstance(loader, className); Properties properties = PropertyUtil.parseProperties(factoryConfiguration.getProperties(), factoryConfiguration.getPropertySeparator()); if (null == properties) { properties = new Properties(); } cacheWriter = factory.createCacheWriter(cache, properties); } return cacheWriter; }
/** * Tries to load the class specified otherwise defaults to null * * @return a map of CacheManagerPeerProviders */ public Map<String, CacheManagerPeerProvider> createCachePeerProviders() { String className = null; Map<String, CacheManagerPeerProvider> cacheManagerPeerProviders = new HashMap<String, CacheManagerPeerProvider>(); List<FactoryConfiguration> cachePeerProviderFactoryConfiguration = configuration.getCacheManagerPeerProviderFactoryConfiguration(); for (FactoryConfiguration factoryConfiguration : cachePeerProviderFactoryConfiguration) { if (factoryConfiguration != null) { className = factoryConfiguration.getFullyQualifiedClassPath(); } if (className == null) { LOG.debug("No CachePeerProviderFactoryConfiguration specified. Not configuring a CacheManagerPeerProvider."); return null; } else { CacheManagerPeerProviderFactory cacheManagerPeerProviderFactory = (CacheManagerPeerProviderFactory) ClassLoaderUtil.createNewInstance(loader, className); Properties properties = PropertyUtil.parseProperties(factoryConfiguration.getProperties(), factoryConfiguration.getPropertySeparator()); CacheManagerPeerProvider cacheManagerPeerProvider = cacheManagerPeerProviderFactory.createCachePeerProvider(cacheManager, properties); cacheManagerPeerProviders.put(cacheManagerPeerProvider.getScheme(), cacheManagerPeerProvider); } } return cacheManagerPeerProviders; }
/** * Tries to load the class specified otherwise defaults to null. * * @param factoryConfiguration * @param loader */ private static CacheEventListener createCacheEventListener( CacheConfiguration.CacheEventListenerFactoryConfiguration factoryConfiguration, ClassLoader loader) { String className = null; CacheEventListener cacheEventListener = null; if (factoryConfiguration != null) { className = factoryConfiguration.getFullyQualifiedClassPath(); } if (className == null) { LOG.debug("CacheEventListener factory not configured. Skipping..."); } else { CacheEventListenerFactory factory = (CacheEventListenerFactory) ClassLoaderUtil.createNewInstance(loader, className); Properties properties = PropertyUtil.parseProperties(factoryConfiguration.getProperties(), factoryConfiguration.getPropertySeparator()); cacheEventListener = factory.createCacheEventListener(properties); } return cacheEventListener; }
return (ClusteredInstanceFactory) ClassLoaderUtil.createNewInstance(getClass().getClassLoader(), factoryClass.getName(), new Class[] {TerracottaClientConfiguration.class, ClassLoader.class}, new Object[] {terracottaConfig, loader}); } catch (CacheException ce) {
/** * Creates the decorated cache from the decorator config specified. Returns null if the name of the factory class is not specified */ private static Ehcache createDecoratedCache(Ehcache cache, CacheConfiguration.CacheDecoratorFactoryConfiguration factoryConfiguration, boolean forDefaultCache, ClassLoader loader) { if (factoryConfiguration == null) { return null; } String className = factoryConfiguration.getFullyQualifiedClassPath(); if (className == null) { LOG.debug("CacheDecoratorFactory was specified without the name of the factory. Skipping..."); return null; } else { CacheDecoratorFactory factory = (CacheDecoratorFactory) ClassLoaderUtil.createNewInstance(loader, className); Properties properties = PropertyUtil.parseProperties(factoryConfiguration.getProperties(), factoryConfiguration.getPropertySeparator()); if (forDefaultCache) { return factory.createDefaultDecoratedEhcache(cache, properties); } else { return factory.createDecoratedEhcache(cache, properties); } } }
/** * Creates a new class instance with the given loader. Logs errors along the way. * * @param loader the classloader to load the class * @param className a fully qualified class name * @return the newly created instance * @throws CacheException if instance cannot be created due to a missing class or exception */ public static Object createNewInstance(ClassLoader loader, String className) throws CacheException { return createNewInstance(loader, className, new Class[0], new Object[0]); }
/** * Creates a new class instance. Logs errors along the way. Classes are loaded using the * ehcache standard classloader. * * @param className a fully qualified class name * @return the newly created instance * @throws CacheException if instance cannot be created due to a missing class or exception */ public static Object createNewInstance(String className) throws CacheException { return createNewInstance(className, new Class[0], new Object[0]); }
/** * Creates a new class instance with the given loader. Logs errors along the way. * * @param loader the classloader to load the class * @param className a fully qualified class name * @return the newly created instance * @throws CacheException if instance cannot be created due to a missing class or exception */ public static Object createNewInstance(ClassLoader loader, String className) throws CacheException { return createNewInstance(loader, className, new Class[0], new Object[0]); }
/** * Get (and potentially) instantiate the instance * * @param cacheConfiguration the cache configuration * @return the instance */ public ElementValueComparator createElementComparatorInstance(CacheConfiguration cacheConfiguration) { try { return (ElementValueComparator) ClassLoaderUtil.createNewInstance( className, new Class[] {CacheConfiguration.class}, new Object[] {cacheConfiguration} ); } catch (ClassCastException cce) { throw new CacheException(className + " must implement " + ElementValueComparator.class.getName(), cce); } }
/** * {@inheritDoc} */ @Override public NonstopTimeoutBehaviorFactory getTimeoutBehaviorFactory(Properties properties) { if (properties == null || !properties.containsKey(CUSTOM_TYPE_FACTORY_PROPERTY_NAME)) { throw new CacheException("When using " + getTypeName() + " timeout behavior type, need to set properties with key '" + CUSTOM_TYPE_FACTORY_PROPERTY_NAME + "', specified properties: " + (properties == null ? "NULL" : properties)); } final String customFactoryClassName = properties.getProperty(CUSTOM_TYPE_FACTORY_PROPERTY_NAME); Object factory = ClassLoaderUtil.createNewInstance(customFactoryClassName); if (!(factory instanceof NonstopTimeoutBehaviorFactory)) { throw new CacheException("The factory '" + customFactoryClassName + "' is NOT an instance of " + NonstopTimeoutBehaviorFactory.class.getName()); } return (NonstopTimeoutBehaviorFactory) factory; } };
/** * Tries to load the class specified. * * @return If there is none returns null. * @param cacheManager */ public final CacheManagerEventListener createCacheManagerEventListener(CacheManager cacheManager) throws CacheException { String className = null; FactoryConfiguration cacheManagerEventListenerFactoryConfiguration = configuration.getCacheManagerEventListenerFactoryConfiguration(); if (cacheManagerEventListenerFactoryConfiguration != null) { className = cacheManagerEventListenerFactoryConfiguration.getFullyQualifiedClassPath(); } if (className == null || className.length() == 0) { LOG.debug("No CacheManagerEventListenerFactory class specified. Skipping..."); return null; } else { CacheManagerEventListenerFactory factory = (CacheManagerEventListenerFactory) ClassLoaderUtil.createNewInstance(loader, className); Properties properties = PropertyUtil.parseProperties(cacheManagerEventListenerFactoryConfiguration.properties, cacheManagerEventListenerFactoryConfiguration.getPropertySeparator()); return factory.createCacheManagerEventListener(cacheManager, properties); } }