ist.palcom.rascal
Class RascalMediaManager

java.lang.Object
  extended by ist.palcom.rascal.RascalMediaManager
All Implemented Interfaces:
MediaManager

public class RascalMediaManager
extends java.lang.Object
implements MediaManager

This media manager sends and receives messages to the RASCAL agent running on the same host through a socket. The RASCAL agent takes care for the dispatching.


Nested Class Summary
 class RascalMediaManager.DistributorThread
           
 
Field Summary
protected  RascalMediaManager.DistributorThread distributorThread
          This thread is used to distribute messages to the threads registered as listeners
static java.lang.String MY_MULTICAST_ADDRESS
           
static java.lang.String MY_UNICAST_ADDRESS
           
static java.lang.String PALCOM_URL_PREFIX
           
protected  PalcomScheduler scheduler
           
 
Constructor Summary
RascalMediaManager(PalcomScheduler scheduler, PalcomThread errorHandler)
          Deprecated. Currently, this API is replaced by ist.palcom.services.communication.rascal.RascalMediaManager#RascalMediaManager(PalcomScheduler scheduler, PalcomThread errorHandler). This means that the RASCAL agent will run within the Palcom device instance.
 
Method Summary
 void addErrorHandler(PalcomThread handler)
          Subscribe to error events from this media manager.
 URL[] getDefaultGroupAddresses()
           
 int getDefaultReceiveBufferSize()
           
 URL getDefaultUnicastURL()
           
 RascalMediaManager.DistributorThread getDistributorThread()
           
 java.lang.String getLocalDeviceCache()
           
 java.lang.String getLocalDeviceID()
           
static URL getProtocolSpecificUrl(URL url)
           
protected  CommunicationThread getReceivingThread(URL url)
           
 java.util.ArrayList getRegisteredDevices()
          Get all devices registered at this media manager except itself.
 int getSendBufferSize()
           
protected  CommunicationThread getSendingThread(URL url)
           
protected  boolean isBroadcast(URL url)
           
 boolean isDeviceRegistered(java.lang.String deviceID)
          Checks if the device with ID deviceID is known to the media manager.
 void registerAsListener(PalcomThread listener)
          Registers as a listener to messages received by this manager from the network.
 void registerDevice(java.lang.String deviceID, DeviceCacheObject device)
          This method is public so it can be used by test programs, but it is usually not called from other classes.
 void registerForHeartBeats(PalcomThread listener)
          Register as a listener for heartbeats and heartattacks.
protected  void removeReceivingThread(URL url)
           
 boolean send(Message message, java.lang.String receiverURN)
          Send a message to a receiver at a given deviceID.
 void sendBroadcast(Message message)
          Send out a broadcast message, with required message header nodes inserted before.
 void sendHeartAttack()
          Send out a broadcast HeartAttack message.
 void sendHeartBeat(boolean isHeartBeatAck)
           
 void sendHeartBeat(boolean isHeartBeatAck, LinkedList messageHeaderNodes)
          Send out a broadcast HeartBeat message.
 void setDefaultReceiveBufferSize(int size)
           
 void setDiscoverySelector(Selector selector)
           
 void setLocalDeviceCache(java.lang.String deviceCache)
           
 void setLocalDeviceID(java.lang.String deviceID)
           
 void setLocalDiscoveryVersion(java.lang.String discoveryVersion)
           
 void setLocalStatusFlag(byte statusFlag)
           
 void setPeriod(long period)
          Set the time interval between heartbeats.
 void stop()
          Stop the manager.
 void suggestSendBufferSize(int size)
          Used in the same manner as setSendBufferSize.
 boolean unRegisterDevice(java.lang.String deviceID)
          This method removes a device and its information from the list with registered devices.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PALCOM_URL_PREFIX

public static final java.lang.String PALCOM_URL_PREFIX
See Also:
Constant Field Values

distributorThread

protected RascalMediaManager.DistributorThread distributorThread
This thread is used to distribute messages to the threads registered as listeners


scheduler

protected final PalcomScheduler scheduler

MY_MULTICAST_ADDRESS

public static final java.lang.String MY_MULTICAST_ADDRESS
See Also:
Constant Field Values

MY_UNICAST_ADDRESS

public static final java.lang.String MY_UNICAST_ADDRESS
See Also:
Constant Field Values
Constructor Detail

RascalMediaManager

public RascalMediaManager(PalcomScheduler scheduler,
                          PalcomThread errorHandler)
Deprecated. Currently, this API is replaced by ist.palcom.services.communication.rascal.RascalMediaManager#RascalMediaManager(PalcomScheduler scheduler, PalcomThread errorHandler). This means that the RASCAL agent will run within the Palcom device instance.

Method Detail

registerAsListener

public void registerAsListener(PalcomThread listener)
Description copied from interface: MediaManager
Registers as a listener to messages received by this manager from the network. Currently only one listener at a time is supported.

Specified by:
registerAsListener in interface MediaManager
Parameters:
listener - The PalcomThread that are interested in messages from the media manager.

registerForHeartBeats

public void registerForHeartBeats(PalcomThread listener)
Description copied from interface: MediaManager
Register as a listener for heartbeats and heartattacks.

Specified by:
registerForHeartBeats in interface MediaManager

getDistributorThread

public RascalMediaManager.DistributorThread getDistributorThread()
Specified by:
getDistributorThread in interface MediaManager

