Class ConcurrentHashMapHeaders
- java.lang.Object
-
- com.newrelic.api.agent.ConcurrentHashMapHeaders
-
- All Implemented Interfaces:
Headers,InboundHeaders,OutboundHeaders
public class ConcurrentHashMapHeaders extends java.lang.Object implements Headers
A thread safe implementation ofHeadersusingConcurrentHashMapas the backing data structure. Concurrent writes are supported. Reads return immutable data types.NOTE: If using this implementation of
Headers, an agent of the same version should be used. Failure to do so may cause unexpected results at runtime, since the agent's definition may be different than provided by thenewrelic-api.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddHeader(java.lang.String name, java.lang.String value)Add a header with the given name and value.static ConcurrentHashMapHeadersbuild(HeaderType headerType)Build an empty instance with the givenHeaderType.static ConcurrentHashMapHeadersbuildFromFlatMap(HeaderType headerType, java.util.Map<java.lang.String,java.lang.String> map)Build an instance with the givenHeaderTypeand callsetHeader(String, String)with each entry in themap.static ConcurrentHashMapHeadersbuildFromMap(HeaderType headerType, java.util.Map<java.lang.String,java.util.List<java.lang.String>> map)Build an instance with the givenHeaderTypeand calladdHeader(String, String)with each entry in themap.booleancontainsHeader(java.lang.String name)Return a boolean indicating whether the named header has already been set.java.lang.StringgetHeader(java.lang.String name)Returns the value of the first specified message header as aString.java.util.Collection<java.lang.String>getHeaderNames()Get the names of the headers.java.util.Collection<java.lang.String>getHeaders(java.lang.String name)Return all the values of the specified message header as aListofStringobjects.HeaderTypegetHeaderType()Return the type of header key syntax used for this.java.util.Map<java.lang.String,java.util.List<java.lang.String>>getMapCopy()Obtain a copy of the backing map.voidremoveHeader(java.lang.String name)Remove any headers with the name.voidsetHeader(java.lang.String name, java.lang.String value)Set a header with the given name and value.
-
-
-
Method Detail
-
getMapCopy
public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getMapCopy()
Obtain a copy of the backing map. The result is not guaranteed to be thread safe, or mutable. If it is mutable, changes do not modify the backingheadersmap.- Returns:
- The map copy.
-
removeHeader
public void removeHeader(java.lang.String name)
Remove any headers with the name.- Parameters:
name- The name of the header.
-
getHeaderType
public HeaderType getHeaderType()
Description copied from interface:HeadersReturn the type of header key syntax used for this.- Specified by:
getHeaderTypein interfaceHeaders- Specified by:
getHeaderTypein interfaceInboundHeaders- Specified by:
getHeaderTypein interfaceOutboundHeaders- Returns:
- An
enumspecifying the type of headers present.
-
getHeader
public java.lang.String getHeader(java.lang.String name)
Description copied from interface:HeadersReturns the value of the first specified message header as aString. If the message does not include a header with the specified input name, then this method returnsnull.- Specified by:
getHeaderin interfaceHeaders- Specified by:
getHeaderin interfaceInboundHeaders- Parameters:
name- The name of the desired message header.- Returns:
- A
Stringcontaining the value of the requested header, ornullif the message header is not present.
-
getHeaders
public java.util.Collection<java.lang.String> getHeaders(java.lang.String name)
Description copied from interface:HeadersReturn all the values of the specified message header as aListofStringobjects. If the message does not include any headers of the specified name, this method returns an empty list.Changes to the returned collection must not affect the Headers instance.
- Specified by:
getHeadersin interfaceHeaders- Parameters:
name- The name of the desired message header.- Returns:
- A
Listcontaining the values of the requested header, or an empty list of the message header is not present.
-
setHeader
public void setHeader(java.lang.String name, java.lang.String value)Description copied from interface:HeadersSet a header with the given name and value. If the header had already been set, the new value overwrites the previous one.Headers.containsHeader(String)can be used to test for the presence of a header before setting its value.- Specified by:
setHeaderin interfaceHeaders- Specified by:
setHeaderin interfaceOutboundHeaders- Parameters:
name- The name of the header.value- The value of the header.
-
addHeader
public void addHeader(java.lang.String name, java.lang.String value)Description copied from interface:HeadersAdd a header with the given name and value. This method allows headers to have multiple values.
-
getHeaderNames
public java.util.Collection<java.lang.String> getHeaderNames()
Description copied from interface:HeadersGet the names of the headers.Changes to the returned collection must not affect the Headers instance.
- Specified by:
getHeaderNamesin interfaceHeaders- Returns:
- A possibly empty
Collectionof the names of present headers.
-
containsHeader
public boolean containsHeader(java.lang.String name)
Description copied from interface:HeadersReturn a boolean indicating whether the named header has already been set.- Specified by:
containsHeaderin interfaceHeaders- Parameters:
name- The name of the header.- Returns:
trueif the header has already been set,falseotherwise.
-
build
public static ConcurrentHashMapHeaders build(HeaderType headerType)
Build an empty instance with the givenHeaderType.NOTE: If using this implementation of
Headers, an agent of the same version should be used. Failure to do so may cause unexpected results at runtime, since the agent's definition may be different than provided by thenewrelic-api.- Parameters:
headerType- The type of headers the instance represents.- Returns:
- The instance.
-
buildFromFlatMap
public static ConcurrentHashMapHeaders buildFromFlatMap(HeaderType headerType, java.util.Map<java.lang.String,java.lang.String> map)
Build an instance with the givenHeaderTypeand callsetHeader(String, String)with each entry in themap.NOTE: If using this implementation of
Headers, an agent of the same version should be used. Failure to do so may cause unexpected results at runtime, since the agent's definition may be different than provided by thenewrelic-api.- Parameters:
headerType- The type of headers the instance represents.map- A map of header names and values used to populate the instance.- Returns:
- The instance.
-
buildFromMap
public static ConcurrentHashMapHeaders buildFromMap(HeaderType headerType, java.util.Map<java.lang.String,java.util.List<java.lang.String>> map)
Build an instance with the givenHeaderTypeand calladdHeader(String, String)with each entry in themap.NOTE: If using this implementation of
Headers, an agent of the same version should be used. Failure to do so may cause unexpected results at runtime, since the agent's definition may be different than provided by thenewrelic-api.- Parameters:
headerType- The type of headers the instance represents.map- A map of header names and potentially several values each used to populate the instance.- Returns:
- The instance.
-
-