aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tjwat...@apache.org
Subject svn commit: r1760012 - in /aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal: Activator.java InstallAction.java LockingStrategy.java StartAction.java StopAction.java UninstallAction.java
Date Fri, 09 Sep 2016 13:21:45 GMT
Author: tjwatson
Date: Fri Sep  9 13:21:44 2016
New Revision: 1760012

URL: http://svn.apache.org/viewvc?rev=1760012&view=rev
Log:
[ARIES-1609] Increase timeout for subsystem locking strategy and make it configurable

Modified:
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/InstallAction.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/LockingStrategy.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StartAction.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StopAction.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/UninstallAction.java

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java?rev=1760012&r1=1760011&r2=1760012&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java
Fri Sep  9 13:21:44 2016
@@ -46,6 +46,7 @@ import org.slf4j.LoggerFactory;
 public class Activator implements BundleActivator, ServiceTrackerCustomizer<Object, Object>
{
     private static final Logger logger = LoggerFactory.getLogger(Activator.class);
     public static final String MODELLED_RESOURCE_MANAGER = "org.apache.aries.application.modelling.ModelledResourceManager";
+    private static final String LOCK_TIMEOUT = "org.apache.aries.subsystem.lock.timeout";
 
     public static final String LOG_ENTRY = "Method entry: {}, args {}";
     public static final String LOG_EXIT = "Method exit: {}, returning {}";
@@ -59,6 +60,7 @@ public class Activator implements Bundle
 	}
 	
 	private volatile BundleContext bundleContext;
+	private volatile LockingStrategy lockingStrategy;
     private volatile ConfigAdminContentHandler configAdminHandler;
 	private volatile Coordinator coordinator;
     private volatile Object modelledResourceManager;
@@ -79,6 +81,10 @@ public class Activator implements Bundle
 		return bundleContext;
 	}
 
+	public LockingStrategy getLockingStrategy() {
+		return lockingStrategy;
+	}
+
 	public Coordinator getCoordinator() {
 		return coordinator;
 	}
