Interface AttributesGetters

All Known Subinterfaces:
Attributes, ConcurrentAttributes

@UnstableApi public interface AttributesGetters
Provides the getter methods to Attributes and ConcurrentAttributes.
  • Method Details

    • attr

      @Nullable <T> T attr(io.netty.util.AttributeKey<T> key)
      Returns the value associated with the given AttributeKey or null if there's no value set by AttributesSetters.set(AttributeKey, Object). If there is no value in this AttributesGetters but it exists in parent(), the value in the parent()} will be returned.
      See Also:
    • ownAttr

      @Nullable <T> T ownAttr(io.netty.util.AttributeKey<T> key)
      Returns the value associated with the given AttributeKey or null if there's no value set by AttributesBuilder.set(AttributeKey, Object).

      Unlike attr(AttributeKey), this does not search in parent().

      See Also:
    • hasAttr

      default boolean hasAttr(io.netty.util.AttributeKey<?> key)
      Returns true if and only if the value associated with the specified AttributeKey is not null.
      See Also:
    • hasOwnAttr

      default boolean hasOwnAttr(io.netty.util.AttributeKey<?> key)
      Returns true if and only if the value associated with the specified AttributeKey is not null.

      Unlike hasAttr(AttributeKey), this does not search in parent().

      See Also:
    • ownAttrs

      Iterator<Map.Entry<io.netty.util.AttributeKey<?>,Object>> ownAttrs()
      Returns the Iterator of all Map.Entrys this AttributesGetters contains.

      Unlike attrs(), this does not iterate parent()}.

      For example:
      
       static final AttributeKey<String> USER_ID = AttributeKey.valueOf("USER_ID");
       static final AttributeKey<String> SECRET_TOKEN = AttributeKey.valueOf("SECRET_TOKEN");
       static final AttributeKey<String> TRACE_ID = AttributeKey.valueOf("TRACE_ID");
      
       Attributes parent = Attributes.of(USER_ID, "Meri Kim",
                                         SECRET_TOKEN, "secret-1");
      
       Attributes child = Attributes.builder(parent)
                                    .set(SECRET_TOKEN, "secret-2")
                                    .set(TRACE_ID, "trace-1")
                                    .build();
      
       Iterator<Entry<AttributeKey<?>, Object>> attrs = child.ownAttrs();
       assert Iterables.size(attrs) == 2;
       assert Streams.stream(child.attrs())
                     .map(Entry::getValue)
                     .sorted()
                     .collect(Collectors.toList())
                     .equals(List.of("secret-2", "trace-1"));
       
      See Also:
    • attrs

      Iterator<Map.Entry<io.netty.util.AttributeKey<?>,Object>> attrs()
      Returns the Iterator of all Map.Entrys this AttributesGetters contains.

      The Iterator returned by this method will also yield the Map.Entrys from the parent()} except those whose AttributeKey exist already in this context. For example:

      
       static final AttributeKey<String> USER_ID = AttributeKey.valueOf("USER_ID");
       static final AttributeKey<String> SECRET_TOKEN = AttributeKey.valueOf("SECRET_TOKEN");
       static final AttributeKey<String> TRACE_ID = AttributeKey.valueOf("TRACE_ID");
      
       Attributes parent = Attributes.of(USER_ID, "Meri Kim",
                                         SECRET_TOKEN, "secret-1");
      
       Attributes child = Attributes.builder(parent)
                                    .set(SECRET_TOKEN, "secret-2")
                                    .set(TRACE_ID, "trace-1")
                                    .build();
      
       Iterator<Entry<AttributeKey<?>, Object>> attrs = child.attrs();
       assert Iterables.size(attrs) == 3;
       assert Streams.stream(child.attrs())
                     .map(Entry::getValue)
                     .sorted()
                     .collect(Collectors.toList())
                     // "secret-1" is overridden by "secret-2"
                     .equals(List.of("Meri Kim", "secret-2", "trace-1"));
       
    • parent

      Returns the parent() which was specified when creating this AttributesGetters.
      See Also:
    • isEmpty

      boolean isEmpty()
      Returns true if this AttributesGetters does not contain any entries.
    • size

      int size()
      Returns the number of AttributeKey-value mappings in this AttributesGetters.

      If the same AttributeKey is both in the parent() and the child Attributes, only the AttributeKey-value mapping in the child will be counted.

      
       static final AttributeKey<String> USER_ID = AttributeKey.valueOf("USER_ID");
       static final AttributeKey<String> SECRET_TOKEN = AttributeKey.valueOf("SECRET_TOKEN");
       static final AttributeKey<String> TRACE_ID = AttributeKey.valueOf("TRACE_ID");
      
       Attributes parent = Attributes.of(USER_ID, "Meri Kim",
                                         SECRET_TOKEN, "secret-1");
       assert parent.size() == 2;
      
       Attributes child = Attributes.builder(parent)
                                    .set(SECRET_TOKEN, "secret-2")
                                    .set(TRACE_ID, "trace-1")
                                    .build();
       assert child.size() == 3;