Browse files

Reduce DomainClass autowiring call overhead (it showed up in top bloc…

…king methods while profiling)

Conflicts:

	grails-core/src/main/groovy/org/codehaus/groovy/grails/commons/spring/GrailsRuntimeConfigurator.java
  • Loading branch information...
1 parent 5e026c8 commit 8e29470aa640d52b26ae331ba1e44cae32583780 @lhotari lhotari committed Apr 27, 2012
View
9 grails-bootstrap/src/main/groovy/grails/util/Environment.java
@@ -93,6 +93,7 @@
TEST_ENVIRONMENT_SHORT_NAME, Environment.TEST.getName());
private static Holder<Environment> cachedCurrentEnvironment = new Holder<Environment>("Environment");
private static final boolean cachedHasGrailsHome = System.getProperty("grails.home") != null;
+ private static boolean initializingState = false;
private String name;
Environment() {
@@ -400,8 +401,14 @@ public static boolean isInteractiveMode() {
* @return Whether interactive mode is enabled
*/
public static boolean isInitializing() {
- return Boolean.getBoolean(INITIALIZING);
@lhotari
grails member
lhotari added a line comment Apr 27, 2012

This used to be a bug. Autowiring stopped working in other Grails apps in the same JVM while some Grails app was starting up. This change also fixes that problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ return initializingState;
}
+
+ public static void setInitializing(boolean initializing) {
+ initializingState=initializing;
+ System.setProperty(INITIALIZING, String.valueOf(initializing));
+ }
+
/**
* @return true if the reloading agent is active
*/
View
4 .../src/main/groovy/org/codehaus/groovy/grails/commons/spring/GrailsRuntimeConfigurator.java
@@ -166,9 +166,9 @@ public WebApplicationContext configure(ServletContext context, boolean loadExter
application.setMainContext(webSpringConfig.getUnrefreshedApplicationContext());
- System.setProperty(Environment.INITIALIZING, "true");
+ Environment.setInitializing(true);
ctx = (WebApplicationContext) webSpringConfig.getApplicationContext();
- System.setProperty(Environment.INITIALIZING, "");
+ Environment.setInitializing(false);
pluginManager.setApplicationContext(ctx);
pluginManager.doDynamicMethods();
View
3 ...oovy/org/codehaus/groovy/grails/commons/spring/ReloadAwareAutowireCapableBeanFactory.java
@@ -182,6 +182,9 @@ protected boolean isExcludedFromDependencyCheck(PropertyDescriptor pd) {
@Override
public void autowireBeanProperties(Object existingBean, int autowireMode,
boolean dependencyCheck) throws BeansException {
+ if(Environment.isInitializing()) {
+ return;
+ }
if(autowireMode == AUTOWIRE_BY_NAME) {
if(DISABLE_AUTOWIRE_BY_NAME_OPTIMIZATIONS || dependencyCheck || existingBean instanceof Aware) {
super.autowireBeanProperties(existingBean, autowireMode, dependencyCheck);
View
6 ...n-class/src/main/groovy/org/codehaus/groovy/grails/plugins/DomainClassGrailsPlugin.groovy
@@ -203,9 +203,11 @@ class DomainClassGrailsPlugin {
return gormValidationApi
}
}
+
+ AutowireCapableBeanFactory autowireCapableBeanFactory=ctx.autowireCapableBeanFactory
+ int byName=AutowireCapableBeanFactory.AUTOWIRE_BY_NAME
metaClass.static.autowireDomain = { instance ->
- if(!Environment.isInitializing())
- ctx.autowireCapableBeanFactory.autowireBeanProperties(instance,AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false)
+ autowireCapableBeanFactory.autowireBeanProperties(instance, byName, false)
}
}
}

0 comments on commit 8e29470

Please sign in to comment.