Package io.aeron

Class ChannelUri

java.lang.Object
io.aeron.ChannelUri

public final class ChannelUri extends Object
Parser for Aeron channel URIs. The format is:
 aeron-uri = "aeron:" media [ "?" param *( "|" param ) ]
 media     = *( "[^?:]" )
 param     = key "=" value
 key       = *( "[^=]" )
 value     = *( "[^|]" )
 

Multiple params with the same key are allowed, the last value specified takes precedence.

See Also:
  • Field Details

    • AERON_SCHEME

      public static final String AERON_SCHEME
      URI Scheme for Aeron channels and destinations.
      See Also:
    • SPY_QUALIFIER

      public static final String SPY_QUALIFIER
      Qualifier for spy subscriptions which spy on outgoing network destined traffic efficiently.
      See Also:
    • INVALID_TAG

      public static final long INVALID_TAG
      Invalid tag value returned when calling getTag(String) and the channel is not tagged.
      See Also:
    • MAX_URI_LENGTH

      public static final int MAX_URI_LENGTH
      Max length in characters for the URI string.
      See Also:
  • Method Details

    • prefix

      public String prefix()
      The prefix for the channel.
      Returns:
      the prefix for the channel.
    • prefix

      public ChannelUri prefix(String prefix)
      Change the prefix from what has been parsed.
      Parameters:
      prefix - to replace the existing prefix.
      Returns:
      this for a fluent API.
    • media

      public String media()
      The media over which the channel operates.
      Returns:
      the media over which the channel operates.
    • media

      public ChannelUri media(String media)
      Set the media over which the channel operates.
      Parameters:
      media - to replace the parsed value.
      Returns:
      this for a fluent API.
    • isUdp

      public boolean isUdp()
      Is the channel media() equal to CommonContext.UDP_MEDIA.
      Returns:
      true the channel media() equals CommonContext.UDP_MEDIA.
    • isIpc

      public boolean isIpc()
      Is the channel media() equal to CommonContext.IPC_MEDIA.
      Returns:
      true the channel media() equals CommonContext.IPC_MEDIA.
    • scheme

      public String scheme()
      The scheme for the URI. Must be "aeron".
      Returns:
      the scheme for the URI.
    • get

      public String get(String key)
      Get a value for a given parameter key.
      Parameters:
      key - to lookup.
      Returns:
      the value if set for the key otherwise null.
    • get

      public String get(String key, String defaultValue)
      Get the value for a given parameter key or the default value provided if the key does not exist.
      Parameters:
      key - to lookup.
      defaultValue - to be returned if no key match is found.
      Returns:
      the value if set for the key otherwise the default value provided.
    • put

      public String put(String key, String value)
      Put a key and value pair in the map of params.
      Parameters:
      key - of the param to be put.
      value - of the param to be put.
      Returns:
      the existing value otherwise null.
    • remove

      public String remove(String key)
      Remove a key pair in the map of params.
      Parameters:
      key - of the param to be removed.
      Returns:
      the previous value of the param or null.
    • containsKey

      public boolean containsKey(String key)
      Does the URI contain a value for the given key.
      Parameters:
      key - to be lookup.
      Returns:
      true if the key has a value otherwise false.
    • channelTag

      public String channelTag()
      Get the channel tag, if it exists, that refers to another channel.
      Returns:
      channel tag if it exists or null if not in this URI.
      See Also:
    • entityTag

      public String entityTag()
      Get the entity tag, if it exists, that refers to an entity such as subscription or publication.
      Returns:
      entity tag if it exists or null if not in this URI.
      See Also:
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Generate a String representation of the URI that is valid for an Aeron channel.
      Overrides:
      toString in class Object
      Returns:
      a String representation of the URI that is valid for an Aeron channel.
    • initialPosition

      public void initialPosition(long position, int initialTermId, int termLength)
      Initialise a channel for restarting a publication at a given position.
      Parameters:
      position - at which the publication should be started.
      initialTermId - what which the stream would start.
      termLength - for the stream.
    • parse

      public static ChannelUri parse(CharSequence uri)
      Parse a CharSequence which contains an Aeron URI.
      Parameters:
      uri - to be parsed.
      Returns:
      a new ChannelUri representing the URI string.
    • addSessionId

      public static String addSessionId(String channel, int sessionId)
      Add a sessionId to a given channel.
      Parameters:
      channel - to add sessionId to.
      sessionId - to add to channel.
      Returns:
      new string that represents channel with sessionId added.
    • addAliasIfAbsent

      public static String addAliasIfAbsent(String uri, String alias)
      Add alias to the uri if none exists.
      Parameters:
      uri - to add alias to.
      alias - to add to the uri.
      Returns:
      original uri if alias is empty or one is already defined, otherwise new uri with an alias.
    • transformAlias

      public static String transformAlias(String uri, Function<String,String> function)
      Transforms an alias of the given uri using the given function. The function will be invoked with the original alias or null if absent. The function's return value will be used as the alias in the returned uri. If the function returns null or an empty string, the alias will be removed.
      Parameters:
      uri - the uri to transform the alias of.
      function - the transformation function.
      Returns:
      uri equivalent to the one passed in with its alias transformed.
    • isTagged

      public static boolean isTagged(String paramValue)
      Is the param value tagged? (starts with the "tag:" prefix).
      Parameters:
      paramValue - to check if tagged.
      Returns:
      true if tagged or false if not.
      See Also:
    • getTag

      public static long getTag(String paramValue)
      Get the value of the tag from a given parameter value.
      Parameters:
      paramValue - to extract the tag value from.
      Returns:
      the value of the tag or INVALID_TAG if not tagged.
      See Also:
    • createDestinationUri

      public static String createDestinationUri(String channel, String endpoint)
      Create a channel URI for a destination, i.e. a channel that uses media and interface parameters of the original channel and adds specified endpoint to it. For example given the input channel is aeron:udp?mtu=1440|ttl=0|endpoint=localhost:8090|term-length=128k|interface=eth0 and the endpoint is 192.168.0.14 the output of this method will be aeron:udp?endpoint=192.168.0.14|interface=eth0.
      Parameters:
      channel - for which the destination is being added.
      endpoint - for the target destination.
      Returns:
      new channel URI for a destination.
    • replaceEndpointWildcardPort

      public void replaceEndpointWildcardPort(String resolvedEndpoint)
      Uses the supplied endpoint to resolve any wildcard ports. If the existing endpoint has a value of "0" for then the port of this endpoint will be used instead. If the endpoint is not specified in this uri, then the whole supplied endpoint is used. If the endpoint exists and has a non-wildcard port, then the existing endpoint is retained.
      Parameters:
      resolvedEndpoint - The endpoint to supply a resolved endpoint port.
      Throws:
      IllegalArgumentException - if the supplied resolvedEndpoint does not have a port or the port is zero.
      NullPointerException - if the supplied resolvedEndpoint is null
    • forEachParameter

      public void forEachParameter(BiConsumer<String,String> consumer)
      Call consumer for each parameter defined in the URI.
      Parameters:
      consumer - to be invoked for each parameter.
    • hasControlModeResponse

      public boolean hasControlModeResponse()
      Determines if this channel has specified control-mode=response.
      Returns:
      true if this channel has specified control-mode=response.
    • replacePortWithWildcard

      public static String replacePortWithWildcard(String endpoint)
      Take an endpoint with the format host:port and replace the port with a wildcard (0).
      Parameters:
      endpoint - to replace with a wildcard.
      Returns:
      the transformed value.
    • isControlModeResponse

      public static boolean isControlModeResponse(String channelUri)
      Determines if the supplied channel has specified control-mode=response.
      Parameters:
      channelUri - to check if the control mode is response
      Returns:
      true if the supplied channel has specified control-mode=response.