de.anneck.jcast.channels
Class AbstractChannelThread

java.lang.Object
  |
  +--de.anneck.jcast.core.AbstractThread
        |
        +--de.anneck.jcast.channels.AbstractChannelThread
All Implemented Interfaces:
org.apache.avalon.framework.configuration.Configurable, IChannel, IChannelThread, IStartable, IThread, java.lang.Runnable
Direct Known Subclasses:
MP3ChannelThread, SimpleChannelThread

public abstract class AbstractChannelThread
extends AbstractThread
implements IChannelThread

AbstractChannelThread the abstract implementation of the "bus" for Sources and Listeners. The Channel implements the "Bus" of a Producer-Bus-Consumer pattern.

Version:
$Revision: 1.18 $
Author:
andre.anneck@web.de

Field Summary
protected  int m_dist_timeout
          Timeout between each packet distribution
protected  java.lang.String m_Identifying_Name
          The identifying name of this channel.
protected  java.lang.String m_listener_response
          The listener respones header
protected  java.util.List m_Listeners
          All listeners subscribed to this channel.
protected  java.lang.String m_source_response
          The source response header
protected  java.util.List m_Sources
          All sources feeding this channel.
 
Fields inherited from class de.anneck.jcast.core.AbstractThread
m_class, m_log, m_mutex, m_name, m_prio, m_state
 
Fields inherited from interface de.anneck.jcast.core.IThread
RUNNING, STOPPED, WAITING
 
Constructor Summary
AbstractChannelThread()
          Creates new Channel
 
Method Summary
 void add(IListener listener)
          Adds a listener into the Channel.
 void add(IListener listener, ISource source)
          Adds a listener into the Channel listening to the specified source only.
 void add(ISource source)
          Adds a source into the Channel.
 void configure(org.apache.avalon.framework.configuration.Configuration configuration)
          Configures a SimpleChannel.
 java.lang.String getIdentifyingName()
          Returns the unique name for the Channel
 java.lang.String getListenerResponseHeader()
          Returns the current ListenerResponseHeader
 java.util.List getListeners()
          Returns a list of all listeners.
 java.util.List getListeners(ISource source)
          Returns a list of all listeners, subscribed to source.
 java.lang.String getSourceResponseHeader()
          Returns the current SourceResponseHeader
 java.util.List getSources()
          Returns a list of all sources.
 java.lang.String getStats()
          Returns some statistiks infos, for debugging mainly.
 void remove(IListener listener)
          Removes a IListner from the Channel.
 void remove(IListener listener, ISource source)
          Removes the IListener from the specified ISource in the Channel.
 void remove(ISource source)
          Removes a ISource from the Channel.
 void send(byte[] b)
          Sends the specified byteArray to all listeners in the channel
 void send(byte[] b, ISource source)
          Sends the specified byteArray to all subscribed listeners.
 void setIdentifyingName(java.lang.String idName)
          Sets a unique name for a channel.
 void setListenerResponseHeader(java.lang.String resHeader)
          Sets the response header to be send to listeners connecting to this channel
 void setSourceResponseHeader(java.lang.String resHeader)
          Sets the response header to be send to sources connecting to this channel
 java.lang.String toString()
          Returns a meaningfull string of the ChannelThread.
 
Methods inherited from class de.anneck.jcast.core.AbstractThread
checkState, doKill, doRestart, doStart, doStop, getAllThreads, getThreadClass, getThreadName, getThreadPriority, isRunning, isStopped, isWaiting, run, setState, setThreadPriority
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface de.anneck.jcast.core.IThread
checkState, doKill, doRestart, doStart, doStop, doWork, getThreadClass, getThreadName, getThreadPriority, isRunning, isStopped, isWaiting, setState, setThreadPriority
 
Methods inherited from interface java.lang.Runnable
run
 

Field Detail

m_Listeners

protected java.util.List m_Listeners
All listeners subscribed to this channel.

m_Sources

protected java.util.List m_Sources
All sources feeding this channel.

m_Identifying_Name

protected java.lang.String m_Identifying_Name
The identifying name of this channel.

m_listener_response

protected java.lang.String m_listener_response
The listener respones header

m_source_response

protected java.lang.String m_source_response
The source response header

m_dist_timeout

protected int m_dist_timeout
Timeout between each packet distribution
Constructor Detail

AbstractChannelThread

public AbstractChannelThread()
Creates new Channel
Method Detail

add

public final void add(ISource source)
               throws ChannelException
Adds a source into the Channel.
Specified by:
add in interface IChannel
Parameters:
source - The source to be added. Must implement ISource.

