Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill another out of date script
[simgrid.git] / contrib / psg / src / peersim / edsim / ControlEvent.java
1 /*
2  * Copyright (c) 2003-2005 The BISON Project
3  *
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.
7  *
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.
12  *
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.
16  *
17  */
18
19 package peersim.edsim;
20
21 import peersim.core.Control;
22 import peersim.core.Scheduler;
23
24
25 /**
26  * Wrapper for {@link Control}s to be executed in an event driven simulation.
27  *
28  * @author Alberto Montresor
29  * @version $Revision: 1.5 $
30  */
31 class ControlEvent
32 {
33
34 //---------------------------------------------------------------------
35 //Fields
36 //---------------------------------------------------------------------
37
38 /** 
39  * The reference to the dynamics to be executed; null if this cycle event
40  * refers to an observer.
41  */
42 private Control control;
43
44 /** Order index used to maintain order between cycle-based events */
45 private int order;
46
47
48 //---------------------------------------------------------------------
49 //Initialization
50 //---------------------------------------------------------------------
51
52 /** 
53  * Scheduler object to obtain the next schedule time of this event 
54  */
55 private Scheduler scheduler;
56
57 /**
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
60  * simulation.
61  */
62 public ControlEvent(Control control, Scheduler scheduler, int order)
63 {
64         this.control = control;
65         this.order = order;
66         this.scheduler = scheduler;
67         long next = scheduler.getNext();
68         if( next>=0 ) EDSimulator.addControlEvent(next, order, this);
69 }
70
71 //---------------------------------------------------------------------
72 //Methods
73 //---------------------------------------------------------------------
74
75 /**
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.
78 */
79 public boolean execute() {
80
81         boolean ret = control.execute();
82         long next = scheduler.getNext();
83         if( next>=0 ) EDSimulator.addControlEvent(next, order, this);
84         return ret;
85 }
86
87 }
88
89