/** * Parse EhCache configuration from the given resource, for further use with * custom {@link CacheManager} creation. * @param configLocation the location of the configuration file (as a Spring resource) * @return the EhCache Configuration handle * @throws CacheException in case of configuration parsing failure * @see CacheManager#CacheManager(Configuration) * @see CacheManager#create(Configuration) */ public static Configuration parseConfiguration(Resource configLocation) throws CacheException { InputStream is = null; try { is = configLocation.getInputStream(); return ConfigurationFactory.parseConfiguration(is); } catch (IOException ex) { throw new CacheException("Failed to parse EhCache configuration resource", ex); } finally { if (is != null) { try { is.close(); } catch (IOException ex) { // ignore } } } }
/** * Parse EhCache configuration from the given resource, for further use with * custom {@link CacheManager} creation. * @param configLocation the location of the configuration file (as a Spring resource) * @return the EhCache Configuration handle * @throws CacheException in case of configuration parsing failure * @see CacheManager#CacheManager(Configuration) * @see CacheManager#create(Configuration) */ public static Configuration parseConfiguration(Resource configLocation) throws CacheException { InputStream is = null; try { is = configLocation.getInputStream(); return ConfigurationFactory.parseConfiguration(is); } catch (IOException ex) { throw new CacheException("Failed to parse EhCache configuration resource", ex); } finally { if (is != null) { try { is.close(); } catch (IOException ex) { // ignore } } } }
/** * Set rejoin value * * @param rejoin the rejoin to set */ public void setRejoin(boolean rejoin) { if (configFrozen) { throw new CacheException("Cannot enable/disable rejoin once config has been frozen"); } this.rejoin = rejoin; }
/** * Set wanEnabledTSA value * * @param wanEnabledTSA */ public void setWanEnabledTSA(boolean wanEnabledTSA) { if (configFrozen) { throw new CacheException("Cannot set wanEnabledTSA once config has been frozen"); } this.wanEnabledTSA = wanEnabledTSA; }
private void checkDynamicChange() { if (frozen) { throw new CacheException("Dynamic configuration changes are disabled for this cache"); } }
private void checkDynamicChange() { if (frozen) { throw new CacheException("Dynamic configuration changes are disabled for this cache"); } }
/** * Register a {@link CacheLoader} with the cache. It will then be tied into the cache lifecycle. * <p> * If the CacheLoader is not initialised, initialise it. * * @param cacheLoader A Cache Loader to register */ @Override public void registerCacheLoader(CacheLoader cacheLoader) { throw new CacheException("This method is not appropriate for a blocking cache."); }
/** * This method is not appropriate to use with BlockingCache. * * @throws CacheException if this method is called */ @Override public Map getAllWithLoader(Collection keys, Object loaderArgument) throws CacheException { throw new CacheException("This method is not appropriate for a Blocking Cache"); }
/** * This method is not appropriate to use with BlockingCache. * * @throws CacheException if this method is called */ @Override public void loadAll(Collection keys, Object argument) throws CacheException { throw new CacheException("This method is not appropriate for a Blocking Cache"); }
private V throwOrReturn() { if (throwable != null) { if (throwable instanceof RuntimeException) { throw (RuntimeException) throwable; } throw new CacheException("Faulting from repository failed", throwable); } return value; }
private static Class<? extends QueryManager> getImplementationClass() { try { return (Class<? extends QueryManager>)Class.forName("net.sf.ehcache.search.parser.QueryManagerImpl"); } catch (ClassNotFoundException e) { throw new CacheException(e); } }
/** * Creates an object name using the scheme "net.sf.ehcache:type=Store,CacheManager=<cacheManagerName>,name=<cacheName>" */ static ObjectName createObjectName(String cacheManagerName, String cacheName) { try { return new ObjectName("net.sf.ehcache:type=Store,CacheManager=" + cacheManagerName + ",name=" + EhcacheHibernateMbeanNames.mbeanSafe(cacheName)); } catch (MalformedObjectNameException e) { throw new CacheException(e); } }
private void checkCASOperationSupported(boolean doNotNotifyCacheReplicators) { if (!doNotNotifyCacheReplicators && registeredEventListeners.hasCacheReplicators()) { throw new CacheException( "You have configured the cache with a replication scheme that cannot properly support CAS operation guarantees."); } }
@Override public void process(SingleAsyncOperation item) { try { item.performSingleOperation(cacheWriter); } catch (Exception e) { throw new CacheException("Unexpected exception while processing write behind operation", e); } }
@Override public WriteBehind createWriteBehind() { if (underlyingStore instanceof TerracottaStore) { return ((TerracottaStore)underlyingStore).createWriteBehind(); } throw new CacheException("underlying store is not an instance of TerracottaStore"); }
@Override public void quickClear() { if (underlyingStore instanceof TerracottaStore) { ((TerracottaStore)underlyingStore).quickClear(); } throw new CacheException("underlying store is not an instance of TerracottaStore"); }
private MemoryEfficientByteArrayOutputStream serializeElement(Element element) throws IOException { // A ConcurrentModificationException can occur because Java's serialization // mechanism is not threadsafe and POJOs are seldom implemented in a threadsafe way. // e.g. we are serializing an ArrayList field while another thread somewhere in the application is appending to it. try { return MemoryEfficientByteArrayOutputStream.serialize(element); } catch (ConcurrentModificationException e) { throw new CacheException("Failed to serialize element due to ConcurrentModificationException. " + "This is frequently the result of inappropriately sharing thread unsafe object " + "(eg. ArrayList, HashMap, etc) between threads", e); } }
/** * {@inheritDoc} */ public Query createQuery() { if (!isSearchable()) { throw new CacheException("This cache is not configured for search"); } return new CacheQuery(this); }
/** * {@inheritDoc} */ public void waitUntilClusterBulkLoadComplete() throws UnsupportedOperationException, TerracottaNotRunningException { checkStatus(); try { compoundStore.waitUntilClusterCoherent(); } catch (InterruptedException e) { // re-throw as cacheException throw new CacheException(e); } }
private void setId(Element element) { long id = elementIdSequence.next(); if (id <= 0) { throw new CacheException("Element ID must be > 0"); } ElementIdHelper.setId(element, id); }