Coherence Configuration Enhancements - Part 3 - Creating Custom Configuration Namespaces

Post on 22-Nov-2014

485 views 7 download

description

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

Transcript of 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

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.

The Agenda…

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

Your First Custom Configuration Namespace…

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>

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>

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)

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"); }}

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

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; } }}

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

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);

. . .}

Hello World in Action!

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

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

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

Summary

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

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

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

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.

<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