|
| 1 | +# [Backends](@id backends) |
| 2 | + |
| 3 | +The active backend controls how `concore_read` and `concore_write` move the |
| 4 | +same wire-format strings. File is the default backend. |
| 5 | + |
| 6 | +## File |
| 7 | + |
| 8 | +`FileBackend` uses ordinary files and has no external Julia dependencies. |
| 9 | + |
| 10 | +```julia |
| 11 | +include("concore.jl") |
| 12 | +using .Concore |
| 13 | + |
| 14 | +concore_init!(FileBackend()) |
| 15 | +``` |
| 16 | + |
| 17 | +Local input and output path prefixes are `./in` and `./out`. The numeric port |
| 18 | +is appended to the prefix, so port 1 uses `./in1` and `./out1`. |
| 19 | + |
| 20 | +## Mmap |
| 21 | + |
| 22 | +`MmapBackend` keeps the file-based naming and wire format but accesses each |
| 23 | +file through a fixed-size memory-mapped segment. The default segment size is |
| 24 | +4096 bytes. |
| 25 | + |
| 26 | +```julia |
| 27 | +concore_init!(MmapBackend()) |
| 28 | + |
| 29 | +try |
| 30 | + value = concore_read(1, "ym", "[0.0, 0.0]") |
| 31 | + concore_write(1, "u", value) |
| 32 | +finally |
| 33 | + mmap_cleanup() |
| 34 | +end |
| 35 | +``` |
| 36 | + |
| 37 | +Pass a different segment size when constructing the backend if the wire value |
| 38 | +does not fit in the default segment: |
| 39 | + |
| 40 | +```julia |
| 41 | +concore_init!(MmapBackend(8192)) |
| 42 | +``` |
| 43 | + |
| 44 | +## [ZMQ](@id zmq) |
| 45 | + |
| 46 | +ZMQ support is optional. Install ZMQ.jl in the active Julia environment before |
| 47 | +including `concore.jl`: |
| 48 | + |
| 49 | +```julia |
| 50 | +using Pkg |
| 51 | +Pkg.add("ZMQ") |
| 52 | +``` |
| 53 | + |
| 54 | +`Concore.HAS_ZMQ` reports whether the package was available when the runtime |
| 55 | +was loaded. ZMQ ports use string names instead of numeric file ports. This |
| 56 | +example shows the request side of a REQ/REP pair: |
| 57 | + |
| 58 | +```julia |
| 59 | +include("concore.jl") |
| 60 | +using .Concore |
| 61 | + |
| 62 | +concore_init!(ZmqBackend()) |
| 63 | +init_zmq_port("req", "connect", "tcp://127.0.0.1:5555", "REQ") |
| 64 | + |
| 65 | +try |
| 66 | + concore_write("req", "u", [1.0]) |
| 67 | + ym = concore_read("req", "ym", "[0.0, 0.0]") |
| 68 | +finally |
| 69 | + terminate_zmq() |
| 70 | +end |
| 71 | +``` |
| 72 | + |
| 73 | +A REP peer must bind the same address and receive before replying. |
| 74 | + |
| 75 | +## Docker |
| 76 | + |
| 77 | +Docker is a runtime path variant, not a separate backend type. |
| 78 | +`concoredocker.jl` uses `/in` and `/out` as its path prefixes, producing paths |
| 79 | +such as `/in1/ym` and `/out1/u`. |
| 80 | + |
| 81 | +For generated Docker studies, `mkconcore.py` copies `concoredocker.jl` into the |
| 82 | +node build directory as `concore.jl`. The node source therefore keeps the same |
| 83 | +include statement used locally: |
| 84 | + |
| 85 | +```julia |
| 86 | +include("concore.jl") |
| 87 | +using .Concore |
| 88 | +``` |
| 89 | + |
| 90 | +Build the mixed Julia controller and Python plant example with the existing |
| 91 | +study generator: |
| 92 | + |
| 93 | +```sh |
| 94 | +concore build demo/sampleJ.graphml --source demo --output docker-julia-demo --type docker --compose |
| 95 | +cd docker-julia-demo |
| 96 | +./build |
| 97 | +./maxtime 5 |
| 98 | +docker compose up |
| 99 | +``` |
| 100 | + |
| 101 | +The generated Compose file mounts the connected input and output directories |
| 102 | +at the paths expected by each container. |
0 commit comments