From c6deff15901f1f4ae649bf6aaf257484175113b7 Mon Sep 17 00:00:00 2001 From: Asad Ahmed Date: Wed, 27 Nov 2013 10:41:59 -0800 Subject: [PATCH] Addding a new method to let the clients of clustering service specify a transaction timeout when they start a transaction Change-Id: Icad02808e37d7852907a417436c72cbcff8e62f1 Signed-off-by: Asad Ahmed --- .../clustering/integrationtest/pom.xml | 2 +- opendaylight/clustering/services/pom.xml | 2 +- .../clustering/services/IClusterServices.java | 11 +++++++++++ .../services/IClusterServicesCommon.java | 11 +++++++++++ .../services_implementation/pom.xml | 2 +- .../internal/ClusterManager.java | 19 +++++++++++++++++++ .../internal/ClusterManagerCommon.java | 12 ++++++++++++ opendaylight/clustering/stub/pom.xml | 2 +- .../stub/internal/ClusterManagerCommon.java | 17 +++++++++++------ opendaylight/commons/opendaylight/pom.xml | 1 + .../configuration/integrationtest/pom.xml | 2 +- .../distribution/opendaylight/pom.xml | 2 +- .../integrationtest/pom.xml | 2 +- .../hosttracker/integrationtest/pom.xml | 2 +- .../northbound/integrationtest/pom.xml | 2 +- .../statisticsmanager/integrationtest/pom.xml | 2 +- .../switchmanager/integrationtest/pom.xml | 2 +- 17 files changed, 76 insertions(+), 17 deletions(-) diff --git a/opendaylight/clustering/integrationtest/pom.xml b/opendaylight/clustering/integrationtest/pom.xml index ca1e37e3be..43fa74fba8 100644 --- a/opendaylight/clustering/integrationtest/pom.xml +++ b/opendaylight/clustering/integrationtest/pom.xml @@ -21,7 +21,7 @@ org.opendaylight.controller clustering.services - 0.4.1-SNAPSHOT + 0.5.0-SNAPSHOT org.opendaylight.controller diff --git a/opendaylight/clustering/services/pom.xml b/opendaylight/clustering/services/pom.xml index 7eede83638..ebaffc29df 100644 --- a/opendaylight/clustering/services/pom.xml +++ b/opendaylight/clustering/services/pom.xml @@ -16,7 +16,7 @@ clustering.services - 0.4.1-SNAPSHOT + 0.5.0-SNAPSHOT bundle diff --git a/opendaylight/clustering/services/src/main/java/org/opendaylight/controller/clustering/services/IClusterServices.java b/opendaylight/clustering/services/src/main/java/org/opendaylight/controller/clustering/services/IClusterServices.java index 77e300e95a..b3427c7fcc 100644 --- a/opendaylight/clustering/services/src/main/java/org/opendaylight/controller/clustering/services/IClusterServices.java +++ b/opendaylight/clustering/services/src/main/java/org/opendaylight/controller/clustering/services/IClusterServices.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.Properties; import java.util.Set; import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.TimeUnit; import javax.transaction.HeuristicMixedException; import javax.transaction.HeuristicRollbackException; @@ -215,6 +216,16 @@ public interface IClusterServices { */ void tbegin() throws NotSupportedException, SystemException; + /** + * tbegin with a timeout + * @see IClusterServices#tbegin + * @param timeout the transaction timeout + * @param unit TimeUnit for the timeout + * @throws NotSupportedException + * @throws SystemException + */ + void tbegin(long timeout, TimeUnit unit) throws NotSupportedException, SystemException; + /** * Commit a transaction covering all the data structures/HW updates. */ diff --git a/opendaylight/clustering/services/src/main/java/org/opendaylight/controller/clustering/services/IClusterServicesCommon.java b/opendaylight/clustering/services/src/main/java/org/opendaylight/controller/clustering/services/IClusterServicesCommon.java index 6850c64a0e..7ea86c6db7 100644 --- a/opendaylight/clustering/services/src/main/java/org/opendaylight/controller/clustering/services/IClusterServicesCommon.java +++ b/opendaylight/clustering/services/src/main/java/org/opendaylight/controller/clustering/services/IClusterServicesCommon.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.Properties; import java.util.Set; import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.TimeUnit; import javax.transaction.HeuristicMixedException; import javax.transaction.HeuristicRollbackException; @@ -118,6 +119,16 @@ public interface IClusterServicesCommon { */ void tbegin() throws NotSupportedException, SystemException; + /** + * tbegin with a timeout + * @see IClusterServicesCommon#tbegin + * @param timeout the transaction timeout + * @param unit TimeUnit for the timeout + * @throws NotSupportedException + * @throws SystemException + */ + void tbegin(long timeout, TimeUnit unit) throws NotSupportedException, SystemException; + /** * Commit a transaction covering all the data structures/HW updates. */ diff --git a/opendaylight/clustering/services_implementation/pom.xml b/opendaylight/clustering/services_implementation/pom.xml index ab75eb8dd1..90df7511e4 100644 --- a/opendaylight/clustering/services_implementation/pom.xml +++ b/opendaylight/clustering/services_implementation/pom.xml @@ -137,7 +137,7 @@ org.opendaylight.controller clustering.services - 0.4.1-SNAPSHOT + 0.5.0-SNAPSHOT org.opendaylight.controller diff --git a/opendaylight/clustering/services_implementation/src/main/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManager.java b/opendaylight/clustering/services_implementation/src/main/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManager.java index a9e6948a40..fcf71a90ac 100644 --- a/opendaylight/clustering/services_implementation/src/main/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManager.java +++ b/opendaylight/clustering/services_implementation/src/main/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManager.java @@ -22,6 +22,7 @@ import java.util.Properties; import java.util.Set; import java.util.StringTokenizer; import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.TimeUnit; import javax.transaction.HeuristicMixedException; import javax.transaction.HeuristicRollbackException; @@ -69,6 +70,9 @@ public class ClusterManager implements IClusterServices { private static String loopbackAddress = "127.0.0.1"; + // defaultTransactionTimeout is 60 seconds + private static int DEFAULT_TRANSACTION_TIMEOUT = 60; + /** * Start a JGroups GossipRouter if we are a supernode. The * GosispRouter is nothing more than a simple @@ -525,6 +529,12 @@ public class ClusterManager implements IClusterServices { @Override public void tbegin() throws NotSupportedException, SystemException { + // call tbegin with the default timeout + tbegin(DEFAULT_TRANSACTION_TIMEOUT, TimeUnit.SECONDS); + } + + @Override + public void tbegin(long timeout, TimeUnit unit) throws NotSupportedException, SystemException { EmbeddedCacheManager manager = this.cm; if (manager == null) { throw new IllegalStateException(); @@ -534,6 +544,15 @@ public class ClusterManager implements IClusterServices { if (tm == null) { throw new IllegalStateException(); } + long timeoutSec = unit.toSeconds(timeout); + if((timeoutSec > Integer.MAX_VALUE) || (timeoutSec <= 0)) { + // fall back to the default timeout + tm.setTransactionTimeout(DEFAULT_TRANSACTION_TIMEOUT); + } else { + // cast is ok here + // as here we are sure that timeoutSec < = Integer.MAX_VALUE. + tm.setTransactionTimeout((int) timeoutSec); + } tm.begin(); } diff --git a/opendaylight/clustering/services_implementation/src/main/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManagerCommon.java b/opendaylight/clustering/services_implementation/src/main/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManagerCommon.java index 9ee00484ce..97d9ded6c8 100644 --- a/opendaylight/clustering/services_implementation/src/main/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManagerCommon.java +++ b/opendaylight/clustering/services_implementation/src/main/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManagerCommon.java @@ -19,12 +19,15 @@ import java.util.Properties; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.TimeUnit; + import javax.transaction.HeuristicMixedException; import javax.transaction.HeuristicRollbackException; import javax.transaction.NotSupportedException; import javax.transaction.RollbackException; import javax.transaction.SystemException; import javax.transaction.Transaction; + import org.apache.felix.dm.Component; import org.opendaylight.controller.clustering.services.CacheConfigException; import org.opendaylight.controller.clustering.services.CacheExistException; @@ -255,6 +258,15 @@ public abstract class ClusterManagerCommon implements IClusterServicesCommon { } } + @Override + public void tbegin(long timeout, TimeUnit unit) throws NotSupportedException, SystemException { + if (this.clusterService != null) { + this.clusterService.tbegin(timeout, unit); + } else { + throw new IllegalStateException(); + } + } + @Override public void tcommit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, java.lang.SecurityException, diff --git a/opendaylight/clustering/stub/pom.xml b/opendaylight/clustering/stub/pom.xml index 607b48b3aa..8fe1a99a0d 100644 --- a/opendaylight/clustering/stub/pom.xml +++ b/opendaylight/clustering/stub/pom.xml @@ -48,7 +48,7 @@ org.opendaylight.controller clustering.services - 0.4.1-SNAPSHOT + 0.5.0-SNAPSHOT org.opendaylight.controller diff --git a/opendaylight/clustering/stub/src/main/java/org/opendaylight/controller/clustering/stub/internal/ClusterManagerCommon.java b/opendaylight/clustering/stub/src/main/java/org/opendaylight/controller/clustering/stub/internal/ClusterManagerCommon.java index b6cb742d47..fe73e240f9 100644 --- a/opendaylight/clustering/stub/src/main/java/org/opendaylight/controller/clustering/stub/internal/ClusterManagerCommon.java +++ b/opendaylight/clustering/stub/src/main/java/org/opendaylight/controller/clustering/stub/internal/ClusterManagerCommon.java @@ -9,14 +9,16 @@ package org.opendaylight.controller.clustering.stub.internal; -import java.util.ArrayList; -import java.util.concurrent.ConcurrentHashMap; -import java.net.UnknownHostException; import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.Dictionary; import java.util.List; import java.util.Properties; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.TimeUnit; import javax.transaction.HeuristicMixedException; import javax.transaction.HeuristicRollbackException; @@ -25,6 +27,7 @@ import javax.transaction.RollbackException; import javax.transaction.SystemException; import javax.transaction.Transaction; +import org.apache.felix.dm.Component; import org.opendaylight.controller.clustering.services.CacheConfigException; import org.opendaylight.controller.clustering.services.CacheExistException; import org.opendaylight.controller.clustering.services.IClusterServices; @@ -32,9 +35,6 @@ import org.opendaylight.controller.clustering.services.IClusterServicesCommon; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Dictionary; -import org.apache.felix.dm.Component; - public abstract class ClusterManagerCommon implements IClusterServicesCommon { protected String containerName = ""; protected static final Logger logger = LoggerFactory @@ -120,6 +120,11 @@ public abstract class ClusterManagerCommon implements IClusterServicesCommon { java.lang.IllegalStateException, SystemException { } + @Override + public void tbegin(long timeout, TimeUnit unit) throws NotSupportedException, SystemException { + + } + @Override public void trollback() throws java.lang.IllegalStateException, java.lang.SecurityException, SystemException { diff --git a/opendaylight/commons/opendaylight/pom.xml b/opendaylight/commons/opendaylight/pom.xml index a652845770..f277b545bf 100644 --- a/opendaylight/commons/opendaylight/pom.xml +++ b/opendaylight/commons/opendaylight/pom.xml @@ -100,6 +100,7 @@ java 0.5.0-SNAPSHOT 0.5.0-SNAPSHOT + 0.5.0-SNAPSHOT 2.5.1 1.7 1.7 diff --git a/opendaylight/configuration/integrationtest/pom.xml b/opendaylight/configuration/integrationtest/pom.xml index 894f94bc46..6bcee92544 100644 --- a/opendaylight/configuration/integrationtest/pom.xml +++ b/opendaylight/configuration/integrationtest/pom.xml @@ -40,7 +40,7 @@ org.opendaylight.controller clustering.services - 0.4.1-SNAPSHOT + 0.5.0-SNAPSHOT org.opendaylight.controller diff --git a/opendaylight/distribution/opendaylight/pom.xml b/opendaylight/distribution/opendaylight/pom.xml index 9ce668da85..35ebbbe0dd 100644 --- a/opendaylight/distribution/opendaylight/pom.xml +++ b/opendaylight/distribution/opendaylight/pom.xml @@ -509,7 +509,7 @@ org.opendaylight.controller clustering.services - ${controller.version} + ${clustering.services.version} org.opendaylight.controller diff --git a/opendaylight/forwardingrulesmanager/integrationtest/pom.xml b/opendaylight/forwardingrulesmanager/integrationtest/pom.xml index 7904bd3a8f..95fbd5dafb 100644 --- a/opendaylight/forwardingrulesmanager/integrationtest/pom.xml +++ b/opendaylight/forwardingrulesmanager/integrationtest/pom.xml @@ -61,7 +61,7 @@ org.opendaylight.controller clustering.services - 0.4.1-SNAPSHOT + 0.5.0-SNAPSHOT org.opendaylight.controller diff --git a/opendaylight/hosttracker/integrationtest/pom.xml b/opendaylight/hosttracker/integrationtest/pom.xml index 8f4163d686..2e80cac2ac 100644 --- a/opendaylight/hosttracker/integrationtest/pom.xml +++ b/opendaylight/hosttracker/integrationtest/pom.xml @@ -58,7 +58,7 @@ org.opendaylight.controller clustering.services - 0.4.1-SNAPSHOT + 0.5.0-SNAPSHOT diff --git a/opendaylight/northbound/integrationtest/pom.xml b/opendaylight/northbound/integrationtest/pom.xml index b4e0b34d09..4e1de914f7 100644 --- a/opendaylight/northbound/integrationtest/pom.xml +++ b/opendaylight/northbound/integrationtest/pom.xml @@ -74,7 +74,7 @@ org.opendaylight.controller clustering.services - 0.4.1-SNAPSHOT + 0.5.0-SNAPSHOT org.opendaylight.controller diff --git a/opendaylight/statisticsmanager/integrationtest/pom.xml b/opendaylight/statisticsmanager/integrationtest/pom.xml index 743c6784a5..a3ecf526c0 100644 --- a/opendaylight/statisticsmanager/integrationtest/pom.xml +++ b/opendaylight/statisticsmanager/integrationtest/pom.xml @@ -50,7 +50,7 @@ org.opendaylight.controller clustering.services - 0.4.1-SNAPSHOT + 0.5.0-SNAPSHOT org.opendaylight.controller diff --git a/opendaylight/switchmanager/integrationtest/pom.xml b/opendaylight/switchmanager/integrationtest/pom.xml index 5d8ce9b303..c06efb91b8 100644 --- a/opendaylight/switchmanager/integrationtest/pom.xml +++ b/opendaylight/switchmanager/integrationtest/pom.xml @@ -51,7 +51,7 @@ org.opendaylight.controller clustering.services - 0.4.1-SNAPSHOT + 0.5.0-SNAPSHOT org.opendaylight.controller -- 2.36.6