@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() { this.cache.removeListener(this); this.shutdown(this.topologyChangeExecutor); try (Batch batch = this.batcher.createBatch()) { // If this remove fails, the entry will be auto-removed on topology change by the new primary owner this.cache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES, Flag.FAIL_SILENTLY).remove(this.group.getAddress(this.group.getLocalMember())); } catch (CacheException e) { ClusteringLogger.ROOT_LOGGER.warn(e.getLocalizedMessage(), e); } finally { // Cleanup any unregistered listeners for (ExecutorService executor : this.listeners.values()) { this.shutdown(executor); } this.listeners.clear(); this.closeTask.run(); } }
@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 fromStorage(Object stored) { try { return stored instanceof byte[] ? marshaller.objectFromByteBuffer((byte[]) stored) : stored; } catch (IOException | ClassNotFoundException e) { throw new CacheException(e); } }
@Override public void validate() { if (connectionUrl == null) { throw new CacheConfigurationException("A connectionUrl has not been specified"); } }
@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 public void validate() { if (jndiUrl == null) { throw new CacheConfigurationException("The jndiUrl has not been specified"); } }
@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 void validate() { // If a propertyFile is specified, then no exceptions are thrown for an incorrect config until the pool is created if (propertyFile == null && connectionUrl == null) { throw new CacheConfigurationException("Missing connectionUrl parameter"); } }
@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 String objectToString(Object object) { throw new CacheException("NYI."); } }
public static CacheException rewrapAsCacheException(Throwable t) { if (t instanceof CacheException) return (CacheException) t; else return new CacheException(t); }
@Override public Object visitGetCacheEntryCommand(InvocationContext ctx, GetCacheEntryCommand command) throws Throwable { throw new CacheException("Injected"); } }
private void fail() { if (fail) throw new CacheException("Induced failure"); }
@Override protected EntityInfo loadEntityInfo(int index) { try { return extractor.extract(index); } catch (IOException e) { throw new CacheException("Cannot load result at index " + index, 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); } } }
public static byte[] marshall(Object obj) { try { return obj == null ? null : new JBossMarshaller().objectToByteBuffer(obj, 64); } catch (IOException | InterruptedException e) { throw new CacheException(e); } }