KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jalisto > se > test > threads > BookClientThread


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.se.test.threads;
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
31 import java.util.ArrayList JavaDoc;
32 import java.util.Iterator JavaDoc;
33 import java.util.List JavaDoc;
34
35 public abstract class BookClientThread extends Thread JavaDoc {
36
37     public BookClientThread(String JavaDoc jalistoPropertiesFilename, int numClient,
38                             int nbrBook, int nbrAction, int nbrIteration) {
39         this.jalistoPropertiesFilename = jalistoPropertiesFilename;
40         this.nbrBook = nbrBook;
41         this.numClient = numClient;
42         this.nbrCreate = nbrAction;
43         this.nbrRead = nbrAction;
44         this.nbrUpdate = nbrAction;
45         this.nbrDelete = nbrAction;
46         this.nbrIteration = nbrIteration;
47         this.continueWorking = true;
48         this.withExtent = false;
49         oids = new ArrayList JavaDoc();
50     }
51
52     public void define(boolean withDefineClass) {
53         System.out.println("JalistoClientThread " + numClient + " : define");
54         session = JalistoFactory.getSession(jalistoPropertiesFilename);
55         session.openSession();
56         tx = session.currentTransaction();
57         if (withDefineClass) {
58             session.defineClass(Book.getMetaDescription());
59         }
60     }
61
62     public void cleanUp() {
63         tx.begin();
64         Iterator JavaDoc extent = session.getExtent(Book.class).readFully().iterator();
65         while (extent.hasNext()) {
66             session.deleteObjectByOid(extent.next());
67         }
68         tx.commit();
69     }
70
71     public void populate() {
72         System.out.println("JalistoClientThread " + numClient + " : populateJalisto");
73         tx.begin();
74         oids.clear();
75         if (nbrBook > 0) {
76             for (int i = 0; i < nbrBook; i++) {
77                 oids.add(session.createObject(Book.newBook().toArray(), Book.class));
78             }
79         } else {
80             oids.addAll(session.getExtent(Book.class).readFully().collection());
81         }
82         tx.commit();
83     }
84
85     public void run() {
86         try {
87             stabilityTest();
88         } catch (Exception JavaDoc e) {
89             e.printStackTrace();
90         }
91         if ((tx != null) && tx.isActive()) {
92             tx.rollback();
93         }
94         if (session != null) {
95             session.closeSession();
96         }
97     }
98
99     public void stopWorking() {
100         continueWorking = false;
101     }
102
103     public Session getSession() {
104         return session;
105     }
106
107     public abstract void stabilityTest();
108
109     /**
110      * ************************************************************************************
111      */

112
113     public List JavaDoc getOids() {
114         return oids;
115     }
116
117     public void setOids(List JavaDoc oids) {
118         this.oids = oids;
119     }
120
121     public void setWithTimer(boolean withTimer) {
122         this.withTimer = withTimer;
123     }
124
125     public void setWithRead(boolean withRead) {
126         this.withRead = withRead;
127     }
128
129     public void setNbrCreate(int nbrCreate) {
130         this.nbrCreate = nbrCreate;
131     }
132
133     public void setNbrDelete(int nbrDelete) {
134         this.nbrDelete = nbrDelete;
135     }
136
137     public void setNbrRead(int nbrRead) {
138         this.nbrRead = nbrRead;
139     }
140
141     public void setNbrUpdate(int nbrUpdate) {
142         this.nbrUpdate = nbrUpdate;
143     }
144
145     public boolean isWithExtent() {
146         return withExtent;
147     }
148
149     public void setWithExtent(boolean withExtent) {
150         this.withExtent = withExtent;
151     }
152
153
154     protected String JavaDoc jalistoPropertiesFilename;
155     protected int numClient;
156
157     protected int nbrBook;
158     protected int nbrIteration;
159     protected int nbrCreate;
160     protected int nbrRead;
161     protected int nbrUpdate;
162     protected int nbrDelete;
163     protected boolean withExtent;
164
165     protected boolean withTimer = true;
166     protected boolean withRead = false;
167
168     protected boolean continueWorking;
169
170     protected Session session;
171     protected Transaction tx;
172
173     protected List JavaDoc oids;
174 }
175
Popular Tags