[ROOT] / doc / toc / ARCCore / Class / StreamProcessor / OutsideLocalReceiver


The outside (in the sense outside of this class) local mechanism which receives all PropertyStreamLine registered by this class.
(except changes with HasLocalOrigin.)

The 'outside' implementation will typically store data to a PRich instance through ParseAndStore.

Set this method when you want an always-up-to-date in-memory object collection of your data.
Most relevant for Client.
Also relevant for ArmDB (see AdHocQuery).

If this method is set, then incoming data will be stored both to disk (unless DoNotStoreLocally is TRUE) and sent to this method.
Also, at application startup (StartTCPIPCommunication), all data from disk will be sent to this method.

Rationale for not distributing HasLocalOrigin via this method:
If local originated content also was sent to this method, it would most probably have been sent twice, after a round-trip to CoreDB and back, resulting in duplicate updates to the (presumed PRich) outside's storage. The 'outside' can instead choose whether to update its presumed PRich storage immediately or not, by just calling this method itself whenever it also calls ReceiveAndDistribute


Remember thread-safety regarding use of this method.

Possible implementions on outside could be:

1) Approach suitable for a processor, running in a continous loop:

var queue = new System.Collections.Concurrent.ConcurrentQueue<string>();
myStreamProcessorInstance.OutsideLocalReceiver = s => queue.Enqueue(s);

You can then pick up from the queue inside your continous processing loop in a thread-safe manner, for instance like this:

var dataStorage = new PRich();
while (true) { // Your continous processing loop
DoTask1(dataStorage); // Task1 may freely access dataStorage (within calling thread)
DoTask2(dataStorage); // Task2 may freely access dataStorage (within calling thread)
while (queue.TryDequeue(out var s)) PropertyStreamLine.ParseAndStore(dataStorage, s);
}


2) Approach suitable for an API with incoming requests occuring on multiple threads:
(simplified code)

var lock = new System.Threading.ReaderWriterLockSlim();
var dataStorage = new PRich();
myStreamProcessorInstance.OutsideLocalReceiver = s => {
try {
lock.EnterWriteLock();
PropertyStreamLine.ParseAndStore(_storage, s);
} finally {
lock.ExitWriteLock();
}
};

You must also remember to acquire the corresponding lock (lock.EnterReadLock or lock.EnterWriteLock) when processing API methods, for instance like this:
public APIResponse ServeAPIMethod(APIRequest request) {
try {
lock.EnterReadLock();
return dataStorage.Query(request);
} finally {
lock.ExitReadLock();
}
}


Details

Generated 2024-11-14 04:17:57.342 UTC