Top Description Fields Constructors Methods
io.netty.handler.codec.haproxy

public final Class HAProxyMessage

extends AbstractReferenceCounted
Class Inheritance
Imports
io.netty.buffer.ByteBuf, io.netty.handler.codec.haproxy.HAProxyProxiedProtocol.AddressFamily, io.netty.util.AbstractReferenceCounted, .ByteProcessor, .CharsetUtil, .NetUtil, .ResourceLeakDetector, .ResourceLeakDetectorFactory, .ResourceLeakTracker, io.netty.util.internal.ObjectUtil, .StringUtil, java.util.ArrayList, .Collections, .List

Message container for decoded HAProxy proxy protocol parameters

Field Summary

Modifier and TypeField and Description
private final HAProxyCommand
private final String
private final int
private final ResourceLeakTracker<HAProxyMessage>
private static final ResourceLeakDetector<HAProxyMessage>
private static final int
private final HAProxyProtocolVersion
private final HAProxyProxiedProtocol
private final String
private final int
private final List<HAProxyTLV>

Constructor Summary

AccessConstructor and Description
private
HAProxyMessage(HAProxyProtocolVersion protocolVersion, HAProxyCommand command, HAProxyProxiedProtocol proxiedProtocol, String sourceAddress, String destinationAddress, String sourcePort, String destinationPort)

Creates a new instance

public
HAProxyMessage(HAProxyProtocolVersion
the protocol version.
protocolVersion
,
HAProxyCommand
the command.
command
,
HAProxyProxiedProtocol
the protocol containing the address family and transport protocol.
proxiedProtocol
,
String
the source address.
sourceAddress
,
String
the destination address.
destinationAddress
,
int
the source port. This value must be 0 for unix, unspec addresses.
sourcePort
,
int
the destination port. This value must be 0 for unix, unspec addresses.
destinationPort
)

Creates a new instance of HAProxyMessage.

public
HAProxyMessage(HAProxyProtocolVersion
the protocol version.
protocolVersion
,
HAProxyCommand
the command.
command
,
HAProxyProxiedProtocol
the protocol containing the address family and transport protocol.
proxiedProtocol
,
String
the source address.
sourceAddress
,
String
the destination address.
destinationAddress
,
int
the source port. This value must be 0 for unix, unspec addresses.
sourcePort
,
int
the destination port. This value must be 0 for unix, unspec addresses.
destinationPort
,
List<? extends HAProxyTLV>
the list of tlvs.
tlvs
)

Creates a new instance of HAProxyMessage.

Method Summary

Modifier and TypeMethod and Description
private static void
checkAddress(String
human-readable address
address
,
HAProxyProxiedProtocol.AddressFamily
the AddressFamily to check the address against
addrFamily
)

Validate an address (IPv4, IPv6, Unix Socket)

private static void
checkPort(int
the UDP/TCP port
port
,
HAProxyProxiedProtocol.AddressFamily addrFamily)

Validate the port depending on the addrFamily.

public HAProxyCommand
command()

Returns the HAProxyCommand of this HAProxyMessage.

protected void
deallocate()

Implements abstract io.netty.util.AbstractReferenceCounted.deallocate.

Called once refCnt() is equals 0.
pack-priv static HAProxyMessage

Returns:

HAProxyMessage instance
decodeHeader
(ByteBuf
a version 2 proxy protocol header
header
)

Decodes a version 2, binary proxy protocol header.

pack-priv static HAProxyMessage

Returns:

HAProxyMessage instance
decodeHeader
(String
a version 1 proxy protocol header
header
)

Decodes a version 1, human-readable proxy protocol header.

public String
destinationAddress()

Returns the human-readable destination address of this HAProxyMessage.

public int
destinationPort()

Returns the UDP/TCP destination port of this HAProxyMessage.

private static String

Returns:

string representation of the ip address
ipBytesToString
(ByteBuf
buffer containing ip address bytes
header
,
int
number of bytes to read (4 bytes for IPv4, 16 bytes for IPv6)
addressLen
)

Convert ip address bytes to string representation

private static int

Returns:

port as an integer
portStringToInt
(String
the port
value
)

Convert port to integer

public HAProxyProtocolVersion
public HAProxyProxiedProtocol
private static HAProxyTLV
readNextTLV(final ByteBuf header, int nestingLevel)

private static List<HAProxyTLV>
readTlvs(final ByteBuf header)

public boolean
release()

Overrides io.netty.util.AbstractReferenceCounted.release.

Implements io.netty.util.ReferenceCounted.release.

Decreases the reference count by 1 and deallocates this object if the reference count reaches at 0.
public boolean
release(int decrement)

Overrides io.netty.util.AbstractReferenceCounted.release.

Implements io.netty.util.ReferenceCounted.release.

Decreases the reference count by the specified decrement and deallocates this object if the reference count reaches at 0.
public HAProxyMessage
retain()

Overrides io.netty.util.AbstractReferenceCounted.retain.

Implements io.netty.util.ReferenceCounted.retain.

Increases the reference count by 1.
public HAProxyMessage
retain(int increment)

