tu sca ny 1 the tuscany java sca runtime 20 august 2006

29
1 tu sca ny The Tuscany Java SCA Runtime 20 August 2006

Upload: morgan-gervase-lane

Post on 04-Jan-2016

216 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Tu sca ny 1 The Tuscany Java SCA Runtime 20 August 2006

1 tu sca ny

The Tuscany Java SCA Runtime

20 August 2006

Page 2: Tu sca ny 1 The Tuscany Java SCA Runtime 20 August 2006

2 tu sca ny

Agenda

• Overview

• Architecture• Runtime artifacts

• Assembly processing

• Bootstrap

• Wiring

Page 3: Tu sca ny 1 The Tuscany Java SCA Runtime 20 August 2006

3 tu sca ny

Java Runtime

• Is an SCA implementation• Specs at http://www.osoa.org

• Provides infrastructure for creating service assemblies• Heterogeneous services connected through wires

• Containers for managing service instances and lifecycle• Spring, Java POJOs, Groovy

• Infrastructure for wiring services together• Apply qualities of service

• Sync, non-blocking, callbacks, conversations

• Framework for mediation

• Dynamic re-wiring

• Embeddable in a variety of host environments• Standalone, J2EE, OSGi, etc.

• Leverage qualities of service provided by host • Transactions, clustering, fail-over

Page 4: Tu sca ny 1 The Tuscany Java SCA Runtime 20 August 2006

4 tu sca ny

Project Structure

API

SPI

HOST-API

Core

Base interfaces for interacting with the runtime (eventually will contain management)

API for the runtime to interact with its host environment

SPI and base classes for extending the runtime

The runtime implementation

WSDL

Important Extensions

Launcher

Test

Page 5: Tu sca ny 1 The Tuscany Java SCA Runtime 20 August 2006

5 tu sca ny

Agenda

• Overview

• Architecture• Runtime artifacts

• Assembly processing

• Bootstrap

• Wiring

Page 6: Tu sca ny 1 The Tuscany Java SCA Runtime 20 August 2006

6 tu sca ny

Basic Runtime Artifacts

• Component• Basic unit of executable code

• Offer services and have references

• Service• A contract for component clients consisting of 0..n operations

• Services may be local or remote

• Reference• A dependency on a service

• Component references are wired to services by the runtime

ServiceReferenceWire

Component Component

Page 7: Tu sca ny 1 The Tuscany Java SCA Runtime 20 August 2006

7 tu sca ny

The Runtime is Recursive• Components may be Atomic or Composite

• Composite components contain 0..n components

• Composite services are exposed over 1..n bindings (e.g. SOAP/HTTP, JMS, RMI)

• Composite references have 1..n bindings and may target• A service exposed by another composite

• A service outside the SCA system, e.g. “Google search”

• A composite may contain just a service wired to a references (mediation)

ReferenceService

Composite Component

Composite or AtomicComponents

Page 8: Tu sca ny 1 The Tuscany Java SCA Runtime 20 August 2006

8 tu sca ny

Runtime Capabilities

• The runtime is responsible for wiring at the atomic and composite levels

• Extensions “plug into” this wiring infrastructure• Component implementation types

• SCA Java, Spring, Groovy, JavaScript

• Binding extensions• Web services, JMS, RMI, etc.

• Enables heterogeneous wiring

Page 9: Tu sca ny 1 The Tuscany Java SCA Runtime 20 August 2006

9 tu sca ny

Assembly Processing

• The runtime processes service assemblies• Serialized using SCA XML vocabulary, SCDL, but can take other forms

• The load phase processes SCDL and creates an in-memory model

• The build phase evaluates the model and produces corresponding runtime artifacts (e.g. components, services, references)

• The connect phase wires references to services

load build connect

Page 10: Tu sca ny 1 The Tuscany Java SCA Runtime 20 August 2006

10 tu sca ny

• Deployment initiates evaluation of an assembly and wiring• Deploy composites or single artifacts (component, service or reference)

Deployment

Deployer

Loads artifacts to create configuration modelLoader

Builder

Connector

Creates components, service,s and references from model

Connects wiring between references and services

Coordinates deployment

Page 11: Tu sca ny 1 The Tuscany Java SCA Runtime 20 August 2006

11 tu sca ny

Configuration Loading

Loader

StAXElementLoader

Loads XML elements from StAX stream

ComponentTypeLoader

Loads componentType for an implementation

Page 12: Tu sca ny 1 The Tuscany Java SCA Runtime 20 August 2006

