Coherence Configuration Enhancements - Part 3 - Creating Custom Configuration Namespaces

23
<Insert Picture Here> Coherence 12.1.2 Configuration Enhancements Part 3: Creating Custom Configuration Namespaces Brian Oliver Senior Consulting Member of Staff Cloud Application Foundation - Oracle Coherence Oracle Fusion Middleware 12c Cloud Application Foundation Coherence 12.1.2

description

Watch on YouTube: http://www.youtube.com/watch?v=tDbtpn4bFx4

Transcript of Coherence Configuration Enhancements - Part 3 - Creating Custom Configuration Namespaces

Page 1: Coherence Configuration Enhancements - Part 3 - Creating Custom Configuration Namespaces

<Insert Picture Here>

Coherence 12.1.2 Configuration EnhancementsPart 3: Creating Custom Configuration NamespacesBrian OliverSenior Consulting Member of StaffCloud Application Foundation - Oracle Coherence

Oracle Fusion Middleware 12c Cloud Application Foundation

Coherence 12.1.2

Page 2: Coherence Configuration Enhancements - Part 3 - Creating Custom Configuration Namespaces

2 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.

The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.

Page 3: Coherence Configuration Enhancements - Part 3 - Creating Custom Configuration Namespaces

The Agenda…

Page 4: Coherence Configuration Enhancements - Part 3 - Creating Custom Configuration Namespaces

4 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.

Coherence 12.1.2 ConfigurationEnhancements…• Your First Custom Configuration Namespace

– HelloWorld for Namespaces!

• Coherence Cache Configuration Model– Important JavaDocs!

• Summary

Page 5: Coherence Configuration Enhancements - Part 3 - Creating Custom Configuration Namespaces

Your First Custom Configuration Namespace…

Page 6: Coherence Configuration Enhancements - Part 3 - Creating Custom Configuration Namespaces

6 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.

The Hello World Example<cache-config xmlns="http://xmlns.oracle.com/coherence/coherence-cache-config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance” xmlns:helloworld=“class://HelloWorldNamespaceHandler” xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-cache-config coherence-cache-config.xsd">

<helloworld:greeting>Gudday</helloworld:greeting>

<caching-scheme-mapping> <cache-mapping> <cache-name>dist-*</cache-name> <scheme-name>distributed-scheme</scheme-name> </cache-mapping> </caching-scheme-mapping>

<caching-schemes> <distributed-scheme> <scheme-name>distributed-scheme</scheme-name> <service-name>DistributedCache</service-name>

<backing-map-scheme> <local-scheme/> </backing-map-scheme> <autostart>true</autostart> </distributed-scheme> </caching-schemes></cache-config>

Page 7: Coherence Configuration Enhancements - Part 3 - Creating Custom Configuration Namespaces

7 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.

The Hello World Example<cache-config xmlns="http://xmlns.oracle.com/coherence/coherence-cache-config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance” xmlns:helloworld=“class://HelloWorldNamespaceHandler” xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-cache-config coherence-cache-config.xsd">

<helloworld:greeting>Gudday</helloworld:greeting>

<caching-scheme-mapping> <cache-mapping> <cache-name>dist-*</cache-name> <scheme-name>distributed-scheme</scheme-name> </cache-mapping> </caching-scheme-mapping>

<caching-schemes> <distributed-scheme> <scheme-name>distributed-scheme</scheme-name> <service-name>DistributedCache</service-name>

<backing-map-scheme> <local-scheme/> </backing-map-scheme> <autostart>true</autostart> </distributed-scheme> </caching-schemes></cache-config>

Page 8: Coherence Configuration Enhancements - Part 3 - Creating Custom Configuration Namespaces

8 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.

Your First Custom Configuration Namespace…

• Four Steps to Writing and Using Namespaces1. Create a NamespaceHandler

• Extend com.tangosol.config.xml.AbstractNamespaceHandler• Or implement com.tangosol.config.xml.NamespaceHandler

2. Create XSD for the Namespace (optional)

3. Develop Xml Content Processors for your custom Xml Content

4. Leverage Coherence Lifecycle Events (optional)

Page 9: Coherence Configuration Enhancements - Part 3 - Creating Custom Configuration Namespaces

9 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.

A Basic HelloWorldNamespaceHandler

import com.tangosol.config.xml.AbstractNamespaceHandler;import com.tangosol.config.xml.ProcessingContext;import com.tangosol.run.xml.XmlElement;

import java.net.URI;

/** * A Simple Hello World NamespaceHandler. * * @author Brian Oliver */public class HelloWorldNamespaceHandler extends AbstractNamespaceHandler{ @Override public void onStartNamespace(ProcessingContext context, XmlElement element, String prefix, URI uri) { super.onStartNamespace(context, element, prefix, uri);

System.out.println("Hello World Namespace Started"); }}

Page 10: Coherence Configuration Enhancements - Part 3 - Creating Custom Configuration Namespaces

10 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.

What about <helloworld:greeting/>?

• The Detail…– The Configuration Framework delegates Xml content processing to

NamespaceHandler provided Content “processors”– Xml Content Processors “process” Xml content that belongs to a

namespace

• So… We must define an appropriate Xml ElementProcessor for the <helloworld:greeting> element in our NamespaceHandler

