sonatype/nexus — pull request #331 by cstamas (2012-03-02 14:54:38+00:00)
Title: NEXUS-4894: Fixes for TargetRegistry thread safety.

Multiple problems, as this is one of the oldest unchanged class in core it seems.

* looking for target by ID is very, very, VERY often done by Security, but it was done
in a "linear search" manner, by iterating over a list and constructing object(s) on the fly
* a "cache view" (list) was present (but unused in case above, unsure why) but was only
nullified in case of configuration change, and was "lazily" rebuilt on lookups/gets. This was not only
thread unsafe (see related issue), but also caused slow-downs for target getter (most certainly
security). Now, the "cache view" is a map, keyed by Target ID and eagerly rebuilt on config
changes.
* other minor improvements

Now we ensure that the "cache view" is rebuilt on config change (in config changing thread,
where through-output is not a concern). Also, this excludes the thread safety problem
of lazily creating the "cache view" and stealing CPU cycles from security.

Also, this makes a get-target-by-ID faster by orders of magnitude, as the "cache view"
is now a map that already contains pre created "live" object (no object creation on the fly)
keyed by target id (no linear search).

CI build:
https://builds.sonatype.org/view/nexus/job/nexus-oss-its-feature/272/