Coherence Configuration Enhancements - Part 4 - Cron as a Custom Configuration Namespace

24
<Insert Picture Here> Coherence 12.1.2 Configuration Enhancements Part 4: Cron as a Custom Configuration Namespace 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=aW4TejyTfv0

Transcript of Coherence Configuration Enhancements - Part 4 - Cron as a Custom Configuration Namespace

Page 1: Coherence Configuration Enhancements - Part 4 - Cron as a Custom Configuration Namespace

<Insert Picture Here>

Coherence 12.1.2 Configuration EnhancementsPart 4: Cron as a Custom Configuration NamespaceBrian 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 4 - Cron as a Custom Configuration Namespace

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 4 - Cron as a Custom Configuration Namespace

The Agenda…

Page 4: Coherence Configuration Enhancements - Part 4 - Cron as a Custom Configuration Namespace

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

Coherence 12.1.2 ConfigurationEnhancements…• Creating a Cron Service using a Custom Namespace

• Coherence Cache Configuration Lifecycle– Using Live Events to react to the Coherence Configuration

Lifecycle

• Summary

Page 5: Coherence Configuration Enhancements - Part 4 - Cron as a Custom Configuration Namespace

Cron as a Custom Namespace…

Page 6: Coherence Configuration Enhancements - Part 4 - Cron as a Custom Configuration Namespace

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

Cron for Coherence

<cache-config xmlns="http://xmlns.oracle.com/coherence/coherence-cache-config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance” xmlns:cron=“class://com.oracle.coherence.example.cron.CronNamespaceHandler” xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-cache-config coherence-cache-config.xsd">

. . .

<cron:job> <cron:schedule>* * * * *</cron:schedule> <cron:task> <instance> <class-name>MyRunnable</class-name> </instance> </cron:task> </cron:job>

. . .

</cache-config>

Page 7: Coherence Configuration Enhancements - Part 4 - Cron as a Custom Configuration Namespace

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

The Cron Library…

1. Let’s not reinvent the wheel!– http://www.sauronsoftware.it/projects/cron4j

2. Create the Namespace

3. Create an ElementProcessor that Schedules a Runnable

4. Start/Stop the Scheduler with the Application/CCF Lifecycle

Page 8: Coherence Configuration Enhancements - Part 4 - Cron as a Custom Configuration Namespace

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

