@SPI
public abstract class ChannelHub<C extends MessageChannel>
extends java.lang.Object
implements java.lang.AutoCloseable
Serves for channel creation and storage-per-ID which in a way makes the hub similar to an entity repository.
Modifier | Constructor and Description |
---|---|
protected |
ChannelHub(TransportFactory transportFactory) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
closeStaleChannels()
Closes the stale channels and removes those from the hub.
|
C |
get(io.spine.server.transport.ChannelId channelId)
Obtains a channel from this hub by the given channel ID.
|
boolean |
hasChannel(io.spine.server.transport.ChannelId id)
Checks if this channel hub contains a channel with a given ID.
|
java.util.Set<io.spine.server.transport.ChannelId> |
ids() |
protected abstract C |
newChannel(io.spine.server.transport.ChannelId id)
Creates a new channel under the specified ID.
|
protected ChannelHub(TransportFactory transportFactory)
public java.util.Set<io.spine.server.transport.ChannelId> ids()
public boolean hasChannel(io.spine.server.transport.ChannelId id)
id
- the ID of the channeltrue
if such a channel is established in this hub, false
otherwiseChannelHub.get(ChannelId)
protected abstract C newChannel(io.spine.server.transport.ChannelId id)
id
- the ID of the channel to createpublic C get(io.spine.server.transport.ChannelId channelId)
If there is no channel with this ID in this hub, creates it and adds to the hub prior to returning it as a result of this method call.
channelId
- the identifier of the resulting channelpublic void closeStaleChannels()
public void close() throws java.lang.Exception
close
in interface java.lang.AutoCloseable
java.lang.Exception