@Override public State getState() { try { switch (this.tx.getStatus()) { case Status.STATUS_ACTIVE: { if (this.active) { return State.ACTIVE; } // Otherwise fall through } case Status.STATUS_MARKED_ROLLBACK: { return State.DISCARDED; } default: { return State.CLOSED; } } } catch (SystemException e) { throw new CacheException(e); } }
@Override public void close() { if (this.count.getAndDecrement() == 0) { try { switch (this.tx.getStatus()) { case Status.STATUS_ACTIVE: { if (this.active) { try { this.tx.commit(); break; } catch (RollbackException e) { throw new IllegalStateException(e); } catch (HeuristicMixedException | HeuristicRollbackException e) { throw new CacheException(e); } } // Otherwise fall through } case Status.STATUS_MARKED_ROLLBACK: { this.tx.rollback(); break; } } } catch (SystemException e) { throw new CacheException(e); } } }
@Override protected void initChannel() { try { this.channel = this.factory.createChannel(this.configuration.globalJmxStatistics().cacheManagerName()); this.channel.setDiscardOwnMessages(false); } catch (Exception e) { throw new CacheException(e); } } }
@Override public TransactionBatch suspendBatch() { if (this.tm == null) return NON_TX_BATCH; TransactionBatch batch = getCurrentBatch(); if (batch != null) { try { Transaction tx = this.tm.suspend(); if (batch.getTransaction() != tx) { throw new IllegalStateException(); } } catch (SystemException e) { throw new CacheException(e); } finally { setCurrentBatch(null); } } return batch; } }
@Override public TransactionBatch createBatch() { if (this.tm == null) return NON_TX_BATCH; TransactionBatch batch = getCurrentBatch(); try { if ((batch != null) && (batch.getState() == Batch.State.ACTIVE)) { return batch.interpose(); } this.tm.suspend(); this.tm.begin(); Transaction tx = this.tm.getTransaction(); tx.registerSynchronization(CURRENT_BATCH_SYNCHRONIZATION); batch = new InfinispanBatch(tx); setCurrentBatch(batch); return batch; } catch (RollbackException | SystemException | NotSupportedException e) { throw new CacheException(e); } }
this.tm.resume(existingBatch.getTransaction()); } catch (InvalidTransactionException e) { throw new CacheException(e); throw new CacheException(e); } finally { setCurrentBatch(existingBatch); throw new CacheException(e);
private boolean remove(String id, Cache<SessionCreationMetaDataKey, SessionCreationMetaDataEntry<L>> creationMetaDataCache) { SessionCreationMetaDataKey key = new SessionCreationMetaDataKey(id); try { if (!this.properties.isLockOnWrite() || (creationMetaDataCache.getAdvancedCache().getTransactionManager().getTransaction() == null) || creationMetaDataCache.getAdvancedCache().withFlags(Flag.ZERO_LOCK_ACQUISITION_TIMEOUT, Flag.FAIL_SILENTLY).lock(key)) { creationMetaDataCache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES).remove(key); this.accessMetaDataCache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES).remove(new SessionAccessMetaDataKey(id)); return true; } return false; } catch (SystemException e) { throw new CacheException(e); } }
@Override public void accept(ConfigurationBuilder builder) { TransactionConfiguration tx = this.transaction.get(); builder.memory().read(this.memory.get()); builder.expiration().read(this.expiration.get()); builder.locking().read(this.locking.get()); builder.persistence().read(this.persistence.get()); builder.transaction().read(tx); builder.jmxStatistics().enabled(this.statisticsEnabled).available(this.statisticsEnabled); try { // Configure invocation batching based on transaction configuration builder.invocationBatching().enable(tx.transactionMode().isTransactional() && (tx.transactionManagerLookup().getTransactionManager() != ContextTransactionManager.getInstance())); } catch (Exception e) { throw new CacheException(e); } }
@Override public Object visitGetCacheEntryCommand(InvocationContext ctx, GetCacheEntryCommand command) throws Throwable { throw new CacheException("Injected"); } }
@Override public Object fromString(String str) { byte[] objBytes = Base64.getDecoder().decode(str); try { ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(objBytes)); return ois.readObject(); } catch (IOException | ClassNotFoundException e) { log.error("Error while decoding object", e); throw new CacheException(e); } }
@Override public Object fromString(String encodedObject) { byte[] objBytes = Base64.getDecoder().decode(encodedObject); try { ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(objBytes)); return ois.readObject(); } catch (IOException | ClassNotFoundException e) { log.error("Error while decoding object", e); throw new CacheException(e); } }
@Override protected EntityInfo loadEntityInfo(int index) { try { return extractor.extract(index); } catch (IOException e) { throw new CacheException("Cannot load result at index " + index, e); } } }
private <T extends Serializable> CommandResult<T> invokeSync(final K key, final JCacheEntryProcessor<K, T> entryProcessor) { try { return readWriteMap.eval(key, new SerializableFunctionAdapter<>(entryProcessor)).get(); } catch (InterruptedException | ExecutionException e) { throw new CacheException(e); } }
private <T extends Serializable> CommandResult<T> invokeSync(final K key, final JCacheEntryProcessor<K, T> entryProcessor) { try { return readWriteMap.eval(key, new SerializableFunctionAdapter<>(entryProcessor)).get(); } catch (InterruptedException | ExecutionException e) { throw new CacheException(e); } }
@Override public final CacheException cacheIsStoppingNoCommandAllowed(final String cacheName) { final CacheException result = new CacheException(String.format(getLoggingLocale(), cacheIsStoppingNoCommandAllowed$str(), cacheName)); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } @Override
@Override public final CacheException rootDirectoryIsNotADirectory(final String fileRoot) { final CacheException result = new CacheException(String.format(getLoggingLocale(), rootDirectoryIsNotADirectory$str(), fileRoot)); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String unableToCreateDirectory = "ISPN015007: LuceneCacheLoader was unable to create the root directory at path '%s'";
private Object handle(InvocationContext ctx, VisitableCommand command, Runnable logFailure) throws Throwable { if (isFailing) { logFailure.run(); throw new CacheException("Induced failure"); } else { return invokeNextInterceptor(ctx, command); } }
@Override protected ConfigurationBuilder createTopologyCacheConfig(long distSyncTimeout) { if (delay > 0) try { Thread.sleep(delay); } catch (InterruptedException e) { throw new CacheException(e); } return super.createTopologyCacheConfig(distSyncTimeout); }
private byte[] serialize(MarshalledEntry o) { try { return marshaller.objectToByteBuffer(new KeyValuePair(o.getValue(), o.getMetadata())); } catch (IOException e) { throw new CacheException(e); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new CacheException(e); } }
public void testGetReplicaException() { CompletableFuture<Void> taskFuture = new CompletableFuture<>(); taskFuture.completeExceptionally(new CacheException("Problem encountered retrieving state")); initTransferTaskMock(taskFuture); CompletableFuture<List<Map<Address, CacheEntry<Object, Object>>>> cf = stateReceiver.getAllReplicasForSegment(0, localizedCacheTopology, 10000); Exceptions.expectExecutionException(CacheException.class, cf); }