Package avrora.sim

Examples of avrora.sim.SimulatorThread


                sdi.instantiate(platform);
            }
        }

        private void createNode() {
            thread = new SimulatorThread(this);
            super.instantiate();
            radio = (Radio)platform.getDevice("radio");
            air.addRadio(radio);
            simulator.delay(startup);
        }
View Full Code Here


         * the global timing properties of simulation.
         */
        public void start() {
            if ( node == null )
                throw Avrora.failure("No nodes in simulation");
            thread = new SimulatorThread(node);
            thread.start();
        }
View Full Code Here

     * the global timing properties of simulation.
     */
    public synchronized void start() {
        Iterator threadIterator = threadMap.keySet().iterator();
        while (threadIterator.hasNext()) {
            SimulatorThread thread = (SimulatorThread)threadIterator.next();
            thread.start();
        }
    }
View Full Code Here

     * being called, or terminating normally such as through a timeout.
     */
    public void join() throws java.lang.InterruptedException {
        Iterator threadIterator = threadMap.keySet().iterator();
        while (threadIterator.hasNext()) {
            SimulatorThread thread = (SimulatorThread)threadIterator.next();
            thread.join();
        }
    }
View Full Code Here

     * not guaranteed to stop all the simulation threads at the same global time.
     */
    public synchronized void stop() {
        Iterator threadIterator = threadMap.keySet().iterator();
        while (threadIterator.hasNext()) {
            SimulatorThread thread = (SimulatorThread)threadIterator.next();
            thread.getSimulator().stop();
        }
    }
View Full Code Here

     * called.
     * @param t the simulator representing the node to add to this group
     */
    public synchronized void addNode(Simulation.Node t) {
        // if we already have this thread, do nothing
        SimulatorThread st = t.getThread();
        if (threadMap.containsKey(st)) return;

        st.setSynchronizer(this);

        // create a new synchronization event for this thread's queue
        SynchEvent event = new SynchEvent(st);
        threadMap.put(st, event);
        // insert the synch event in the thread's queue
View Full Code Here

     * threads catch up in global time.
     */
    public void waitForNeighbors(long time) {

        // get the current simulator thread
        SimulatorThread thread = (SimulatorThread)Thread.currentThread();
        SynchEvent event = (SynchEvent)threadMap.get(thread);
        // if the current thread is not in the synchronizer, do nothing
        if ( event == null ) return;

        WaitSlot w;
View Full Code Here

        sdi.instantiate(platform);
      }
    }

    private void createNode() {
      thread = new SimulatorThread(this);
      super.instantiate();
      simulator.delay(startup);
    }
View Full Code Here

   @param node the node to add to the list
   */
  public synchronized void addNode(Simulation.Node node) {
    Utils.debugMsg("Fuege Node "+node.hashCode()+" hinzu", this);

    SimulatorThread st = node.getThread();
    timing.addThread(st);
    num_threads++;
   
    // Wenn der Thread schon in der threadMap enthalten ist, abbrechen
    // Urspruengliche Version macht einfach ein return, aber falls
    // versucht wird, einen Knoten mehrfach einzufuegen, liegt ein
    // Fehler vor, der beseitigt werden sollte.
    if (threadMap.containsKey(st)) {
      System.err.println("Versuch, Objekt doppelt in die Thread-Liste einzufuegen");
      System.exit(1);
      return;
    } // if
   
    st.setSynchronizer(this); // thread should be synchronized by this instance
   
    SyncEvent event = new SyncEvent(st);
    threadMap.put(st, event);
    simMap.put(st.getSimulator(), st);
   
    nodeMap.put(new Integer(node.hashCode()), node);
   
    event.clock.insertEvent(event, START_PERIOD); // insert the sync event in the thread's queue
  } // addNode
View Full Code Here

   *
   *  @param node the node to remove from the list
   */
  public synchronized void removeNode(Simulation.Node node) {
    Utils.debugMsg("removeNode()", this);
    SimulatorThread st = node.getThread();
    timing.removeThread(st);
    num_threads--;
    Utils.debugMsg("Loesche Node "+node.hashCode()+" mit Thread "+st.hashCode(), this);
   
    if (!threadMap.containsKey(st)) {
      System.err.println("Versuch, Objekt aus Liste zu loeschen, das gar nicht enthalten ist");
      System.exit(1);
      return;
    } // if
   
    threadMap.remove(st); // remove SimulatorThread from the local list
    simMap.remove(st.getSimulator());
    nodeMap.remove(new Integer(node.hashCode()));
   
    // Wenn zwischendurch ein Knoten terminiert, dann eigentlich nur, weil
    // sein Programm komplett abgearbeitet wurde. Da immer nur ein Knoten
    // gleichzeitig aktiv ist, muss es sich hier um den aktiven Knoten
    // gehandelt haben. Um Stillstand zu vermeiden, muss also ein neuer
    // Knoten als aktiv gekennzeichnet werden, der dann bei einem erneuten
    // Aufruf der fire()-Methode den naechsten Knoten abfragt. Der neu zu
    // markierende Knoten wird zufaellig ausgesucht.
    // Synchronisation hier, damit unten auf dem Monitor das notifyAll
    // aufgerufen werden kann, der neue Knoten muss ja wieder aufwachen.
    synchronized(condition) {
      if (num_threads > 0) { // are there still other threads?
        Iterator threadIterator = threadMap.keySet().iterator();
        if (threadIterator.hasNext()) { // activate random thread
          SimulatorThread thread = (SimulatorThread)threadIterator.next();
          SyncEvent event = (SyncEvent) threadMap.get(thread);
          event.activate = true;
          thread.getSimulator().insertEvent(event, 0); // fire at once
          nodeRemoved = true;
        } else {
          System.err.println("HashMap leer, obwohl Zaehler != 0");
          System.exit(1);
        }
View Full Code Here

TOP

Related Classes of avrora.sim.SimulatorThread

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.