Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 9 Next »

Description

The Dynamic Server Configuration Service (DSCS) is built around the Basic Configuration Service. The DSCS provides the environment to change specific Sakai properties during run-time using JMX.

Usage

Simple Case 1: Configure a String object
  • First we configure the DSCS so that it knows about the property. Define your property as a static string in:
    • org.sakaiproject.component.configuration.properties.api.ConfigurationProperties
    • e.g.
      package org.sakaiproject.component.configuration.properties.api;
      
      	public interface ConfigurationProperties {
      
      		// Person's First Name
      		public static final String PERSON_FIRST_NAME = "org.sakaiproject.example.Person.FirstName";
      
      		// ...
      	}
      	
      
  • Now, modify the component-impl's components.xml file.
  • Find the following bean: "<bean id="org.sakaiproject.component.configuration.service.api.DynamicServerConfigurationService" and locate the "dynamicSakaiProperties" bean property. Then add your configurable property to the map and assign it an initial value:
    • e.g.
      <property name="dynamicSakaiProperties">
      	<map>
      		<entry key="org.sakaiproject.example.Person.FirstName">
      			<value>Thomas</value>
      		</entry>
      	</map>
      </property>
      
  • The target class that wants to add a dynamically configurable property needs to implement "ConfigurationNotificationListener" and "ConfigurationProperties"
    • e.g.
      public class PersonImpl implements ConfigurationNotificationListener, ConfigurationProperties { ... }
      
  • The class needs to get the initial property value either at construction time or during a Spring init() method invocation
    • e.g.
      
      package org.sakaiproject.example.Person;
      
      public class PersonImpl implements ConfigurationNotificationListener, ConfigurationProperties {
      
      	// ...
      
      	private String firstName;
      	private DynamicServerConfigurationService dynamicServerConfigurationService;
      	
      	// ...
      
      	// Spring DSCS injection
      	public void setDynamicServerConfigurationService(DynamicServerConfigurationService dynamicServerConfigurationService) {
      		this.dynamicServerConfigurationService = dynamicServerConfigurationService;
      	}
      
      	// Spring init method
      	public void init() {
      		
      		// Configuration Service
      		dynamicServerConfigurationService.addNotificationListener(this, PERSON_FIRST_NAME);
      		
      		try {
      			
      			firstName = dynamicServerConfigurationService.getDynamicString(PERSON_FIRST_NAME);
      			
      		} catch (ConfigurationObjectNotFound e) {
      			LOG.error("Was not able to find configuration property");
      		} catch (InvalidConfigurationKey e) {
      			LOG.error("Provided invalid configuration key");
      		}
      	}
      	
      	// Implementing ConfigurationNotificationListener API: handleNotification
      	public void handleNotification(String configurationItemKey) {
      		
      		try {
      
      			if(PERSON_FIRST_NAME.equals(configurationItemKey)) {
      				firstName = dynamicServerConfigurationService.getDynamicString(PERSON_FIRST_NAME);
      			}
      
      		} catch (ConfigurationObjectNotFound e) {
      			LOG.error("Was not able to find configuration property for key = " + configurationItemKey);
      		} catch (InvalidConfigurationKey e) {
      			LOG.error("Provided invalid configuration key = " + configurationItemKey);
      		}
      	}	
      
  • No labels