Class Keys
SessionData and RepositoryCache instances as keys.
Resolver codebase started with String keys, that are generally perfect for keys in these constructs, as
long as they are used by components loaded once in system. As we saw, some subsystems like transports can be
loaded multiple times. For example, in case of Maven, some transport may be present in Maven core, but also loaded up
by some extension. In this case, key should distinguish between their ClassLoaders.
It is this class caller responsibility to use proper objects as keys, this class merely helps one to create composite
keys out of object instances that are expected to be anyway good candidates as key. Examples of these objects are
String instances but also Class instances, and many other types also usable as keys.
Important: never forget to perform null-check, when getting cache from RepositorySystemSession.getCache()
method as it may return null, when cache is disabled session-wise.
Historical note: As mentioned above, use of String instances for keys is perfect match, and it worked from
very start. But, as use cases got more and more complex and keys used started to be constructed in more and more
sophisticated ways, but were still String instances. Believe, or not, the sole purpose of string keys
was easier debugging. By using this helper class, this convenience should remain.
- Since:
- 2.0.19
- See Also:
-
Method Summary
-
Method Details
-
of
Creates object instance usable as key in session data and cache. Objects passed to this method may or may not implement equals/hashCode, but it is responsibility of caller to understand what is she or he doing.If the first element of key elements is an object instance that was created by this method, creation of "subkeys" happens, where original key elements expanded from first element and are concatenated with new ones. This expansion happens only, if the first key element was already a key created by this class. If the arguments contain only one argument, and it is an object instance that was created by this method, the passed in instance is returned unmodified.
Based on what kind of elements are used, one can create multiple kind of keys:
- To create globally matched keys, preferred is to use
Stringkey elements - To create ClassLoader wide matched keys, make sure at least one key element is
Classthat needs to be scoped to ClassLoader - To create private, matched by creator only keys, make sure to have one key element, that requires instance equality matching, and there is no other same instance of element
- Parameters:
keys- The key elements, it may not benulland may not have zero elements.- Returns:
- An object instance usable as key.
- To create globally matched keys, preferred is to use
-