@@ -118,6 +124,7 @@ public class Activator implements Bundle
 	public synchronized void start(BundleContext context) throws Exception {
 		logger.debug(LOG_ENTRY, "start", context);
 		bundleContext = context;
+		lockingStrategy = new LockingStrategy(bundleContext.getProperty(LOCK_TIMEOUT));
 		serviceTracker = new ServiceTracker<Object, Object>(bundleContext, generateServiceFilter(),
this);
 		serviceTracker.open();
 		logger.debug(LOG_EXIT, "start");

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/InstallAction.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/InstallAction.java?rev=1760012&r1=1760011&r2=1760012&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/InstallAction.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/InstallAction.java
Fri Sep  9 13:21:44 2016
@@ -46,7 +46,7 @@ public class InstallAction implements Pr
 		BasicSubsystem result = null;
 		// Acquire the global write lock to prevent all other operations until
 		// the installation is complete. There is no need to hold any other locks.
-		LockingStrategy.writeLock();
+		Activator.getInstance().getLockingStrategy().writeLock();
 		try {
 			State state = parent.getState();
 			if (State.INSTALLING.equals(state)) {
@@ -101,7 +101,7 @@ public class InstallAction implements Pr
 		}
 		finally {
 			// Release the global write lock.
-			LockingStrategy.writeUnlock();
+			Activator.getInstance().getLockingStrategy().writeUnlock();
 		}
 		return result;
 	}

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/LockingStrategy.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/LockingStrategy.java?rev=1760012&r1=1760011&r2=1760012&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/LockingStrategy.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/LockingStrategy.java
Fri Sep  9 13:21:44 2016
@@ -15,20 +15,32 @@ import org.osgi.service.subsystem.Subsys
 import org.osgi.service.subsystem.SubsystemException;
 
 public class LockingStrategy {
-	private static final int TRY_LOCK_TIME = 30000;
-	private static final TimeUnit TRY_LOCK_TIME_UNIT = TimeUnit.MILLISECONDS;
-	
+	private final int TRY_LOCK_TIME;
+	private final TimeUnit TRY_LOCK_TIME_UNIT = TimeUnit.SECONDS;
+
+	public LockingStrategy(String tryLockTime) {
+		int value = 600; // ten mins by default
+		if (tryLockTime != null) {
+			try {
+				value = Integer.parseInt(tryLockTime);
+			} catch (NumberFormatException e) {
+				// ignore, the default will be used
+			}
+		}
+		TRY_LOCK_TIME = value;
+	}
+
 	/*
 	 * A mutual exclusion lock used when acquiring the state change locks of
 	 * a collection of subsystems in order to prevent cycle deadlocks.
 	 */
-	private static final ReentrantLock lock = new ReentrantLock();
+	private final ReentrantLock lock = new ReentrantLock();
 	/*
 	 * Used when the state change lock of a subsystem cannot be acquired. All
 	 * other state change locks are released while waiting. The condition is met
 	 * whenever the state change lock of one or more subsystems is released.
 	 */
-	private static final Condition condition = lock.newCondition();
+	private final Condition condition = lock.newCondition();
 	
 	/*
 	 * Allow only one of the following operations to be executing at the same 
@@ -45,16 +57,16 @@ public class LockingStrategy {
 	 * (2) Start
 	 * (3) Stop
 	 */
-	private static final ReentrantReadWriteLock rwlock = new ReentrantReadWriteLock();
+	private final ReentrantReadWriteLock rwlock = new ReentrantReadWriteLock();
 	
-	private static final ThreadLocal<Map<Subsystem.State, Set<BasicSubsystem>>>
local = new ThreadLocal<Map<Subsystem.State, Set<BasicSubsystem>>>() {
+	private final ThreadLocal<Map<Subsystem.State, Set<BasicSubsystem>>> local
= new ThreadLocal<Map<Subsystem.State, Set<BasicSubsystem>>>() {
 		@Override
 		protected Map<Subsystem.State, Set<BasicSubsystem>> initialValue() {
 			return new HashMap<Subsystem.State, Set<BasicSubsystem>>();
 		}
 	};
 	
-	public static void lock() {
+	public void lock() {
 		try {
 			if (!lock.tryLock(TRY_LOCK_TIME, TRY_LOCK_TIME_UNIT)) {
 				throw new SubsystemException("Unable to acquire the global mutual exclusion lock in time.");
@@ -65,11 +77,11 @@ public class LockingStrategy {
 		}
 	}
 	
-	public static void unlock() {
+	public void unlock() {
 		lock.unlock();
 	}
 	
-	public static void lock(Collection<BasicSubsystem> subsystems) {
+	public void lock(Collection<BasicSubsystem> subsystems) {
 		Collection<BasicSubsystem> locked = new ArrayList<BasicSubsystem>(subsystems.size());
 		try {
 			while (locked.size() < subsystems.size()) {
@@ -77,7 +89,7 @@ public class LockingStrategy {
 					if (!subsystem.stateChangeLock().tryLock()) {
 						unlock(locked);
 						locked.clear();
-						if (!LockingStrategy.condition.await(TRY_LOCK_TIME, TimeUnit.SECONDS)) {
+						if (!condition.await(TRY_LOCK_TIME, TimeUnit.SECONDS)) {
 							throw new SubsystemException("Unable to acquire the state change lock in time: " +
subsystem);
 						}
 						break;
@@ -92,14 +104,14 @@ public class LockingStrategy {
 		}
 	}
 	
-	public static void unlock(Collection<BasicSubsystem> subsystems) {
+	public void unlock(Collection<BasicSubsystem> subsystems) {
 		for (BasicSubsystem subsystem : subsystems) {
 			subsystem.stateChangeLock().unlock();
 		}
 		signalAll();
 	}
 	
-	private static void signalAll() {
+	private void signalAll() {
 		lock();
 		try {
 			condition.signalAll();
@@ -109,7 +121,7 @@ public class LockingStrategy {
 		}
 	}
 	
-	public static boolean set(Subsystem.State state, BasicSubsystem subsystem) {
+	public boolean set(Subsystem.State state, BasicSubsystem subsystem) {
 		Map<Subsystem.State, Set<BasicSubsystem>> map = local.get();
 		Set<BasicSubsystem> subsystems = map.get(state);
 		if (subsystems == null) {
@@ -124,7 +136,7 @@ public class LockingStrategy {
 		return true;
 	}
 	
-	public static void unset(Subsystem.State state, BasicSubsystem subsystem) {
+	public void unset(Subsystem.State state, BasicSubsystem subsystem) {
 		Map<Subsystem.State, Set<BasicSubsystem>> map = local.get();
 		Set<BasicSubsystem> subsystems = map.get(state);
 		if (subsystems != null) {
@@ -132,7 +144,7 @@ public class LockingStrategy {
 		}
 	}
 	
-	public static void readLock() {
+	public void readLock() {
 		try {
 			if (!rwlock.readLock().tryLock(TRY_LOCK_TIME, TRY_LOCK_TIME_UNIT)) {
 				throw new SubsystemException("Unable to acquire the global read lock in time.");
@@ -143,11 +155,11 @@ public class LockingStrategy {
 		}
 	}
 	
-	public static void readUnlock() {
+	public void readUnlock() {
 		rwlock.readLock().unlock();
 	}
 	
-	public static void writeLock() {
+	public void writeLock() {
 		try {
 			if (!rwlock.writeLock().tryLock(TRY_LOCK_TIME, TRY_LOCK_TIME_UNIT)) {
 				throw new SubsystemException("Unable to acquire the global write lock in time.");
@@ -158,7 +170,7 @@ public class LockingStrategy {
 		}
 	}
 	
-	public static void writeUnlock() {
+	public void writeUnlock() {
 		rwlock.writeLock().unlock();
 	}
 }

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StartAction.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StartAction.java?rev=1760012&r1=1760011&r2=1760012&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StartAction.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StartAction.java
Fri Sep  9 13:21:44 2016
@@ -197,7 +197,7 @@ public class StartAction extends Abstrac
 	@Override
 	public Object run() {
 		// Protect against re-entry now that cycles are supported.
-		if (!LockingStrategy.set(State.STARTING, target)) {
+		if (!Activator.getInstance().getLockingStrategy().set(State.STARTING, target)) {
 			return null;
 		}
 		try {
@@ -206,7 +206,7 @@ public class StartAction extends Abstrac
 			// If necessary, install the dependencies.
 	    	if (State.INSTALLING.equals(target.getState()) && !Utils.isProvisionDependenciesInstall(target))
{
 	    		// Acquire the global write lock while installing dependencies.
-				LockingStrategy.writeLock();
+				Activator.getInstance().getLockingStrategy().writeLock();
 				try {
 					// We are now protected against installs, starts, stops, and uninstalls.
 		    		// We need a separate coordination when installing 
@@ -228,7 +228,7 @@ public class StartAction extends Abstrac
 						}
 						// Downgrade to the read lock in order to prevent 
 		    			// installs and uninstalls but allow starts and stops.
-						LockingStrategy.readLock();
+						Activator.getInstance().getLockingStrategy().readLock();
 		    		}
 		    		catch (Throwable t) {
 		    			c.fail(t);
@@ -241,13 +241,13 @@ public class StartAction extends Abstrac
 				}
 				finally {
 					// Release the global write lock as soon as possible.
-					LockingStrategy.writeUnlock();
+					Activator.getInstance().getLockingStrategy().writeUnlock();
 				}
 	    	}
 	    	else {
 	    		// Acquire the read lock in order to prevent installs and
 	    		// uninstalls but allow starts and stops.
-	    		LockingStrategy.readLock();
+	    		Activator.getInstance().getLockingStrategy().readLock();
 	    	}
 	    	try {
 	    		// We now hold the read lock and are protected against installs
@@ -263,15 +263,15 @@ public class StartAction extends Abstrac
 	    		affectedResources = computeAffectedResources(target);
 				// Acquire the global mutual exclusion lock while acquiring the
 				// state change locks of affected subsystems.
-				LockingStrategy.lock();
+				Activator.getInstance().getLockingStrategy().lock();
 				try {
 					// We are now protected against cycles.
 					// Acquire the state change locks of affected subsystems.
-					LockingStrategy.lock(affectedResources.subsystems());
+					Activator.getInstance().getLockingStrategy().lock(affectedResources.subsystems());
 				}
 				finally {
 					// Release the global mutual exclusion lock as soon as possible.
-					LockingStrategy.unlock();
+					Activator.getInstance().getLockingStrategy().unlock();
 				}
 				Coordination coordination = this.coordination;
 				try {
@@ -323,13 +323,13 @@ public class StartAction extends Abstrac
 					}
 					finally {
 						// Release the state change locks of affected subsystems.
-						LockingStrategy.unlock(affectedResources.subsystems());
+						Activator.getInstance().getLockingStrategy().unlock(affectedResources.subsystems());
 					}
 				}
 	    	}
 	    	finally {
 				// Release the read lock.
-				LockingStrategy.readUnlock();
+				Activator.getInstance().getLockingStrategy().readUnlock();
 			}
 		}
 		catch (CoordinationException e) {
@@ -347,7 +347,7 @@ public class StartAction extends Abstrac
 		}
 		finally {
 			// Protection against re-entry no longer required.
-			LockingStrategy.unset(State.STARTING, target);
+			Activator.getInstance().getLockingStrategy().unset(State.STARTING, target);
 		}
 		return null;
 	}

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StopAction.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StopAction.java?rev=1760012&r1=1760011&r2=1760012&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StopAction.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StopAction.java
Fri Sep  9 13:21:44 2016
@@ -44,14 +44,14 @@ public class StopAction extends Abstract
 	@Override
 	public Object run() {
 		// Protect against re-entry now that cycles are supported.
-		if (!LockingStrategy.set(State.STOPPING, target)) {
+		if (!Activator.getInstance().getLockingStrategy().set(State.STOPPING, target)) {
 			return null;
 		}
 		try {
 			// We are now protected against re-entry.
 			// Acquire the global read lock to prevent installs and uninstalls
 			// but allow starts and stops.
-			LockingStrategy.readLock();
+			Activator.getInstance().getLockingStrategy().readLock();
 			try {
 				// We are now protected against installs and uninstalls.
 				checkRoot();
@@ -68,15 +68,15 @@ public class StopAction extends Abstract
 				}
 				// Acquire the global mutual exclusion lock while acquiring the
 				// state change locks of affected subsystems.
-				LockingStrategy.lock();
+				Activator.getInstance().getLockingStrategy().lock();
 				try {
 					// We are now protected against cycles.
 					// Acquire the state change locks of affected subsystems.
-					LockingStrategy.lock(subsystems);
+					Activator.getInstance().getLockingStrategy().lock(subsystems);
 				}
 				finally {
 					// Release the global mutual exclusion lock as soon as possible.
-					LockingStrategy.unlock();
+					Activator.getInstance().getLockingStrategy().unlock();
 				}
 				try {
 					// We are now protected against other starts and stops of the affected subsystems.
@@ -128,17 +128,17 @@ public class StopAction extends Abstract
 				}
 				finally {
 					// Release the state change locks of affected subsystems.
-					LockingStrategy.unlock(subsystems);
+					Activator.getInstance().getLockingStrategy().unlock(subsystems);
 				}
 			}
 			finally {
 				// Release the read lock.
-				LockingStrategy.readUnlock();
+				Activator.getInstance().getLockingStrategy().readUnlock();
 			}
 		}
 		finally {
 			// Protection against re-entry no longer required.
-			LockingStrategy.unset(State.STOPPING, target);
+			Activator.getInstance().getLockingStrategy().unset(State.STOPPING, target);
 		}
 		return null;
 	}

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/UninstallAction.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/UninstallAction.java?rev=1760012&r1=1760011&r2=1760012&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/UninstallAction.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/UninstallAction.java
Fri Sep  9 13:21:44 2016
@@ -25,14 +25,14 @@ public class UninstallAction extends Abs
 	@Override
 	public Object run() {
 		// Protect against re-entry now that cycles are supported.
-		if (!LockingStrategy.set(State.UNINSTALLING, target)) {
+		if (!Activator.getInstance().getLockingStrategy().set(State.UNINSTALLING, target)) {
 			return null;
 		}
 		try {
 			// Acquire the global write lock to prevent all other operations 
 			// until the uninstall is complete. There is no need to hold any 
 			// other locks.
-			LockingStrategy.writeLock();
+			Activator.getInstance().getLockingStrategy().writeLock();
 			try {
 				checkRoot();
 				checkValid();
@@ -47,12 +47,12 @@ public class UninstallAction extends Abs
 			}
 			finally {
 				// Release the global write lock.
-				LockingStrategy.writeUnlock();
+				Activator.getInstance().getLockingStrategy().writeUnlock();
 			}
 		}
 		finally {
 			// Protection against re-entry no longer required.
-			LockingStrategy.unset(State.UNINSTALLING, target);
+			Activator.getInstance().getLockingStrategy().unset(State.UNINSTALLING, target);
 		}
 		return null;
 	}



Mime
View raw message