Overrides io.netty.util.AbstractReferenceCounted.retain.

Implements io.netty.util.ReferenceCounted.retain.

Increases the reference count by the specified increment.
public String
sourceAddress()

Returns the human-readable source address of this HAProxyMessage or null if HAProxy performs health check with send-proxy-v2.

public int
sourcePort()

Returns the UDP/TCP source port of this HAProxyMessage.

pack-priv int
public List<HAProxyTLV>
tlvs()

Returns a list of HAProxyTLV or an empty list if no TLVs are present.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public HAProxyMessage
touch()

Overrides io.netty.util.AbstractReferenceCounted.touch.

Implements io.netty.util.ReferenceCounted.touch.

Records the current access location of this object for debugging purposes.
public HAProxyMessage
touch(Object hint)

Implements io.netty.util.ReferenceCounted.touch.

Records the current access location of this object with an additional arbitrary information for debugging purposes.
private void
private static HAProxyMessage
unknownMsg(HAProxyProtocolVersion version, HAProxyCommand command)

Proxy protocol message for 'UNKNOWN' proxied protocols.

Inherited from io.netty.util.AbstractReferenceCounted:
refCntsetRefCnt

Field Detail

commandback to summary
private final HAProxyCommand command
destinationAddressback to summary
private final String destinationAddress
destinationPortback to summary
private final int destinationPort
leakback to summary
private final ResourceLeakTracker<HAProxyMessage> leak
leakDetectorback to summary
private static final ResourceLeakDetector<HAProxyMessage> leakDetector
MAX_NESTING_LEVELback to summary
private static final int MAX_NESTING_LEVEL
protocolVersionback to summary
private final HAProxyProtocolVersion protocolVersion
proxiedProtocolback to summary
private final HAProxyProxiedProtocol proxiedProtocol
sourceAddressback to summary
private final String sourceAddress
sourcePortback to summary
private final int sourcePort
tlvsback to summary
private final List<HAProxyTLV> tlvs

Constructor Detail

HAProxyMessageback to summary
private HAProxyMessage(HAProxyProtocolVersion protocolVersion, HAProxyCommand command, HAProxyProxiedProtocol proxiedProtocol, String sourceAddress, String destinationAddress, String sourcePort, String destinationPort)

Creates a new instance

HAProxyMessageback to summary
public HAProxyMessage(HAProxyProtocolVersion protocolVersion, HAProxyCommand command, HAProxyProxiedProtocol proxiedProtocol, String sourceAddress, String destinationAddress, int sourcePort, int destinationPort)

Creates a new instance of HAProxyMessage.

Parameters
protocolVersion:HAProxyProtocolVersion

the protocol version.

command:HAProxyCommand

the command.

proxiedProtocol:HAProxyProxiedProtocol

the protocol containing the address family and transport protocol.

sourceAddress:String

the source address.

destinationAddress:String

the destination address.

sourcePort:int

the source port. This value must be 0 for unix, unspec addresses.

destinationPort:int

the destination port. This value must be 0 for unix, unspec addresses.

HAProxyMessageback to summary
public HAProxyMessage(HAProxyProtocolVersion protocolVersion, HAProxyCommand command, HAProxyProxiedProtocol proxiedProtocol, String sourceAddress, String destinationAddress, int sourcePort, int destinationPort, List<? extends HAProxyTLV> tlvs)

Creates a new instance of HAProxyMessage.

Parameters
protocolVersion:HAProxyProtocolVersion

the protocol version.

command:HAProxyCommand

the command.

proxiedProtocol:HAProxyProxiedProtocol

the protocol containing the address family and transport protocol.

sourceAddress:String

the source address.

destinationAddress:String

the destination address.

sourcePort:int

the source port. This value must be 0 for unix, unspec addresses.

destinationPort:int

the destination port. This value must be 0 for unix, unspec addresses.

tlvs:List<? extends HAProxyTLV>

the list of tlvs.

Method Detail

checkAddressback to summary
private static void checkAddress(String address, HAProxyProxiedProtocol.AddressFamily addrFamily)

Validate an address (IPv4, IPv6, Unix Socket)

Parameters
address:String

human-readable address

addrFamily:HAProxyProxiedProtocol.AddressFamily

the AddressFamily to check the address against

Exceptions
IllegalArgumentException:
if the address is invalid
checkPortback to summary
private static void checkPort(int port, HAProxyProxiedProtocol.AddressFamily addrFamily)

Validate the port depending on the addrFamily.

Parameters
port:int

the UDP/TCP port

Exceptions
IllegalArgumentException:
if the port is out of range (0-65535 inclusive)
commandback to summary
public HAProxyCommand command()

Returns the HAProxyCommand of this HAProxyMessage.

deallocateback to summary
protected void deallocate()

Implements abstract io.netty.util.AbstractReferenceCounted.deallocate.

Doc from io.netty.util.AbstractReferenceCounted.deallocate.

Called once refCnt() is equals 0.

Annotations
@Override
decodeHeaderback to summary
pack-priv static HAProxyMessage decodeHeader(ByteBuf header)

