This closes #595

This commit is contained in:
Clebert Suconic 2016-08-15 14:30:01 -04:00
commit 4fade1073e
6 changed files with 59 additions and 2 deletions

View File

@ -154,6 +154,12 @@ public enum ActiveMQExceptionType {
return new ActiveMQTransactionOutcomeUnknownException(msg);
}
},
TRANSACTION_TIMEOUT(116) {
@Override
public ActiveMQException createException(String msg) {
return new ActiveMQTranasactionTimeoutException(msg);
}
},
ALREADY_REPLICATING(116) {
@Override
public ActiveMQException createException(String msg) {

View File

@ -0,0 +1,29 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.artemis.api.core;
public class ActiveMQTranasactionTimeoutException extends ActiveMQException {
public ActiveMQTranasactionTimeoutException() {
super(ActiveMQExceptionType.TRANSACTION_TIMEOUT);
}
public ActiveMQTranasactionTimeoutException(String message) {
super(ActiveMQExceptionType.TRANSACTION_TIMEOUT, message);
}
}

View File

@ -855,10 +855,16 @@ public class ServerSessionImpl implements ServerSession, FailureListener {
else if (tx.getState() == Transaction.State.ROLLEDBACK) {
final String msg = "Cannot end, transaction is rolled back";
final boolean timeout = tx.hasTimedOut();
tx = null;
if (timeout) {
throw new ActiveMQXAException(XAException.XA_RBTIMEOUT, msg);
}
else {
throw new ActiveMQXAException(XAException.XAER_PROTO, msg);
}
}
else {
tx = null;
}

View File

@ -76,6 +76,10 @@ public interface Transaction {
boolean hasTimedOut(long currentTime, int defaultTimeout);
/** To validate if the Transaction had previously timed out.
* This is to check the reason why a TX has been rolled back. */
boolean hasTimedOut();
void putProperty(int index, Object property);
Object getProperty(int index);

View File

@ -23,7 +23,9 @@ import java.util.LinkedList;
import java.util.List;
import org.apache.activemq.artemis.api.core.ActiveMQException;
import org.apache.activemq.artemis.api.core.ActiveMQExceptionType;
import org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException;
import org.apache.activemq.artemis.api.core.ActiveMQTranasactionTimeoutException;
import org.apache.activemq.artemis.core.io.IOCallback;
import org.apache.activemq.artemis.core.persistence.StorageManager;
import org.apache.activemq.artemis.core.server.ActiveMQServerLogger;
@ -169,13 +171,18 @@ public class TransactionImpl implements Transaction {
}
if (timedout) {
markAsRollbackOnly(new ActiveMQException("TX Timeout"));
markAsRollbackOnly(new ActiveMQTranasactionTimeoutException());
}
return timedout;
}
}
@Override
public boolean hasTimedOut() {
return state == State.ROLLBACK_ONLY && exception.getType() == ActiveMQExceptionType.TRANSACTION_TIMEOUT;
}
@Override
public void prepare() throws Exception {
if (logger.isTraceEnabled()) {

View File

@ -256,6 +256,11 @@ public class BindingsImplTest extends ActiveMQTestBase {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean hasTimedOut() {
return false;
}
}
private final class FakeFilter implements Filter {