KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > scenario > util > isac > engine > IsacWithoutPoolEngine


1 /*
2  * CLIF is a Load Injection Framework
3  * Copyright (C) 2004 France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * CLIF
20  *
21  * Contact: clif@objectweb.org
22  */

23 package org.objectweb.clif.scenario.util.isac.engine;
24
25 import org.objectweb.clif.scenario.util.isac.engine.loadprofile.GroupExecutionThread;
26 import org.objectweb.clif.scenario.util.isac.exception.IsacRuntimeException;
27 import org.objectweb.clif.scenario.util.isac.util.BooleanHolder;
28 import org.objectweb.util.monolog.api.BasicLevel;
29
30 /**
31  * org.objectweb.clif.scenario.util.isac.engine.IsacWithoutPoolEngine
32  *
33  * @author JC Meillaud
34  * @author A Peyrard
35  */

36 public class IsacWithoutPoolEngine extends IsacScenarioEngine {
37     // attributes
38
private Object JavaDoc scenarioLock = new Object JavaDoc();
39
40     private Object JavaDoc activitiesLock = new Object JavaDoc();
41
42     // this lock will be used by the group execution to wait during the surplus
43
// time
44
private Object JavaDoc surplusLock = new Object JavaDoc();
45
46     private volatile BooleanHolder started = new BooleanHolder(false);
47
48     private volatile BooleanHolder suspended = new BooleanHolder(false);
49
50     private volatile BooleanHolder stopped = new BooleanHolder(false);
51
52     private GroupExecutionThread groupExecutionThread;
53
54     /**
55      * Empty constructor
56      */

57     public IsacWithoutPoolEngine() {
58     }
59
60     /**
61      * @see org.objectweb.clif.server.api.ActivityControl#join()
62      */

63     public void join() {
64     }
65
66     /**
67      * @see org.objectweb.clif.server.api.ActivityControl#resume()
68      */

69     public void resume() {
70         synchronized (scenarioLock) {
71             suspended.setBooleanValue(false);
72             scenarioLock.notifyAll();
73         }
74         // wait the local resume mode of the group execution,
75
// resume mode is when suspended mode is false
76
// this state means that
77
// all the threads have been put in suspended mode
78
synchronized (this.activitiesLock) {
79             while (this.groupExecutionThread.isLocalSuspended()) {
80                 try {
81                     this.activitiesLock.wait();
82                 } catch (InterruptedException JavaDoc ex) {
83                     throw new IsacRuntimeException(
84                             "Unable to wait the resumed mode of the group execution thread",ex);
85                 }
86             }
87         }
88     }
89
90     /**
91      * @see org.objectweb.clif.server.api.ActivityControl#start()
92      */

93     public void start() {
94         super.log.log(BasicLevel.INFO, "Isac start !!!");
95         synchronized (this.scenarioLock) {
96             this.started.setBooleanValue(true);
97             // if we do a previous execution, this variale may be still true
98
this.stopped.setBooleanValue(false);
99             this.suspended.setBooleanValue(false);
100         }
101         // init the group execution thread
102
this.groupExecutionThread = new GroupExecutionThread(
103                 scenarioId,
104                 super.groupDescriptionManager, super.behaviorManager,
105                 super.sessionObjectManager, this.scenarioLock,
106                 this.activitiesLock, super.dataCollectorWrite,
107                 super.dataCollectorWrite_lock, super.bladeInsertResponse,
108                 super.bladeInsertResponse_lock, this.started, this.stopped,
109                 this.suspended, this.surplusLock);
110
111         // start the group execution thread
112
this.groupExecutionThread.start();
113     }
114
115     /**
116      * @see org.objectweb.clif.server.api.ActivityControl#stop()
117      */

118     public void stop() {
119         // switch to stopped mode
120
synchronized (this.scenarioLock) {
121             stopped.setBooleanValue(true);
122         }
123         // if we was in suspended mode resume the activities
124
if (suspended.getBooleanValue()) {
125             resume();
126         }
127         // awake the group execution thread, if it is in surplus time wait
128
synchronized (this.surplusLock) {
129             this.surplusLock.notify();
130         }
131         // wait the stop of all thread
132
synchronized (this.activitiesLock) {
133             while (!this.groupExecutionThread.isLocalStopped()) {
134                 try {
135                     this.activitiesLock.wait();
136                 } catch (InterruptedException JavaDoc ex) {
137                     throw new IsacRuntimeException(
138                             "Unable to wait the stopped mode of the group execution thread",ex);
139                 }
140             }
141         }
142     }
143
144     /**
145      * @see org.objectweb.clif.server.api.ActivityControl#suspend()
146      */

147     public void suspend() {
148         synchronized (scenarioLock) {
149             suspended.setBooleanValue(true);
150         }
151         // awake the group execution thread, if it is in surplus time wait
152
synchronized (this.surplusLock) {
153             this.surplusLock.notify();
154         }
155         // wait the local suspend mode of the group execution, this state means
156
// that
157
// all the threads have been put in suspended mode
158
synchronized (this.activitiesLock) {
159             while (!this.groupExecutionThread.isLocalSuspended()) {
160                 try {
161                     this.activitiesLock.wait();
162                 } catch (InterruptedException JavaDoc ex) {
163                     throw new IsacRuntimeException(
164                             "Unable to wait the suspended mode of the group execution thread",ex);
165                 }
166             }
167         }
168     }
169 }
Popular Tags