public interface ChannelId<T>
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
application 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)
.
Modifier and Type | Interface and Description |
---|---|
static class |
ChannelId.StringId<T>
Internal implementation of string-based channel IDs.
|
Modifier and Type | Method and Description |
---|---|
static ChannelId<java.lang.Boolean> |
booleanChannel(java.lang.String sId)
Creates a channel ID with a boolean datatype.
|
static <T> ChannelId<T> |
channel(java.lang.String sId,
java.lang.Class<T> rDatatype)
Creates a new channel ID from an identifier string.
|
static ChannelId<java.lang.Integer> |
intChannel(java.lang.String sId)
Creates a channel ID with an integer datatype.
|
static ChannelId<java.lang.String> |
stringChannel(java.lang.String sId)
Creates a channel ID with a string datatype.
|
static ChannelId<java.lang.Boolean> booleanChannel(java.lang.String sId)
sId
- The ID stringchannel(String, Class)
static <T> ChannelId<T> channel(java.lang.String sId, java.lang.Class<T> rDatatype)
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).
sId
- The channel ID stringrDatatype
- The class of the channel datatype to ensurestatic ChannelId<java.lang.Integer> intChannel(java.lang.String sId)
sId
- The ID stringchannel(String, Class)
static ChannelId<java.lang.String> stringChannel(java.lang.String sId)
sId
- The ID stringchannel(String, Class)