/** * Returns the factory class for this mode or null if class is not present in classpath * * @return the factory class for this mode or null if class is not present in classpath */ public Class getFactoryClassOrNull() { try { return ClassLoaderUtil.loadClass(factoryClassName); } catch (ClassNotFoundException e) { return null; } } }
@Override protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { return ClassLoaderUtil.loadClass(desc.getName()); }
/** * {@inheritDoc} */ @Override protected TransactionManager doLookup() { TransactionManager transactionManager = null; try { Class txManagerClass = ClassLoaderUtil.loadClass(classname); transactionManager = (TransactionManager) txManagerClass.newInstance(); } catch (ClassNotFoundException e) { LOG.debug("FactorySelector failed lookup", e); } catch (InstantiationException e) { LOG.debug("FactorySelector failed lookup", e); } catch (IllegalAccessException e) { LOG.debug("FactorySelector failed lookup", e); } return transactionManager; } }
/** * {@inheritDoc} */ @Override public void registerResource(EhcacheXAResource ehcacheXAResource, boolean forRecovery) { String uniqueName = ehcacheXAResource.getCacheName(); try { Class producerClass = ClassLoaderUtil.loadClass("bitronix.tm.resource.ehcache.EhCacheXAResourceProducer"); Class[] signature = new Class[] {String.class, XAResource.class}; Object[] args = new Object[] {uniqueName, ehcacheXAResource}; Method method = producerClass.getMethod("registerXAResource", signature); method.invoke(null, args); } catch (Exception e) { LOG.error("unable to register resource of cache " + uniqueName + " with BTM", e); } }
/** * {@inheritDoc} */ @Override public void unregisterResource(EhcacheXAResource ehcacheXAResource, boolean forRecovery) { String uniqueName = ehcacheXAResource.getCacheName(); try { Class producerClass = ClassLoaderUtil.loadClass("bitronix.tm.resource.ehcache.EhCacheXAResourceProducer"); Class[] signature = new Class[] {String.class, XAResource.class}; Object[] args = new Object[] {uniqueName, ehcacheXAResource}; Method method = producerClass.getMethod("unregisterXAResource", signature); method.invoke(null, args); } catch (Exception e) { LOG.error("unable to unregister resource of cache " + uniqueName + " with BTM", e); } } }
/** * {@inheritDoc} */ @Override protected TransactionManager doLookup() { TransactionManager transactionManager = null; try { Class factoryClass = ClassLoaderUtil.loadClass(factoryClassName); Class[] signature = null; Object[] args = null; Method method = factoryClass.getMethod(factoryMethodName, signature); transactionManager = (TransactionManager) method.invoke(null, args); } catch (ClassNotFoundException e) { LOG.debug("FactorySelector failed lookup", e); } catch (NoSuchMethodException e) { LOG.debug("FactorySelector failed lookup", e); } catch (InvocationTargetException e) { LOG.debug("FactorySelector failed lookup", e); } catch (IllegalAccessException e) { LOG.debug("FactorySelector failed lookup", e); } return transactionManager; } }
/** * {@inheritDoc} */ @Override public void registerResource(EhcacheXAResource ehcacheXAResource, boolean forRecovery) { if (!forRecovery) { return; } String uniqueName = ehcacheXAResource.getCacheName(); try { Class tmImplClass = ClassLoaderUtil.loadClass("weblogic.transaction.TransactionManager"); Class[] signature = new Class[] {String.class, XAResource.class}; Object[] args = new Object[] {uniqueName, ehcacheXAResource}; Method method = tmImplClass.getMethod("registerResource", signature); method.invoke(getTransactionManager(), args); } catch (Exception e) { LOG.error("unable to register resource of cache " + uniqueName + " with Weblogic", e); } }
/** * Get (and potentially) instantiate the instance * * @return the instance */ public synchronized ReadWriteCopyStrategy<Element> getCopyStrategyInstance() { if (strategy == null) { Class copyStrategy = null; try { copyStrategy = ClassLoaderUtil.loadClass(className); Object strategyObject = copyStrategy.newInstance(); if (strategyObject instanceof CopyStrategy) { strategy = new LegacyCopyStrategyAdapter((CopyStrategy) strategyObject); } else { strategy = (ReadWriteCopyStrategy<Element>) strategyObject; } } catch (ClassNotFoundException e) { throw new RuntimeException("Couldn't find the CopyStrategy class!", e); } catch (InstantiationException e) { throw new RuntimeException("Couldn't instantiate the CopyStrategy instance!", e); } catch (IllegalAccessException e) { throw new RuntimeException("Couldn't instantiate the CopyStrategy instance!", e); } catch (ClassCastException e) { throw new RuntimeException(copyStrategy != null ? copyStrategy.getSimpleName() + " doesn't implement net.sf.ehcache.store.compound.CopyStrategy" : "Error with CopyStrategy", e); } } return strategy; }
/** * {@inheritDoc} */ @Override public void unregisterResource(final EhcacheXAResource ehcacheXAResource, final boolean forRecovery) { if (!forRecovery) { return; } String uniqueName = ehcacheXAResource.getCacheName(); try { Class tmImplClass = ClassLoaderUtil.loadClass("weblogic.transaction.TransactionManager"); Class[] signature = new Class[] {String.class, Boolean.TYPE}; Object[] args = new Object[] {uniqueName, Boolean.TRUE}; Method method = tmImplClass.getMethod("unregisterResource", signature); method.invoke(getTransactionManager(), args); } catch (Exception e) { LOG.error("unable to unregister resource of cache " + uniqueName + " with Weblogic", e); } }
private FeaturesManager retrieveFeaturesManager() { try { Class<? extends FeaturesManager> featuresManagerClass = ClassLoaderUtil.loadClass(FeaturesManager.ENTERPRISE_FM_CLASSNAME); try { return featuresManagerClass.getConstructor(CacheManager.class).newInstance(this); } catch (NoSuchMethodException e) { throw new CacheException("Cannot find Enterprise features manager"); } catch (InvocationTargetException e) { Throwable cause = e.getCause(); if (cause instanceof CacheException) { throw (CacheException) cause; } else { throw new CacheException("Cannot instantiate enterprise features manager", cause); } } catch (IllegalAccessException e) { throw new CacheException("Cannot instantiate enterprise features manager", e); } catch (InstantiationException e) { throw new CacheException("Cannot instantiate enterprise features manager", e); } } catch (ClassNotFoundException e) { return null; } } }
Object newInstance; try { clazz = loadClass(className); } catch (ClassNotFoundException e) { throw new CacheException("Unable to load class " + className +
private long getOffHeapLimit() { try { Class<Store> enterpriseFmClass = ClassLoaderUtil.loadClass(FeaturesManager.ENTERPRISE_FM_CLASSNAME); try { return (Long)enterpriseFmClass.getMethod("getMaxBytesAllocatable").invoke(null); } catch (NoSuchMethodException e) { throw new CacheException("Cache: " + getName() + " cannot find static factory" + " method create(Ehcache, String)" + " in store class " + FeaturesManager.ENTERPRISE_FM_CLASSNAME, e); } catch (InvocationTargetException e) { Throwable cause = e.getCause(); throw new CacheException("Cache: " + getName() + " cannot instantiate store " + FeaturesManager.ENTERPRISE_FM_CLASSNAME, cause); } catch (IllegalAccessException e) { throw new CacheException("Cache: " + getName() + " cannot instantiate store " + FeaturesManager.ENTERPRISE_FM_CLASSNAME, e); } } catch (ClassNotFoundException e) { throw new CacheException("Cache " + getName() + " cannot be configured because the off-heap store class could not be found. " + "You must use an enterprise version of Ehcache to successfully enable overflowToOffHeap."); } }