Class AddressPattern

  • All Implemented Interfaces:
    AddressSelector

    public class AddressPattern
    extends Object
    implements AddressSelector
    Pattern-based implementation of AddressSelector 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).

    See Also:
    AddressSelector, NetworkServiceFactory.setHostSelector(AddressSelector)
    • 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.