KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > client > test > perf > ThreadInstancesPerfTest


1 /**
2  *
3  * Bonita
4  * Copyright (C) 1999 Bull S.A.
5  * Bull 68 route de versailles 78434 Louveciennes Cedex France
6  * Further information: bonita@objectweb.org
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21  * USA
22  *
23  *
24 --------------------------------------------------------------------------
25  * $Id: ThreadInstancesPerfTest.java,v 1.1 2005/03/18 14:51:23 mvaldes Exp $
26  *
27 --------------------------------------------------------------------------
28  */

29
30 package hero.client.test.perf;
31
32 import javax.security.auth.login.LoginContext JavaDoc;
33 import hero.client.test.SimpleCallbackHandler;
34
35 import hero.interfaces.BnProject;
36 import hero.interfaces.BnProjectHome;
37 import hero.interfaces.BnProjectPK;
38 import hero.interfaces.BnProjectValue;
39 import hero.interfaces.ProjectSession;
40 import hero.interfaces.ProjectSessionHome;
41 import hero.interfaces.ProjectSessionUtil;
42 import hero.interfaces.UserSession;
43 import hero.interfaces.UserSessionHome;
44 import hero.interfaces.UserSessionUtil;
45 import hero.interfaces.UserRegistration;
46 import hero.interfaces.UserRegistrationHome;
47 import hero.interfaces.UserRegistrationUtil;
48 import junit.framework.TestCase;
49 import junit.framework.TestSuite;
50 import hero.interfaces.Constants;
51 import hero.util.BonitaServiceException;
52
53 import java.util.Collection JavaDoc;
54 import java.util.Iterator JavaDoc;
55
56 public class ThreadInstancesPerfTest extends Thread JavaDoc {
57
58      private int userNb = 0;
59      private String JavaDoc uNb = "0" ;
60      private int instNb = 10 ;
61      private int tpsRunDbtInst = 3;
62      
63      SimpleCallbackHandler handler = null;
64      LoginContext JavaDoc lc=null;
65      ProjectSessionHome pHome;
66      static int instRunEnCours = 0;
67      static int instTotales = 0;
68      static int userCrees = 0;
69      String JavaDoc uName=null;
70      
71      public ThreadInstancesPerfTest(int user, int inst, int tpsdbtinst)
72      {
73        this.userNb = user ;
74        this.uNb = String.valueOf(user) ;
75        this.instNb = inst;
76        this.tpsRunDbtInst=tpsdbtinst;
77        
78        uName = "user"+uNb;
79        char[] password=uName.toCharArray();
80         try
81         {
82         handler = new SimpleCallbackHandler(uName,password);
83         lc = new LoginContext JavaDoc("TestClient", handler);
84         lc.login();
85         pHome = ProjectSessionUtil.getHome();
86         }
87         catch (Exception JavaDoc e)
88         {
89             System.out.println("pffffffff....meme pas en reve "+e);
90         }
91      }
92
93
94      
95      public void run()
96      {
97          
98         //System.out.println("Starting really runInstance (using " + uNb +", "+instNb + ")...");
99
String JavaDoc result="";
100         long startTime = 0;
101         int instRunDebut = instRunEnCours;
102         int userCreesDbt = userCrees;
103         
104       try
105       {
106         
107
108         int i=0;
109         
110         Thread.sleep(tpsRunDbtInst * 1000);
111         startTime = System.currentTimeMillis();
112         ProjectSession ps = pHome.create();
113         instRunEnCours +=1;
114         instTotales +=1;
115         //for (i=0;i<instNb;i++) {
116
// threader CA :::::::: + timer par instance + stats instances en cours
117
ps.instantiateProject("Stress");
118             //System.out.println(" --> User: " + uName +" -- Instanciate Stress Model");
119

120         //}
121

122         ps.remove();
123         /*
124         UserSessionHome uHome = UserSessionUtil.getHome();
125         UserSession us = uHome.create();
126         Collection instances = us.getInstancesListNames();
127         Iterator index = instances.iterator();
128         UserSession usUser = uHome.create();
129         while (index.hasNext())
130         {
131             String name = (String)index.next();
132             Collection task = usUser.getToDoList(name);
133             Iterator it = task.iterator();
134             while (it.hasNext())
135             {
136               String activity = (String)it.next();
137               usUser.startActivity(name,activity);
138               System.out.println(" --> User: " + uName +" Instance: "+name+" -- Start Act: " + activity);
139               if (activity.matches(".*_instance.*"))
140                  executeSubProcess(activity);
141     
142               Thread.sleep(100);
143               usUser.terminateActivity(name,activity);
144               System.out.println(" --> User: " + uName +" -- Stop Act: " + activity);
145               task = usUser.getToDoList(name);
146               it = task.iterator();
147             }
148         }*/

149            } catch(Exception JavaDoc e){System.out.println(" --> " + e);}
150     
151         long time = System.currentTimeMillis();
152         long tmp = time - startTime; // tps en millisecondes
153
long h = tmp/3600000;
154         long m = (tmp-3600000*h)/60000;
155         long s = (tmp-3600000*h-60000*m)/1000;
156         long millis = tmp-3600000*h-60000*m-1000*s;
157         System.out.println( " --> "+ uName + " / ( "+userCreesDbt+" -> "+ userCrees +" ) " +" Stressed Model ( "+ instRunDebut+" -> "+instRunEnCours +" / " + instTotales +" ) : system time elapsed : " + h + ":"+ m + ":" + s + ":" + millis );
158         instRunEnCours -=1;
159
160      }
161
162    public static void executeSubProcess(String JavaDoc subProcess) throws Exception JavaDoc
163    {
164      UserSessionHome uHome = UserSessionUtil.getHome();
165      UserSession us = uHome.create();
166      us.startActivity(subProcess,"subNode1");
167      us.terminateActivity(subProcess,"subNode1");
168      us.startActivity(subProcess,"subNode2");
169      us.terminateActivity(subProcess,"subNode2");
170    }
171 }
172
173
174
Popular Tags