remove

public final void remove(ISource source)
                  throws ChannelException
Removes a ISource from the Channel. A ChannelException is thrown if you try to remove a source that does not exist.
Specified by:
remove in interface IChannel
Parameters:
source - A valid ISource
Throws:
A - Channel excpetion

add

public final void add(IListener listener)
               throws ChannelException
Adds a listener into the Channel.
Specified by:
add in interface IChannel
Parameters:
listener - The listener to be added. Must implement IListener.
Throws:
ChannelException - only if an otherwise successfull attempt to add the listener into the channel failed for an internal reason. If you try to add a listener that is already listening to this channel a warning is logged but no exception is throw.

remove

public final void remove(IListener listener)
                  throws ChannelException
Removes a IListner from the Channel. IF the Channel is a ISingleSource type of Channel than the listener is also removed from the source.
Specified by:
remove in interface IChannel
Parameters:
listener - The IListener to be removed.
Throws:
ChannelException - if the specified listener is not inside of this channel or if an otherwise successfull attempt to remove the specified listener fails.

add

public final void add(IListener listener,
                      ISource source)
               throws ChannelException
Adds a listener into the Channel listening to the specified source only.
Specified by:
add in interface IChannel
Parameters:
listener - The listener to be added. Must implement IListener.
source - The source to listen to. Must implement ISource.
Throws:
ChannelException - if the specified ISource is not registered within this IChannel. Also if the ISource exists but fails to subscribe the IListener to the specified ISource.

remove

public final void remove(IListener listener,
                         ISource source)
                  throws ChannelException
Removes the IListener from the specified ISource in the Channel.
Specified by:
remove in interface IChannel
Parameters:
listener - The IListener to be removed.
source - The ISource to which the specified IListener is subscribed.

send

public final void send(byte[] b,
                       ISource source)
Sends the specified byteArray to all subscribed listeners.
Specified by:
send in interface IChannel
Parameters:
b - The byte[] array.
source - The sending ISource

send

public final void send(byte[] b)
Sends the specified byteArray to all listeners in the channel
Parameters:
b - The byteArray to be send.

getIdentifyingName

public final java.lang.String getIdentifyingName()
Returns the unique name for the Channel
Specified by:
getIdentifyingName in interface IChannel
Returns:
String The Identifying name of the Channel.

setIdentifyingName

public final void setIdentifyingName(java.lang.String idName)
Sets a unique name for a channel.
Specified by:
setIdentifyingName in interface IChannel
Parameters:
idName - The unique name for the IChannel

setListenerResponseHeader

public final void setListenerResponseHeader(java.lang.String resHeader)
Sets the response header to be send to listeners connecting to this channel
Specified by:
setListenerResponseHeader in interface IChannel
Parameters:
resHeader - The response header.

getListenerResponseHeader

public final java.lang.String getListenerResponseHeader()
Returns the current ListenerResponseHeader
Specified by:
getListenerResponseHeader in interface IChannel
Returns:
The response header.

setSourceResponseHeader

public final void setSourceResponseHeader(java.lang.String resHeader)
Sets the response header to be send to sources connecting to this channel
Specified by:
setSourceResponseHeader in interface IChannel
Parameters:
resHeader - The response header.

getSourceResponseHeader

public final java.lang.String getSourceResponseHeader()
Returns the current SourceResponseHeader
Specified by:
getSourceResponseHeader in interface IChannel
Returns:
The response header.

getStats

public java.lang.String getStats()
Returns some statistiks infos, for debugging mainly.
Returns:
A String with some bogus statistics.

toString

public java.lang.String toString()
Returns a meaningfull string of the ChannelThread.
Overrides:
toString in class java.lang.Object
Returns:
Description of Channel.

configure

public void configure(org.apache.avalon.framework.configuration.Configuration configuration)
               throws org.apache.avalon.framework.configuration.ConfigurationException
Configures a SimpleChannel.
Specified by:
configure in interface org.apache.avalon.framework.configuration.Configurable
Parameters:
configuration - The configuration object.
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - Error during configuration.

getSources

public final java.util.List getSources()
Returns a list of all sources.
Specified by:
getSources in interface IChannel
Returns:
All sources in this channel.

getListeners

public final java.util.List getListeners()
Returns a list of all listeners.
Specified by:
getListeners in interface IChannel
Returns:
All listeners in this channel.

getListeners

public final java.util.List getListeners(ISource source)
Returns a list of all listeners, subscribed to source.
Specified by:
getListeners in interface IChannel
Parameters:
source - The target source.
Returns:
All subscribed listeners of source.