Skip to content

1.1.2 ‐ On Demand Request Wrapper (ODRW)

Guilherme Branco Stracini edited this page Oct 8, 2023 · 2 revisions

This request wrapper only handles operations of type CrudServiceRemove and CrudServiceSave. It handles operations with a defined throughput using a dedicated session identifier (authentication) and preventing concurrent/parallel requests, so no collisions or deadlocks should be returned from Sankhya.

On Demand Request Wrapper (ODRW)

How it works:

This class has 2 public methods:

  • Add - adds an entity to be processed
  • Flush - wait until all entities are processed (ignores the throughput, and block the thread until all items are processed).

Example:

var onDemandSaverPartner = new OnDemandRequestWrapper<Partner>(ServiceName.CrudServiceSave, CancellationToken.None, 20);

for(var i=0; i < 100; i++) {
    onDemandSaverPartner.Add(new Partner { Code = i; FirstName = "John", LastName = "Doe" });
}

// some other long running task

onDemandSaverPartner.Flush(); //this will guarantee that all 100 partners entities will be sent to Sankhya if they wasn't yet

On Demand Request Wrapper Factory

The factory class manage and handles instances of ODRW. This class is useful when you want to use ODRW cross contexts and don't want to manage the instances by yourself.

When the factory is used, it creates an instance (and a session identifier) for that given combination on service and entity.