Class 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$
    Author:
    Daniel Lazaro Cuadrado (kapokasa@kom.aau.dk)
    See Also:
    ClientThread
    Pt.AcceptedRating:
    Red (cxh)
    Pt.ProposedRating:
    Red (kapokasa)
    • Constructor Summary

      Constructors 
      Constructor Description
      ThreadSynchronizer()
      Construct a ThreadSynchronizer.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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
    • 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.