Decodes a version 2, binary proxy protocol header.

Parameters
header:ByteBuf

a version 2 proxy protocol header

Returns:HAProxyMessage

HAProxyMessage instance

Exceptions
HAProxyProtocolException:
if any portion of the header is invalid
decodeHeaderback to summary
pack-priv static HAProxyMessage decodeHeader(String header)

Decodes a version 1, human-readable proxy protocol header.

Parameters
header:String

a version 1 proxy protocol header

Returns:HAProxyMessage

HAProxyMessage instance

Exceptions
HAProxyProtocolException:
if any portion of the header is invalid
destinationAddressback to summary
public String destinationAddress()

Returns the human-readable destination address of this HAProxyMessage.

destinationPortback to summary
public int destinationPort()

Returns the UDP/TCP destination port of this HAProxyMessage.

ipBytesToStringback to summary
private static String ipBytesToString(ByteBuf header, int addressLen)

Convert ip address bytes to string representation

Parameters
header:ByteBuf

buffer containing ip address bytes

addressLen:int

number of bytes to read (4 bytes for IPv4, 16 bytes for IPv6)

Returns:String

string representation of the ip address

portStringToIntback to summary
private static int portStringToInt(String value)

Convert port to integer

Parameters
value:String

the port

Returns:int

port as an integer

Exceptions
IllegalArgumentException:
if port is not a valid integer
protocolVersionback to summary
public HAProxyProtocolVersion protocolVersion()

Returns the HAProxyProtocolVersion of this HAProxyMessage.

proxiedProtocolback to summary
public HAProxyProxiedProtocol proxiedProtocol()

Returns the HAProxyProxiedProtocol of this HAProxyMessage.

readNextTLVback to summary
private static HAProxyTLV readNextTLV(final ByteBuf header, int nestingLevel)
readTlvsback to summary
private static List<HAProxyTLV> readTlvs(final ByteBuf header)
releaseback to summary
public boolean release()

Overrides io.netty.util.AbstractReferenceCounted.release.

Implements io.netty.util.ReferenceCounted.release.

Doc from io.netty.util.ReferenceCounted.release.

Decreases the reference count by 1 and deallocates this object if the reference count reaches at 0.

Returns:boolean

true if and only if the reference count became 0 and this object has been deallocated

Annotations
@Override
releaseback to summary
public boolean release(int decrement)

Overrides io.netty.util.AbstractReferenceCounted.release.

Implements io.netty.util.ReferenceCounted.release.

Doc from io.netty.util.ReferenceCounted.release.

Decreases the reference count by the specified decrement and deallocates this object if the reference count reaches at 0.

Returns:boolean

true if and only if the reference count became 0 and this object has been deallocated

Annotations
@Override
retainback to summary
public HAProxyMessage retain()

Overrides io.netty.util.AbstractReferenceCounted.retain.

Implements io.netty.util.ReferenceCounted.retain.

Doc from io.netty.util.ReferenceCounted.retain.

Increases the reference count by 1.

Annotations
@Override
retainback to summary
public HAProxyMessage retain(int increment)

Overrides io.netty.util.AbstractReferenceCounted.retain.

Implements io.netty.util.ReferenceCounted.retain.

Doc from io.netty.util.ReferenceCounted.retain.

Increases the reference count by the specified increment.

Annotations
@Override
sourceAddressback to summary
public String sourceAddress()

Returns the human-readable source address of this HAProxyMessage or null if HAProxy performs health check with send-proxy-v2.

sourcePortback to summary
public int sourcePort()

Returns the UDP/TCP source port of this HAProxyMessage.

tlvNumBytesback to summary
pack-priv int tlvNumBytes()
tlvsback to summary
public List<HAProxyTLV> tlvs()

Returns a list of HAProxyTLV or an empty list if no TLVs are present.

TLVs are only available for the Proxy Protocol V2

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
touchback to summary
public HAProxyMessage touch()

Overrides io.netty.util.AbstractReferenceCounted.touch.

Implements io.netty.util.ReferenceCounted.touch.

Doc from io.netty.util.ReferenceCounted.touch.

Records the current access location of this object for debugging purposes. If this object is determined to be leaked, the information recorded by this operation will be provided to you via ResourceLeakDetector. This method is a shortcut to touch(null).

Annotations
@Override
touchback to summary
public HAProxyMessage touch(Object hint)

Implements io.netty.util.ReferenceCounted.touch.

Doc from io.netty.util.ReferenceCounted.touch.

Records the current access location of this object with an additional arbitrary information for debugging purposes. If this object is determined to be leaked, the information recorded by this operation will be provided to you via ResourceLeakDetector.

Annotations
@Override
tryRecordback to summary
private void tryRecord()
unknownMsgback to summary
private static HAProxyMessage unknownMsg(HAProxyProtocolVersion version, HAProxyCommand command)

Proxy protocol message for 'UNKNOWN' proxied protocols. Per spec, when the proxied protocol is 'UNKNOWN' we must discard all other header values.