suggestSendBufferSize

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

Specified by:
suggestSendBufferSize in interface MediaManager

stop

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

Specified by:
stop in interface MediaManager

getProtocolSpecificUrl

public static URL getProtocolSpecificUrl(URL url)
Returns:
The protocol-specific part of the URL (the URL that can be used for addressing the device).

getDefaultUnicastURL

public URL getDefaultUnicastURL()

getReceivingThread

protected CommunicationThread getReceivingThread(URL url)

removeReceivingThread

protected void removeReceivingThread(URL url)

getSendingThread

protected CommunicationThread getSendingThread(URL url)

isBroadcast

protected boolean isBroadcast(URL url)

getDefaultGroupAddresses

public URL[] getDefaultGroupAddresses()

getDefaultReceiveBufferSize

public int getDefaultReceiveBufferSize()
Returns:
the default receive buffer size for UDP sockets, or zero if not set.

getSendBufferSize

public int getSendBufferSize()
Specified by:
getSendBufferSize in interface MediaManager
Returns:
the default send buffer size for UDP sockets, or zero if not set.

setDefaultReceiveBufferSize

public void setDefaultReceiveBufferSize(int size)

send

public boolean send(Message message,
                    java.lang.String receiverURN)
Description copied from interface: MediaManager
Send a message to a receiver at a given deviceID.

Specified by:
send in interface MediaManager
Parameters:
message - The message to send.
receiverURN - The deviceID of the receiver.
Returns:
True if the AbstractMediaManager knows about the device, and has sent the message.

sendBroadcast

public void sendBroadcast(Message message)
Description copied from interface: MediaManager
Send out a broadcast message, with required message header nodes inserted before.

Specified by:
sendBroadcast in interface MediaManager

addErrorHandler

public void addErrorHandler(PalcomThread handler)
Description copied from interface: MediaManager
Subscribe to error events from this media manager. Unhandled errors within the MediaManager will be send to the handler in the form of MALErrorEvent events. Notice: Currently, only one error handler at a time is supported

Specified by:
addErrorHandler in interface MediaManager

getLocalDeviceCache

public java.lang.String getLocalDeviceCache()
Specified by:
getLocalDeviceCache in interface MediaManager

getLocalDeviceID

public java.lang.String getLocalDeviceID()
Specified by:
getLocalDeviceID in interface MediaManager

isDeviceRegistered

public boolean isDeviceRegistered(java.lang.String deviceID)
Description copied from interface: MediaManager
Checks if the device with ID deviceID is known to the media manager.

Specified by:
isDeviceRegistered in interface MediaManager
Parameters:
deviceID - must contain deviceID but nothing more.
Returns:
true if device is registered

registerDevice

public void registerDevice(java.lang.String deviceID,
                           DeviceCacheObject device)
Description copied from interface: MediaManager
This method is public so it can be used by test programs, but it is usually not called from other classes.

Specified by:
registerDevice in interface MediaManager

sendHeartAttack

public void sendHeartAttack()
Description copied from interface: MediaManager
Send out a broadcast HeartAttack message. This method is used by the DiscoveryManager and tells the receiving devices that this devices is about to close down.

Specified by:
sendHeartAttack in interface MediaManager

sendHeartBeat

public void sendHeartBeat(boolean isHeartBeatAck)

setDiscoverySelector

public void setDiscoverySelector(Selector selector)
Specified by:
setDiscoverySelector in interface MediaManager

setLocalDeviceCache

public void setLocalDeviceCache(java.lang.String deviceCache)
Specified by:
setLocalDeviceCache in interface MediaManager

setLocalDeviceID

public void setLocalDeviceID(java.lang.String deviceID)
Specified by:
setLocalDeviceID in interface MediaManager

setLocalDiscoveryVersion

public void setLocalDiscoveryVersion(java.lang.String discoveryVersion)
Specified by:
setLocalDiscoveryVersion in interface MediaManager

setLocalStatusFlag

public void setLocalStatusFlag(byte statusFlag)
Specified by:
setLocalStatusFlag in interface MediaManager

unRegisterDevice

public boolean unRegisterDevice(java.lang.String deviceID)
Description copied from interface: MediaManager
This method removes a device and its information from the list with registered devices.

Specified by:
unRegisterDevice in interface MediaManager
Parameters:
deviceID - The ID of the device to be removed.
Returns:
True if the device was removed from the list.

sendHeartBeat

public void sendHeartBeat(boolean isHeartBeatAck,
                          LinkedList messageHeaderNodes)
Description copied from interface: MediaManager
Send out a broadcast HeartBeat message. This method is used by the ResourceManager. Sending HeartBeatAck messages are handled automatically by the AbstractMediaManager.

Specified by:
sendHeartBeat in interface MediaManager
Parameters:
isHeartBeatAck - is the heartBeat an ack or a request for others to answer with heartbeatAcks.
messageHeaderNodes - used when for instance a mark node should be sent with the heartBeat.

getRegisteredDevices

public java.util.ArrayList getRegisteredDevices()
Description copied from interface: MediaManager
Get all devices registered at this media manager except itself.

Specified by:
getRegisteredDevices in interface MediaManager
Returns:
ArrayList with DeviceCacheObjects

setPeriod

public void setPeriod(long period)
Description copied from interface: MediaManager
Set the time interval between heartbeats.

Specified by:
setPeriod in interface MediaManager