Bulding a Modular Application with Coherence David Whitmarsh Independent Contractor Technical...

25
Bulding a Modular Application with Coherence David Whitmarsh Independent Contractor Technical Architect Investment Banks [email protected]

description

2. Modularity Spring, Maven, OSGi

Transcript of Bulding a Modular Application with Coherence David Whitmarsh Independent Contractor Technical...

Page 1: Bulding a Modular Application with Coherence David Whitmarsh Independent Contractor Technical Architect Investment Banks

Bulding a Modular Application with Coherence

David Whitmarsh Independent Contractor Technical Architect Investment Banks

[email protected]

Page 2: Bulding a Modular Application with Coherence David Whitmarsh Independent Contractor Technical Architect Investment Banks

1. Objective

Describe a modular architecture using Coherence

Applicable to static IoC approach (Spring) Aimed at dynamic modular approach (OSGi/Spring

DM)

Page 3: Bulding a Modular Application with Coherence David Whitmarsh Independent Contractor Technical Architect Investment Banks

2. Modularity

Spring, Maven, OSGi

Page 4: Bulding a Modular Application with Coherence David Whitmarsh Independent Contractor Technical Architect Investment Banks

Module Dependencies

Classpath dependencies Module imports a class/resource from another

module Instance dependencies

Class instance in one module calls method on a class instance in another.

Page 5: Bulding a Modular Application with Coherence David Whitmarsh Independent Contractor Technical Architect Investment Banks

Module with Spring/Maven

All classes/resources in dependent artifacts visible

Change module classes only by restart Object instances resolved during

ApplicationContext initialisation

Page 6: Bulding a Modular Application with Coherence David Whitmarsh Independent Contractor Technical Architect Investment Banks

Module with Spring DM/OSGi

Explicitly exported/imported packages visible Changing module classes reloads dependents Referenced object instances may change while

running

Page 7: Bulding a Modular Application with Coherence David Whitmarsh Independent Contractor Technical Architect Investment Banks

3. Vanilla Coherence

What support is there for modular design?

Page 8: Bulding a Modular Application with Coherence David Whitmarsh Independent Contractor Technical Architect Investment Banks

Principal Entities

Page 9: Bulding a Modular Application with Coherence David Whitmarsh Independent Contractor Technical Architect Investment Banks

Module Requirements

Distinct data service layers Each with own caches and ”DAO” instances Own data models, serialisers, CacheStores,

CacheLoaders Independently stopped/started/deployed

Page 10: Bulding a Modular Application with Coherence David Whitmarsh Independent Contractor Technical Architect Investment Banks

What Level?

We can build data access modules around: CacheFactoryBuilder

Classpath trickery, or embed entire Coherence jar inside module Separate grid node (or even grid) per service Static access ok

CacheFactory Distinct configuration files per service Must delegate dependencies (Serialisers, CacheStores) No static access methods

Service or Cache Single config across modules – coupling

Page 11: Bulding a Modular Application with Coherence David Whitmarsh Independent Contractor Technical Architect Investment Banks

4. Building Modules

Extending and Overriding Coherence default behaviour

Page 12: Bulding a Modular Application with Coherence David Whitmarsh Independent Contractor Technical Architect Investment Banks

Class Dependencies

Page 13: Bulding a Modular Application with Coherence David Whitmarsh Independent Contractor Technical Architect Investment Banks

Instance Dependencies

Page 14: Bulding a Modular Application with Coherence David Whitmarsh Independent Contractor Technical Architect Investment Banks

Distinct Services per Module

Ensure that an instance of Service is used only in a single CacheFactory

use STRATEGY_VALIDATION

Page 15: Bulding a Modular Application with Coherence David Whitmarsh Independent Contractor Technical Architect Investment Banks

Static Methods

DefaultCacheFactoryBuilder has an internal defaultCacheFactory

Static access Don't use CacheFactory.getCache or

DefaultCacheFactoryBuilder.getDefaultCacheFactory Use non-static CacheFactory.ensureCache

But Coherence itself uses getDefaultCacheFactory! Proxy service Incubation projects Cohql

Page 16: Bulding a Modular Application with Coherence David Whitmarsh Independent Contractor Technical Architect Investment Banks

Hacky Bit #1

Provide a ConfigurableCacheFactory implementation that delegates to the appropriate factory

Not all methods need sensible overrides EnsureService – API exists to map service to

factory EnsureCache – not so easy

Page 17: Bulding a Modular Application with Coherence David Whitmarsh Independent Contractor Technical Architect Investment Banks

Configuring CacheFactory

Configuration needs to come from config module (I disapprove of URL)

File resource in config module not on classpath for Coherence module (under OSGi)

Provide config as String or InputStream URL used as unique id for config, hence factory

Suppress load from URL and use as a simple id

Page 18: Bulding a Modular Application with Coherence David Whitmarsh Independent Contractor Technical Architect Investment Banks

IoC instance injection

Provide CacheStore, PofContext by injection XMLHelper only constructs new classes Configure a proxy to delegate to injected

instance In an OSGi environment implementations will

not be visible in Coherence module. Would prefer config mechanism to use a

reference – perhaps a <class-factory-scheme>?

Page 19: Bulding a Modular Application with Coherence David Whitmarsh Independent Contractor Technical Architect Investment Banks

Complete Module Config

As per example code Add destroy-method hook to stop factory,

remove services on module stop (OSGi) In OSGi, factories can be deployed, started and

stopped at any time. Use a separate config module to create a proxy

service factory

Page 20: Bulding a Modular Application with Coherence David Whitmarsh Independent Contractor Technical Architect Investment Banks

System Properties

Coherence substitutes system properties in config files

Apparently read in some static initialiser No way to inject config properties other than

setting system properties before they're read.

Page 21: Bulding a Modular Application with Coherence David Whitmarsh Independent Contractor Technical Architect Investment Banks

OSGi

Using an OSGi container

Page 22: Bulding a Modular Application with Coherence David Whitmarsh Independent Contractor Technical Architect Investment Banks

Add/Remove Services

Coherence module has no classpath dependencies on data models

Add, upgrade, remove services without interruption Rolling upgrade on only those services that need to

change

Page 23: Bulding a Modular Application with Coherence David Whitmarsh Independent Contractor Technical Architect Investment Banks

Dynamic Data Model 1

Page 24: Bulding a Modular Application with Coherence David Whitmarsh Independent Contractor Technical Architect Investment Banks

Dynamic Data Model 2

Page 25: Bulding a Modular Application with Coherence David Whitmarsh Independent Contractor Technical Architect Investment Banks

Dynamic Data Model 3

All handling of serialisation/persistence delegated via OSGi

New versions of data model and data model support deployed and old versions removed without changing cache config/CacheFactory instance

Evolvable objects updated in-place No rolling upgrade required