Page 11: Coherence Configuration Enhancements - Part 3 - Creating Custom Configuration Namespaces

11 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.

HelloWorldNamespaceHandlerpublic class HelloWorldNamespaceHandler extends AbstractNamespaceHandler{ @Override public void onStartNamespace(ProcessingContext context, XmlElement element, String prefix, URI uri) { super.onStartNamespace(context, element, prefix, uri); System.out.println("Hello World Namespace Started"); }

@XmlSimpleName("greeting") public static class GreetingProcessor implements ElementProcessor<Void> { @Override public Void process(ProcessingContext context, XmlElement element) throws ConfigurationException { System.out.println(”Greeting was [" + element.getString() + “]”); return null; } }}

Page 12: Coherence Configuration Enhancements - Part 3 - Creating Custom Configuration Namespaces

12 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.

AbstractNamespaceHandler…

• Provides auto discovery of Xml Processors using Annotations– Supports manual registration through explicit calls

• Internally tracks known Processors

• Provides default behaviors for unknown Xml Content

• Advanced… – Can “inject” values into Objects– Can “create” values from known Xml content types– Can “auto-create” Processors for Annotated Types

Page 13: Coherence Configuration Enhancements - Part 3 - Creating Custom Configuration Namespaces

13 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.

AbstractNamespaceHandler classpublic abstract class AbstractNamespaceHandler implements com.tangosol.config.xml.NamespaceHandler { public AbstractNamespaceHandler(); . . .

public void registerProcessor(Class<?> processorClass); public void registerProcessor(String localName, ElementProcessor<?> processor); public void registerProcessor(String localName, AttributeProcessor<?> processor);

public <T> void registerElementType(String localName, Class<T> elementClass); public <T> void registerAttributeType(String localName, Class<T> attributeClass);

protected AttributeProcessor<?> onUnknownAttribute(XmlAttribute attribute); protected ElementProcessor<?> onUnknownElement(XmlElement element);

. . .}

Page 14: Coherence Configuration Enhancements - Part 3 - Creating Custom Configuration Namespaces

Hello World in Action!

Page 15: Coherence Configuration Enhancements - Part 3 - Creating Custom Configuration Namespaces

15 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.

Custom Configuration Namespace Development

• How to think about the Cache Configuration XML…– When “processed” Xml Content “produces” a specific type of instance– The Framework processes Xml documents to produce “configurations”

– For Example:<cache-config> produces a CacheConfig

<class-scheme> produces a ClassScheme

<distributed-scheme> produces a DistributedScheme

Page 16: Coherence Configuration Enhancements - Part 3 - Creating Custom Configuration Namespaces

16 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.

Coherence 12.1.2 Custom Configuration Namespaces

• How to think about the Cache Configuration XML?– NamespaceHandlers define Element/Attribute Processors for XML in a

Namespace

• ElementProcessor<?>’s…– Are responsible for processing Xml Elements to produce values

• AttributeProcessor<?>’s…– Are responsible for processing Xml Attributes to produce values

Page 17: Coherence Configuration Enhancements - Part 3 - Creating Custom Configuration Namespaces

17 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.

Important Packages…

• The com.tangosol.coherence.config package– Defines the runtime configuration model for Coherence 12.1.2– Defines the Coherence Cache Configuration Namespace Handler– Defines the Coherence Xml Element and Attribute Processors– Defines Classes produced by the *Processors

• The com.tangosol.config package– Defines the Configuration Framework for Coherence 12.1.2– The core framework that processes Xml Documents

Page 18: Coherence Configuration Enhancements - Part 3 - Creating Custom Configuration Namespaces

Summary

Page 19: Coherence Configuration Enhancements - Part 3 - Creating Custom Configuration Namespaces

19 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.

Summary

• Coherence 12.1.2 introduces Custom Namespace Configurations– Allows integration of third-party frameworks directly into Coherence– Allows independent development of extensions– Allows customization of Coherence

Page 20: Coherence Configuration Enhancements - Part 3 - Creating Custom Configuration Namespaces

20 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.

Next Part?

• Developing a Cron service using Custom Namespaces– Leverage the Coherence Configuration Framework– Leverage the Coherence Configuration Model– Leverage the Coherence Configuration Lifecycle

Page 21: Coherence Configuration Enhancements - Part 3 - Creating Custom Configuration Namespaces

Join the Coherence Community

http://coherence.oracle.com

@OracleCoherence

/OracleCoherence

blogs.oracle.com/OracleCoherence

Group: Oracle Coherence Users

/OracleCoherence

coherence.oracle.com/display/CSIGCoherence Special Interest Group

Page 22: Coherence Configuration Enhancements - Part 3 - Creating Custom Configuration Namespaces

22 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.

The proceeding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.

Page 23: Coherence Configuration Enhancements - Part 3 - Creating Custom Configuration Namespaces

<Insert Picture Here>

Coherence 12.1.2 Configuration EnhancementsPart 3: Creating Custom Configuration NamespacesBrian OliverSenior Consulting Member of StaffCloud Application Foundation - Oracle Coherence

Oracle Fusion Middleware 12c Cloud Application Foundation

Coherence 12.1.2