当前位置: 首页>>代码示例>>Java>>正文


Java CachePersistenceException类代码示例

本文整理汇总了Java中org.ehcache.CachePersistenceException的典型用法代码示例。如果您正苦于以下问题:Java CachePersistenceException类的具体用法?Java CachePersistenceException怎么用?Java CachePersistenceException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CachePersistenceException类属于org.ehcache包,在下文中一共展示了CachePersistenceException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPersistenceSpaceIdentifier

import org.ehcache.CachePersistenceException; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public PersistenceSpaceIdentifier<DiskResourceService> getPersistenceSpaceIdentifier(String name, CacheConfiguration<?, ?> config) throws CachePersistenceException {
  if (persistenceService == null) {
    return null;
  }
  boolean persistent = config.getResourcePools().getPoolForResource(ResourceType.Core.DISK).isPersistent();
  while (true) {
    PersistenceSpace persistenceSpace = knownPersistenceSpaces.get(name);
    if (persistenceSpace != null) {
      return persistenceSpace.identifier;
    }
    PersistenceSpace newSpace = createSpace(name, persistent);
    if (newSpace != null) {
      return newSpace.identifier;
    }
  }
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:21,代码来源:DefaultDiskResourceService.java

示例2: releasePersistenceSpaceIdentifier

import org.ehcache.CachePersistenceException; //导入依赖的package包/类
@Override
public void releasePersistenceSpaceIdentifier(PersistenceSpaceIdentifier<?> identifier) throws CachePersistenceException {
  String name = null;
  for (Map.Entry<String, PersistenceSpace> entry : knownPersistenceSpaces.entrySet()) {
    if (entry.getValue().identifier.equals(identifier)) {
      name = entry.getKey();
    }
  }
  if (name == null) {
    throw newCachePersistenceException(identifier);
  }
  PersistenceSpace persistenceSpace = knownPersistenceSpaces.remove(name);
  if (persistenceSpace != null) {
    for (FileBasedStateRepository stateRepository : persistenceSpace.stateRepositories.values()) {
      try {
        stateRepository.close();
      } catch (IOException e) {
        LOGGER.warn("StateRepository close failed - destroying persistence space {} to prevent corruption", identifier, e);
        persistenceService.destroySafeSpace(((DefaultPersistenceSpaceIdentifier)identifier).persistentSpaceId, true);
      }
    }
  }
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:24,代码来源:DefaultDiskResourceService.java

示例3: createSpace

import org.ehcache.CachePersistenceException; //导入依赖的package包/类
private PersistenceSpace createSpace(String name, boolean persistent) throws CachePersistenceException {
  DefaultPersistenceSpaceIdentifier persistenceSpaceIdentifier =
      new DefaultPersistenceSpaceIdentifier(persistenceService.createSafeSpaceIdentifier(PERSISTENCE_SPACE_OWNER, name));
  PersistenceSpace persistenceSpace = new PersistenceSpace(persistenceSpaceIdentifier);
  if (knownPersistenceSpaces.putIfAbsent(name, persistenceSpace) == null) {
    boolean created = false;
    try {
      if (!persistent) {
        persistenceService.destroySafeSpace(persistenceSpaceIdentifier.persistentSpaceId, true);
      }
      persistenceService.createSafeSpace(persistenceSpaceIdentifier.persistentSpaceId);
      created = true;
    } finally {
      if (!created) {
        // this happens only if an exception is thrown..clean up for any throwable..
        knownPersistenceSpaces.remove(name, persistenceSpace);
      }
    }
    return persistenceSpace;
  }
  return null;
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:23,代码来源:DefaultDiskResourceService.java

示例4: getStateRepositoryWithin

import org.ehcache.CachePersistenceException; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public StateRepository getStateRepositoryWithin(PersistenceSpaceIdentifier<?> identifier, String name)
    throws CachePersistenceException {

  PersistenceSpace persistenceSpace = getPersistenceSpace(identifier);
  if(persistenceSpace == null) {
    throw newCachePersistenceException(identifier);
  }

  FileBasedStateRepository stateRepository = new FileBasedStateRepository(
      FileUtils.createSubDirectory(persistenceSpace.identifier.persistentSpaceId.getRoot(), name));
  FileBasedStateRepository previous = persistenceSpace.stateRepositories.putIfAbsent(name, stateRepository);
  if (previous != null) {
    return previous;
  }
  return stateRepository;
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:21,代码来源:DefaultDiskResourceService.java

示例5: testPhysicalDestroy

import org.ehcache.CachePersistenceException; //导入依赖的package包/类
@Test
public void testPhysicalDestroy() throws IOException, CachePersistenceException {
  final File f = folder.newFolder("testPhysicalDestroy");
  final DefaultLocalPersistenceService service = new DefaultLocalPersistenceService(new DefaultPersistenceConfiguration(f));
  service.start(null);

  assertThat(service.getLockFile().exists(), is(true));
  assertThat(f, isLocked());

  LocalPersistenceService.SafeSpaceIdentifier id = service.createSafeSpaceIdentifier("test", "test");
  service.createSafeSpace(id);

  assertThat(f, containsCacheDirectory("test", "test"));

  // try to destroy the physical space without the logical id
  LocalPersistenceService.SafeSpaceIdentifier newId = service.createSafeSpaceIdentifier("test", "test");
  service.destroySafeSpace(newId, false);

  assertThat(f, not(containsCacheDirectory("test", "test")));

  service.stop();

  assertThat(f, not(isLocked()));
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:25,代码来源:DefaultLocalPersistenceServiceTest.java

示例6: testCreateCacheWithSameAliasAfterDestroy

import org.ehcache.CachePersistenceException; //导入依赖的package包/类
@Test
public void testCreateCacheWithSameAliasAfterDestroy() throws URISyntaxException, CachePersistenceException {
  File file = new File(getStoragePath(), "testDestroy");
  initCacheManager(file);

  persistentCacheManager.destroyCache(PERSISTENT_CACHE);

  persistentCacheManager.createCache(PERSISTENT_CACHE, CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
      newResourcePoolsBuilder()
          .heap(10, EntryUnit.ENTRIES)
          .disk(10L, MemoryUnit.MB, true))
      .build());

  assertNotNull(persistentCacheManager.getCache(PERSISTENT_CACHE, Long.class, String.class));

  persistentCacheManager.close();
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:18,代码来源:CacheManagerDestroyRemovesPersistenceTest.java

示例7: getStartedProvider

import org.ehcache.CachePersistenceException; //导入依赖的package包/类
private DefaultSerializationProvider getStartedProvider() throws CachePersistenceException {
  DefaultSerializationProvider defaultProvider = new DefaultSerializationProvider(null);

  @SuppressWarnings("unchecked")
  ServiceProvider<Service> serviceProvider = mock(ServiceProvider.class);
  DiskResourceService diskResourceService = mock(DiskResourceService.class);
  when(diskResourceService.createPersistenceContextWithin(any(PersistableResourceService.PersistenceSpaceIdentifier.class), anyString()))
        .thenReturn(() -> {
          try {
            return tempFolder.newFolder();
          } catch (IOException e) {
            fail("unable to create persistence ");
            return null;
          }
        });
  when(serviceProvider.getService(DiskResourceService.class)).thenReturn(diskResourceService);
  defaultProvider.start(serviceProvider);
  return defaultProvider;
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:20,代码来源:DefaultSerializationProviderTest.java

示例8: closeEhcache

import org.ehcache.CachePersistenceException; //导入依赖的package包/类
/**
 * Perform cache closure actions specific to a cache manager implementation.
 * This method is called <i>after</i> the {@code InternalCache} instance is closed.
 *
 * @param alias the cache alias
 * @param ehcache the {@code InternalCache} instance for the cache to close
 */
protected void closeEhcache(final String alias, final InternalCache<?, ?> ehcache) {
  for (ResourceType<?> resourceType : ehcache.getRuntimeConfiguration().getResourcePools().getResourceTypeSet()) {
    if (resourceType.isPersistable()) {
      ResourcePool resourcePool = ehcache.getRuntimeConfiguration()
          .getResourcePools()
          .getPoolForResource(resourceType);
      if (!resourcePool.isPersistent()) {
        PersistableResourceService persistableResourceService = getPersistableResourceService(resourceType);
        try {
          persistableResourceService.destroy(alias);
        } catch (CachePersistenceException e) {
          LOGGER.warn("Unable to clear persistence space for cache {}", alias, e);
        }
      }
    }
  }
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:25,代码来源:EhcacheManager.java

示例9: testDestroyCacheFailsAndStopIfStartingServicesFails

import org.ehcache.CachePersistenceException; //导入依赖的package包/类
@Test
public void testDestroyCacheFailsAndStopIfStartingServicesFails() throws CachePersistenceException, InterruptedException {
  Map<String, CacheConfiguration<?, ?>> caches = newCacheMap();
  DefaultConfiguration config = new DefaultConfiguration(caches, null);
  List<Service> services = minimumCacheManagerServices();
  MaintainableService service = mock(MaintainableService.class);
  doThrow(new RuntimeException("failed")).when(service)
    .startForMaintenance(Mockito.<ServiceProvider<MaintainableService>>any(), eq(MaintainableService.MaintenanceScope.CACHE));
  services.add(service);

  EhcacheManager manager = new EhcacheManager(config, services);

  expectedException.expect(StateTransitionException.class);
  expectedException.expectMessage("failed");

  manager.destroyCache("test");

  assertThat(manager.getStatus(), equalTo(Status.UNINITIALIZED));
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:20,代码来源:EhcacheManagerTest.java

示例10: getStateRepositoryWithin

import org.ehcache.CachePersistenceException; //导入依赖的package包/类
@Override
public StateRepository getStateRepositoryWithin(PersistenceSpaceIdentifier<?> identifier, String name) throws CachePersistenceException {
  ClusteredCacheIdentifier clusterCacheIdentifier = (ClusteredCacheIdentifier) identifier;
  ClusteredSpace clusteredSpace = knownPersistenceSpaces.get(clusterCacheIdentifier.getId());
  if (clusteredSpace == null) {
    throw new CachePersistenceException("Clustered space not found for identifier: " + clusterCacheIdentifier);
  }
  ConcurrentMap<String, ClusterStateRepository> stateRepositories = clusteredSpace.stateRepositories;
  ClusterStateRepository currentRepo = stateRepositories.get(name);
  if(currentRepo != null) {
    return currentRepo;
  } else {
    ClusterStateRepository newRepo = new ClusterStateRepository(clusterCacheIdentifier, name, clusterTierEntities.get(clusterCacheIdentifier.getId()));
    currentRepo = stateRepositories.putIfAbsent(name, newRepo);
    if (currentRepo == null) {
      return newRepo;
    } else {
      return currentRepo;
    }
  }
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:22,代码来源:DefaultClusteringService.java

示例11: testGetNoExpirationPropagatedToHigherTiers

import org.ehcache.CachePersistenceException; //导入依赖的package包/类
@Test
public void testGetNoExpirationPropagatedToHigherTiers() throws CachePersistenceException {
  CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder = cacheManagerBuilder(ExpiryPolicyBuilder.noExpiration());

  try(PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(true)) {

    Map<String, TierStatistics> tierStatistics = statisticsService.getCacheStatistics(CLUSTERED_CACHE).getTierStatistics();
    TierStatistics onheap = tierStatistics.get("OnHeap");
    TierStatistics offheap = tierStatistics.get("OffHeap");

    Cache<Long, String> cache = cacheManager.getCache(CLUSTERED_CACHE, Long.class, String.class);
    for (long i = 0; i < 30; i++) {
      cache.put(i, "value"); // store on the cluster
      cache.get(i); // push it up on heap and offheap tier
    }

    assertThat(onheap.getMappings()).isEqualTo(10);
    assertThat(offheap.getMappings()).isEqualTo(20);
  }
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:21,代码来源:ClusteredCacheExpirationTest.java

示例12: testTooLowResourceException

import org.ehcache.CachePersistenceException; //导入依赖的package包/类
@Test
public void testTooLowResourceException() throws InterruptedException {

  DedicatedClusteredResourcePool resourcePool = ClusteredResourcePoolBuilder.clusteredDedicated(10, MemoryUnit.KB);
  CacheManagerBuilder<PersistentCacheManager> cacheManagerBuilder = getPersistentCacheManagerCacheManagerBuilder(resourcePool);

  try {
    cacheManagerBuilder.build(true);
    fail("InvalidServerStoreConfigurationException expected");
  } catch (Exception e) {
    Throwable cause = getCause(e, CachePersistenceException.class);
    assertThat(cause, notNullValue());
    assertThat(cause.getMessage(), startsWith("Unable to create"));
  }
  resourcePool = ClusteredResourcePoolBuilder.clusteredDedicated(100, MemoryUnit.KB);
  cacheManagerBuilder = getPersistentCacheManagerCacheManagerBuilder(resourcePool);
  PersistentCacheManager persistentCacheManager = cacheManagerBuilder.build(true);

  assertThat(persistentCacheManager, notNullValue());
  persistentCacheManager.close();

}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:23,代码来源:ResourcePoolAllocationFailureTest.java

示例13: persistenceServiceTest

import org.ehcache.CachePersistenceException; //导入依赖的package包/类
public void persistenceServiceTest() {
    LocalPersistenceService persistenceService = new DefaultLocalPersistenceService(
            new DefaultPersistenceConfiguration(new File("", "myUserData")));

    PersistentUserManagedCache<Long, String> cache = UserManagedCacheBuilder
            .newUserManagedCacheBuilder(Long.class, String.class)
            .with(new UserManagedPersistenceContext<Long, String>("cache-name", persistenceService))
            .withResourcePools(ResourcePoolsBuilder.newResourcePoolsBuilder().heap(10L, EntryUnit.ENTRIES).disk(10L,
                    MemoryUnit.MB, true))
            .build(true);

    // Work with the cache
    cache.put(42L, "The Answer!");
    // assertThat(cache.get(42L), is("The Answer!"));

    cache.close();
    try {
        cache.destroy();
    } catch (CachePersistenceException e) {
        e.printStackTrace();
    }

    persistenceService.stop();
}
 
开发者ID:dzh,项目名称:jframe,代码行数:25,代码来源:TestUserManagedCache.java

示例14: destroy

import org.ehcache.CachePersistenceException; //导入依赖的package包/类
@Override
public void destroy() {
  try {
    cacheManager.destroy();
  } catch (CachePersistenceException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:Terracotta-OSS,项目名称:tinypounder,代码行数:9,代码来源:CacheManagerBusinessApiImpl.java

示例15: destroyCache

import org.ehcache.CachePersistenceException; //导入依赖的package包/类
@Override
public void destroyCache(String alias) {
  try {
    cacheManager.destroyCache(alias);
  } catch (CachePersistenceException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:Terracotta-OSS,项目名称:tinypounder,代码行数:9,代码来源:CacheManagerBusinessApiImpl.java


注:本文中的org.ehcache.CachePersistenceException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。