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.cdsim;
21 import peersim.core.CommonState;
25 * This is the common state of a cycle driven simulation that all objects see.
26 * It contains additional information, specific to the cycle driven model,
27 * in addition to the info in {@link peersim.core.CommonState}.
29 public class CDState extends CommonState {
32 // ======================= fields ==================================
33 // =================================================================
36 * Current time within the current cycle.
37 * Note that {@link #cycle} gives the cycle id to which this value is relative.
39 private static int ctime = -1;
42 * Current cycle in the simulation. It makes sense only in the case of a
43 * cycle based simulator, that is, cycle based simulators will maintain this
44 * value, others will not. It still makes sense to keep it separate from
45 * {@link #time} because it is an int, while time is a long.
47 private static int cycle = -1;
50 // ======================== initialization =========================
51 // =================================================================
56 /** to avoid construction */
59 // ======================= methods =================================
60 // =================================================================
64 * Returns true if and only if there is a cycle driven simulation going on.
66 public static boolean isCD() { return cycle >= 0; }
68 //-----------------------------------------------------------------
71 * Returns the current cycle.
72 * Note that {@link #getTime()} returns the same value.
73 * @throws UnsupportedOperationException if no cycle-driven state is available
75 public static int getCycle()
77 if( cycle >= 0 ) return cycle;
78 else throw new UnsupportedOperationException(
79 "Cycle driven state accessed when "+
80 "no cycle state information is available.");
83 //-----------------------------------------------------------------
86 * Sets current cycle. Resets also cycle time to 0. It also calls
87 * {@link #setTime(long)} with the given parameter, to make sure
88 * {@link #getTime()} is indeed independent of the simulation model.
90 public static void setCycle(int t)
97 //-----------------------------------------------------------------
100 * Returns current cycle as an Integer object.
101 * @throws UnsupportedOperationException if no cycle-driven state is available
103 public static Integer getCycleObj()
105 if( cycle >= 0 ) return Integer.valueOf(cycle);
106 else throw new UnsupportedOperationException(
107 "Cycle driven state accessed when "+
108 "no cycle state information is available.");
111 //-----------------------------------------------------------------
114 * Returns the current time within the current cycle.
115 * Note that the time returned by {@link #getCycle} is the cycle id
116 * in this case. In other words, it returns the number of nodes that have
117 * already been visited in a given cycle.
118 * @throws UnsupportedOperationException if no cycle-driven state is available
120 public static int getCycleT()
122 if( ctime >= 0 ) return ctime;
123 else throw new UnsupportedOperationException(
124 "Cycle driven state accessed when "+
125 "no cycle state information is available.");
128 // -----------------------------------------------------------------
130 public static void setCycleT(int t)