coherence configuration enhancements - part 4 - cron as a custom configuration namespace

Post on 22-Nov-2014

549 Views

Category:

Technology

4 Downloads

Preview:

Click to see full reader

DESCRIPTION

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

TRANSCRIPT

<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

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…• Creating a Cron Service using a Custom Namespace

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

Lifecycle

• Summary

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

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

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…

Where to “hold” resources we create?

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

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

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

When and How do we start/stop the Scheduler?

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

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

What about the Cron Job?

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>

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

The Cron Namespace in Action!

Summary

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

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

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.

<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

top related