List of usage examples for javax.transaction.xa XAException XAException
public XAException(int errcode)
From source file:com.alibaba.napoli.metamorphosis.client.transaction.TransactionContext.java
@Override public int prepare(final Xid xid) throws XAException { if (LOG.isDebugEnabled()) { LOG.debug("Prepare: " + xid); }//from w w w .j a va 2 s . c o m XATransactionId x; // ???endprepare?associatedXid?null if (xid == null || this.equals(this.associatedXid, xid)) { throw new XAException(XAException.XAER_PROTO); } else { x = new XATransactionId(xid); } MetaStatLog.addStat(null, StatConstants.TX_PREPARE); final TransactionInfo info = new TransactionInfo(x, this.sessionId, TransactionInfo.TransactionType.PREPARE); final BooleanCommand response = this.syncSendXATxCommand(info); final int result = Integer.parseInt(response.getErrorMsg()); if (XAResource.XA_RDONLY == result) { if (LOG.isDebugEnabled()) { LOG.debug("XA_RDONLY from prepare: " + xid); } } return result; }
From source file:com.alibaba.napoli.metamorphosis.client.transaction.TransactionContext.java
@Override public Xid[] recover(final int flag) throws XAException { if (LOG.isDebugEnabled()) { LOG.debug("Recover: " + flag); }//w ww . j a v a 2 s . c o m this.checkConnectionConnected(); final TransactionInfo info = new TransactionInfo(null, this.sessionId, TransactionInfo.TransactionType.RECOVER); try { final BooleanCommand receipt = (BooleanCommand) this.remotingClient.invokeToGroup(this.serverUrl, new TransactionCommand(info, OpaqueGenerator.getNextOpaque())); if (receipt.getCode() != HttpStatus.Success) { throw new XAException(receipt.getErrorMsg()); } final String data = receipt.getErrorMsg(); if (StringUtils.isBlank(data)) { return EMPTY_IDS; } final String[] xidStrs = NEW_LINE_PATTERN.split(data); final XATransactionId[] answer = new XATransactionId[xidStrs.length]; int i = 0; for (final String key : xidStrs) { if (!StringUtils.isBlank(key)) { answer[i++] = new XATransactionId(key); } } return answer; } catch (final InterruptedException e) { Thread.currentThread().interrupt(); throw this.toXAException(e); } catch (final Exception e) { throw this.toXAException(e); } }
From source file:com.alibaba.napoli.metamorphosis.client.transaction.TransactionContext.java
@Override public void rollback(final Xid xid) throws XAException { if (LOG.isDebugEnabled()) { LOG.debug("Rollback: " + xid); }//w w w . j av a 2s . c om XATransactionId x; if (xid == null) { throw new XAException(XAException.XAER_PROTO); } if (this.equals(this.associatedXid, xid)) { x = (XATransactionId) this.transactionId; } else { x = new XATransactionId(xid); } MetaStatLog.addStat(null, StatConstants.TX_ROLLBACK); this.checkConnectionConnected(); try { final TransactionInfo info = new TransactionInfo(x, this.sessionId, TransactionInfo.TransactionType.ROLLBACK); this.syncSendXATxCommand(info); } finally { this.associatedSession.removeContext(this); this.logTxTime(); } }
From source file:com.alibaba.napoli.metamorphosis.client.transaction.TransactionContext.java
private BooleanCommand syncSendXATxCommand(final TransactionInfo info) throws XAException { try {/*from ww w . j a va2 s .co m*/ final BooleanCommand resp = (BooleanCommand) this.remotingClient.invokeToGroup(this.serverUrl, new TransactionCommand(info, OpaqueGenerator.getNextOpaque())); if (resp.getResponseStatus() != ResponseStatus.NO_ERROR) { final String msg = resp.getErrorMsg(); if (msg.startsWith("XAException:")) { final Matcher m = EXCEPTION_PAT.matcher(msg); if (m.find()) { final int code = Integer.parseInt(m.group(1)); final String error = m.group(2); final XAException xaException = new XAException(error); xaException.errorCode = code; throw xaException; } else { this.throwRMFailException(resp); } } else { this.throwRMFailException(resp); } } return resp; } catch (final InterruptedException e) { Thread.currentThread().interrupt(); throw this.toXAException(e); } catch (final Exception e) { throw this.toXAException(e); } }
From source file:com.alibaba.napoli.metamorphosis.client.transaction.TransactionContext.java
private void throwRMFailException(final BooleanCommand resp) throws XAException { final XAException xaException = new XAException(resp.getErrorMsg()); xaException.errorCode = XAException.XAER_RMERR; throw xaException; }
From source file:com.alibaba.napoli.metamorphosis.client.transaction.TransactionContext.java
@Override public boolean setTransactionTimeout(final int seconds) throws XAException { if (seconds < 0) { throw new XAException(XAException.XAER_INVAL); }/* www .ja v a 2 s .com*/ this.transactionTimeout = seconds; return true; }
From source file:com.alibaba.napoli.metamorphosis.client.transaction.TransactionContext.java
/** * XA//from w w w . ja v a2 s . com * * @param e * @return */ XAException toXAException(final Exception e) { if (e.getCause() != null && e.getCause() instanceof XAException) { final XAException original = (XAException) e.getCause(); final XAException xae = new XAException(original.getMessage()); xae.errorCode = original.errorCode; xae.initCause(original); return xae; } if (e instanceof XAException) { // ((XAException) e).errorCode = XAException.XAER_RMFAIL; return (XAException) e; } final XAException xae = new XAException(e.getMessage()); xae.errorCode = XAException.XAER_RMFAIL; xae.initCause(e); return xae; }
From source file:com.alibaba.napoli.metamorphosis.client.transaction.TransactionContext.java
@Override public void start(final Xid xid, final int flags) throws XAException { if (LOG.isDebugEnabled()) { LOG.debug("Start: " + xid); }//w w w .j a v a 2 s . c om if ((flags & TMJOIN) == TMJOIN || (flags & TMRESUME) == TMRESUME) { // resumexid?xid if (!this.equals(this.associatedXid, xid)) { throw new XAException(XAException.XAER_NOTA); } } if (this.isInLocalTransaction()) { throw new XAException(XAException.XAER_PROTO); } if (this.associatedXid != null) { throw new XAException(XAException.XAER_DUPID); } this.setXid(xid); }
From source file:it.doqui.index.ecmengine.business.personalization.multirepository.index.lucene.RepositoryAwareAbstractLuceneIndexerAndSearcherFactory.java
public void commit(Xid xid, boolean onePhase) throws XAException { try {// w w w . j av a 2 s. c om // TODO: Should be remembering overall state // TODO: Keep track of prepare responses Map<String, LuceneIndexer> indexers = activeIndexersInGlobalTx.get(xid); if (indexers == null) { if (suspendedIndexersInGlobalTx.containsKey(xid)) { throw new XAException("Trying to commit indexes for a suspended transaction."); } else { // nothing to do return; } } if (onePhase) { if (indexers.isEmpty()) { return; } else if (indexers.size() == 1) { for (LuceneIndexer indexer : indexers.values()) { indexer.commit(); } return; } else { throw new XAException("Trying to do one phase commit on more than one index"); } } else { // two phase for (LuceneIndexer indexer : indexers.values()) { indexer.commit(); } return; } } finally { activeIndexersInGlobalTx.remove(xid); } }
From source file:it.doqui.index.ecmengine.business.personalization.multirepository.index.lucene.RepositoryAwareAbstractLuceneIndexerAndSearcherFactory.java
public void end(Xid xid, int flag) throws XAException { Map<String, LuceneIndexer> indexers = activeIndexersInGlobalTx.get(xid); if (indexers == null) { if (suspendedIndexersInGlobalTx.containsKey(xid)) { throw new XAException("Trying to commit indexes for a suspended transaction."); } else {//from w ww . jav a 2s . c om // nothing to do return; } } if (flag == XAResource.TMSUSPEND) { activeIndexersInGlobalTx.remove(xid); suspendedIndexersInGlobalTx.put(xid, indexers); } else if (flag == TMFAIL) { activeIndexersInGlobalTx.remove(xid); suspendedIndexersInGlobalTx.remove(xid); } else if (flag == TMSUCCESS) { activeIndexersInGlobalTx.remove(xid); } }