Package com.tccc.kos.commons.util
Interface AttributeAware
- All Known Subinterfaces:
HttpRequest
,WebsocketConnection
- All Known Implementing Classes:
WebsocketClient
public interface AttributeAware
Interface for objects that can accumulate additional data in the
form of attributes. For example, consider an
HttpReqeust
object where filters or interceptors may attach additional data to the request
that can then be consumed later on by handlers. Consider attributes as
public information riding with the AttributeAware
object, almost
like dynamic properties. This allows code written by one developer to
pass data to code written by another developer via the AttributeAware
object. This is in contrast to the UserDataAware
interface which
is very similar, but is intended to pass data from one control point to
another control point within a single developer's code. That is, data stored
UserDataAware
can be thought of as private while data stored
using AttributeAware
can be thought of as public. There are no
actual restrictions when using these interfaces, but the distinct interfaces
indicate the intention of the developer using them. For example, you should
not add data to UserDataAware
objects if you didn't write the original
code, whereas AttributeAware
objects expect 3rd party data to be added.
AttributeAware
data is not expected to be serialized to json as
it uses Object
keys for maximum flexibility, but aren't compatible
with json encoding. Similarly, there is no way to restrict the json view
of the values. Consider using ClientAttributeAware
for objects that need
to expose attributes via json serialization.
- Since:
- 1.0
- Version:
- 2022-08-30
-
Method Summary
Modifier and TypeMethodDescriptiongetAttribute
(Object key) Given a key, returns its attribute.removeAttribute
(Object key) Given a key, removes the attribute.void
setAttribute
(Object key, Object value) Sets the attribute for the given key.
-
Method Details
-
setAttribute
Sets the attribute for the given key.- Parameters:
key
- the attribute keyvalue
- the attribute value
-
getAttribute
Given a key, returns its attribute.- Parameters:
key
- the attribute key- Returns:
- the value of the attribute, or
null
if it doesn't exist
-
removeAttribute
Given a key, removes the attribute.- Parameters:
key
- the attribute key- Returns:
- the value of the attribute being removed, or
null
if it didn't exist
-