12 tu sca ny

Component Type Loading

• Loads the component type definition for a specific implementation• How it does this is implementation-specific

• May load XML sidefile (location set by implementation)

• May introspect an implementation artifact (e.g. Java annotations)

• … or anything else

• Composite ComponentType Loader• Load SCDL from supplied URL

• Extract and load SCDL from composite package

• POJO ComponentType Loader• Introspect Java annotations

• Uses a pluggable “annotation processing” framework to introspect Java classes

Page 13: Tu sca ny 1 The Tuscany Java SCA Runtime 20 August 2006

13 tu sca ny

Annotation Processing

• Pluggable annotation processors• Ability to add new annotations

• Extend componentType structure• @Init

• @Destroy

• Magic Property and Reference definitions• @Monitor

• Ability to extend the core programming model• e.g., JPA

Page 14: Tu sca ny 1 The Tuscany Java SCA Runtime 20 August 2006

14 tu sca ny

Building

• Builder creates a runtime component from the configuration model• Builder for each implementation type

• Builder for each binding type (service or reference component)

• Runtime component manages:• Implementation instances

• Inbound and Outbound wires

• Every implementation is likely to be different• Different artifacts, programming model, …

• Composite implementation recurses for contained components• Re-invokes the Builder for every child

Page 15: Tu sca ny 1 The Tuscany Java SCA Runtime 20 August 2006

15 tu sca ny

Bootstrap

• Bootstrap process is controlled by Host environment

• Default process implemented in DefaultBootstrapper

CreateRuntime

Component

CreateBootstrapDeployer

DeploySystem

Assembly

Locate Application Assemblies

Locate System Assembly

Deploy Application Assembly

Start Server

Page 16: Tu sca ny 1 The Tuscany Java SCA Runtime 20 August 2006

16 tu sca ny

Wiring

• To understand how wiring works, we need to detail how Components function in the system…

• Start with Atomic Components and then discuss Composite Components

Page 17: Tu sca ny 1 The Tuscany Java SCA Runtime 20 August 2006

17 tu sca ny

Atomic Component

• AtomicComponent: the most basic component form• Corresponds to the spec concept

• Offers services, has references and properties

• Implementation types e.g. Java, XSLT, etc.

• Are wired

• Have properties

Outbound wire Inbound wire

Properties

Page 18: Tu sca ny 1 The Tuscany Java SCA Runtime 20 August 2006

18 tu sca ny

Implementation Instances

• Atomic Components have implementation instances• Instances are associated with a scope: e.g. request, conversation, module

• A SCDL entry defines a Component

<component name=“Foo”>…</component>

association

instances of “FooImpl”Foo component

Page 19: Tu sca ny 1 The Tuscany Java SCA Runtime 20 August 2006

19 tu sca ny

Atomic Component Instance Management

• Atomic components use a ScopeContainer to manage implementation instances• Module, HTTP Session, Request, Stateless• ScopeContainers track implementation instances by scope id and the AtomicComponent instance identity• Instances are stored in an InstanceWrapper which is specific to the component implementation type (e.g.

PojoInstanceWrapper.java)

ScopeContainer

AtomicComponent

AtomicComponent

Collection of instance wrappers keyed by scope id and collection keyed by AtomicComponent

Page 20: Tu sca ny 1 The Tuscany Java SCA Runtime 20 August 2006

20 tu sca ny

Component Implementation Instance Creation

ScopeContainer

getInstance(this)

no instance cachedcreateInstance

return instance

track and enqueue instance (for destruction)

return instance

AtomicComponent

Instantiate and inject the instance (which will recurse for dependents)

Page 21: Tu sca ny 1 The Tuscany Java SCA Runtime 20 August 2006

21 tu sca ny

Component Wiring

• Component references are connected to services through wires

• Two sides• InboundWire - handles the source side of a wire, including policy

• OutboundWire - handles the target side of a wire, including policy

• The runtime connects inbound and outbound wires, performing optimizations if possible

• Inbound and outbound wires may be associated with different service contracts

• Different implementation types• “Standard” wires contain invocation chains that have Interceptors and

MessageHandlers that perform some form of mediation (e.g. policy)

• Other wire types exist that, for example, do not perform mediations

Outbound wire Inbound wire

Page 22: Tu sca ny 1 The Tuscany Java SCA Runtime 20 August 2006

22 tu sca ny

Invocation Chains

• A wire has an InvocationChain per service operation• An InvocationChain may have

• Interceptors - “Around-style” mediation• One-way MessageHandlers

