use of javax.transaction.SystemException in project wildfly by wildfly.
the class TransactionalServiceImpl method isTransactionActive.
@Override
public boolean isTransactionActive() {
LOG.debug("TransactionalServiceImpl.isTransactionActive()");
Transaction transaction = null;
try {
transaction = TransactionManager.transactionManager().getTransaction();
} catch (SystemException e) {
}
if (transaction == null) {
return false;
}
try {
return transaction.getStatus() == Status.STATUS_ACTIVE;
} catch (SystemException e) {
return false;
}
}
use of javax.transaction.SystemException in project Activiti by Activiti.
the class JtaTransactionContext method addTransactionListener.
public void addTransactionListener(TransactionState transactionState, final TransactionListener transactionListener) {
Transaction transaction = getTransaction();
CommandContext commandContext = Context.getCommandContext();
try {
transaction.registerSynchronization(new TransactionStateSynchronization(transactionState, transactionListener, commandContext));
} catch (IllegalStateException e) {
throw new ActivitiException("IllegalStateException while registering synchronization ", e);
} catch (RollbackException e) {
throw new ActivitiException("RollbackException while registering synchronization ", e);
} catch (SystemException e) {
throw new ActivitiException("SystemException while registering synchronization ", e);
}
}
use of javax.transaction.SystemException in project galley by Commonjava.
the class FastLocalCacheProvider method copy.
@Override
public void copy(ConcreteResource from, ConcreteResource to) throws IOException {
final String fromNFSPath = getKeyForResource(from);
final String toNFSPath = getKeyForResource(to);
//FIXME: there is no good solution here for thread locking as there are two resource needs to be locked. If handled not correctly, will cause dead lock
InputStream nfsFrom = null;
OutputStream nfsTo = null;
try {
//FIXME: need to think about this lock of the re-entrant way and ISPN lock wait
nfsOwnerCache.beginTransaction();
nfsOwnerCache.lock(fromNFSPath, toNFSPath);
plCacheProvider.copy(from, to);
nfsFrom = new FileInputStream(getNFSDetachedFile(from));
File nfsToFile = getNFSDetachedFile(to);
if (!nfsToFile.exists() && !nfsToFile.isDirectory()) {
if (!nfsToFile.getParentFile().exists()) {
nfsToFile.getParentFile().mkdirs();
}
try {
nfsToFile.createNewFile();
} catch (IOException e) {
logger.error("[galley] New nfs file created not properly.", e);
}
}
nfsTo = new FileOutputStream(nfsToFile);
IOUtils.copy(nfsFrom, nfsTo);
//FIXME: need to use put?
nfsOwnerCache.putIfAbsent(toNFSPath, getCurrentNodeIp());
nfsOwnerCache.commit();
} catch (NotSupportedException | SystemException | RollbackException | HeuristicMixedException | HeuristicRollbackException e) {
logger.error("[galley] Transaction error for nfs cache during file copying.", e);
try {
nfsOwnerCache.rollback();
} catch (SystemException se) {
final String errorMsg = "[galley] Transaction rollback error for nfs cache during file copying.";
logger.error(errorMsg, se);
throw new IllegalStateException(errorMsg, se);
}
} finally {
IOUtils.closeQuietly(nfsFrom);
IOUtils.closeQuietly(nfsTo);
}
}
use of javax.transaction.SystemException in project galley by Commonjava.
the class FastLocalCacheProvider method delete.
@Override
public boolean delete(ConcreteResource resource) throws IOException {
final File nfsFile = getNFSDetachedFile(resource);
final String pathKey = getKeyForPath(nfsFile.getCanonicalPath());
synchronized (getTransfer(resource)) {
boolean localDeleted = false;
try {
// must make sure the local file is not in reading/writing status
if (!plCacheProvider.isWriteLocked(resource) && !plCacheProvider.isReadLocked(resource)) {
logger.debug("[galley] Local cache file is not locked, will be deleted now.");
localDeleted = plCacheProvider.delete(resource);
} else {
logger.warn("Resource {} is locked by other threads for waiting and writing, can not be deleted now", resource);
}
if (!localDeleted) {
// if local deletion not success, no need to delete NFS to keep data consistency
logger.info("local file deletion failed for {}", resource);
return false;
}
lockByISPN(resource);
nfsOwnerCache.remove(pathKey);
final boolean nfsDeleted = nfsFile.delete();
if (!nfsDeleted) {
logger.info("nfs file deletion failed for {}", nfsFile);
}
return nfsDeleted;
} catch (NotSupportedException | SystemException e) {
final String errorMsg = String.format("[galley] Cache TransactionManager got error, locking key is %s", pathKey);
logger.error(errorMsg, e);
throw new IllegalStateException(errorMsg, e);
} finally {
if (localDeleted) {
try {
nfsOwnerCache.rollback();
} catch (SystemException e) {
final String errorMsg = String.format("[galley] Cache TransactionManager rollback got error, locking key is %s", pathKey);
logger.error(errorMsg, e);
}
}
}
}
}
use of javax.transaction.SystemException in project galley by Commonjava.
the class FastLocalCacheProvider method openOutputStream.
/**
* For file writing, will wrapping two output streams to caller - one for local cache file, another for nfs file -,
* and the caller can write to these two streams in the meantime. <br />
* For the local part, because it uses {@link org.commonjava.maven.galley.cache.partyline.PartyLineCacheProvider} as
* i/o provider, this supports the R/W on the same resource in the meantime. For details, please see
* {@link org.commonjava.maven.galley.cache.partyline.PartyLineCacheProvider}.
*
* @param resource - the resource will be read
* @return - the output stream for further writing
* @throws IOException
*/
@Override
public OutputStream openOutputStream(ConcreteResource resource) throws IOException {
OutputStream dualOut;
final String nodeIp = getCurrentNodeIp();
final String pathKey = getKeyForResource(resource);
final File nfsFile = getNFSDetachedFile(resource);
synchronized (getTransfer(resource)) {
try {
lockByISPN(resource);
nfsOwnerCache.put(pathKey, nodeIp);
logger.debug("Start to get output stream from local cache through partyline to do join stream");
final OutputStream localOut = plCacheProvider.openOutputStream(resource);
logger.debug("The output stream from local cache through partyline is got successfully");
if (!nfsFile.exists() && !nfsFile.isDirectory()) {
try {
if (!nfsFile.getParentFile().exists()) {
nfsFile.getParentFile().mkdirs();
}
nfsFile.createNewFile();
} catch (IOException e) {
logger.error("[galley] New nfs file created not properly.", e);
throw e;
}
}
final OutputStream nfsOutputStream = new FileOutputStream(nfsFile);
logger.debug("The output stream from NFS is got successfully");
// will wrap the cache manager in stream wrapper, and let it do tx commit in stream close to make sure
// the two streams writing's consistency.
dualOut = new DualOutputStreamsWrapper(localOut, nfsOutputStream, nfsOwnerCache, pathKey, resource);
if (nfsOwnerCache.getLockOwner(pathKey) != null) {
logger.trace("ISPN locker for key {} with resource {} is {}", pathKey, resource, nfsOwnerCache.getLockOwner(pathKey));
}
ThreadContext streamHolder = ThreadContext.getContext(true);
Set<WeakReference<OutputStream>> streams = (Set<WeakReference<OutputStream>>) streamHolder.get(FAST_LOCAL_STREAMS);
if (streams == null) {
streams = new HashSet<>(10);
}
streams.add(new WeakReference<>(dualOut));
streamHolder.put(FAST_LOCAL_STREAMS, streams);
} catch (NotSupportedException | SystemException e) {
logger.error("[galley] Transaction error for nfs cache during file writing.", e);
throw new IllegalStateException(String.format("[galley] Output stream for resource %s open failed.", resource.toString()), e);
}
logger.debug("The dual output stream wrapped and returned successfully");
return dualOut;
}
}
Aggregations