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 Restore this Version View Page History

« Previous Version 2 Next »

Fabric3 supports defining components using annotations, XML, or a DSL. This section focuses on the details of using annotations and the DSL.  

Annotation Basics

The Fabric3 is a modular runtime that is designed to be configured and deployed based on the specific functional requirements of the services it is hosting. For example, if a runtime is to host a service that requires JAX-RS functionality, a runtime image can be assembled from the Fabric3 kernel and JAX-RS extensions; extensions for other technologies such as JMS or WS-* will be excluded.

This modularity is reflected in the structure of the Fabric3 API. The main API module, org.fabric3:fabric3-api contains base annotations for working with Java POJO. Component implementation types (such as the timer component) and bindings also have API modules that extend from the core fabric3-api module. For example, the org.fabric3:fabric3-timer-api contains the Timer annotation used to declare a Java class as timer component. It may therefore be necessary to configure multiple API modules as dependencies in a project build. At runtime, Fabric3 will ensure installed API module classes are visible to applications.

 

Throughout this manual, we refer to Fabric3 modules (JARs) using their coordinate names, e.g. org.fabric3:fabric3-api. These coordinates can be used to derive dependency configuration for various build systems such as Maven and Gradle.

 

The following table lists the set of Fabric3 API modules:

 

CoordinatesDescription
org.fabric3:fabric3-apiThe base package containing general annotations and API classes
org.fabric3:fabric3-model-apiThe base package for DSL classes
org.fabric3:fabric3-binding-jms-apiPackage for JMS annotations and DSL classes
org.fabric3:fabric3-binding-file-apiPackage for file binding annotations and DSL classes
org.fabric3:fabric3-binding-rs-apiPackage for JAX-RS annotations and DSL classes
org.fabric3:fabric3-binding-ws-apiPackage for JAX-WS annotations and DSL classes
org.fabric3:fabric3-binding-zeromq-apiPackage for ZeroMQ annotations and DSL classes
org.fabric3:fabric3-junit-apiPackage for JUnit annotations
org.fabric3:fabric3-timer-apiPackage for Timer annotations and DSL classes
  

Using the DSL

    

Components and channels can also be defined using a DSL. To use the DSL, one or more provider classes must be packaged in an application archive under the Java package "f3". Provider classes are invoked by the runtime to programmatically create composites. The following demonstrates a provider class:

 

package f3;
 
public class ContributionServiceProvider {
    private static final QName QNAME = new QName(Namespaces.F3, "TestComposite");
    
	@Provides
    public static Composite getComposite() {
        CompositeBuilder compositeBuilder = CompositeBuilder.newBuilder(QNAME);
        compositeBuilder.component(JavaComponentDefinitionBuilder.newBuilder(ContributionServiceImpl.class).build());
		return compositeBuilder.build();
	}


}

 

A provider contains one or more static methods annotated with org.fabric3.api.annotation.model.Provides that returns a Composite. Programmatic configuration is extremely flexible as it can be used to create conditional configuration such as changing binding settings based on the environment. To facilitate this, Fabric3 supports the org.fabric3.api.annotation.model.Environment annotation:

 

 public class CompositeProvider {
    @Provides
    public static Composite getScannedComposite(@Environment String environment) {
        if (!"production".equals(environment)) {
            // create a composite specific to production
        } else {
			// create another composite
		} 
    }
}

The Environment annotation signals to Fabric3 to inject the name of the environment the runtime is started with.

For specific examples of using annotations or the DSL, refer to the sample applications.