Permalink
Browse files

Optimize singleton creation in Yaml processors

Change-Id: I60d989765584411f37c1ff7f2120d0e3d9ce8569
  • Loading branch information...
1 parent 2e679eb commit 6af4c930aa2b4ff32b0a4b1d4665c2730991ba81 @dsyer dsyer committed Nov 29, 2012
@@ -30,6 +30,7 @@
* bar:
* one: two
* three: four
+ *
* <pre>
*
* plus (later in the list)
@@ -39,6 +40,7 @@
* bar:
* one: 2
* five: six
+ *
* <pre>
*
* results in an effecive input of
@@ -49,6 +51,7 @@
* one: 2
* three: four
* five: six
+ *
* <pre>
*
* Note that the value of "foo" in the first document is not simply replaced with the value in the second, but it's nested values are merged.
@@ -58,8 +61,17 @@
*/
public class YamlMapFactoryBean extends YamlProcessor implements FactoryBean<Map<String, Object>> {
+ private Map<String, Object> instance;
+
@Override
public Map<String, Object> getObject() {
+ if (instance==null) {
+ instance = doGetObject();
+ }
+ return instance;
+ }
+
+ private Map<String, Object> doGetObject() {
final Map<String, Object> result = new LinkedHashMap<String, Object>();
MatchCallback callback = new MatchCallback() {
@Override
@@ -98,6 +98,7 @@ public void setMatchDefault(boolean matchDefault) {
* decide which map entries to keep in the final output from this factory. Possible values:
* <ul>
* <li><code>OVERRIDE</code> for replacing values from earlier in the list</li>
+ * <li><code>OVERRIDE_AND_IGNORE</code> the same, but ignore IO errors loading individual resources</li>
* <li><code>FIRST_FOUND</code> if you want to take the first resource in the list that exists and use just that.</li>
* </ul>
*
@@ -64,8 +64,17 @@
*/
public class YamlPropertiesFactoryBean extends YamlProcessor implements FactoryBean<Properties> {
+ private Properties instance;
+
@Override
public Properties getObject() {
+ if (instance==null) {
+ instance = doGetObject();
+ }
+ return instance;
+ }
+
+ private Properties doGetObject() {
final Properties result = new Properties();
MatchCallback callback = new MatchCallback() {
@Override
@@ -24,8 +24,27 @@
</property>
</bean>
- <!-- This is for the account bootstrap. If someone edits web.xml they can load yml from other locations for the environment
- and it won't be picked up here. -->
+ <bean class="org.springframework.jmx.export.MBeanExporter">
+ <property name="server" ref="mbeanServer" />
+ <property name="registrationBehaviorName" value="REGISTRATION_REPLACE_EXISTING" />
+ <property name="beans">
+ <map>
+ <entry key="spring.application:type=Config,name=uaa" value-ref="&amp;config" />
+ </map>
+ </property>
+ <property name="assembler">
+ <bean class="org.springframework.jmx.export.assembler.MethodNameBasedMBeanInfoAssembler">
+ <property name="methodMappings">
+ <map>
+ <entry key="spring.application:type=Config,name=uaa" value="getObject" />
+ </map>
+ </property>
+ </bean>
+ </property>
+ </bean>
+
+ <!-- This is for the client bootstrap and other places where we need to inject a Map, as opposed to replace properties.
+ If someone edits web.xml they can load yml from other locations for the environment and it won't be picked up here. -->
<bean id="config" class="org.cloudfoundry.identity.uaa.config.YamlMapFactoryBean">
<property name="resources">
<list>
@@ -37,6 +56,11 @@
</property>
<!-- Default configuration should contain only the admin client to avoid bootstrapping extra clients -->
<property name="resolutionMethod" value="OVERRIDE_AND_IGNORE" />
+ <property name="documentMatchers">
+ <map>
+ <entry key="platform" value-ref="platform" />
+ </map>
+ </property>
</bean>
<beans profile="default,hsqldb">

0 comments on commit 6af4c93

Please sign in to comment.