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 ofHeaders
usingConcurrentHashMap
as 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 void
addHeader(java.lang.String name, java.lang.String value)
Add a header with the given name and value.static ConcurrentHashMapHeaders
build(HeaderType headerType)
Build an empty instance with the givenHeaderType
.static ConcurrentHashMapHeaders
buildFromFlatMap(HeaderType headerType, java.util.Map<java.lang.String,java.lang.String> map)
Build an instance with the givenHeaderType
and callsetHeader(String, String)
with each entry in themap
.static ConcurrentHashMapHeaders
buildFromMap(HeaderType headerType, java.util.Map<java.lang.String,java.util.List<java.lang.String>> map)
Build an instance with the givenHeaderType
and calladdHeader(String, String)
with each entry in themap
.boolean
containsHeader(java.lang.String name)
Return a boolean indicating whether the named header has already been set.java.lang.String
getHeader(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 aList
ofString
objects.HeaderType
getHeaderType()
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.void
removeHeader(java.lang.String name)
Remove any headers with the name.void
setHeader(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 backingheaders
map.- 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:Headers
Return the type of header key syntax used for this.- Specified by:
getHeaderType
in interfaceHeaders
- Specified by:
getHeaderType
in interfaceInboundHeaders
- Specified by:
getHeaderType
in interfaceOutboundHeaders
- Returns:
- An
enum
specifying the type of headers present.
-
getHeader
public java.lang.String getHeader(java.lang.String name)
Description copied from interface:Headers
Returns 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:
getHeader
in interfaceHeaders
- Specified by:
getHeader
in interfaceInboundHeaders
- Parameters:
name
- The name of the desired message header.- Returns:
- A
String
containing the value of the requested header, ornull
if the message header is not present.
-
getHeaders
public java.util.Collection<java.lang.String> getHeaders(java.lang.String name)
Description copied from interface:Headers
Return all the values of the specified message header as aList
ofString
objects. 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:
getHeaders
in interfaceHeaders
- Parameters:
name
- The name of the desired message header.- Returns:
- A
List
containing 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:Headers
Set 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:
setHeader
in interfaceHeaders
- Specified by:
setHeader
in 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:Headers
Add 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:Headers
Get the names of the headers.Changes to the returned collection must not affect the Headers instance.
- Specified by:
getHeaderNames
in interfaceHeaders
- Returns:
- A possibly empty
Collection
of the names of present headers.
-
containsHeader
public boolean containsHeader(java.lang.String name)
Description copied from interface:Headers
Return a boolean indicating whether the named header has already been set.- Specified by:
containsHeader
in interfaceHeaders
- Parameters:
name
- The name of the header.- Returns:
true
if the header has already been set,false
otherwise.
-
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 givenHeaderType
and 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 givenHeaderType
and 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.
-
-