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

440
-1

Published on

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

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
440
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
22
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • We’ve made some significant investments in Coherence Cache Configuration for 12.1.2This presentation outlines some of the enhancements and flexibility of the new internal infrastructure for improving integration and extension of Coherence, especially by third-parties.
  • Here we use the ProcessingContext to gain access to the ResourceRegistry that will be owned by the ConfigurableCacheFactory once it’s created.We register an instance (singleton) of our Cron Scheduler with the ResourceRegistry so that it can be accessed later
  • Here we use the ProcessingContext to gain access to the ResourceRegistry that will be owned by the ConfigurableCacheFactory once it’s created.We register an instance (singleton) of our Cron Scheduler with the ResourceRegistry so that it can be accessed later
  • Here we use the ProcessingContext to gain access to the ResourceRegistry that will be owned by the ConfigurableCacheFactory once it’s created.We register an instance (singleton) of our Cron Scheduler with the ResourceRegistry so that it can be accessed later
  • We use the Resource Registry to gain access to the InterceptorRegistry that will be used by the Configurable Cache Factory when it’s eventually created.We register an Event Interceptor with the InterceptorRegistry for a Lifecycle event (lifecycle of the Configurable Cache Factory).We use the Lifecycle event to start and stop the scheduler.
  • Here we use theProcessingContext to retrieve the appropriate property values, with the expected types. If this fails a suitable ConfigurationException is thrown.Here we make use of the Coherence provided ParameterizedBuilders to build an instance of our task. Both <class-scheme> and <instance> Element Processors return these.Here we also use the ProcessingContext to access the ResourceRegistry, thus enabling us to have access to the Scheduler defined by the Namespace
  • Come join this large, vibrant community.We have a pretty significant engagement through various social media channels like twitter and facebook. ….
  • We’ve made some significant investments in Coherence Cache Configuration for 12.1.2This presentation outlines some of the enhancements and flexibility of the new internal infrastructure for improving integration and extension of Coherence, especially by third-parties.
  • Coherence Configuration Enhancements - Part 4 - Cron as a Custom Configuration Namespace

    1. 1. <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
    2. 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.
    3. 3. The Agenda…
    4. 4. 4 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Coherence 12.1.2 Configuration Enhancements… • Creating a Cron Service using a Custom Namespace • Coherence Cache Configuration Lifecycle – Using Live Events to react to the Coherence Configuration Lifecycle • Summary
    5. 5. Cron as a Custom Namespace…
    6. 6. 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. 7. 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 1. Create the Namespace 2. Create an ElementProcessor that Schedules a Runnable 3. Start/Stop the Scheduler with the Application/CCF Lifecycle
    8. 8. 8 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. CronNamespaceHandler public 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…
    9. 9. Where to “hold” resources we create?
    10. 10. 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. 11. 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. 12. 12 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. CronNamespaceHandler public 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 */);
    13. 13. When and How do we start/stop the Scheduler?
    14. 14. 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. 15. 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
    16. 16. What about the Cron Job?
    17. 17. 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. 18. 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); } }
    19. 19. The Cron Namespace in Action!
    20. 20. Summary
    21. 21. 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
    22. 22. Join the Coherence Community http://coherence.oracle.com @OracleCoherence /OracleCoherence blogs.oracle.com/OracleCoherence Group: Oracle Coherence Users /OracleCoherence coherence.oracle.com/display/CSIG Coherence Special Interest Group
    23. 23. 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.
    24. 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

    ×