Tuscany 2.x Extensibility and SPIs Raymond Feng
Tuscany Extensibility Cx2x/Tuscany+2.x+Extensibility+and+SPIs#extensions Cx2x/Tuscany+2.x+Extensibility+and+SPIs#extensions
Tuscany Core and Extensions
How is Extensibility achieved? Inspired by Eclipse ExtensionPoint/Extension pattern Use Jar service provider configuration files with extended syntax – ar.html#Service Provider –META-INF/services/
ExtensionPoint Registry
META-INF/services META- INF/services/ org.apache.tuscany.sca.contribution. processor.StAXArtifactProcessor –org.apache.tuscany.sca.assembly.xml.CompositeProcessor;qname= asis- open.org/ns/opencsa/sca/200903#composite,model=org.apache.tuscany.sca.ass embly.Composite
An example
Service Discovery Two types of service discovery mechanisms –Classloader –OSGi bundles Sort by ranking attribute (to override default implementations) –A: ;ranking=100 (A is picked) –B: ;ranking=50 Discover by a filter
OSGi-friendly Service Discovery Bundle.getResource() An implementation of ExtensionPointRegistry that uses OSGi service registry
Service Attributes Similar with OSGi header syntax – ;attr1=value1,attr2=value2 –Both, and ; can be used to separate attributes –| can be used to declare multiple providers on one line – | ;attr1=value1
Service Constructors The Tuscany runtime introspects the constrcutors of an implementation class by the following order for extension points – (ExtensionPointRegistry registry) – (ExtensionPointRegistry registry, Map attributes) – () The extension point controls how to instantiate an extension implementation class
LifeCycle of Extensions The implementation class of an extension point or extension can optionally implement the LifeCycleListener –start() –stop()
Extension Points org.apache.tuscany.sca.core.ModuleActivatorExtensionPoint org.apache.tuscany.sca.core.UtilityExtensionPoint org.apache.tuscany.sca.core.FactoryExtensionPoint org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint org.apache.tuscany.sca.definitions.xml.DefinitionsExtensionPoint org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessorExtensionPoint org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint org.apache.tuscany.sca.contribution.processor.ValidationSchemaExtensionPoint org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint org.apache.tuscany.sca.contribution.scanner.ContributionScannerExtensionPoint org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint org.apache.tuscany.sca.context.ContextFactoryExtensionPoint org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint org.apache.tuscany.sca.databinding.DataBindingExtensionPoint org.apache.tuscany.sca.databinding.TransformerExtensionPoint org.apache.tuscany.sca.databinding.jaxb.XMLAdapterExtensionPoint org.apache.tuscany.sca.host.http.ServletHostExtensionPoint org.apache.tuscany.sca.host.rmi.RMIHostExtensionPoint org.apache.tuscany.sca.implementation.web.runtime.ClientExtensionPoint org.apache.tuscany.sca.web.javascript.ComponentJavaScriptGeneratorExtensionPoint org.apache.tuscany.sca.web.javascript.JavascriptProxyFactoryExtensionPoint
ModuleActivator ModuleActivator is now a special type of LifeCycleListener –void start() –void stop() In 2.x, the implementation class of a ModuleActivator receives ExtensionPointRegistry via constructors instead of start/stop methods Almost all of the 1.x module activators are now converted into regular extension
Utility Extension Point A collection of utility functions Replace static singletons with a registry managed utilities Utilities without a META-INF/services configuration –org.apache.tuscany.sca.common.xml.stax.StA XHelper (concrete class)
Tuscany SPIs OCx2x/Tuscany+2.x+Extensibility+and+SPIs OCx2x/Tuscany+2.x+Extensibility+and+SPIs
Tuscany SPI packages Listed by OSGi Export-Package header The categories –model interfaces (assembly, implementation- java) –base implementation classes –extension point and extension interfaces (extensibility, core-spi, contribution) –common utilities (common-xml, common-java) –node apis and base implementations
Models tuscany-assembly –org.apache.tuscany.sca.assembly –org.apache.tuscany.sca.assembly.builder –org.apache.tuscany.sca.assembly.impl –org.apache.tuscany.sca.definitions –org.apache.tuscany.sca.definitions.util –org.apache.tuscany.sca.interfacedef –org.apache.tuscany.sca.interfacedef.impl –org.apache.tuscany.sca.interfacedef.util –org.apache.tuscany.sca.policy –org.apache.tuscany.sca.policy.impl –org.apache.tuscany.sca.policy.util
Interface-java and interface-wsdl Interface-java –org.apache.tuscany.sca.interfacedef.java.impl –org.apache.tuscany.sca.interfacedef.java.introspect –org.apache.tuscany.sca.interfacedef.java Interface-wsdl –org.apache.tuscany.sca.interfacedef.wsdl Xsd –org.apache.tuscany.sca.xsd –org.apache.tuscany.sca.xsd.xml
Contribution and deployment Contribution –org.apache.tuscany.sca.contribution.scanner –org.apache.tuscany.sca.contribution.resolver –org.apache.tuscany.sca.contribution.processor –org.apache.tuscany.sca.contribution –org.apache.tuscany.sca.contribution.namespace –org.apache.tuscany.sca.contribution.java Deployment –org.apache.tuscany.sca.deployment –org.apache.tuscany.sca.deployment.impl
Extensibility and core-spi Extensibility –org.apache.tuscany.sca.core –org.apache.tuscany.sca.extensibility Core-spi –org.apache.tuscany.sca.context –org.apache.tuscany.sca.invocation –org.apache.tuscany.sca.management –org.apache.tuscany.sca.provider –org.apache.tuscany.sca.runtime –org.apache.tuscany.sca.work Monitor –org.apache.tuscany.sca.monitor
Databinding –org.apache.tuscany.sca.databinding –org.apache.tuscany.sca.databinding.xml –org.apache.tuscany.sca.databinding.impl –org.apache.tuscany.sca.databinding.util –org.apache.tuscany.sca.databinding.annotation –org.apache.tuscany.sca.databinding.javabeans
Node-api and launcher Node-api –org.apache.tuscany.sca.node –org.apache.tuscany.sca.node.configuration Node-impl –org.apache.tuscany.sca.node.impl
Common utilities Common-java –org.apache.tuscany.sca.common.java.classloader –org.apache.tuscany.sca.common.java.collection –org.apache.tuscany.sca.common.java.io –org.apache.tuscany.sca.common.java.reflection Common-xml –org.apache.tuscany.sca.common.xml –org.apache.tuscany.sca.common.xml.dom –org.apache.tuscany.sca.common.xml.sax –org.apache.tuscany.sca.common.xml.stax –org.apache.tuscany.sca.common.xml.stax.reader –org.apache.tuscany.sca.common.xml.xpath
A scheme for internal package dependencies Semi-SPIs for internal module dependencies –Export-Package: a.b;version=2.0.0;internal=true;mandatory:=int ernal –Import-Package: a.b;version=2.0.0;internal=true
Changed SPIs Monitor is now mostly request-scoped New Builder SPIs for extensions (implementation, binding and policy) Context –CompositeContext (maybe should be named as NodeContext) –ProcessorContext –BuilderContext
Changed SPIs (2) ???ProviderFactory.create???Provider() now takes RuntimeEndpoint for service binding and RuntimeEndpointReference for reference binding RuntimeWire is removed. RuntimeEndpoint and RuntimeEndpointReference own the invocation chains.
References
Useful Links TUSCANYxDOCx2x/Tuscany+2.x+Extensi bility+and+SPIshttp://cwiki.apache.org/confluence/display/ TUSCANYxDOCx2x/Tuscany+2.x+Extensi bility+and+SPIs (Chapter 13 and Chapter 14)