KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.Serializable JavaDoc;
26
27 import org.objectweb.clif.scenario.util.isac.engine.loadprofile.GroupExecutionWithPoolThread;
28 import org.objectweb.clif.scenario.util.isac.exception.IsacRuntimeException;
29 import org.objectweb.clif.scenario.util.isac.util.BooleanHolder;
30 import org.objectweb.util.monolog.api.BasicLevel;
31
32 /**
33  * org.objectweb.clif.scenario.util.isac.engine.IsacWithPoolEngine
34  *
35  * @author JC Meillaud
36  * @author A Peyrard
37  */

38 public class IsacWithPoolEngine extends IsacScenarioEngine {
39     // attributes
40
private Object JavaDoc suspendLock = new Object JavaDoc();
41
42     private Object JavaDoc componentLock = new Object JavaDoc();
43
44     private Object JavaDoc timerLock = new Object JavaDoc();
45
46     private Object JavaDoc surplusLock = new Object JavaDoc();
47
48     private volatile BooleanHolder started = new BooleanHolder(false);
49
50     private volatile BooleanHolder suspended = new BooleanHolder(false);
51
52     private volatile BooleanHolder stopped = new BooleanHolder(false);
53
54     private GroupExecutionWithPoolThread groupExecutionWithPoolThread;
55
56     /**
57      * Empty constructor
58      */

59     public IsacWithPoolEngine() {
60     }
61
62     /**
63      * Override the init method in order to create the groupexecution and the
64      * pool.
65      *
66      * @see org.objectweb.clif.server.api.ActivityControl#init(java.io.Serializable)
67      */

68     public void init(Serializable JavaDoc arg) {
69         super.init(arg);
70         // if we do a previous execution, this variale may be still true
71
this.stopped.setBooleanValue(false);
72         this.suspended.setBooleanValue(false);
73         // init the group execution thread
74
this.groupExecutionWithPoolThread = new GroupExecutionWithPoolThread(
75                 scenarioId,
76                 super.groupDescriptionManager, super.behaviorManager,
77                 super.sessionObjectManager, suspendLock, timerLock,
78                 componentLock, surplusLock, super.dataCollectorWrite,
79                 super.dataCollectorWrite_lock, super.bladeInsertResponse,
80                 super.bladeInsertResponse_lock, this.stopped, this.suspended);
81     }
82
83     /**
84      * @see org.objectweb.clif.server.api.ActivityControl#join()
85      */

86     public void join() {
87     }
88
89     /**
90      * @see org.objectweb.clif.server.api.ActivityControl#resume()
91      */

92     public void resume() {
93         suspended.setBooleanValue(false);
94         synchronized (this.suspendLock) {
95             suspendLock.notifyAll();
96         }
97         // wait the local resume mode of the group execution,
98
// resume mode is when suspended mode is false
99
// this state means that
100
// all the threads have been put in suspended mode
101
synchronized (this.componentLock) {
102             while (this.groupExecutionWithPoolThread.isLocalSuspended()) {
103                 try {
104                     this.componentLock.wait();
105                 } catch (InterruptedException JavaDoc ex) {
106                     throw new IsacRuntimeException(
107                             "Unable to wait the resumed mode of the group execution thread -> "
108                                     + ex.toString());
109                 }
110             }
111         }
112     }
113
114     /**
115      * @see org.objectweb.clif.server.api.ActivityControl#start()
116      */

117     public void start() {
118         super.log.log(BasicLevel.INFO, "Isac start !!!");
119         this.started.setBooleanValue(true);
120
121         // start the group execution thread
122
this.groupExecutionWithPoolThread.start();
123     }
124
125     /**
126      * @see org.objectweb.clif.server.api.ActivityControl#stop()
127      */

128     public void stop() {
129         // switch to stopped mode
130
stopped.setBooleanValue(true);
131
132         // if we was in suspended mode resume the activities
133
if (suspended.getBooleanValue()) {
134             resume();
135         }
136
137         // wait the stop of all thread
138
synchronized (this.componentLock) {
139             while (!this.groupExecutionWithPoolThread.isLocalStopped()) {
140                 try {
141                     this.componentLock.wait();
142                 } catch (InterruptedException JavaDoc ex) {
143                     throw new IsacRuntimeException(
144                             "Unable to wait the stopped mode of the group execution thread -> "
145                                     + ex.toString());
146                 }
147             }
148         }
149     }
150
151     /**
152      * @see org.objectweb.clif.server.api.ActivityControl#suspend()
153      */

154     public void suspend() {
155         suspended.setBooleanValue(true);
156
157         // wait the local suspend mode of the group execution, this state means
158
// that
159
// all the threads have been put in suspended mode
160
synchronized (this.componentLock) {
161             synchronized (this.surplusLock) {
162                 // notify the group of our change
163
this.surplusLock.notify();
164             }
165             while (!this.groupExecutionWithPoolThread.isLocalSuspended()) {
166                 try {
167                     super.log
168                             .log(BasicLevel.INFO,
169                                     "WAIT EVERY BODY SUSPENDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD");
170                     this.componentLock.wait();
171                 } catch (InterruptedException JavaDoc ex) {
172                     throw new IsacRuntimeException(
173                             "Unable to wait the suspended mode of the group execution thread -> "
174                                     + ex.toString());
175                 }
176             }
177         }
178     }
179 }
Popular Tags