|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectist.palcom.mal.AbstractMediaManager
public abstract class AbstractMediaManager
AbstractMediaManager is the central class which hides details about different media and protocols (such as UDP or IR). It is an abstract class. Concrete subclasses implement medium/protocol specifics by instantiating proper subclasses of CommunicationThread.
AbstractMediaManager handles two kinds of communication: unicast and broadcast (in the case of UDP, "broadcast" means multicast). Subclasses implement the method isBroadcast, which determines whether an address is unicast or broadcast.
Communication between this class and the CommunicationThreads that do the actual sending and receiving of messages is done through events. For a message to be sent, the AbstractMediaManager posts a MessageArrayWithURLEvent in the CommunicationThread's mailbox (putEvent). The MessageArrayWithURLEvent contains the message and the URL to send it to. When a message is received, the CommunicationThread posts a MessageArrayWithURLEvent in the mailbox of the AbstractMediaManager's DistributorThread (the AbstractMediaManager is not itself a thread). The URL in the MessageArrayWithURLEvent now contains the URL of the device which the message was received from.. The DistributorThread handles the distribution of the message to interested receivers.
The public methods of this class are used by clients. The protected abstract methods are implemented by subclasses for supporting a particular combination of protocols/media.
CommunicationThread,
UDPMediaManager| Nested Class Summary | |
|---|---|
class |
AbstractMediaManager.DistributorThread
Thread for receiving MessageArrayWithURLEvents and distributing them to interested listeners. |
| Field Summary | |
|---|---|
protected AbstractMediaManager.DistributorThread |
distributorThread
|
static java.lang.String |
PALCOM_URL_PREFIX
|
protected PalcomScheduler |
scheduler
|
protected static int |
TIMEOUTS_BEFORE_REMOVAL
The number of times a heartBeat (device) can time out before it is removed (during normal, periodic updating - after initiateDiscovery, heartBeat (devices) are removed after the first timeout) |
static java.lang.String |
WIRE_PROTOCOL_VERSION
|
| Constructor Summary | |
|---|---|
AbstractMediaManager(PalcomScheduler scheduler,
PalcomThread errorHandler)
Default AbstractMediaManager constructor. |
|
| Method Summary | |
|---|---|
void |
addErrorHandler(PalcomThread handler)
Subscribe to error events from this media manager. |
abstract URL[] |
getDefaultGroupAddresses()
|
abstract URL |
getDefaultUnicastURL()
Returns the URL that the manager listens for messages at by default. |
PalcomPriorityThread |
getDistributorThread()
|
static java.lang.String |
getHost(URL url)
|
java.lang.String |
getLocalDeviceCache()
|
java.lang.String |
getLocalDeviceID()
|
static int |
getPort(URL url)
|
static java.lang.String |
getProtocol(URL url)
|
static URL |
getProtocolSpecificUrl(URL url)
|
protected abstract CommunicationThread |
getReceivingThread(URL url)
|
java.util.ArrayList |
getRegisteredDevices()
Get all devices registered at this media manager except itself. |
static Selector |
getSelector(URL url)
|
abstract int |
getSendBufferSize()
|
protected abstract CommunicationThread |
getSendingThread(URL url)
|
protected abstract boolean |
isBroadcast(URL url)
|
boolean |
isDeviceRegistered(java.lang.String deviceID)
Checks if the device with ID deviceID is known to the media manager. |
protected void |
messageReceived(Message message)
This method is called every time a message is received. |
protected void |
raiseErrorEvent(MALErrorEvent mee)
When unhandled errors occur, concrete implementations of this class should call this method for notifying error handlers about the events. |
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. |
protected abstract void |
removeReceivingThread(URL url)
Stop receiving at url, and remove the receiving thread. |
boolean |
send(Message message,
java.lang.String receiverDeviceID)
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,
LinkedList messageHeaderNodes)
Send out a broadcast HeartBeat message. |
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. |
abstract 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 |
|---|
public static final java.lang.String PALCOM_URL_PREFIX
protected static int TIMEOUTS_BEFORE_REMOVAL
protected final PalcomScheduler scheduler
protected AbstractMediaManager.DistributorThread distributorThread
public static final java.lang.String WIRE_PROTOCOL_VERSION
| Constructor Detail |
|---|
public AbstractMediaManager(PalcomScheduler scheduler,
PalcomThread errorHandler)
| Method Detail |
|---|
public void registerAsListener(PalcomThread listener)
registerAsListener in interface MediaManagerlistener - The PalcomThread that are
interested in messages from the media manager.public void registerForHeartBeats(PalcomThread listener)
registerForHeartBeats in interface MediaManagerpublic void setPeriod(long period)
setPeriod in interface MediaManagerpublic PalcomPriorityThread getDistributorThread()
getDistributorThread in interface MediaManagerpublic abstract void suggestSendBufferSize(int size)
suggestSendBufferSize in interface MediaManagerpublic abstract int getSendBufferSize()
getSendBufferSize in interface MediaManagerpublic void setLocalDeviceCache(java.lang.String deviceCache)
setLocalDeviceCache in interface MediaManagerpublic java.lang.String getLocalDeviceCache()
getLocalDeviceCache in interface MediaManagerpublic java.lang.String getLocalDeviceID()
getLocalDeviceID in interface MediaManagerpublic void setLocalDeviceID(java.lang.String deviceID)
setLocalDeviceID in interface MediaManagerpublic void setLocalStatusFlag(byte statusFlag)
setLocalStatusFlag in interface MediaManagerpublic void setLocalDiscoveryVersion(java.lang.String discoveryVersion)
setLocalDiscoveryVersion in interface MediaManagerpublic void setDiscoverySelector(Selector selector)
setDiscoverySelector in interface MediaManager
public void sendHeartBeat(boolean isHeartBeatAck,
LinkedList messageHeaderNodes)
sendHeartBeat in interface MediaManagerisHeartBeatAck - 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.public void sendHeartAttack()
sendHeartAttack in interface MediaManagerpublic void stop()
stop in interface MediaManagerpublic void addErrorHandler(PalcomThread handler)
MALErrorEvent events.
Notice: Currently, only one error handler at a time is supported
addErrorHandler in interface MediaManager
public boolean send(Message message,
java.lang.String receiverDeviceID)
send in interface MediaManagermessage - The message to send.receiverDeviceID - The deviceID of the receiver.
public void sendBroadcast(Message message)
sendBroadcast in interface MediaManager
public void registerDevice(java.lang.String deviceID,
DeviceCacheObject device)
registerDevice in interface MediaManagerpublic boolean unRegisterDevice(java.lang.String deviceID)
unRegisterDevice in interface MediaManagerdeviceID - The ID of the device to be removed.
public java.util.ArrayList getRegisteredDevices()
getRegisteredDevices in interface MediaManagerpublic boolean isDeviceRegistered(java.lang.String deviceID)
isDeviceRegistered in interface MediaManagerdeviceID - must contain deviceID but nothing more.
public abstract URL getDefaultUnicastURL()
protected abstract CommunicationThread getReceivingThread(URL url)
protected abstract void removeReceivingThread(URL url)
protected abstract CommunicationThread getSendingThread(URL url)
protected abstract boolean isBroadcast(URL url)
protected void messageReceived(Message message)
public abstract URL[] getDefaultGroupAddresses()
protected void raiseErrorEvent(MALErrorEvent mee)
public static java.lang.String getProtocol(URL url)
public static java.lang.String getHost(URL url)
public static int getPort(URL url)
public static URL getProtocolSpecificUrl(URL url)
public static Selector getSelector(URL url)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||