KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jalisto > test > core > single > MultiUsersTestReadDatas


1 /*
2  * Jalisto - JAva LIght STOrage
3  * Copyright (C) 2000-2005 Xcalia http://www.xcalia.com
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.1 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  * Xcalia
20  * 71, rue Desnouettes
21  * 75014 Paris - France
22  * http://www.xcalia.com
23  */

24 package org.objectweb.jalisto.test.core.single;
25
26 import org.objectweb.jalisto.se.JalistoFactory;
27 import org.objectweb.jalisto.se.api.Session;
28 import org.objectweb.jalisto.se.api.Transaction;
29 import org.objectweb.jalisto.se.test.data.Book;
30 import org.objectweb.jalisto.se.test.threads.BookClientBasic;
31
32 import java.util.ArrayList JavaDoc;
33 import java.util.Collections JavaDoc;
34 import java.util.List JavaDoc;
35
36 public class MultiUsersTestReadDatas {
37     public static void main(String JavaDoc[] args) {
38         String JavaDoc jalistoPropertiesFilename = args[0];
39         boolean sameDatas = args[1].equalsIgnoreCase("same");
40         int nbrClient = Integer.parseInt(args[2]);
41         int nbrBook = Integer.parseInt(args[3]);
42         int nbrAction = Integer.parseInt(args[4]);
43         int nbrIteration = Integer.parseInt(args[5]);
44
45         ArrayList JavaDoc threads = new ArrayList JavaDoc();
46         List JavaDoc oids = null;
47         if (sameDatas) {
48             oids = populate(jalistoPropertiesFilename, nbrBook);
49             oids = Collections.synchronizedList(oids);
50         }
51
52         for (int i = 0; i < nbrClient; i++) {
53             BookClientBasic c = new BookClientBasic(jalistoPropertiesFilename, i, nbrBook, nbrAction, nbrIteration);
54             threads.add(c);
55             c.define(true);
56             if (sameDatas) {
57 // c.setWithExtent(true);
58
c.setNbrCreate(5);
59                 c.setNbrUpdate(5);
60                 c.setNbrDelete(5);
61 // c.setNbrDelete(0);
62
c.setOids(oids);
63             } else {
64                 c.setNbrCreate(nbrAction);
65                 c.setNbrUpdate(nbrAction);
66                 c.setNbrDelete(nbrAction);
67                 c.define(true);
68                 c.populate();
69             }
70         }
71
72         try {
73             for (int i = 0; i < nbrClient; i++) {
74                 ((BookClientBasic) threads.get(i)).start();
75                 Thread.sleep(500);
76             }
77         } catch (Exception JavaDoc e) {
78             e.printStackTrace();
79         }
80     }
81
82     public static List JavaDoc populate(String JavaDoc jalistoPropertiesFilename, int nbrBook) {
83         Session session = JalistoFactory.getSession(jalistoPropertiesFilename);
84         session.openSession();
85         Transaction tx = session.currentTransaction();
86         session.defineClass(Book.getMetaDescription());
87         List JavaDoc oids = new ArrayList JavaDoc();
88         tx.begin();
89         for (int i = 0; i < nbrBook; i++) {
90             oids.add(session.createObject(Book.newBook().toArray(), Book.class));
91         }
92         tx.commit();
93         session.closeSession();
94         return oids;
95     }
96 }
97
Popular Tags