KickJava   Java API By Example, From Geeks To Geeks.

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


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.exception.JalistoException;
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
34 public class ReadOnlyMultiUsersTest {
35     public static void main(String JavaDoc[] args) {
36         String JavaDoc jalistoPropertiesFilename = args[0];
37         String JavaDoc jalistoPropertiesFilenamePre = args[1];
38         int nbrInstance = Integer.parseInt(args[2]);
39         int nbrClient = Integer.parseInt(args[3]);
40         int nbrRead = Integer.parseInt(args[4]);
41         int nbrIteration = Integer.parseInt(args[5]);
42
43         ArrayList JavaDoc threads = new ArrayList JavaDoc();
44         ArrayList JavaDoc oids = new ArrayList JavaDoc();
45
46         System.out.println("ReadOnlyMultiUsersTest : use " + jalistoPropertiesFilename);
47
48         System.out.println("get extent...");
49         Session session = getSession(jalistoPropertiesFilename, jalistoPropertiesFilenamePre, nbrInstance);
50         session.currentTransaction().begin();
51         oids.addAll(session.getExtent(Book.class).readFully().collection());
52         session.currentTransaction().commit();
53
54         System.out.println("reduce oids collection size to " + nbrInstance + " books...");
55         if (oids.size() > nbrInstance) {
56             ArrayList JavaDoc tmp = new ArrayList JavaDoc();
57             while (tmp.size() < nbrInstance) {
58                 tmp.add(oids.remove(0));
59             }
60             oids = tmp;
61             System.gc();
62             System.runFinalization();
63             System.gc();
64         }
65
66         System.out.println("test : " + nbrRead + " for each of the " + nbrIteration + " iteration");
67
68         System.out.println("create " + nbrClient + " clients...");
69         for (int i = 0; i < nbrClient; i++) {
70             BookClientBasic c = new BookClientBasic(
71                     jalistoPropertiesFilename, i, -1, nbrRead, nbrIteration);
72             c.setNbrCreate(-1);
73             c.setNbrDelete(-1);
74             c.setNbrUpdate(-1);
75             threads.add(c);
76             c.define(false);
77             c.setOids(oids);
78         }
79
80         System.out.println("start clients...");
81         try {
82             for (int i = 0; i < nbrClient; i++) {
83                 ((BookClientBasic) threads.get(i)).start();
84             }
85         } catch (Exception JavaDoc e) {
86             e.printStackTrace();
87         }
88     }
89
90
91     private static Session getSession(String JavaDoc propFileName, String JavaDoc propFileNamePre, int nbrInstance) {
92         try {
93             return JalistoFactory.getSession(propFileName);
94         } catch (JalistoException jalistoExc) {
95             System.out.println("need to create datas...");
96             Session prepareSession = JalistoFactory.getSession(propFileNamePre);
97             prepareSession.defineClass(Book.getMetaDescription());
98             prepareSession.currentTransaction().begin();
99             for (int i = 0; i < nbrInstance; i++) {
100                 prepareSession.createObject(Book.newBook().toArray(), Book.class);
101             }
102             prepareSession.currentTransaction().commit();
103             System.out.println("datas created !");
104             return JalistoFactory.getSession(propFileName);
105         }
106     }
107 }
108
Popular Tags