From OpenCog

The ReadWriteProxyNode is a ProxyNode that specifies distinct StorageNode targets for reads and writes.


Suppose you wish to copy Atoms from one location to another. This can be done by specifying the source and the target as follows:

     (ReadWriteProxy "copier")
        (RocksStorageNode "rocks:///tmp/source.rdb")
        (RocksStorageNode "rocks:///tmp/target.rdb"))))

Reads will always be sent to the source, and writes will always be sent to the target. The ReadWriteProxy always expects exactly two parameters: the source followed by the target.

To actually use this, open the proxy just like any other StorageNode:

(cog-open (ReadWWriteProxy "copier"))

Then fetch data, maybe modify it, and write it out:

(fetch-atom (Concept "sky blue"))
(cog-set-value! (Concept "sky blue")
    (Predicate "context on the moon") (SimpleTruthValue 0.1 0.9))
(store-atom (Concept "sky blue"))

which will fetch all of the Values on (Concept "sky blue"), modify the contextual truth for the sky being blue on the moon, and then write out the Atom (along with all of it's Values).

Identity example

Note that setting the same StorageNode for both source and target is the same as just using the StorageNode directly, but slower, because there is now a dispatcher in the middle:

     (ReadWriteProxy "just plain foo")
        (RocksStorageNode "rocks:///tmp/foo.rdb")
        (RocksStorageNode "rocks:///tmp/foo.rdb"))))

Using the (ReadWriteProxy "just plain foo") proxy is exactly the same as using (RocksStorageNode "rocks:///tmp/foo.rdb") directly. All inputs and outputs are wired straight-through.

Read-Write Overlays

See the SequentialReadProxy for an example of using the ReadWriteProxy to construct a read-write overlay on top of a read-only StorageNode.

See also