CronNamespaceHandlerpublic class CronNamespaceHandler extends AbstractNamespaceHandler{ @Override public void onStartNamespace(ProcessingContext ctx, XmlElement xml, String prefix, URI uri) { super.onStartNamespace(ctx, xml, prefix, uri);

//TODO: create Scheduler for Cron and // and hold onto the reference so we can use it later…

Page 9: Coherence Configuration Enhancements - Part 4 - Cron as a Custom Configuration Namespace

Where to “hold” resources we create?

Page 10: Coherence Configuration Enhancements - Part 4 - Cron as a Custom Configuration Namespace

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

Introducing the Resource Registry

• Provides Type-Safe Registry of Resources– No special interfaces to implement – No special annotations

• Available everywhere!– CacheFactory.getConfigurableCacheFactory().getResourceRegistry()– processingContext.getResourceRegistry()

• Scoped by Cache Configuration– Bound to Lifecycle of Cache Configuration

Page 11: Coherence Configuration Enhancements - Part 4 - Cron as a Custom Configuration Namespace

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

The Resource Registry…package com.tangosol.util;

public interface ResourceRegistry extends ResourceResolver, Disposable{ public <R> String registerResource(Class<R> clzResource, R resource)

public <R> String registerResource(Class<R> clzResource, String sResourceName, R resource)

public <R> String registerResource(Class<R> clzResource, Builder<? extends R> bldrResource, RegistrationBehavior behavior, ResourceLifecycleObserver<R> observer)

public <R> String registerResource(Class<R> clzResource, String sResourceName, Builder<? extends R> bldrResource, RegistrationBehavior behavior, ResourceLifecycleObserver<R> observer)

public <R> void unregisterResource(Class<R> clzResource, String sResourceName);

public static final String DEFAULT_NAME = "default";}

Page 12: Coherence Configuration Enhancements - Part 4 - Cron as a Custom Configuration Namespace

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

CronNamespaceHandlerpublic class CronNamespaceHandler extends AbstractNamespaceHandler{ @Override public void onStartNamespace(ProcessingContext ctx, XmlElement xml, String prefix, URI uri) { super.onStartNamespace(ctx, xml, prefix, uri);

// register the Scheduler as a resource for the Configurable Cache Factory ResourceRegistry resourceRegistry = ctx.getResourceRegistry();

resourceRegistry.registerResource(Scheduler.class, new Builder<Scheduler>() { @Override public Scheduler realize() { return new Scheduler(); } }, RegistrationBehavior.IGNORE, null /* no resource-lifecycle-listener required */);

Page 13: Coherence Configuration Enhancements - Part 4 - Cron as a Custom Configuration Namespace

When and How do we start/stop the Scheduler?

Page 14: Coherence Configuration Enhancements - Part 4 - Cron as a Custom Configuration Namespace

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

Brief Introduction to Live Events

• Live Events…– Provide information about Server-Side activities and lifecycle– May be intercepted to observe and/or change Server-Side behavior

• How?– Simply register an Interceptor with the InterceptorRegistry

• InterceptorRegistry available via…– processingContext.getResourceRegistry(InterceptorRegistry.class)– configurableCacheFactory.getInterceptorRegistry()

Page 15: Coherence Configuration Enhancements - Part 4 - Cron as a Custom Configuration Namespace

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

CronNamespaceHandler… // start / stop the Scheduler with the Configurable Cache Factory lifecycle (Using Live Events!) InterceptorRegistry interceptorRegistry = resourceRegistry.getResource(InterceptorRegistry.class);

interceptorRegistry.registerEventInterceptor(new EventInterceptor<LifecycleEvent>() { @Override public void onEvent(LifecycleEvent event) { ResourceRegistry resourceRegistry = event.getConfigurableCacheFactory().getResourceRegistry(); Scheduler scheduler = resourceRegistry.getResource(Scheduler.class);

switch (event.getType()) { case ACTIVATED : scheduler.start(); break;

case DISPOSING : scheduler.stop();

break; } } }, RegistrationBehavior.IGNORE); } //onStartNamespace

Page 16: Coherence Configuration Enhancements - Part 4 - Cron as a Custom Configuration Namespace

What about the Cron Job?

Page 17: Coherence Configuration Enhancements - Part 4 - Cron as a Custom Configuration Namespace

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

Cron for Coherence

<cache-config xmlns="http://xmlns.oracle.com/coherence/coherence-cache-config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance” xmlns:cron=“class://com.oracle.coherence.example.cron.CronNamespaceHandler” xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-cache-config coherence-cache-config.xsd">

. . .

<cron:job> <cron:schedule>* * * * *</cron:schedule> <cron:task> <instance> <class-name>MyRunnable</class-name> </instance> </cron:task> </cron:job>

. . .

</cache-config>

Page 18: Coherence Configuration Enhancements - Part 4 - Cron as a Custom Configuration Namespace

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

CronNamespaceHandler… @XmlSimpleName("job") public static class CronJobProcessor implements ElementProcessor<Void> { @Override public Void process(ProcessingContext ctx, XmlElement xml) throws ConfigurationException { String schedule = ctx.getMandatoryProperty("schedule", String.class, xml); ParameterizedBuilder<?> builder = ctx.getMandatoryProperty("task", ParameterizedBuilder.class, xml);

Scheduler scheduler = ctx.getResourceRegistry().getResource(Scheduler.class);

Object task = builder.realize(ctx.getDefaultParameterResolver(), ctx.getContextClassLoader(), null);

if (task instanceof Runnable) { scheduler.schedule(schedule, (Runnable) task); } else if (task instanceof Task) { scheduler.schedule(schedule, (Task) task); } }

Page 19: Coherence Configuration Enhancements - Part 4 - Cron as a Custom Configuration Namespace

The Cron Namespace in Action!

Page 20: Coherence Configuration Enhancements - Part 4 - Cron as a Custom Configuration Namespace

Summary

Page 21: Coherence Configuration Enhancements - Part 4 - Cron as a Custom Configuration Namespace

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

Summary

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

• Coherence 12.1.2 introduces Live Events– Allows server-side event interception, including lifecycle notification

Page 22: Coherence Configuration Enhancements - Part 4 - Cron as a Custom Configuration Namespace

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 23: Coherence Configuration Enhancements - Part 4 - Cron as a Custom Configuration Namespace

23 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 24: Coherence Configuration Enhancements - Part 4 - Cron as a Custom Configuration Namespace

<Insert Picture Here>

Coherence 12.1.2 Configuration EnhancementsPart 4: Cron as a Custom Configuration NamespaceBrian OliverSenior Consulting Member of StaffCloud Application Foundation - Oracle Coherence

Oracle Fusion Middleware 12c Cloud Application Foundation

Coherence 12.1.2