Externalising Alfresco Configuration – One Step further
Rich Hart, Consultant, Tuesday 12th July 2011
It is good practice to externalise configuration, to allow for changes to be more flexible, and remove the requirement of code changes, compile and redeploy.
For example it’s not good practice to have a hard coded batch size which determines the size of batches of transfers between two Alfresco instances. Also, how often does it happen where a customer states they’d like everything to be batched in groups of x, to then, later down the line say they would now like it to be y.
Taking this one step further, the first stage is to externalise via spring context and bean properties. The next stage is to access these properties via JMX using Managed Beans, which Alfresco has good support for. The benefit being; if a large production system needs to minimise down time, you can make configuration changes on the fly without the requirement of a server restart. The only gotcha to this, is to ensure that you persist the changes (if permanent) in the relevant context/property files, as when a server restart eventually comes round, you will lose your JMX configuration settings.Here is how to do it:
Some standard spring bean for concrete pojo class Batch with a property “batchSize”:
<bean id ="someBeanForBatch" class="com.some.bean.impl.Batch">
<property name="batchSize" value="100"/>
</bean>
Create a Managed Bean class that exposes this property value by injecting its bean reference:
package com.some.management.impl;
import org.alfresco.enterprise.repo.management.MBeanSupport;
import org.springframework.jmx.export.annotation.ManagedAttribute;
import org.springframework.jmx.export.annotation.ManagedResource;
import com.some.bean.impl.Batch;
@ManagedResource
public class BatchConfigMBean extends MBeanSupport {
private Batch batch;
@ManagedAttribute(description = "Set the default batch size")
public void setBatchSize(String newBatchSize) {
if (newBatchSize != null) {
batch.setBatchSize(newBatchSize);
}
}
@ManagedAttribute(description = "Get the default batch size")
public String getBatchSize() {
return batch.getBatchSize();
}
public void setBatch(Batch batch) {
this.batch = batch;
}
public Batch getBatch() {
return batch;
}
}
Now create the bean for the MBean config class:
<bean id="batchMBean" class="com.some.management.implBatchConfigMBean">
<property name="batch" ref="someBeanForBatch" />
</bean>
Now reference the MBean in the JMX Exporter, so that it will appear in the JMX Console window under the following MBean path Alfresco -> ProjectBatch -> Batch Size Config.
<bean id="bmiJmxExporter" class="org.springframework.jmx.export.MBeanExporter">
<property name="assembler" ref="assembler"/>
<property name="beans">
<map>
<entry key="Alfresco:Name=ProjectBatch,Type=Batch Size Config" value-ref="batchMBean"/>
</map>
</property>
</bean>
<bean id="jmxAttributeSource" class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource"/>
<bean id="assembler" class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler">
<property name="attributeSource" ref="jmxAttributeSource"/>
</bean>
Thats it. You are now ready to rebuild, and using a tool such as JConsole you can connect to JMX port and view and set the batchSize property.








Comments
Comment 1
Jamen said:
This is very handy. But I would actually say that what would be very useful is if you could bootstrap the spring configuration properties the first time into a database (or some other registry that could even be on the file system). The JMX console allows you to directly modify the value there. Some installations shouldn't have these system admin type configuration properties being part of a build in source control to be built and distributed.
Posted: 02:07pm on 3 Aug 2011
Add your comment