Entry Processing

Entry processors are a defining feature of Coherence and provide the ability to send the data modification code into the grid and execute it where the data is, against one or more entries. This can not only significantly impact how much data needs to be moved over the wire, but it also takes care of cluster-wide concurrency control — each entry processor has the exclusive access to the entry it is processing for the duration of its execution.

See the utility class Processors for the entry processors supported out-of-the-box by this client.

The following example demonstrates various entry processing operations against a NamedMap:

 1# Copyright (c) 2023, Oracle and/or its affiliates.
 2# Licensed under the Universal Permissive License v 1.0 as shown at
 3# https://oss.oracle.com/licenses/upl.
 4
 5import asyncio
 6from dataclasses import dataclass
 7from typing import List
 8
 9from coherence import NamedMap, Processors, Session
10
11
12@dataclass
13class Hobbit:
14    """
15    A simple class representing a Hobbit.
16    """
17
18    id: int
19    name: str
20    age: int
21
22
23async def do_run() -> None:
24    """
25    Demonstrates various EntryProcessor operations against a NamedMap.
26
27    :return: None
28    """
29    session: Session = await Session.create()
30    try:
31        named_map: NamedMap[int, Hobbit] = await session.get_map("hobbits")
32
33        await named_map.clear()
34
35        hobbit: Hobbit = Hobbit(1, "Bilbo", 111)
36        print("Add new hobbit :", hobbit)
37        await named_map.put(hobbit.id, hobbit)
38
39        print("NamedMap size is :", await named_map.size())
40
41        print("Hobbit from get() :", await named_map.get(hobbit.id))
42
43        print("Update Hobbit using processor ...")
44        await named_map.invoke(hobbit.id, Processors.update("age", 112))
45
46        print("Updated Hobbit is :", await named_map.get(hobbit.id))
47
48        hobbit2: Hobbit = Hobbit(2, "Frodo", 50)
49
50        print("Add new hobbit :", hobbit2)
51        await named_map.put(hobbit2.id, hobbit2)
52
53        print("NamedMap size is :", await named_map.size())
54
55        print("Sending all Hobbits ten years into the future!")
56        keys: List[int] = []
57        async for entry in named_map.invoke_all(Processors.increment("age", 10)):
58            keys.append(entry.key)
59            print("Updated age of Hobbit with id ", entry.key, "to", entry.value)
60
61        print("Displaying all updated Hobbits ...")
62        async for result in named_map.get_all(set(keys)):
63            print(result.value)
64
65        await named_map.remove(hobbit.id)
66        await named_map.remove(hobbit2.id)
67    finally:
68        await session.close()
69
70
71asyncio.run(do_run())
  • Line 37 - insert a new Hobbit into the NamedMap

  • Line 44 - invoke an entry processor to update the age of the inserted Hobbit

  • Line 51 - insert a second Hobbit into the NamedMap

  • Lines 57 - 58 - Increment the ages of all Hobbits in the NamedMap by 10. Store the keys of the updated Hobbits

  • Line 62 - get all of the updated Hobbits to display