coherence-functor-pattern

Skip to end of metadata
Go to start of metadata
Deprecation Announcement
This release of the Coherence Incubator is now deprecated. For the latest supported release, help and documentation, please refer to the Coherence Incubator Project on java.net at http://cohinc.java.net.

The Functor Pattern Project
Provides a distributed implementation of the classic Functor Pattern.

Overview

This is an example implementation of Function Objects (Wikipedia) or as it is also known, the Functor Pattern, built with Coherence.

The Functor Pattern is an extension to the Command Pattern. In fact the semantics are identical with the exception that the Functor Pattern additionally provides a mechanism to return values (or re-throw exceptions) to the Submitter (using Java 5+ Futures) where as the Command Pattern does not provide such capabilities. Consequently in order to use Functor Pattern it is highly recommended that you understand the Command Pattern.

The Functor Pattern provides a useful alternative to Oracle Coherence EntryProcessors with the advantage that Functors are executed asynchronously, instead of synchronously as is the case with EntryProcessors.

Version 1.5.5 (changes since 1.5.3)

Version 1.5.5 is a patch release to upgrade dependencies to Coherence Common and the Coherence Command Pattern.

Version 1.5.4 was an internal unreleased version.
Version 1.5.3 (changes since 1.5.2)

Version 1.5.3 is a patch release to upgrade dependencies to Coherence Common and the Coherence Command Pattern.

Version 1.5.2 (changes since 1.5.1)

Version 1.5.2 is a patch release to upgrade dependencies to Coherence Common and the Coherence Command Pattern.

Version 1.5.1 (changes since 1.5.0)

Version 1.5.1 is a patch release to upgrade dependencies to Coherence Common, Coherence Command Pattern and to support the out and coming Coherence release.

Version 1.5.0 (changes since 1.4.3)

The most significant upgrade for this release is the adoption of Coherence 3.7. Overtime this will allow the pattern to take advantage of the lastest features, like "lite transactions" to ensure atomicity of multi-cache updates, without the overhead of "heavy" transactions.

Legend | = Fixed | = Breaking Change / Deprecation | = Improved | = New
  • Removed the separate pof and non-pof cache configurations. Cache configuration files now use the system-wide defined serializer. This dramatically simplifies serialization configuration and halves the number of cache configuration files.
  • Explicitly specifies xsds in configuration files to strictly enforce document validation.

Release Version: Version 1.5.5.39174
Release Date: March 7, 2012
Coherence Version: 3.7.1+
Target Platforms: Java Standard Edition 6+
Dependencies: Coherence Common
Command Pattern
Download: coherence-functorpattern-1.5.5.39174.jar
MD5: f48f1d534b1b2cd4d489d0ff8a7cd37c
Source and
Java Doc:
coherence-functorpattern-1.5.5.39174-src.zip

* Previous releases are available from the attachments page

Examples

Let's start with a simple example where we use the Functor Pattern to asynchronously increment and return the value of a Counter

First, we'll start by writing a simple Counter:

Counter.java

Second, let's write a Functor that will increment the value of a Counter

NextValueFunctor.java

Lastly, let's write a simple example to test our Functor.

FunctorPatternExample.java
Frequently Asked Questions

What is the relationship between the Functor Pattern, Command Pattern, Entry Processors and the Invocation Service for performing work in a cluster?

The following table outlines the main differences.

  Functor Pattern Command Pattern EntryProcessors InvocationService
Processing Target A Context A Context A Cache Entry A Cluster Member
Submission Behavior Non-Blocking Non-Blocking Blocking Blocking and Non-Blocking
Execution Order Order of Submission Order of Submission Order of Submission (unless using PriorityTasks) Order of Submission
Supports Return Values?
(and re-throwing Exceptions)
Yes No Yes Yes
Guaranteed to Execute?
(if Submitter terminates after submission)
Yes Yes Yes (submitter blocks) Yes (for blocking), No (for non-blocking)
Guaranteed to Execute?
(if Target JVM terminates during execution)
Yes Yes Yes (submitter automatically retries) No (retry up to developer)
Submitted requests recoverable from disk? Yes (when using Cache Store) Yes (when using Cache Store) No No
Request may be cancelled? Yes Yes No Yes (for non-blocking)

Can Functors and Commands be submitted to the same Context?
Yes. Functors and Commands may be submitted for execution against the same Context. They will be executed in the order of submission from the Submitter. Further, FunctorSubmitters may be used instead of CommandSubmitters (as the FunctorSubmitter interface is a sub-interface of the CommandSubmitter interface)

How do I monitor the execution of Functors ?

As the Functor Pattern uses the Command Pattern for the internal implementation (and that is JMX enabled), all you need to do is simply enable JMX.

References and Additional Information
Labels:
current current Delete
project project Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.