All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.jbotsim.core.Scheduler Maven / Gradle / Ivy

There is a newer version: 1.2.0
Show newest version
/*
 * Copyright 2008 - 2019, Arnaud Casteigts and the JBotSim contributors 
 *
 *
 * This file is part of JBotSim.
 *
 * JBotSim is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * JBotSim is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with JBotSim.  If not, see .
 *
 */
package io.jbotsim.core;

import io.jbotsim.core.event.ClockListener;

import java.util.List;

/**
 * 

The {@link Scheduler} defines JBotSim's scheduler.

* *

On each clock, it performs the following:

*
    *
  1. performs messages processing (via {@link MessageEngine#onClock()}
  2. *
  3. performs onPreClock on each {@link Node} (via {@link Node#onPreClock()}
  4. *
  5. performs onPreClock on each {@link Node} (via {@link Node#onPreClock()}
  6. *
  7. performs onClock on each {@link Node} (via {@link Node#onClock()}
  8. *
  9. performs onPostClock on each {@link Node} (via {@link Node#onPostClock()}
  10. *
  11. performs onClock on the {@link Topology} (via {@link Topology#onClock()}
  12. *
  13. performs remaining listeners work (via {@link ClockListener#onClock()}
  14. *
*/ public class Scheduler { /** * Performs the regular scheduling operations. * * @param tp a {@link Topology} object on which the scheduling must take place * @param expiredListeners a list of {@link ClockListener} that are to be informed */ public void onClock(Topology tp, List expiredListeners) { // Delivers messages first tp.getMessageEngine().onClock(); // Then give the hand to the nodes for (Node node : tp.getNodes()) node.onPreClock(); for (Node node : tp.getNodes()) node.onClock(); for (Node node : tp.getNodes()) node.onPostClock(); // Then to the topology itself tp.onClock(); // And finally the other listeners for (ClockListener cl : expiredListeners) cl.onClock(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy