@This Configuration<MyServiceConfiguration> config;
where MyServiceConfiguration extends {@link ConfigurationComposite}, which itself is an ordinary {@link org.qi4j.api.entity.EntityComposite}. The Configuration implementation will either locate an instance of the given Configuration type in the persistent store using the identity of the Service, or create a new such instance if one doesn't already exist. If a new Configuration instance is created then it will be populated with properties from the properties file whose filesystem name is the same as the identity (e.g. "MyService.properties"). If a service is not given a name via the {@link org.qi4j.bootstrap.ServiceDeclaration#identifiedBy(String)}, the name will default to the FQCN of the ServiceComposite type.
The Configuration instance can be modified externally just like any other EntityComposite, but its values will not be updated in the Service until {@link #refresh()} is called. This allowssafe reloads of Configuration state to ensure that it is not reloaded while the Service is handling a request.
The Configuration will be automatically refreshed when the Service is activated through the {@link org.qi4j.api.service.Activatable#activate()} method by the Qi4j runtime.Any refreshes at other points will have to be done manually or triggered through some other mechanism.
The user configuration entity is part of a long running {@link UnitOfWork}, and to persist changes to it the {@link #save()} method must be called. No other actions are required. Example;
public interface MyConfiguration extends ConfigurationComposite { Property<Long> timeout(); } : @This Configuration<MyConfiguration> config; : private void setTimeoutConfiguration( long timeout ) { config.configuration().timeout().set( timeout ); config.save(); }
And even if a separate thread is using the {@code timeout()} configuration when this is happening, the{@link UnitOfWork} isolation will ensure that the other thread is not affected. That thread, on the other handwill need to do a {@link #refresh()} at an appropriate time to pick up the timeout change. For instance;
|
|