org.apache.tomcat.bayeux
Class ChannelImpl

java.lang.Object
  extended by org.apache.tomcat.bayeux.ChannelImpl
All Implemented Interfaces:
Channel

public class ChannelImpl
extends java.lang.Object
implements Channel

Version:
1.0
Author:
Filip Hanik

Field Summary
protected  java.util.LinkedList<DataFilter> filters
          A list of the current filters
protected  java.lang.String id
          The unique id of this channel
protected  boolean persistent
          Is this channel persistent, default value is true
protected  java.util.LinkedList<Client> subscribers
          A list of the current subscribers
 
Constructor Summary
protected ChannelImpl(java.lang.String id)
          Creates a new channel
 
Method Summary
 void addFilter(DataFilter filter)
          Adds a data filter to this channel.
 java.lang.String getId()
          returns the id of this channel
 java.util.List<Client> getSubscribers()
          returns a non modifiable list of all the subscribers to this channel.
 boolean isPersistent()
          Non persistent channels are removed when the last subscription is removed.
 boolean matches(java.lang.String pattern)
          Returns true if this channel matches the pattern to its id.
 void publish(Message msg)
          Publishes a message to all the subscribers of this channel.
 void publish(Message[] msgs)
          Publishes more than one message to all the subscribers of this channel.
 DataFilter removeFilter(DataFilter filter)
          Removes a filter from this channel.
 void setPersistent(boolean persistent)
           
 void subscribe(Client subscriber)
          Subscribes a client to a channel.
 java.lang.String toString()
           
 Client unsubscribe(Client subscriber)
          Unsubscribes a client from a channel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

id

protected java.lang.String id
The unique id of this channel


subscribers

protected java.util.LinkedList<Client> subscribers
A list of the current subscribers


filters

protected java.util.LinkedList<DataFilter> filters
A list of the current filters


persistent

protected boolean persistent
Is this channel persistent, default value is true

Constructor Detail

ChannelImpl

protected ChannelImpl(java.lang.String id)
Creates a new channel

Parameters:
id - String - the id of the channel, can not be null
Method Detail

getId

public java.lang.String getId()
returns the id of this channel

Specified by:
getId in interface Channel
Returns:
String

matches

public boolean matches(java.lang.String pattern)
Returns true if this channel matches the pattern to its id. The channel pattern can be a complete name like /service/mychannel or it can be a wild card pattern like /service/app2/**

Parameters:
pattern - String according to the Bayeux specification section 2.2.1 Channel Globbing, can not be null.
Returns:
boolean true if the id of this channel matches the pattern

getSubscribers

public java.util.List<Client> getSubscribers()
Description copied from interface: Channel
returns a non modifiable list of all the subscribers to this channel.

Specified by:
getSubscribers in interface Channel
Returns:
returns a non modifiable list of the subscribers for this channel.

isPersistent

public boolean isPersistent()
Description copied from interface: Channel
Non persistent channels are removed when the last subscription is removed. Persistent channels survive periods without any subscribers.

Specified by:
isPersistent in interface Channel
Returns:
true if the Channel will persist without any subscription.

publish

public void publish(Message msg)
Description copied from interface: Channel
Publishes a message to all the subscribers of this channel. The from is contained within the message, by calling msg.getClient()

Specified by:
publish in interface Channel

publish

public void publish(Message[] msgs)
Description copied from interface: Channel
Publishes more than one message to all the subscribers of this channel. The from is contained within the message, by calling msg[x].getClient()

Specified by:
publish in interface Channel

setPersistent

public void setPersistent(boolean persistent)
Specified by:
setPersistent in interface Channel
Parameters:
persistent - true if the Channel will persist without any subscription.
See Also:
isPersistent

subscribe

public void subscribe(Client subscriber)
Description copied from interface: Channel
Subscribes a client to a channel.

Specified by:
subscribe in interface Channel
Parameters:
subscriber - - the client to be subscribed. If the client already is subscribed, this call will not create a duplicate subscription.

unsubscribe

public Client unsubscribe(Client subscriber)
Description copied from interface: Channel
Unsubscribes a client from a channel

Specified by:
unsubscribe in interface Channel
Parameters:
subscriber - - the client to be subscribed.
Returns:
- returns the client that was unsubscribed, or null if the client wasn't subscribed.

addFilter

public void addFilter(DataFilter filter)
Description copied from interface: Channel
Adds a data filter to this channel. All messages received by this channel will run through this filter.

Specified by:
addFilter in interface Channel
Parameters:
filter - Filter

removeFilter

public DataFilter removeFilter(DataFilter filter)
Description copied from interface: Channel
Removes a filter from this channel. returns the filter that was removed, or null if the filter wasn't in the channel.

Specified by:
removeFilter in interface Channel
Parameters:
filter - Filter
Returns:
Filter - null if no filter was removed otherwise it returns the filter that was removed.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2000-2009 Apache Software Foundation. All Rights Reserved.