Package io.hekate.network.address
Class AddressPattern
- java.lang.Object
-
- io.hekate.network.address.AddressPattern
-
- All Implemented Interfaces:
AddressSelector
public class AddressPattern extends Object implements AddressSelector
Pattern-based implementation ofAddressSelector
interface.This implementation of
AddressSelector
interface scans through all available network interfaces of the local host and uses the pattern matching logic in order to decide which address should be selected.The following patterns can be specified:
- any - any non-loopback address
- any-ip4 - any IPv4 non-loopback address
- any-ip6 - any IPv6 non-loopback address
- ip~regex - any IP address that matches the specified regular expression
- ip4~regex - any IPv4 address that matches the specified regular expression
- ip6~regex - any IPv6 address that matches the specified regular expression
- !ip~regex - any IP address that does NOT match the specified regular expression
- !ip4~regex - any IPv4 address that does NOT match the specified regular expression
- !ip6~regex - any IPv6 address that does NOT match the specified regular expression
- net~regex - any IP address of a network interface whose
name
matches the specified regular expression - net4~regex - IPv4 address of a network interface whose
name
matches the specified regular expression - net6~regex - IPv6 address of a network interface whose
name
matches the specified regular expression - !net~regex - any IP address of a network interface whose
name
does NOT match the specified regular expression - !net4~regex - IPv4 address of a network interface whose
name
does NOT match the specified regular expression - !net6~regex - IPv6 address of a network interface whose
name
does NOT match the specified regular expression - ...all other values will be treated as a directly specified address (see
InetAddress.getByName(String)
)
If several addresses match the specified pattern, the first one will be selected (order is not guaranteed, but preference will be given to non-
P2P
addresses).
-
-
Constructor Summary
Constructors Constructor Description AddressPattern()
Constructs a new instance with'any'
pattern.AddressPattern(String pattern)
Constructs a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
pattern()
Returns the host pattern as string.InetAddress
select()
Resolves the IP address for the local node.String
toString()
-
-
-
Constructor Detail
-
AddressPattern
public AddressPattern()
Constructs a new instance with'any'
pattern.
-
AddressPattern
public AddressPattern(String pattern)
Constructs a new instance.- Parameters:
pattern
- Pattern (see the descriptions of this class for the list of supported patterns).
-
-
Method Detail
-
pattern
public String pattern()
Returns the host pattern as string.- Returns:
- Host pattern.
-
select
public InetAddress select() throws HekateException
Description copied from interface:AddressSelector
Resolves the IP address for the local node. The returned address will be used by remote nodes to connect to the local node.- Specified by:
select
in interfaceAddressSelector
- Returns:
- Local node address.
- Throws:
HekateException
- If address resolution fails.
-
-