• Component implementation instances access a wire through a WireInvocationHandler associated with a reference• WireInvocationHandlers may (or may not depending on the component type) be fronted by a proxy • WireInvocationHandlers dispatch an invocation to the correct chain

• A wire has a TargetInvoker that is created from the target side AtomicComponent or Reference and is stored on the source wire invocation handler. The TargetInvoker is resposnible for dispatching the request to the target instance when the message hits the end of the target invocation chain.

Invocation chains

Invocation chains

Page 23: Tu sca ny 1 The Tuscany Java SCA Runtime 20 August 2006

23 tu sca ny

Invocation Overview

• An invocation is dispatched to the WireInvocationHandler• The WireInvocationHandler looks up the correct InvocationChain• It then creates a message, sets the payload, sets the TargetInvoker, and passes the message down the

chain• When the message reaches the end of the chain, the TargetInvoker is called, which in turn is

responsible for dispatching to the target• Having the TargetInvoker stored on the outbound side allows it to cache the target instance when

the wire source has a scope of equal or lesser value than the target (e.g. request-->module)

WireInvocationHandler

Invocation

TargetInvoker associated with the operation

Payload

Dispatch on target

Page 24: Tu sca ny 1 The Tuscany Java SCA Runtime 20 August 2006

24 tu sca ny

Wires and Implementation Instances

• The runtime provides components with InboundWires and OutboundWires• InvocationChains are held in component wires and are therefore stateless

• Allows for dynamic behavior such as introduction of new interceptors or re-wiring

WireInvocationHandler

Implementation instance

Pro

xy

Outboundwire held by component

InboundWire associated with a service and held by component

TargetInvoker may need to resolve the target instance. This may be done by referencing the ScopeContainer

Page 25: Tu sca ny 1 The Tuscany Java SCA Runtime 20 August 2006

25 tu sca ny

Invocation Detail

OutboundInterceptor Chain

TargetInvoker

OutboundRequest Channel

1

InboundRequest ChannelRequest

2

InboundResponse Channel

OutboundResponse Channel

6

7

Response 3 4 5

1. RequestResponseInterceptor (RRI) dispatches to the outbound request channel (OReqC)2. RRI dispatches to the inbound request channel (IReqC)3. MessageDispatcher dispatches to the inbound interceptor chain4. TargetInvokerInterceptor pulls the TargetInvoker from the message and dispatches to it5. TargetInvoker dispatches to the target (implementation instance or to some transport)6. RRI dispatches to the inbound response channel (IRespC)7. RRI dispatches to the outbound response channel (ORespC)8. The response is returned back up the outbound channel to the client

InboundInterceptor Chain

Note the runtime may optimize invocations not to call interceptors or handlers and possibly dispatch directly to a target (or any combination thereof)

Page 26: Tu sca ny 1 The Tuscany Java SCA Runtime 20 August 2006

26 tu sca ny

Composite Component

• CompositeComponent: a component which contains child components• Corresponds to the spec concept

• Offers services, has references over bindings

• Has properties

• Has inbound and outbound wires associated with Services and References

• Implementations deal with the specifics of a type, e.g. Spring

ReferenceService

Properties

Page 27: Tu sca ny 1 The Tuscany Java SCA Runtime 20 August 2006

27 tu sca ny

A Composite Example

• Expose a Spring Bean through a service with a SOAP/HTTP binding and using a reference bound over SOAP/JMS

• Spring application.xml does not need to be modified• Preserves Spring programming model

• Allows existing Spring applications to be wired in an assembly

• Services and references are contributed by SCA bindings (e.g. Celtix)

ReferenceService

SpringCompositeComponent

Spring Bean

Spring Bean

Page 28: Tu sca ny 1 The Tuscany Java SCA Runtime 20 August 2006

28 tu sca ny

Composite Wiring

• Services and references are “twist-ties” for inbound and outbound wires

Services have connected InboundWire/ OutboundWire pairs

OutboundInbound OutboundInbound

References have connected InboundWire/ OutboundWire pairs

Inbound Outbound

CompositeComponent

AtomicComponent

Page 29: Tu sca ny 1 The Tuscany Java SCA Runtime 20 August 2006

29 tu sca ny

Composite Reference Invocations

• When a message reaches the end of the outbound reference wire, the TargetInvoker dispatches over a transport

• In contrast to Component-->Component invocations, where the TargetInvoker would resolve the target implementation instance

OutboundInboundOutbound

Invoke on transport

AtomicComponent Composite Reference