Skip to content

Commit

Permalink
Merge branch '2.5.x'
Browse files Browse the repository at this point in the history
Conflicts:
	grails-core/src/main/groovy/org/grails/core/lifecycle/ShutdownOperations.java
	grails-plugin-domain-class/src/main/groovy/org/codehaus/groovy/grails/plugins/DomainClassGrailsPlugin.groovy
	grails-plugin-testing/src/main/groovy/grails/test/MockUtils.groovy
	grails-plugin-validation/src/main/groovy/org/codehaus/groovy/grails/plugins/ValidationGrailsPlugin.groovy
  • Loading branch information
lhotari committed Jan 7, 2015
2 parents f758126 + f5f9275 commit 9a4fd68
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public class DeferredBindingActions {
static {
ShutdownOperations.addOperation(new Runnable() {
public void run() {
deferredBindingActions.remove();
deferredBindingActions = new ThreadLocal<List<Runnable>>();
}
});
}, true);
}

public static void addBindingAction(Runnable runnable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@
package org.grails.core.lifecycle;

import grails.util.Holders;

import java.util.Collection;
import java.util.concurrent.ConcurrentLinkedQueue;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.grails.core.util.ClassPropertyFetcher;
import java.util.Collection;
import java.util.LinkedHashSet;

/**
* Operations that should be executed on shutdown.
Expand All @@ -31,10 +29,10 @@
* @since 2.0
*/
public class ShutdownOperations {

private static final Log LOG = LogFactory.getLog(ShutdownOperations.class);

private static final Collection<Runnable> shutdownOperations = new ConcurrentLinkedQueue<Runnable>();
private static final Collection<Runnable> shutdownOperations = new LinkedHashSet<Runnable>();
private static final Collection<Runnable> preservedShutdownOperations = new LinkedHashSet<Runnable>();

public static final Runnable DEFAULT_SHUTDOWN_OPERATION = new Runnable() {
public void run() {
Expand All @@ -45,14 +43,13 @@ public void run() {
};

static {
// default operations
shutdownOperations.add(DEFAULT_SHUTDOWN_OPERATION);
resetOperations();
}

/**
* Runs the shutdown operations
*/
public static void runOperations() {
public static synchronized void runOperations() {
try {
for (Runnable shutdownOperation : shutdownOperations) {
try {
Expand All @@ -63,15 +60,37 @@ public static void runOperations() {
}
} finally {
shutdownOperations.clear();
shutdownOperations.add(DEFAULT_SHUTDOWN_OPERATION);
shutdownOperations.addAll(preservedShutdownOperations);
}
}

/**
* Adds a shutdown operation which will be run once for the next shutdown
* @param runnable The runnable operation
*/
public static synchronized void addOperation(Runnable runnable) {
addOperation(runnable, false);
}

/**
* Adds a shutdown operation
* @param runnable The runnable operation
* @param preserveForNextShutdown should preserve the operation for subsequent shutdowns, useful in tests
*/
public static void addOperation(Runnable runnable) {
public static synchronized void addOperation(Runnable runnable, boolean preserveForNextShutdown) {
shutdownOperations.add(runnable);
if(preserveForNextShutdown) {
preservedShutdownOperations.add(runnable);
}
}

/**
* Clears all shutdown operations without running them. Also clears operations that are kept after running operations.
*/
public static synchronized void resetOperations() {
shutdownOperations.clear();
preservedShutdownOperations.clear();
// default operations
addOperation(DEFAULT_SHUTDOWN_OPERATION, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ConstraintEvalUtils {
static {
ShutdownOperations.addOperation({
clearDefaultConstraints()
} as Runnable)
} as Runnable, true)
}

private static defaultConstraintsMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class ConvertersConfigurationHolder {
public void run() {
clear();
}
});
}, true);
}

private static ConvertersConfigurationHolder INSTANCE = new ConvertersConfigurationHolder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public class WrappedResponseHolder {
static {
ShutdownOperations.addOperation(new Runnable() {
public void run() {
wrappedResponseHolder.remove();
wrappedResponseHolder = new ThreadLocal<HttpServletResponse>();
}
});
}, true);
}
private static final ThreadLocal<HttpServletResponse> wrappedResponseHolder =
private static ThreadLocal<HttpServletResponse> wrappedResponseHolder =
new ThreadLocal<HttpServletResponse>();

/**
Expand Down

0 comments on commit 9a4fd68

Please sign in to comment.