2 * Copyright (c) 2003-2005 The BISON Project
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 2 as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 package peersim.edsim;
21 import peersim.core.Control;
22 import peersim.core.Scheduler;
26 * Wrapper for {@link Control}s to be executed in an event driven simulation.
28 * @author Alberto Montresor
29 * @version $Revision: 1.5 $
34 //---------------------------------------------------------------------
36 //---------------------------------------------------------------------
39 * The reference to the dynamics to be executed; null if this cycle event
40 * refers to an observer.
42 private Control control;
44 /** Order index used to maintain order between cycle-based events */
48 //---------------------------------------------------------------------
50 //---------------------------------------------------------------------
53 * Scheduler object to obtain the next schedule time of this event
55 private Scheduler scheduler;
58 * Creates a cycle event for a control object. It also schedules the object
59 * for the first execution adding it to the priority queue of the event driven
62 public ControlEvent(Control control, Scheduler scheduler, int order)
64 this.control = control;
66 this.scheduler = scheduler;
67 long next = scheduler.getNext();
68 if( next>=0 ) EDSimulator.addControlEvent(next, order, this);
71 //---------------------------------------------------------------------
73 //---------------------------------------------------------------------
76 * Executes the control object, and schedules the object for the next execution
77 * adding it to the priority queue of the event driven simulation.
79 public boolean execute() {
81 boolean ret = control.execute();
82 long next = scheduler.getNext();
83 if( next>=0 ) EDSimulator.addControlEvent(next, order, this);