ptolemy.distributed.client
Class ThreadSynchronizer

java.lang.Object
  extended by ptolemy.distributed.client.ThreadSynchronizer

public class ThreadSynchronizer
extends java.lang.Object

Synchronizes the access to the commandsMap. In order to allow parallel execution of commands, the ClientThreads that manage remote actors locally in the DistributedSDFDirector have to be able to access the commands without blocking the main execution Thread in a synchronized manner. Commands are represented by integers. It provides mechanisms to issue sets of commands and synchronize the access to those commands by the client Threads. It is assumed that no new set of commands is issued before the previous set of commands has been processed. Every ClientThread is responsible to set itself as ready after performing a command.

Since:
Ptolemy II 5.1
Version:
$Id: ThreadSynchronizer.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Daniel Lazaro Cuadrado (kapokasa@kom.aau.dk)
See Also:
ClientThread
Accepted Rating:
Red (cxh)
Proposed Rating:
Red (kapokasa)

Field Summary
private  java.util.HashMap commandsMap
          The Map containing the commands to be executed.
private  java.util.HashMap notReadyMap
          The Map containing the Threads that are not ready.
private  boolean VERBOSE
          It states whether debugging messages should be printed.
 
Constructor Summary
ThreadSynchronizer()
          Construct a ThreadSynchronizer.
 
Method Summary
 void commandsProcessed()
          Waits until readyMap is empty.
 int getCommand(java.lang.Object key)
          Synchronizes access to the commands by the ClientThreads.
 void setCommands(java.util.HashMap commands)
          Issues a new set of commands.
 void setReady(java.lang.Object key)
          Removes a given key from the readyMap.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERBOSE

private boolean VERBOSE
It states whether debugging messages should be printed.


commandsMap

private java.util.HashMap commandsMap
The Map containing the commands to be executed.


notReadyMap

private java.util.HashMap notReadyMap
The Map containing the Threads that are not ready.

Constructor Detail

ThreadSynchronizer

public ThreadSynchronizer()
Construct a ThreadSynchronizer.

Method Detail

commandsProcessed

public void commandsProcessed()
Waits until readyMap is empty.


getCommand

public int getCommand(java.lang.Object key)
Synchronizes access to the commands by the ClientThreads. They will block waiting for commands to be issued. Every time a command is fetched, it is removed from the commandsMap and all the waiting threads are notified.

Parameters:
key - An object that used as the key in the commands map.
Returns:
An integer representing the command.

setCommands

public void setCommands(java.util.HashMap commands)
Issues a new set of commands. All the commands are copied to readyMap that keeps track of the completed commands.No new set of commands should be issued before the previous set has been completed. When a new set of commands is issued all the waiting threads are notified.

Parameters:
commands - HashMap representing the commands.

setReady

public void setReady(java.lang.Object key)
Removes a given key from the readyMap. Wakes up all threads that are waiting on this object's monitor.

Parameters:
key - The key to be removed.