Interface ChannelId<T>

  • All Known Implementing Classes:
    ChannelId.StringId

    public interface ChannelId<T>
    This is a marker interface for identifiers of channels which are used for communication between coroutines. One possible usage would be to implement it on enums or similar constants that are to be used as channel IDs. To simplify typed lookup of channels IDs are generically typed with the datatype of the target channel. Either implementations or applications are responsible that their channel IDs are unique also with respect to the datatype.

    Instances of a default implementation of string-based IDs can be created through the generic factory method channel(String, Class). Please check the method comment for informations about the constraints imposed by that implementation. There are also some derived factory methods for common datatypes like stringChannel(String).

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface Description
      static class  ChannelId.StringId<T>
      Internal implementation of string-based channel IDs.
    • Method Summary

      Static Methods 
      Modifier and Type Method Description
      static ChannelId<java.lang.Boolean> booleanChannel​(java.lang.String id)
      Creates a channel ID with a boolean datatype.
      static <T> ChannelId<T> channel​(java.lang.String id, java.lang.Class<T> datatype)
      Creates a new channel ID from an identifier string.
      static ChannelId<java.lang.Integer> intChannel​(java.lang.String id)
      Creates a channel ID with an integer datatype.
      static ChannelId<java.lang.String> stringChannel​(java.lang.String id)
      Creates a channel ID with a string datatype.
    • Method Detail

      • booleanChannel

        static ChannelId<java.lang.Boolean> booleanChannel​(java.lang.String id)
        Creates a channel ID with a boolean datatype.
        Parameters:
        id - The ID string
        Returns:
        The new boolean ID
        See Also:
        channel(String, Class)
      • channel

        static <T> ChannelId<T> channel​(java.lang.String id,
                                        java.lang.Class<T> datatype)
        Creates a new channel ID from an identifier string. Channel IDs with the same identifier string are considered equal and will therefore give access to the same channel in a CoroutineContext. IDs aren't cached so that invocations with the the same string and datatyoe will return different instances which are considered equal (see below). To avoid name clashes in complex scenarios the ID names should be selected appropriately, e.g. by using namespaces. The implementation doesn't impose any restrictions on the strings used to define IDs.

        Equality of string-based IDs is also based on the datatype. That means that it is possible to create equal-named channel IDs for different datatypes. Accessing channels through such IDs would yield different channel instances but that usage is not recommended. It lies in the responsibility of the application to name channel IDs appropriately for the respective context (or provide it's own ChannelId implementations).

        Parameters:
        id - The channel ID string
        datatype - The class of the channel datatype to ensure
        Returns:
        A new channel ID
      • intChannel

        static ChannelId<java.lang.Integer> intChannel​(java.lang.String id)
        Creates a channel ID with an integer datatype.
        Parameters:
        id - The ID string
        Returns:
        The new integer ID
        See Also:
        channel(String, Class)
      • stringChannel

        static ChannelId<java.lang.String> stringChannel​(java.lang.String id)
        Creates a channel ID with a string datatype.
        Parameters:
        id - The ID string
        Returns:
        The new string ID
        See Also:
        channel(String, Class)