Hey,

So here's an example of how this alternative Service Configuration could 
look like:

// The Service Composite itself. Preferably ConfigurationMixin will
// be declared in ServiceComposite
@Mixins( {ServiceConfigurationTest.HelloWorldMixin.class, 
ConfigurationMixin.class} )
public interface HelloWorldService
     extends HelloWorld, ServiceComposite, Activatable
{
}

// The configuration of the Service
// This is an entity, so can be changed through
// the usual UoW mechanism
public interface HelloWorldConfiguration
     extends EntityComposite
{
     Property<String> phrase();

     Property<String> name();
}

// Service implementation
public static class HelloWorldMixin
     implements HelloWorld, Activatable
{
     // Inject Configuration, and specify
     // what type is desired
     // The ConfigurationMixin will figure out what
     // Entity type to load based on this injection
     @This Configuration<HelloWorldConfiguration> config2;

     String result;

     public String sayHello()
     {
         return result;
     }

     public void activate() throws Exception
     {
         // Use the config
         // Even if the user changes the config
         // these changes will not be visible
         // until the Service explicitly calls
         // Configuration.refresh(), which ensures
         // that no strange reconfigurations are done
         // while the service is in the middle of
         // serving a request
         result = config2.configuration().phrase() +
            " " + config2.configuration().name();
     }

     public void passivate() throws Exception
     {
     }
}

// The Configuration interface
// Provides access to the config Entity
// and means to refresh it's state
interface Configuration<T>
{
     T configuration();
     void refresh();
}
----

That's about it. Looks pretty clean and simple, and I really like the 
fact that you can use the regular Entity stuff for the management of the 
configuration, which will simplify UI building and such. The only gotcha 
right now is that ConfigurationMixin uses the SPI to figure out the 
injection type, which makes it impossible to declare the Mixin in 
ServiceComposite since that is in API. No good idea how to get around 
that so far.

/Rickard

_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to