When I started this blog I had no idea how hard it will be to post useful things without revealing too much about the "top secret" projects we are involved in. 🙂 This time though I've been allowed to release an entire class that turned out to be useful in an application we were developing a while back. The piece of software below was created with a financial support by Uratim Ltd. and can be used under the terms of the GPL license. YAY for free software.
The iterator pattern is one of the most frequently occurring patterns used in software design. Even before one learns about design patterns inevitably implements an iterator without actually realizing. The problem I came across not so long ago was that I had an iterator that was returning jobs from job packets that would have to be processed but there were a number of constrains I had to keep in mind:
- For each job there is a resource assigned for the job. It can only be executed using the resource assigned to it.
- As long as possible certain resources should not be accessed too frequently. (But they can be accessed more frequently when it is necessary.)
- Packages are processed semi asynchronously: all jobs in one package are returned at once, but there may be more that one pending package. The maximal number of packages under simultaneous processing is a parameter.
- When there are too many jobs waiting for a single resource than access times should be gradually decreased to avoid too long waiting times for jobs.