本文整理汇总了Java中javax.cache.CacheException类的典型用法代码示例。如果您正苦于以下问题:Java CacheException类的具体用法?Java CacheException怎么用?Java CacheException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CacheException类属于javax.cache包,在下文中一共展示了CacheException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import javax.cache.CacheException; //导入依赖的package包/类
public <R> Future<R> execute(String key, IgniteCache<Long, V> cache, BiFunction<String, IgniteCache<Long, V>, R> function) {
return Futures.future(() -> {
R result = null;
try {
result = function.apply(key, cache);
// in case it is client node , client reconnect with 300 milliseconds timeout is used to retry to connect again to the server nodes grid
} catch (IgniteClientDisconnectedException e) {
e.reconnectFuture().get(300, TimeUnit.MILLISECONDS);
result = function.apply(key, cache);
} catch (CacheException cacheException) {
if (cacheException.getCause() instanceof IgniteClientDisconnectedException) {
((IgniteClientDisconnectedException) cacheException.getCause()).reconnectFuture().get(300, TimeUnit.MILLISECONDS);
result = function.apply(key, cache);
}
}
return result;
}, dispatcher);
}
示例2: verifyIntegrity
import javax.cache.CacheException; //导入依赖的package包/类
private void verifyIntegrity(String familyName) throws CacheException {
if (tableName == null) {
String msg = "TableName must not be null";
logger.warning(msg);
throw new CacheException(msg);
}
if (!ensuredColumnFamilies.contains(familyName)) {
try {
HBaseUtil.ensureTableAndColumnFamilyExist(conn, tableName, familyName);
ensuredColumnFamilies.add(familyName);
} catch (IOException e) {
logger.warning(
"Error ensuring that HBase table '" + tableName + "' and column family '"
+ familyName + "' exists", e);
throw new CacheException(e);
}
}
}
示例3: get
import javax.cache.CacheException; //导入依赖的package包/类
@Override
public V get(K key)
{
checkState();
if (key == null)
{
throw new NullPointerException();
}
if (configuration.isReadThrough())
{
try
{
return ((LoadingCache<K, V>) cache).get(key);
}
catch (ExecutionException e)
{
throw new CacheException(e);
}
}
return cache.getIfPresent(key);
}
示例4: getAll
import javax.cache.CacheException; //导入依赖的package包/类
@Override
public Map<K, V> getAll(Set<? extends K> keys)
{
checkState();
if (keys == null || keys.contains(null))
{
throw new NullPointerException();
}
if (configuration.isReadThrough())
{
try
{
return ((LoadingCache<K, V>) cache).getAll(keys);
}
catch (ExecutionException e)
{
throw new CacheException(e);
}
}
return cache.getAllPresent(keys);
}
示例5: getCacheManagerWithNonNullProperties
import javax.cache.CacheException; //导入依赖的package包/类
@Test // org.jsr107.tck.CacheManagerTest.getCacheManager_nonNullProperties
public void getCacheManagerWithNonNullProperties()
{
// see https://github.com/jsr107/jsr107tck/issues/102
// make sure existing cache managers are closed and the non empty properties get picked up
try
{
Caching.getCachingProvider().close();
}
catch (CacheException ignore)
{
// ignore exception which may happen if the provider is not active
}
CachingProvider provider = Caching.getCachingProvider();
Properties properties = new Properties();
properties.put("dummy.com", "goofy");
provider.getCacheManager(provider.getDefaultURI(), provider.getDefaultClassLoader(), properties);
CacheManager manager = provider.getCacheManager();
assertEquals(properties, manager.getProperties());
}
示例6: createManager
import javax.cache.CacheException; //导入依赖的package包/类
public CacheManager createManager(Map<String, Configuration<?, ?>> configs, ShutdownManager shutdownManager) {
CachingProvider provider;
try {
// TODO: an explicit config property to pick explicit provider out of available choices... though probably
// pointless in most cases (do we realistically expect multiple providers on classpath?)
provider = Caching.getCachingProvider();
} catch (CacheException e) {
throw new RuntimeException("'bootique-jcache' doesn't bundle any JCache providers. " +
"You must place a JCache 1.0 provider on classpath explicitly.", e);
}
shutdownManager.addShutdownHook(provider);
CacheManager manager = getConfigUri().map(u -> provider.getCacheManager(u, null)).orElse(provider.getCacheManager());
shutdownManager.addShutdownHook(manager);
// now load contributed configs
configs.forEach(manager::createCache);
return manager;
}
示例7: query
import javax.cache.CacheException; //导入依赖的package包/类
/** {@inheritDoc} */
@Override public <T, R> QueryCursor<R> query(Query<T> qry, IgniteClosure<T, R> transformer) {
A.notNull(qry, "qry");
A.notNull(transformer, "transformer");
if (!(qry instanceof ScanQuery))
throw new UnsupportedOperationException("Transformers are supported only for SCAN queries.");
try {
ctx.checkSecurity(SecurityPermission.CACHE_READ);
validate(qry);
return query((ScanQuery<K, V>)qry, transformer, projection(qry.isLocal()));
}
catch (Exception e) {
if (e instanceof CacheException)
throw (CacheException)e;
throw new CacheException(e);
}
}
示例8: putAll
import javax.cache.CacheException; //导入依赖的package包/类
@Override
public void putAll(Map<? extends K, ? extends V> map) {
verifyCacheConnectivity();
Object[] keys = new Object[map.size()];
CacheItem[] cItems = new CacheItem[map.size()];
int i = 0;
for(Map.Entry e : map.entrySet())
{
if(e.getKey() == null)
throw new NullPointerException("key cannot be null.");
if(e.getValue() == null)
throw new NullPointerException("value cannot be null.");
keys[i] = e.getKey();
cItems[i] = new CacheItem(e.getValue());
i++;
}
try {
innerCache.insertBulk(keys, cItems, DSWriteOption.OptionalWriteThru, null);
}
catch (Exception ex) {
throw new CacheException(ex);
}
}
示例9: replace
import javax.cache.CacheException; //导入依赖的package包/类
@Override
public boolean replace(K key, V oldValue, V newValue) {
verifyCacheConnectivity();
if(key==null)
throw new NullPointerException("key cannot be null.");
if(newValue == null)
throw new NullPointerException("value cannot be null.");
try {
//--TODO--
InsertParams options = new InsertParams();
options.IsReplaceOperation = true;
options.CompareOldValue = true;
options.OldValue = oldValue;
InsertResult result = innerCache.insertInternal(key, newValue, DSWriteOption.OptionalWriteThru, options);
return result.Success;
} catch (Exception ex) {
throw new CacheException(ex);
}
}
示例10: registerCache
import javax.cache.CacheException; //导入依赖的package包/类
/**
* Registers a Cache to this factory. Registered caches will be used for bulk operations like
* {@link #close()}.
*
* @param cache The Cache to register
* @throws IllegalStateException If a cache with the same id is already registered in this factory.
*/
public void registerCache(Cache<?, ?> cache)
{
assertNotClosed();
String id = cache.id();
synchronized (factoryLock)
{
for (Cache<?, ?> registeredCache : CacheInstances)
{
if (registeredCache.id().equals(id))
{
throw new CacheException("Cache with the same id is already registered: " + id);
}
}
CacheInstances.add(cache);
// Hint: "cache" cannot escape. It is safely published, as it is put in a concurrent collection
}
}
示例11: register
import javax.cache.CacheException; //导入依赖的package包/类
public void register(Cache<?,?> cache)
{
TCacheJSR107<?, ?> jsr107cache = cache.jsr107cache();
// these can change during runtime, so always look it up
ObjectName registeredObjectName = calculateObjectName(jsr107cache, objectNameType());
if (isRegistered(registeredObjectName))
{
// Do not register twice. Actually this contains a race condition due to a
// check-then-act "isRegistered() => registerMBean()" action, but it should not be
// a problem for us, because there are never two caches with the same name alive at the
// same time.
return;
}
try
{
mBeanServer.registerMBean(getMBean(jsr107cache), registeredObjectName);
}
catch (Exception e)
{
throw new CacheException("Error registering cache MXBeans for CacheManager " + registeredObjectName
+ " . Error was " + e.getMessage(), e);
}
}
示例12: unregister
import javax.cache.CacheException; //导入依赖的package包/类
public void unregister(Cache<?, ?> cache)
{
TCacheJSR107<?, ?> jsr107cache = cache.jsr107cache();
ObjectName objectName = calculateObjectName(jsr107cache, objectNameType());
Set<ObjectName> registeredObjectNames = mBeanServer.queryNames(objectName, null);
// should just be one
for (ObjectName registeredObjectName : registeredObjectNames)
{
try
{
mBeanServer.unregisterMBean(registeredObjectName);
}
catch (Exception e)
{
throw new CacheException("Error unregistering object instance " + registeredObjectName
+ " . Error was " + e.getMessage(), e);
}
}
}
示例13: calculateObjectName
import javax.cache.CacheException; //导入依赖的package包/类
/**
* Creates an object name using the scheme
* "javax.cache:type=Cache<Statistics|Configuration>,CacheManager=<cacheManagerName>,name=<cacheName>"
* <p>
* Implementation note: Method modeled after the JSR107 RI
*/
private static ObjectName calculateObjectName(javax.cache.Cache<?, ?> cache, String objectNameType)
{
String cacheManagerName = mbeanSafe(cache.getCacheManager().getURI().toString());
String cacheName = mbeanSafe(cache.getName());
try
{
/**
* JSR107 There seems to be a naming mismatch.
* - (correct) The RI uses "type=CacheConfiguration" and "type=CacheStatistics"
* - (wrong) The API docs of CacheManager.enableManagement() specify "type=Cache" and "type=CacheStatistics"
*/
return new ObjectName("javax.cache:type=Cache" + objectNameType + ",CacheManager=" + cacheManagerName
+ ",Cache=" + cacheName);
}
catch (MalformedObjectNameException e)
{
throw new CacheException("Illegal ObjectName for Management Bean. " + "CacheManager=[" + cacheManagerName
+ "], Cache=[" + cacheName + "] type=[" + objectNameType + "]", e);
}
}
示例14: testTimeoutOnCloseMethod
import javax.cache.CacheException; //导入依赖的package包/类
/**
* Test timeout on {@code DataStreamer.addData()} method
* @throws Exception If fail.
*/
public void testTimeoutOnCloseMethod() throws Exception {
failOn = 1;
Ignite ignite = startGrid(1);
boolean thrown = false;
try (IgniteDataStreamer ldr = ignite.dataStreamer(CACHE_NAME)) {
ldr.timeout(TIMEOUT);
ldr.receiver(new TestDataReceiver());
ldr.perNodeBufferSize(ENTRY_AMOUNT);
for (int i = 0; i < ENTRY_AMOUNT; i++)
ldr.addData(i, i);
}
catch (CacheException | IgniteDataStreamerTimeoutException ignored) {
thrown = true;
}
finally {
stopAllGrids();
}
assertTrue(thrown);
}
示例15: serialize
import javax.cache.CacheException; //导入依赖的package包/类
private ByteArray serialize(Object key)
{
if (key == null)
{
throw new NullPointerException("key must not be null");
}
try
{
return new ByteArray(Serializing.toBytearray(key));
}
catch (IOException e)
{
throw new CacheException("Cannot serialize key class of type: " + key.getClass().getName() , e);
}
}