This page is no more maintained, the current one is at http://www.tiian.org/flom/FLoM_by_examples/Use_Case_12.html
Note: this use case is available since FLOM version 0.5.1
Sometimes you face a problem like this: "A worker process can process different tasks, no more than one worker can access one resource, the number of resources is finite, the resources are not omogeneous".
tiian@mojan:/tmp$ flom -r 'red.green.blue' -- echo
red
tiian@mojan:/tmp$
tiian@mojan:/tmp$ flom -r 'red.green.blue' -- echo
green
tiian@mojan:/tmp$
tiian@mojan:/tmp$ flom -r 'red.green.blue' -- echo
blue
tiian@mojan:/tmp$
the first command "flom -r 'red.green.blue' -- echo" locks the first resource in the set, the second command flom -r 'red.green.blue' -- echo locks the second resource int the set and so on.
FLOM manages resource sets in a different way if compared to simple resources and numeric resources:
The previous example can be slightly reworked to better understand what you can do with resource sets. Let's imagine you have 3 distinct files in /tmp directory (use your preferred editor and create three files named "one", "two", "three" with different content as shown below:
tiian@mojan:/tmp$ cat one
This is file ONE (there's only one row in this file)
tiian@mojan:/tmp$ cat two
This is file TWO
(there are two rows in this file)
tiian@mojan:/tmp$ cat three
This is file THREE
(there are three rows in this file)
tiian@mojan:/tmp$
tiian@mojan:/tmp$ flom -r 'one.two.three' -- cat
This is file ONE (there's only one row in this file)
tiian@mojan:/tmp$
tiian@mojan:/tmp$ flom -r 'one.two.three' -- cat
This is file TWO
(there are two rows in this file)
tiian@mojan:/tmp$
tiian@mojan:/tmp$ flom -r 'one.two.three' -- cat
This is file THREE
(there are three rows in this file)
tiian@mojan:/tmp$
The above example uses a resource set to map three distinct files, but you should pay attention this is only an example: some file names are not valid flom resource names and you need some scripting to map file names to valid resource names.
In the above example the first command (in first terminal) starts a background flom daemon that will serve the first, the second and the third request: the flom daemon keeps the current state and gives any command a different resource (round-robin policy).
flom daemon default lifetime is quite short (5000 milliseconds) and requests interleaved by a pause longer than 5000 milliseconds will start a fresh flom daemon copy; below you can see what happens waiting 5 seconds before first and second command:
tiian@mojan:/tmp$ flom -r 'one.two.three' -- cat
This is file ONE (there's only one row in this file)
tiian@mojan:/tmp$
tiian@mojan:/tmp$ flom -r 'one.two.three' -- cat
This is file ONE (there's only one row in this file)
tiian@mojan:/tmp$
This issue can not be solved using some flom option (like '-d, --daemon-lifespan') because the internal flom garbage collector automatically destroys unused resources indipendently by daemon restart. If you experimented this issue, a better solution could probably be the usage of a flom simple resource, a state file and some shell scripting to manage the state file. Flom is designed to manage resource concurrency, not to manage long term state persistence.
A resource set name is composed by 2 or more simple resource names concatenated using '.' character:
Examples:
Resources "red.green.blue" and "red.blue.green" are distinct resource sets.
Resource sets support this option:
Resource sets don't support this option:
This use case explains you how to manage concurrent access to a finite resource set using a round-robin policy and avoiding the simultaneous access to a resource by more than one locker.
Flom available arguments are documented in man page: use man flom.
Flom [Configuration] explains how you can specify flom behavior without using command line arguments.
Wiki: Configuration
Wiki: FLoM by examples
Wiki: Use Case 13