You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2016/08/15 18:30:13 UTC
[2/3] activemq-artemis git commit: ARTEMIS-591 Improvement on Timeout
check
ARTEMIS-591 Improvement on Timeout check
Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/18563e45
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/18563e45
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/18563e45
Branch: refs/heads/master
Commit: 18563e45396bca5213fa848a7e05fafb6fef040a
Parents: 3def84e
Author: Clebert Suconic <cl...@apache.org>
Authored: Mon Aug 15 13:56:41 2016 -0400
Committer: Clebert Suconic <cl...@apache.org>
Committed: Mon Aug 15 14:09:37 2016 -0400
----------------------------------------------------------------------
.../artemis/api/core/ActiveMQExceptionType.java | 6 ++++
.../ActiveMQTranasactionTimeoutException.java | 29 ++++++++++++++++++++
.../core/server/impl/ServerSessionImpl.java | 3 +-
.../artemis/core/transaction/Transaction.java | 4 +++
.../core/transaction/impl/TransactionImpl.java | 9 +++++-
.../core/postoffice/impl/BindingsImplTest.java | 5 ++++
6 files changed, 53 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/18563e45/artemis-commons/src/main/java/org/apache/activemq/artemis/api/core/ActiveMQExceptionType.java
----------------------------------------------------------------------
diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/api/core/ActiveMQExceptionType.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/api/core/ActiveMQExceptionType.java
index 254d74c..73616a8 100644
--- a/artemis-commons/src/main/java/org/apache/activemq/artemis/api/core/ActiveMQExceptionType.java
+++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/api/core/ActiveMQExceptionType.java
@@ -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) {
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/18563e45/artemis-commons/src/main/java/org/apache/activemq/artemis/api/core/ActiveMQTranasactionTimeoutException.java
----------------------------------------------------------------------
diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/api/core/ActiveMQTranasactionTimeoutException.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/api/core/ActiveMQTranasactionTimeoutException.java
new file mode 100644
index 0000000..753422f
--- /dev/null
+++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/api/core/ActiveMQTranasactionTimeoutException.java
@@ -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);
+ }
+}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/18563e45/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java
index f7c0a29..893b615 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java
@@ -855,8 +855,7 @@ public class ServerSessionImpl implements ServerSession, FailureListener {
else if (tx.getState() == Transaction.State.ROLLEDBACK) {
final String msg = "Cannot end, transaction is rolled back";
- final long now = System.currentTimeMillis();
- final boolean timeout = tx.hasTimedOut(now, resourceManager.getTimeoutSeconds());
+ final boolean timeout = tx.hasTimedOut();
tx = null;
if (timeout) {
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/18563e45/artemis-server/src/main/java/org/apache/activemq/artemis/core/transaction/Transaction.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/transaction/Transaction.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/transaction/Transaction.java
index 65b7339..69ddae6 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/transaction/Transaction.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/transaction/Transaction.java
@@ -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);
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/18563e45/artemis-server/src/main/java/org/apache/activemq/artemis/core/transaction/impl/TransactionImpl.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/transaction/impl/TransactionImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/transaction/impl/TransactionImpl.java
index 185bfb2..4148bec 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/transaction/impl/TransactionImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/transaction/impl/TransactionImpl.java
@@ -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,7 +171,7 @@ public class TransactionImpl implements Transaction {
}
if (timedout) {
- markAsRollbackOnly(new ActiveMQException("TX Timeout"));
+ markAsRollbackOnly(new ActiveMQTranasactionTimeoutException());
}
return timedout;
@@ -177,6 +179,11 @@ public class TransactionImpl implements Transaction {
}
@Override
+ public boolean hasTimedOut() {
+ return state == State.ROLLBACK_ONLY && exception.getType() == ActiveMQExceptionType.TRANSACTION_TIMEOUT;
+ }
+
+ @Override
public void prepare() throws Exception {
if (logger.isTraceEnabled()) {
logger.trace("TransactionImpl::prepare::" + this);
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/18563e45/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/postoffice/impl/BindingsImplTest.java
----------------------------------------------------------------------
diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/postoffice/impl/BindingsImplTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/postoffice/impl/BindingsImplTest.java
index 44b5d82..013ab08 100644
--- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/postoffice/impl/BindingsImplTest.java
+++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/postoffice/impl/BindingsImplTest.java
@@ -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 {