ist.palcom.mal
Class CompoundMediaManager

java.lang.Object
  extended by ist.palcom.mal.AbstractMediaManager
      extended by ist.palcom.mal.CompoundMediaManager
All Implemented Interfaces:
MediaManager

public class CompoundMediaManager
extends AbstractMediaManager

This class implements a media manager that can have other media managers as submanagers, handling the actual communication.

The structure is that of the Composite design pattern - a CompoundMediaManager has the same interface as "ordinary" MediaManagers, and can be used wherever a MediaManager is needed.

Submanagers are added using the add method.

See Also:
MediaManager

Nested Class Summary
 
Nested classes/interfaces inherited from class ist.palcom.mal.AbstractMediaManager
AbstractMediaManager.DistributorThread
 
Field Summary
 
Fields inherited from class ist.palcom.mal.AbstractMediaManager
distributorThread, PALCOM_URL_PREFIX, scheduler, TIMEOUTS_BEFORE_REMOVAL, WIRE_PROTOCOL_VERSION
 
Constructor Summary
CompoundMediaManager(PalcomScheduler scheduler, java.lang.String defaultProtocol, MediaManager defaultManager, PalcomThread errorHandler)
           
 
Method Summary
 void add(java.lang.String protocol, MediaManager manager)
          Add a manager handling a specific protocol, The protocol is the protocol part of the URLs, such as "datagram" for UDP or "http" for HTTP.
 void addErrorHandler(PalcomPriorityThread handler)
          Adds the error handler to all registered managers, and cached for further reference
 URL[] getDefaultGroupAddresses()
           
 URL getDefaultUnicastURL()
          Returns the URL that the manager listens for messages at by default.
protected  CommunicationThread getReceivingThread(URL url)
           
 int getSendBufferSize()
           
protected  CommunicationThread getSendingThread(URL url)
           
protected  boolean isBroadcast(URL url)
           
protected  void removeReceivingThread(URL url)
          Stop receiving at url, and remove the receiving thread.
 boolean send(Message message, java.lang.String senderDeviceID, Selector senderSelector, java.lang.String receiverDeviceID, Selector receiverSelector)
           
 void sendBroadcast(Message message, java.lang.String senderDeviceID, Selector senderSelector)
           
 void stop()
          Stop the manager.
 void suggestSendBufferSize(int size)
          Used in the same manner as setSendBufferSize.
 
Methods inherited from class ist.palcom.mal.AbstractMediaManager
addErrorHandler, getDistributorThread, getHost, getLocalDeviceCache, getLocalDeviceID, getPort, getProtocol, getProtocolSpecificUrl, getRegisteredDevices, getSelector, isDeviceRegistered, messageReceived, raiseErrorEvent, registerAsListener, registerDevice, registerForHeartBeats, send, sendBroadcast, sendHeartAttack, sendHeartBeat, setDiscoverySelector, setLocalDeviceCache, setLocalDeviceID, setLocalDiscoveryVersion, setLocalStatusFlag, setPeriod, unRegisterDevice
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompoundMediaManager

public CompoundMediaManager(PalcomScheduler scheduler,
                            java.lang.String defaultProtocol,
                            MediaManager defaultManager,
                            PalcomThread errorHandler)
Method Detail

suggestSendBufferSize

public void suggestSendBufferSize(int size)
Description copied from class: AbstractMediaManager
Used in the same manner as setSendBufferSize.

Specified by:
suggestSendBufferSize in interface MediaManager
Specified by:
suggestSendBufferSize in class AbstractMediaManager

getSendBufferSize

public int getSendBufferSize()
Specified by:
getSendBufferSize in interface MediaManager
Specified by:
getSendBufferSize in class AbstractMediaManager

send

public boolean send(Message message,
                    java.lang.String senderDeviceID,
                    Selector senderSelector,
                    java.lang.String receiverDeviceID,
                    Selector receiverSelector)

sendBroadcast

public void sendBroadcast(Message message,
                          java.lang.String senderDeviceID,
                          Selector senderSelector)

addErrorHandler

public void addErrorHandler(PalcomPriorityThread handler)
Adds the error handler to all registered managers, and cached for further reference


stop

public void stop()
Description copied from class: AbstractMediaManager
Stop the manager. This will stop all listening for messages.

Specified by:
stop in interface MediaManager
Overrides:
stop in class AbstractMediaManager

add

public void add(java.lang.String protocol,
                MediaManager manager)
Add a manager handling a specific protocol, The protocol is the protocol part of the URLs, such as "datagram" for UDP or "http" for HTTP.


getDefaultUnicastURL

public URL getDefaultUnicastURL()
Description copied from class: AbstractMediaManager
Returns the URL that the manager listens for messages at by default. This method has been made public so it can be used from test programs, but it is not otherwise used by classes other than AbstractMediaManager and its subclasses.

Specified by:
getDefaultUnicastURL in class AbstractMediaManager
Returns:
The default URL. This URL is listened on unless another URL is specified in a call to startReceiving(String, PalcomThread).

getReceivingThread

protected CommunicationThread getReceivingThread(URL url)
Specified by:
getReceivingThread in class AbstractMediaManager
Returns:
CommunicationThread for receiving at url. If it does not exist, a new one is created and returned.

removeReceivingThread

protected void removeReceivingThread(URL url)
Description copied from class: AbstractMediaManager
Stop receiving at url, and remove the receiving thread.

Specified by:
removeReceivingThread in class AbstractMediaManager

getSendingThread

protected CommunicationThread getSendingThread(URL url)
Specified by:
getSendingThread in class AbstractMediaManager
Returns:
A CommunicationThread that can be used for sending a message to the given URL.

isBroadcast

protected boolean isBroadcast(URL url)
Specified by:
isBroadcast in class AbstractMediaManager
Returns:
true if the URL is a broadcast address (or multicast, depending on the protocol), false if not.

getDefaultGroupAddresses

public URL[] getDefaultGroupAddresses()
Specified by:
getDefaultGroupAddresses in class AbstractMediaManager
Returns:
The default broadcast addresses for group communication.