de.anneck.jcast.listeners
Class AbstractListenerThread

java.lang.Object
  |
  +--de.anneck.jcast.core.AbstractThread
        |
        +--de.anneck.jcast.listeners.AbstractListenerThread
All Implemented Interfaces:
java.lang.Cloneable, org.apache.avalon.framework.configuration.Configurable, IListener, IListenerThread, ISignal, IStartable, IThread, java.lang.Runnable
Direct Known Subclasses:
SimpleListenerThread, TCP_ListenerThread, XMMS_ListenerThread

public abstract class AbstractListenerThread
extends AbstractThread
implements IListenerThread, java.lang.Cloneable

AbstractListenerThread provides default implementations of all methods required for a ListenerThread. If you want to create a new type of listener, extends this class. Take a look at SimpleListener for a vanilla implementation.

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

Field Summary
protected  byte[] m_byte
          The internal byte[]
protected  java.util.List m_cache
          Internal cache as vector
protected  IChannel m_channel
          The Channel its listening on
protected static ListenerController m_controller
          My controller
protected  java.lang.String m_Identifying_Name
           
protected  ISource m_source
          The Source its listening to
protected  SimpleStatistics m_stats
          Statistics and Misc informations
 
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
 
Fields inherited from interface de.anneck.jcast.core.ISignal
BUSY, CHANNEL_IS_BUSY, CHANNEL_IS_READY, CLIENT_DISCONNECTED, HELO, READY, SOURCE_GONE
 
Constructor Summary
AbstractListenerThread()
          Creates new AbstractListenerThread
 
Method Summary
 java.lang.Object clone()
           
 void configure(org.apache.avalon.framework.configuration.Configuration configuration)
          Configures the Listenerthread with the configuration object.
 boolean equals(java.lang.Object obj)
          Evaluates equality using the IdentifyingName method.
 IChannel getChannel()
          Returns the channel of this source
 java.lang.String getIdentifyingName()
          Returns the unique name for the Source
 ISource getSource()
          Returns the source this listener is listening to
 int hashCode()
          Standard hashCode from Object.
 void receive(byte[] b)
          Receives a byte array of something.
 void receiveSignal(java.lang.Object source, int param)
          Receives a Signal from a source.
 void setChannel(IChannel channel)
          Sets the channel of this Source
 void setIdentifyingName(java.lang.String idName)
          Sets a unique name for a source
 void setSource(ISource aSource)
          Sets the source this listener is listening to
 void signal(java.lang.Object target, int theSignal)
          Sends a signal to a target.
 void subscribeChannel(IChannel channel)
          Subscribes the listener to a IChannel.
 void subscribeSource(IChannel channel, ISource source)
          Subscribe the listener to a specific Source in a Channel.
 java.lang.String toString()
          Helper to identify objects better.
 
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
finalize, getClass, 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_Identifying_Name

protected java.lang.String m_Identifying_Name

m_channel

protected IChannel m_channel
The Channel its listening on

m_source

protected ISource m_source
The Source its listening to

m_byte

protected byte[] m_byte
The internal byte[]

m_stats

protected SimpleStatistics m_stats
Statistics and Misc informations

m_cache

protected java.util.List m_cache
Internal cache as vector

m_controller

protected static ListenerController m_controller
My controller
Constructor Detail

AbstractListenerThread

public AbstractListenerThread()
Creates new AbstractListenerThread
Method Detail

setIdentifyingName

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

getIdentifyingName

public final java.lang.String getIdentifyingName()
Returns the unique name for the Source
Specified by:
getIdentifyingName in interface IListener
Returns:
The unique name.

setChannel

public final void setChannel(IChannel channel)
                      throws ListenerException
Sets the channel of this Source
Specified by:
setChannel in interface IListener
Parameters:
channel - The IChannel object.

getChannel

public final IChannel getChannel()
Returns the channel of this source
Specified by:
getChannel in interface IListener
Returns:
IChannel The current channel.

setSource

public final void setSource(ISource aSource)
                     throws ListenerException
Sets the source this listener is listening to
Specified by:
setSource in interface IListener
Parameters:
aSource - The ISource object.

getSource

public final ISource getSource()
Returns the source this listener is listening to
Specified by:
getSource in interface IListener
Returns:
The ISource

subscribeChannel

public final void subscribeChannel(IChannel channel)
                            throws ChannelException
Subscribes the listener to a IChannel.
Specified by:
subscribeChannel in interface IListener
Parameters:
channel - The target IChannel to subscribe to.

subscribeSource

public final void subscribeSource(IChannel channel,
                                  ISource source)
                           throws ChannelException,
                                  ListenerException
Subscribe the listener to a specific Source in a Channel. This listener will then listen on the Channel but will only receive data from the subscribed source.
Specified by:
subscribeSource in interface IListener
Parameters:
channel - The channel that contains the source.
source - The source to subscribe to.

receive

public final void receive(byte[] b)
Receives a byte array of something. The byte[] is added into the internal cache. It can be read by any inheriting class.
Specified by:
receive in interface IListener
Parameters:
b - The byte to receive.

receiveSignal

public final void receiveSignal(java.lang.Object source,
                                int param)
Receives a Signal from a source.
Specified by:
receiveSignal in interface ISignal
Parameters:
source - The object sending the signal.
param - The Signal.

signal

public final void signal(java.lang.Object target,
                         int theSignal)
Sends a signal to a target.
Specified by:
signal in interface ISignal
Parameters:
target - The object to receive the signal.
theSignal - The signal to send to the target.

equals

public final boolean equals(java.lang.Object obj)
Evaluates equality using the IdentifyingName method.
Overrides:
equals in class java.lang.Object
Parameters:
obj - The object to compare with
Returns:
True if objects are equal.

hashCode

public int hashCode()
Standard hashCode from Object.
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Helper to identify objects better. Makes the logmessages a lot more readable.
Overrides:
toString in class java.lang.Object
Returns:
The description of the listener thread.

configure

public void configure(org.apache.avalon.framework.configuration.Configuration configuration)
               throws org.apache.avalon.framework.configuration.ConfigurationException
Configures the Listenerthread with the configuration object.
Specified by:
configure in interface org.apache.avalon.framework.configuration.Configurable
Parameters:
configuration - A valid configuration object.
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - Error during configuration.

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Overrides:
clone in class java.lang.Object