public class BlaubotChannel extends java.lang.Object implements IBlaubotChannel
Modifier | Constructor and Description |
---|---|
protected |
BlaubotChannel(short channelId,
BlaubotChannelManager channelManager) |
Modifier and Type | Method and Description |
---|---|
protected void |
activate()
Activates the channel and therefore the message picking
|
void |
addMessageListener(IBlaubotMessageListener messageListener)
Add a message listener to this channel to get notifications when messages arrive.
|
protected void |
addSubscription(java.lang.String uniqueDeviceID)
Adds a subscription to uniqueDeviceId to this channel.
|
void |
addSubscriptionListener(IBlaubotSubscriptionChangeListener subscriptionChangeListener)
Adds a subscription listener to the manager
|
void |
clearMessageQueue()
Clears the message queue.
|
protected boolean |
deactivate()
Deactivates the channel and therefore the message picking.
|
BlaubotChannelConfig |
getChannelConfig()
The channel config specifying the message picking strategy and message rates as well
as the id.
|
protected int |
getQueueCapacity()
The queue capacity
|
protected int |
getQueueSize()
The current amount of messages in the queue
|
long |
getReceivedBytes()
The amount of bytes received by this channel so far.
|
long |
getReceivedMessages()
The message count received by this channel so far.
|
long |
getSentBytes()
The amount of bytes sent through this channel so far.
|
long |
getSentMessages()
The message count sent through this channel so far.
|
protected java.util.concurrent.ConcurrentSkipListSet<java.lang.String> |
getSubscriptions() |
protected boolean |
isActive() |
protected void |
notify(BlaubotMessage message)
Notifies this channel about a new message.
|
boolean |
publish(BlaubotMessage blaubotMessage)
Posts a BlaubotMessage to the message queue of this channel to be dispatched to subscribers later.
|
boolean |
publish(BlaubotMessage blaubotMessage,
boolean excludeSender)
Posts a BlaubotMessage to the message queue of this channel to be dispatched to subscribers later.
|
boolean |
publish(BlaubotMessage blaubotMessage,
long timeout)
Posts a BlaubotMessage to the message queue of this channel to be dispatched to subscribers later.
|
boolean |
publish(BlaubotMessage blaubotMessage,
long timeout,
boolean excludeSender)
Posts a BlaubotMessage to the message queue of this channel to be dispatched to subscribers later.
|
boolean |
publish(byte[] payload)
Post the payload to this channel's queue.
|
boolean |
publish(byte[] payload,
boolean excludeSender)
Post the payload to this channel's queue.
|
boolean |
publish(byte[] payload,
long timeout)
Post the payload to this channel's queue.
|
boolean |
publish(byte[] payload,
long timeout,
boolean excludeSender)
Post the payload to this channel's queue.
|
void |
removeMessageListener(IBlaubotMessageListener messageListener)
Removes a previously added message listener from this channel
If after the operation no listener is attached to this channel anymore, unsubscribe() is
called automatically.
|
protected void |
removeSubscription(java.lang.String uniqueDeviceId)
Removes the subscription of uniqueDeviceId to this channel
The operation is idempotent.
|
void |
removeSubscriptionListener(IBlaubotSubscriptionChangeListener subscriptionChangeListener)
Removes a subscription listener from the manager
|
protected int |
sendAddSubscription(java.lang.String uniqueDeviceID)
Sends the AddSubscriptionMessage to the master.
|
protected int |
sendRemoveSubscription(java.lang.String uniqueDeviceId)
Sends the RemoveSubscriptionMessage to the master.
|
protected void |
setDoNotTransmit(boolean doNotTransmit)
Allows or disallows transmission of messages by this channel.
|
void |
subscribe()
Subscribes to the channel
|
void |
subscribe(IBlaubotMessageListener blaubotMessageListener)
Subscribes to this channel and attaches a message listener
|
void |
unsubscribe()
Remove the subscription of this channel
|
protected BlaubotChannel(short channelId, BlaubotChannelManager channelManager)
channelId
- the channel idchannelManager
- the channelManager instance, that created this channelpublic boolean publish(BlaubotMessage blaubotMessage)
IBlaubotChannel
publish
in interface IBlaubotChannel
blaubotMessage
- the messagepublic boolean publish(BlaubotMessage blaubotMessage, boolean excludeSender)
IBlaubotChannel
publish
in interface IBlaubotChannel
blaubotMessage
- the messageexcludeSender
- if true, the message will not be dispatched back to this channel but to all other subscribers.public boolean publish(BlaubotMessage blaubotMessage, long timeout)
IBlaubotChannel
publish
in interface IBlaubotChannel
blaubotMessage
- the mssagetimeout
- the timeout in mspublic boolean publish(BlaubotMessage blaubotMessage, long timeout, boolean excludeSender)
IBlaubotChannel
publish
in interface IBlaubotChannel
blaubotMessage
- the mssagetimeout
- the timeout in msexcludeSender
- if true, the message will not be dispatched back to this channel but to all other subscribers.public boolean publish(byte[] payload)
IBlaubotChannel
publish
in interface IBlaubotChannel
payload
- the payload as byte arraypublic boolean publish(byte[] payload, boolean excludeSender)
IBlaubotChannel
publish
in interface IBlaubotChannel
payload
- the payload as byte arrayexcludeSender
- if true, the message will not be dispatched back to this channel but to all other subscribers.public boolean publish(byte[] payload, long timeout)
IBlaubotChannel
publish
in interface IBlaubotChannel
payload
- the payload as byte arraytimeout
- the timeout in mspublic boolean publish(byte[] payload, long timeout, boolean excludeSender)
IBlaubotChannel
publish
in interface IBlaubotChannel
payload
- the payload as byte arraytimeout
- the timeout in msexcludeSender
- if true, the message will not be dispatched back to this channel but to all other subscribers.public void subscribe()
IBlaubotChannel
subscribe
in interface IBlaubotChannel
public void subscribe(IBlaubotMessageListener blaubotMessageListener)
IBlaubotChannel
subscribe
in interface IBlaubotChannel
blaubotMessageListener
- the listener to be informed about new messages on this channelpublic void unsubscribe()
IBlaubotChannel
unsubscribe
in interface IBlaubotChannel
public void addMessageListener(IBlaubotMessageListener messageListener)
IBlaubotChannel
addMessageListener
in interface IBlaubotChannel
messageListener
- the message listener to addpublic void removeMessageListener(IBlaubotMessageListener messageListener)
IBlaubotChannel
removeMessageListener
in interface IBlaubotChannel
messageListener
- the listener to removeprotected int sendAddSubscription(java.lang.String uniqueDeviceID)
uniqueDeviceID
- the uniqueprotected int sendRemoveSubscription(java.lang.String uniqueDeviceId)
uniqueDeviceId
- the unique device idprotected void addSubscription(java.lang.String uniqueDeviceID)
uniqueDeviceID
- the unique device id of the device that will be a new subscriberprotected void removeSubscription(java.lang.String uniqueDeviceId)
uniqueDeviceId
- the unique device id of the device that will be unsubscribedprotected java.util.concurrent.ConcurrentSkipListSet<java.lang.String> getSubscriptions()
protected void notify(BlaubotMessage message)
message
- the message posted to this channelpublic BlaubotChannelConfig getChannelConfig()
getChannelConfig
in interface IBlaubotChannel
public void clearMessageQueue()
IBlaubotChannel
clearMessageQueue
in interface IBlaubotChannel
public void addSubscriptionListener(IBlaubotSubscriptionChangeListener subscriptionChangeListener)
subscriptionChangeListener
- the listener to addpublic void removeSubscriptionListener(IBlaubotSubscriptionChangeListener subscriptionChangeListener)
subscriptionChangeListener
- the listener to removeprotected void activate()
protected boolean deactivate()
protected boolean isActive()
protected int getQueueCapacity()
protected int getQueueSize()
public long getSentBytes()
public long getSentMessages()
public long getReceivedMessages()
public long getReceivedBytes()
protected void setDoNotTransmit(boolean doNotTransmit)
doNotTransmit
- if true, no messages will be picked as long as this state is set