การใช้งาน Data Fabric ที่ทรงพลังอย่างหนึ่งคือการกระจายการประมวลผลไปยัง replicated caches ของ Fabric แล้วส่ง ผลลัพธ์ที่รวบรวมได้กลับไปยัง client ซึ่งทำให้ Fabric รองรับการประมวลผลแบบกระจายและขนานในแนวทาง Event-Driven ได้ โดยอาจอาศัย Long-Running Processes เข้ามาช่วย

เพื่อให้เห็นภาพของฟีเจอร์นี้ชัดเจนขึ้น เราจำเป็นต้องกล่าวถึงแนวทางที่เป็นรูปธรรมใน GemFire และ Coherence โดย Process executive ของคุณอาจถูก implement ขึ้นเป็น GemFire Function หรือ Coherence Entry Processor ซึ่งทั้งคู่ทำหน้าที่เป็น Command [Gamma et al.] handler ที่จะถูก execute แบบขนานบน distributed, replicated cache (คุณอาจเลือกที่จะมองว่าคอนเซปต์นี้คือ Domain Service ก็ได้ แต่สิ่งที่มันทำอาจไม่ได้เป็น domain-centric สักเท่าไร) เพื่อความสอดคล้องกัน ขอเรียกฟีเจอร์นี้ว่า Function ซึ่ง Function จะสามารถรับ filter ได้ตามต้องการ เพื่อจำกัดการทำงานให้เหลือเพียง Aggregate instances ที่ตรงตามเงื่อนไข

มาดูตัวอย่าง Function ที่ implement Long-Running Process สำหรับ Phone Number Count Process ที่ได้นำเสนอไว้ก่อนหน้านี้ โดย Process นี้จะถูก execute แบบขนานบน replicated cache ด้วย GemFire Function:

public class PhoneNumberCountSaga extends FunctionAdapter {
    @Override
    public void execute(FunctionContext context) {
        Cache cache = CacheFactory.getAnyInstance();
        QueryService queryService = cache.getQueryService();

        String phoneNumberFilterQuery = (String) context.getArguments();
        ...
        // Pseudo code
        // - Execute Function to obtain MatchedPhoneNumbersCounted.
        //   - Send answer to the aggregator by invoking the
        //     aggregator.sendResult(MatchedPhoneNumbersCounted).
        // - Execute Function to obtain AllPhoneNumbersCounted.
        //   - Send answer to the aggregator by invoking the
        //     aggregator.sendResult(AllPhoneNumbersCounted).
        // - The aggregator automatically accumulates the answers
        //   from each distributed Function call and returns the
        //   single aggregated answer to the client.
    }
}

ต่อไปนี้คือตัวอย่างโค้ดของ client ที่จะใช้ execute Long-Running Process แบบขนานบน distributed replicated cache:

PhoneNumberCountProcess phoneNumberCountProcess =
         new PhoneNumberCountProcess();

String phoneNumberFilterQuery =
        "select phoneNumber from /phoneNumberRegion pnr "
        + "where pnr.areaCode = '303'";

Execution execution =
        FunctionService.onRegion(phoneNumberRegion)
                .withFilter(0)
                .withArgs(phoneNumberFilterQuery)
                .withCollector(new PhoneNumberCountResultCollector());

PhoneNumberCountResultCollector resultCollector =
         execution.execute(phoneNumberCountProcess);

List allPhoneNumberCountResults = (List) resultsCollector.getResult();

แน่นอนว่า process ตัวอย่างนี้อาจซับซ้อนกว่านี้มาก หรือจะง่ายกว่านี้มากก็ได้ และมันยังแสดงให้เห็นว่า Process ไม่ได้จำเป็นต้องเป็นคอนเซปต์แบบ Event-Driven เสมอไป แต่มันสามารถทำงานร่วมกับแนวทางการประมวลผลแบบ concurrent และแบบกระจายอื่น ๆ ได้ สำหรับรายละเอียดทั้งหมดของการประมวลผลแบบกระจายและขนานโดยใช้ Fabric ดูได้จาก [GemFire Functions] .

Image